diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-05-15 00:28:13 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-15 00:28:13 -0400 |
| commit | 5bcb6ec675052ea8fe777e4ea96a960b4641edf5 (patch) | |
| tree | 4c75250a177e33b29f7104d4d68e857b14d275cd /MediaBrowser.Controller | |
| parent | fcf588ac14333442e601559eed0d0991202611a4 (diff) | |
| parent | bc865ce6987cd263c865d9eff8e789c88d435f7a (diff) | |
Merge pull request #2637 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.Controller')
| -rw-r--r-- | MediaBrowser.Controller/Drawing/IImageEncoder.cs | 11 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Drawing/ImageHelper.cs | 69 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/InternalItemsQuery.cs | 2 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Entities/PhotoAlbum.cs | 10 | ||||
| -rw-r--r-- | MediaBrowser.Controller/MediaBrowser.Controller.csproj | 1 |
5 files changed, 74 insertions, 19 deletions
diff --git a/MediaBrowser.Controller/Drawing/IImageEncoder.cs b/MediaBrowser.Controller/Drawing/IImageEncoder.cs index 830093fcf..64d997dba 100644 --- a/MediaBrowser.Controller/Drawing/IImageEncoder.cs +++ b/MediaBrowser.Controller/Drawing/IImageEncoder.cs @@ -15,18 +15,11 @@ namespace MediaBrowser.Controller.Drawing /// </summary> /// <value>The supported output formats.</value> ImageFormat[] SupportedOutputFormats { get; } + /// <summary> /// Encodes the image. /// </summary> - /// <param name="inputPath">The input path.</param> - /// <param name="outputPath">The output path.</param> - /// <param name="autoOrient">if set to <c>true</c> [automatic orient].</param> - /// <param name="width">The width.</param> - /// <param name="height">The height.</param> - /// <param name="quality">The quality.</param> - /// <param name="options">The options.</param> - /// <param name="outputFormat">The output format.</param> - void EncodeImage(string inputPath, string outputPath, bool autoOrient, int width, int height, int quality, ImageProcessingOptions options, ImageFormat outputFormat); + void EncodeImage(string inputPath, ImageSize? originalImageSize, string outputPath, bool autoOrient, int quality, ImageProcessingOptions options, ImageFormat outputFormat); /// <summary> /// Creates the image collage. diff --git a/MediaBrowser.Controller/Drawing/ImageHelper.cs b/MediaBrowser.Controller/Drawing/ImageHelper.cs new file mode 100644 index 000000000..30c4e90fb --- /dev/null +++ b/MediaBrowser.Controller/Drawing/ImageHelper.cs @@ -0,0 +1,69 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Model.Drawing; +using MediaBrowser.Model.Entities; + +namespace MediaBrowser.Controller.Drawing +{ + public static class ImageHelper + { + public static ImageSize GetNewImageSize(ImageProcessingOptions options, ImageSize? originalImageSize) + { + if (originalImageSize.HasValue) + { + // Determine the output size based on incoming parameters + var newSize = DrawingUtils.Resize(originalImageSize.Value, options.Width, options.Height, options.MaxWidth, options.MaxHeight); + + return newSize; + } + return GetSizeEstimate(options); + } + + private static ImageSize GetSizeEstimate(ImageProcessingOptions options) + { + if (options.Width.HasValue && options.Height.HasValue) + { + return new ImageSize(options.Width.Value, options.Height.Value); + } + + var aspect = GetEstimatedAspectRatio(options.Image.Type, options.Item); + + var width = options.Width ?? options.MaxWidth; + + if (width.HasValue) + { + var heightValue = width.Value / aspect; + return new ImageSize(width.Value, heightValue); + } + + var height = options.Height ?? options.MaxHeight ?? 200; + var widthValue = aspect * height; + return new ImageSize(widthValue, height); + } + + private static double GetEstimatedAspectRatio(ImageType type, IHasImages item) + { + switch (type) + { + case ImageType.Art: + case ImageType.Backdrop: + case ImageType.Chapter: + case ImageType.Screenshot: + case ImageType.Thumb: + return 1.78; + case ImageType.Banner: + return 5.4; + case ImageType.Box: + case ImageType.BoxRear: + case ImageType.Disc: + case ImageType.Menu: + return 1; + case ImageType.Logo: + return 2.58; + case ImageType.Primary: + return item.GetDefaultPrimaryImageAspectRatio() ?? .667; + default: + return 1; + } + } + } +} diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index 092461c84..3c948487d 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -251,7 +251,7 @@ namespace MediaBrowser.Controller.Entities if (policy.MaxParentalRating.HasValue) { - BlockUnratedItems = policy.BlockUnratedItems; + BlockUnratedItems = policy.BlockUnratedItems.Where(i => i != UnratedItem.Other).ToArray(); } ExcludeInheritedTags = policy.BlockedTags; diff --git a/MediaBrowser.Controller/Entities/PhotoAlbum.cs b/MediaBrowser.Controller/Entities/PhotoAlbum.cs index c902ac8cd..dd3cd98fb 100644 --- a/MediaBrowser.Controller/Entities/PhotoAlbum.cs +++ b/MediaBrowser.Controller/Entities/PhotoAlbum.cs @@ -1,7 +1,4 @@ -using MediaBrowser.Model.Configuration; -using MediaBrowser.Model.Users; -using System.Linq; -using MediaBrowser.Model.Serialization; +using MediaBrowser.Model.Serialization; namespace MediaBrowser.Controller.Entities { @@ -24,10 +21,5 @@ namespace MediaBrowser.Controller.Entities return false; } } - - protected override bool GetBlockUnratedValue(UserPolicy config) - { - return config.BlockUnratedItems.Contains(UnratedItem.Other); - } } } diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 38cff6d67..b3a29bafa 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -91,6 +91,7 @@ <Compile Include="Drawing\IImageEncoder.cs" /> <Compile Include="Drawing\IImageProcessor.cs" /> <Compile Include="Drawing\ImageCollageOptions.cs" /> + <Compile Include="Drawing\ImageHelper.cs" /> <Compile Include="Drawing\ImageProcessingOptions.cs" /> <Compile Include="Drawing\ImageProcessorExtensions.cs" /> <Compile Include="Drawing\ImageStream.cs" /> |
