aboutsummaryrefslogtreecommitdiff
path: root/Emby.Drawing/ImageProcessor.cs
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2017-05-15 00:34:33 -0400
committerGitHub <noreply@github.com>2017-05-15 00:34:33 -0400
commita4efcf07f42d1ccd2be0c2f4d2af1208366f6ab6 (patch)
treec4d0a9693850b977b66c057508b286ed50da9a3c /Emby.Drawing/ImageProcessor.cs
parente2085763296e32e7ef1532460030e5449725116a (diff)
parent4a8aa20698aa761cba7ab7e45181a2b3251fca64 (diff)
Merge pull request #2639 from MediaBrowser/beta
Beta
Diffstat (limited to 'Emby.Drawing/ImageProcessor.cs')
-rw-r--r--Emby.Drawing/ImageProcessor.cs92
1 files changed, 17 insertions, 75 deletions
diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs
index 82181238b..3fa6f6450 100644
--- a/Emby.Drawing/ImageProcessor.cs
+++ b/Emby.Drawing/ImageProcessor.cs
@@ -227,7 +227,7 @@ namespace Emby.Drawing
originalImageSize = null;
}
- var newSize = GetNewImageSize(options, originalImageSize);
+ var newSize = ImageHelper.GetNewImageSize(options, originalImageSize);
var quality = options.Quality;
var outputFormat = GetOutputFormat(options.SupportedOutputFormats[0]);
@@ -239,14 +239,11 @@ namespace Emby.Drawing
if (!_fileSystem.FileExists(cacheFilePath))
{
- var newWidth = Convert.ToInt32(Math.Round(newSize.Width));
- var newHeight = Convert.ToInt32(Math.Round(newSize.Height));
-
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(cacheFilePath));
var tmpPath = Path.ChangeExtension(Path.Combine(_appPaths.TempDirectory, Guid.NewGuid().ToString("N")), Path.GetExtension(cacheFilePath));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(tmpPath));
- _imageEncoder.EncodeImage(originalImagePath, tmpPath, AutoOrient(options.Item), newWidth, newHeight, quality, options, outputFormat);
+ _imageEncoder.EncodeImage(originalImagePath, originalImageSize, tmpPath, AutoOrient(options.Item), quality, options, outputFormat);
CopyFile(tmpPath, cacheFilePath);
return new Tuple<string, string, DateTime>(tmpPath, GetMimeType(outputFormat, cacheFilePath), _fileSystem.GetLastWriteTimeUtc(tmpPath));
@@ -328,66 +325,6 @@ namespace Emby.Drawing
return MimeTypes.GetMimeType(path);
}
- private 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 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 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;
- }
- }
-
private ImageFormat GetOutputFormat(ImageFormat requestedFormat)
{
if (requestedFormat == ImageFormat.Webp && !_imageEncoder.SupportedOutputFormats.Contains(ImageFormat.Webp))
@@ -513,20 +450,25 @@ namespace Emby.Drawing
/// <returns>ImageSize.</returns>
private ImageSize GetImageSizeInternal(string path, bool allowSlowMethod)
{
- // Can't use taglib because it keeps a lock on the file
//try
//{
- // using (var file = TagLib.File.Create(new StreamFileAbstraction(Path.GetFileName(path), _fileSystem.OpenRead(path), null)))
+ // using (var fileStream = _fileSystem.OpenRead(path))
// {
- // var image = file as TagLib.Image.File;
-
- // var properties = image.Properties;
-
- // return new ImageSize
+ // using (var file = TagLib.File.Create(new StreamFileAbstraction(Path.GetFileName(path), fileStream, null)))
// {
- // Height = properties.PhotoHeight,
- // Width = properties.PhotoWidth
- // };
+ // var image = file as TagLib.Image.File;
+
+ // if (image != null)
+ // {
+ // var properties = image.Properties;
+
+ // return new ImageSize
+ // {
+ // Height = properties.PhotoHeight,
+ // Width = properties.PhotoWidth
+ // };
+ // }
+ // }
// }
//}
//catch