aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2015-03-19 13:21:35 -0400
committerLuke <luke.pulverenti@gmail.com>2015-03-19 13:21:35 -0400
commit9926be0d9de688c04065c916e44ada4177b38a80 (patch)
tree15338144a143948ffbee316641757e81489a7354 /MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
parentb756e677d733992c2033bdd369980a37e17609e4 (diff)
parent0564d454e5ad4f59702aa9022af6bb8fd064a9ff (diff)
Merge pull request #1043 from MediaBrowser/dev
3.0.5557.0
Diffstat (limited to 'MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs')
-rw-r--r--MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs417
1 files changed, 152 insertions, 265 deletions
diff --git a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
index 5055d2750..79e5a0cf0 100644
--- a/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
+++ b/MediaBrowser.Server.Implementations/Drawing/ImageProcessor.cs
@@ -1,10 +1,9 @@
-using Imazen.WebP;
+using ImageMagickSharp;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Entities;
-using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.Entities;
@@ -13,9 +12,6 @@ using MediaBrowser.Model.Serialization;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
-using System.Drawing;
-using System.Drawing.Drawing2D;
-using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Linq;
@@ -54,14 +50,12 @@ namespace MediaBrowser.Server.Implementations.Drawing
private readonly IFileSystem _fileSystem;
private readonly IJsonSerializer _jsonSerializer;
private readonly IServerApplicationPaths _appPaths;
- private readonly IMediaEncoder _mediaEncoder;
- public ImageProcessor(ILogger logger, IServerApplicationPaths appPaths, IFileSystem fileSystem, IJsonSerializer jsonSerializer, IMediaEncoder mediaEncoder)
+ public ImageProcessor(ILogger logger, IServerApplicationPaths appPaths, IFileSystem fileSystem, IJsonSerializer jsonSerializer)
{
_logger = logger;
_fileSystem = fileSystem;
_jsonSerializer = jsonSerializer;
- _mediaEncoder = mediaEncoder;
_appPaths = appPaths;
_saveImageSizeTimer = new Timer(SaveImageSizeCallback, null, Timeout.Infinite, Timeout.Infinite);
@@ -92,7 +86,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
_cachedImagedSizes = new ConcurrentDictionary<Guid, ImageSize>(sizeDictionary);
- LogWebPVersion();
+ LogImageMagickVersionVersion();
}
private string ResizedImageCachePath
@@ -134,13 +128,46 @@ namespace MediaBrowser.Server.Implementations.Drawing
}
}
- public Model.Drawing.ImageFormat[] GetSupportedImageOutputFormats()
+ public ImageFormat[] GetSupportedImageOutputFormats()
{
if (_webpAvailable)
{
- return new[] { Model.Drawing.ImageFormat.Webp, Model.Drawing.ImageFormat.Gif, Model.Drawing.ImageFormat.Jpg, Model.Drawing.ImageFormat.Png };
+ return new[] { ImageFormat.Webp, ImageFormat.Gif, ImageFormat.Jpg, ImageFormat.Png };
}
- return new[] { Model.Drawing.ImageFormat.Gif, Model.Drawing.ImageFormat.Jpg, Model.Drawing.ImageFormat.Png };
+ return new[] { ImageFormat.Gif, ImageFormat.Jpg, ImageFormat.Png };
+ }
+
+ private bool _webpAvailable = true;
+ private void TestWebp()
+ {
+ try
+ {
+ var tmpPath = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".webp");
+ Directory.CreateDirectory(Path.GetDirectoryName(tmpPath));
+
+ using (var wand = new MagickWand(1, 1, new PixelWand("none", 1)))
+ {
+ wand.SaveImage(tmpPath);
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error loading webp: ", ex);
+ _webpAvailable = false;
+ }
+ }
+
+ private void LogImageMagickVersionVersion()
+ {
+ try
+ {
+ _logger.Info("ImageMagick version: " + Wand.VersionString);
+ }
+ catch (Exception ex)
+ {
+ _logger.ErrorException("Error loading ImageMagick: ", ex);
+ }
+ TestWebp();
}
public async Task<string> ProcessImage(ImageProcessingOptions options)
@@ -189,7 +216,8 @@ namespace MediaBrowser.Server.Implementations.Drawing
var quality = options.Quality ?? 90;
- var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, options.OutputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.UnplayedCount, options.BackgroundColor);
+ var outputFormat = GetOutputFormat(options.OutputFormat);
+ var cacheFilePath = GetCacheFilePath(originalImagePath, newSize, quality, dateModified, outputFormat, options.AddPlayedIndicator, options.PercentPlayed, options.UnplayedCount, options.BackgroundColor);
var semaphore = GetLock(cacheFilePath);
@@ -212,77 +240,44 @@ namespace MediaBrowser.Server.Implementations.Drawing
try
{
- var hasPostProcessing = !string.IsNullOrEmpty(options.BackgroundColor) || options.UnplayedCount.HasValue || options.AddPlayedIndicator || options.PercentPlayed > 0;
+ CheckDisposed();
+
+ var newWidth = Convert.ToInt32(newSize.Width);
+ var newHeight = Convert.ToInt32(newSize.Height);
- using (var fileStream = _fileSystem.GetFileStream(originalImagePath, FileMode.Open, FileAccess.Read, FileShare.Read, true))
+ Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
+
+ if (string.IsNullOrWhiteSpace(options.BackgroundColor))
{
- // Copy to memory stream to avoid Image locking file
- using (var memoryStream = new MemoryStream())
+ using (var originalImage = new MagickWand(originalImagePath))
{
- await fileStream.CopyToAsync(memoryStream).ConfigureAwait(false);
+ originalImage.CurrentImage.ResizeImage(newWidth, newHeight);
+
+ DrawIndicator(originalImage, newWidth, newHeight, options);
- using (var originalImage = Image.FromStream(memoryStream, true, false))
+ originalImage.CurrentImage.CompressionQuality = quality;
+
+ originalImage.SaveImage(cacheFilePath);
+
+ return cacheFilePath;
+ }
+ }
+ else
+ {
+ using (var wand = new MagickWand(newWidth, newHeight, options.BackgroundColor))
+ {
+ using (var originalImage = new MagickWand(originalImagePath))
{
- var newWidth = Convert.ToInt32(newSize.Width);
- var newHeight = Convert.ToInt32(newSize.Height);
-
- var selectedOutputFormat = options.OutputFormat;
-
- _logger.Debug("Processing image to {0}", selectedOutputFormat);
-
- // Graphics.FromImage will throw an exception if the PixelFormat is Indexed, so we need to handle that here
- // Also, Webp only supports Format32bppArgb and Format32bppRgb
- var pixelFormat = selectedOutputFormat == Model.Drawing.ImageFormat.Webp
- ? PixelFormat.Format32bppArgb
- : PixelFormat.Format32bppPArgb;
-
- using (var thumbnail = new Bitmap(newWidth, newHeight, pixelFormat))
- {
- // Mono throw an exeception if assign 0 to SetResolution
- if (originalImage.HorizontalResolution > 0 && originalImage.VerticalResolution > 0)
- {
- // Preserve the original resolution
- thumbnail.SetResolution(originalImage.HorizontalResolution, originalImage.VerticalResolution);
- }
-
- using (var thumbnailGraph = Graphics.FromImage(thumbnail))
- {
- thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality;
- thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality;
- thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
- thumbnailGraph.PixelOffsetMode = PixelOffsetMode.HighQuality;
- thumbnailGraph.CompositingMode = !hasPostProcessing ?
- CompositingMode.SourceCopy :
- CompositingMode.SourceOver;
-
- SetBackgroundColor(thumbnailGraph, options);
-
- thumbnailGraph.DrawImage(originalImage, 0, 0, newWidth, newHeight);
-
- DrawIndicator(thumbnailGraph, newWidth, newHeight, options);
-
- var outputFormat = GetOutputFormat(originalImage, selectedOutputFormat);
-
- Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
-
- // Save to the cache location
- using (var cacheFileStream = _fileSystem.GetFileStream(cacheFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, false))
- {
- if (selectedOutputFormat == Model.Drawing.ImageFormat.Webp)
- {
- SaveToWebP(thumbnail, cacheFileStream, quality);
- }
- else
- {
- // Save to the memory stream
- thumbnail.Save(outputFormat, cacheFileStream, quality);
- }
- }
-
- return cacheFilePath;
- }
- }
+ originalImage.CurrentImage.ResizeImage(newWidth, newHeight);
+
+ wand.CurrentImage.CompositeImage(originalImage, CompositeOperator.OverCompositeOp, 0, 0);
+ DrawIndicator(wand, newWidth, newHeight, options);
+
+ wand.CurrentImage.CompressionQuality = quality;
+ wand.SaveImage(cacheFilePath);
+
+ return cacheFilePath;
}
}
}
@@ -293,59 +288,24 @@ namespace MediaBrowser.Server.Implementations.Drawing
}
}
- private void SaveToWebP(Bitmap thumbnail, Stream toStream, int quality)
- {
- new SimpleEncoder().Encode(thumbnail, toStream, quality);
- }
-
- private bool _webpAvailable = true;
- private void LogWebPVersion()
+ private ImageFormat GetOutputFormat(ImageFormat requestedFormat)
{
- try
+ if (requestedFormat == ImageFormat.Webp && !_webpAvailable)
{
- _logger.Info("libwebp version: " + SimpleEncoder.GetEncoderVersion());
+ return ImageFormat.Png;
}
- catch (Exception ex)
- {
- _logger.ErrorException("Error loading libwebp: ", ex);
- _webpAvailable = false;
- }
- }
-
- /// <summary>
- /// Sets the color of the background.
- /// </summary>
- /// <param name="graphics">The graphics.</param>
- /// <param name="options">The options.</param>
- private void SetBackgroundColor(Graphics graphics, ImageProcessingOptions options)
- {
- var color = options.BackgroundColor;
- if (!string.IsNullOrEmpty(color))
- {
- Color drawingColor;
-
- try
- {
- drawingColor = ColorTranslator.FromHtml(color);
- }
- catch
- {
- drawingColor = ColorTranslator.FromHtml("#" + color);
- }
-
- graphics.Clear(drawingColor);
- }
+ return requestedFormat;
}
/// <summary>
/// Draws the indicator.
/// </summary>
- /// <param name="graphics">The graphics.</param>
+ /// <param name="wand">The wand.</param>
/// <param name="imageWidth">Width of the image.</param>
/// <param name="imageHeight">Height of the image.</param>
/// <param name="options">The options.</param>
- private void DrawIndicator(Graphics graphics, int imageWidth, int imageHeight, ImageProcessingOptions options)
+ private void DrawIndicator(MagickWand wand, int imageWidth, int imageHeight, ImageProcessingOptions options)
{
if (!options.AddPlayedIndicator && !options.UnplayedCount.HasValue && options.PercentPlayed.Equals(0))
{
@@ -356,22 +316,20 @@ namespace MediaBrowser.Server.Implementations.Drawing
{
if (options.AddPlayedIndicator)
{
- var currentImageSize = new Size(imageWidth, imageHeight);
+ var currentImageSize = new ImageSize(imageWidth, imageHeight);
- new PlayedIndicatorDrawer().DrawPlayedIndicator(graphics, currentImageSize);
+ new PlayedIndicatorDrawer(_appPaths).DrawPlayedIndicator(wand, currentImageSize);
}
else if (options.UnplayedCount.HasValue)
{
- var currentImageSize = new Size(imageWidth, imageHeight);
+ var currentImageSize = new ImageSize(imageWidth, imageHeight);
- new UnplayedCountIndicator().DrawUnplayedCountIndicator(graphics, currentImageSize, options.UnplayedCount.Value);
+ new UnplayedCountIndicator(_appPaths).DrawUnplayedCountIndicator(wand, currentImageSize, options.UnplayedCount.Value);
}
if (options.PercentPlayed > 0)
{
- var currentImageSize = new Size(imageWidth, imageHeight);
-
- new PercentPlayedDrawer().Process(graphics, currentImageSize, options.PercentPlayed);
+ new PercentPlayedDrawer().Process(wand, options.PercentPlayed);
}
}
catch (Exception ex)
@@ -381,29 +339,6 @@ namespace MediaBrowser.Server.Implementations.Drawing
}
/// <summary>
- /// Gets the output format.
- /// </summary>
- /// <param name="image">The image.</param>
- /// <param name="outputFormat">The output format.</param>
- /// <returns>ImageFormat.</returns>
- private System.Drawing.Imaging.ImageFormat GetOutputFormat(Image image, Model.Drawing.ImageFormat outputFormat)
- {
- switch (outputFormat)
- {
- case Model.Drawing.ImageFormat.Bmp:
- return System.Drawing.Imaging.ImageFormat.Bmp;
- case Model.Drawing.ImageFormat.Gif:
- return System.Drawing.Imaging.ImageFormat.Gif;
- case Model.Drawing.ImageFormat.Jpg:
- return System.Drawing.Imaging.ImageFormat.Jpeg;
- case Model.Drawing.ImageFormat.Png:
- return System.Drawing.Imaging.ImageFormat.Png;
- default:
- return image.RawFormat;
- }
- }
-
- /// <summary>
/// Crops whitespace from an image, caches the result, and returns the cached path
/// </summary>
/// <param name="originalImagePath">The original image path.</param>
@@ -429,28 +364,12 @@ namespace MediaBrowser.Server.Implementations.Drawing
try
{
- using (var fileStream = _fileSystem.GetFileStream(originalImagePath, FileMode.Open, FileAccess.Read, FileShare.Read, true))
- {
- // Copy to memory stream to avoid Image locking file
- using (var memoryStream = new MemoryStream())
- {
- await fileStream.CopyToAsync(memoryStream).ConfigureAwait(false);
-
- using (var originalImage = (Bitmap)Image.FromStream(memoryStream, true, false))
- {
- var outputFormat = originalImage.RawFormat;
+ Directory.CreateDirectory(Path.GetDirectoryName(croppedImagePath));
- using (var croppedImage = originalImage.CropWhitespace())
- {
- Directory.CreateDirectory(Path.GetDirectoryName(croppedImagePath));
-
- using (var outputStream = _fileSystem.GetFileStream(croppedImagePath, FileMode.Create, FileAccess.Write, FileShare.Read, false))
- {
- croppedImage.Save(outputFormat, outputStream, 100);
- }
- }
- }
- }
+ using (var wand = new MagickWand(originalImagePath))
+ {
+ wand.CurrentImage.TrimImage(10);
+ wand.SaveImage(croppedImagePath);
}
}
catch (Exception ex)
@@ -469,14 +388,14 @@ namespace MediaBrowser.Server.Implementations.Drawing
}
/// <summary>
- /// Increment this when indicator drawings change
+ /// Increment this when there's a change requiring caches to be invalidated
/// </summary>
- private const string IndicatorVersion = "2";
+ private const string Version = "3";
/// <summary>
/// Gets the cache file path based on a set of parameters
/// </summary>
- private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, Model.Drawing.ImageFormat format, bool addPlayedIndicator, double percentPlayed, int? unwatchedCount, string backgroundColor)
+ private string GetCacheFilePath(string originalPath, ImageSize outputSize, int quality, DateTime dateModified, ImageFormat format, bool addPlayedIndicator, double percentPlayed, int? unwatchedCount, string backgroundColor)
{
var filename = originalPath;
@@ -490,29 +409,19 @@ namespace MediaBrowser.Server.Implementations.Drawing
filename += "f=" + format;
- var hasIndicator = false;
-
if (addPlayedIndicator)
{
filename += "pl=true";
- hasIndicator = true;
}
if (percentPlayed > 0)
{
filename += "p=" + percentPlayed;
- hasIndicator = true;
}
if (unwatchedCount.HasValue)
{
filename += "p=" + unwatchedCount.Value;
- hasIndicator = true;
- }
-
- if (hasIndicator)
- {
- filename += "iv=" + IndicatorVersion;
}
if (!string.IsNullOrEmpty(backgroundColor))
@@ -520,6 +429,8 @@ namespace MediaBrowser.Server.Implementations.Drawing
filename += "b=" + backgroundColor;
}
+ filename += "v=" + Version;
+
return GetCachePath(ResizedImageCachePath, filename, "." + format.ToString().ToLower());
}
@@ -533,6 +444,11 @@ namespace MediaBrowser.Server.Implementations.Drawing
return GetImageSize(path, File.GetLastWriteTimeUtc(path));
}
+ public ImageSize GetImageSize(ItemImageInfo info)
+ {
+ return GetImageSize(info.Path, info.DateModified);
+ }
+
/// <summary>
/// Gets the size of the image.
/// </summary>
@@ -540,7 +456,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
/// <param name="imageDateModified">The image date modified.</param>
/// <returns>ImageSize.</returns>
/// <exception cref="System.ArgumentNullException">path</exception>
- public ImageSize GetImageSize(string path, DateTime imageDateModified)
+ private ImageSize GetImageSize(string path, DateTime imageDateModified)
{
if (string.IsNullOrEmpty(path))
{
@@ -570,11 +486,34 @@ namespace MediaBrowser.Server.Implementations.Drawing
/// <returns>ImageSize.</returns>
private ImageSize GetImageSizeInternal(string path)
{
- var size = ImageHeader.GetDimensions(path, _logger, _fileSystem);
+ ImageSize size;
+
+ try
+ {
+ size = ImageHeader.GetDimensions(path, _logger, _fileSystem);
+ }
+ catch
+ {
+ _logger.Info("Failed to read image header for {0}. Doing it the slow way.", path);
+
+ CheckDisposed();
+
+ using (var wand = new MagickWand())
+ {
+ wand.PingImage(path);
+ var img = wand.CurrentImage;
+
+ size = new ImageSize
+ {
+ Width = img.Width,
+ Height = img.Height
+ };
+ }
+ }
StartSaveImageSizeTimer();
- return new ImageSize { Width = size.Width, Height = size.Height };
+ return size;
}
private readonly Timer _saveImageSizeTimer;
@@ -727,7 +666,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
}
/// <summary>
- /// Runs an image through the image enhancers, caches the result, and returns the cached path
+ /// Gets the enhanced image internal.
/// </summary>
/// <param name="originalImagePath">The original image path.</param>
/// <param name="item">The item.</param>
@@ -735,8 +674,12 @@ namespace MediaBrowser.Server.Implementations.Drawing
/// <param name="imageIndex">Index of the image.</param>
/// <param name="supportedEnhancers">The supported enhancers.</param>
/// <param name="cacheGuid">The cache unique identifier.</param>
- /// <returns>System.String.</returns>
- /// <exception cref="System.ArgumentNullException">originalImagePath</exception>
+ /// <returns>Task&lt;System.String&gt;.</returns>
+ /// <exception cref="ArgumentNullException">
+ /// originalImagePath
+ /// or
+ /// item
+ /// </exception>
private async Task<string> GetEnhancedImageInternal(string originalImagePath,
IHasImages item,
ImageType imageType,
@@ -770,51 +713,8 @@ namespace MediaBrowser.Server.Implementations.Drawing
try
{
- using (var fileStream = _fileSystem.GetFileStream(originalImagePath, FileMode.Open, FileAccess.Read, FileShare.Read, true))
- {
- // Copy to memory stream to avoid Image locking file
- using (var memoryStream = new MemoryStream())
- {
- await fileStream.CopyToAsync(memoryStream).ConfigureAwait(false);
-
- memoryStream.Position = 0;
-
- var imageStream = new ImageStream
- {
- Stream = memoryStream,
- Format = GetFormat(originalImagePath)
- };
-
- //Pass the image through registered enhancers
- using (var newImageStream = await ExecuteImageEnhancers(supportedEnhancers, imageStream, item, imageType, imageIndex).ConfigureAwait(false))
- {
- var parentDirectory = Path.GetDirectoryName(enhancedImagePath);
-
- Directory.CreateDirectory(parentDirectory);
-
- // Save as png
- if (newImageStream.Format == Model.Drawing.ImageFormat.Png)
- {
- //And then save it in the cache
- using (var outputStream = _fileSystem.GetFileStream(enhancedImagePath, FileMode.Create, FileAccess.Write, FileShare.Read, false))
- {
- await newImageStream.Stream.CopyToAsync(outputStream).ConfigureAwait(false);
- }
- }
- else
- {
- using (var newImage = Image.FromStream(newImageStream.Stream, true, false))
- {
- //And then save it in the cache
- using (var outputStream = _fileSystem.GetFileStream(enhancedImagePath, FileMode.Create, FileAccess.Write, FileShare.Read, false))
- {
- newImage.Save(System.Drawing.Imaging.ImageFormat.Png, outputStream, 100);
- }
- }
- }
- }
- }
- }
+ Directory.CreateDirectory(Path.GetDirectoryName(enhancedImagePath));
+ await ExecuteImageEnhancers(supportedEnhancers, originalImagePath, enhancedImagePath, item, imageType, imageIndex).ConfigureAwait(false);
}
finally
{
@@ -824,43 +724,18 @@ namespace MediaBrowser.Server.Implementations.Drawing
return enhancedImagePath;
}
- private Model.Drawing.ImageFormat GetFormat(string path)
- {
- var extension = Path.GetExtension(path);
-
- if (string.Equals(extension, ".png", StringComparison.OrdinalIgnoreCase))
- {
- return Model.Drawing.ImageFormat.Png;
- }
- if (string.Equals(extension, ".gif", StringComparison.OrdinalIgnoreCase))
- {
- return Model.Drawing.ImageFormat.Gif;
- }
- if (string.Equals(extension, ".webp", StringComparison.OrdinalIgnoreCase))
- {
- return Model.Drawing.ImageFormat.Webp;
- }
- if (string.Equals(extension, ".bmp", StringComparison.OrdinalIgnoreCase))
- {
- return Model.Drawing.ImageFormat.Bmp;
- }
-
- return Model.Drawing.ImageFormat.Jpg;
- }
-
/// <summary>
/// Executes the image enhancers.
/// </summary>
/// <param name="imageEnhancers">The image enhancers.</param>
- /// <param name="originalImage">The original image.</param>
+ /// <param name="inputPath">The input path.</param>
+ /// <param name="outputPath">The output path.</param>
/// <param name="item">The item.</param>
/// <param name="imageType">Type of the image.</param>
/// <param name="imageIndex">Index of the image.</param>
/// <returns>Task{EnhancedImage}.</returns>
- private async Task<ImageStream> ExecuteImageEnhancers(IEnumerable<IImageEnhancer> imageEnhancers, ImageStream originalImage, IHasImages item, ImageType imageType, int imageIndex)
+ private async Task ExecuteImageEnhancers(IEnumerable<IImageEnhancer> imageEnhancers, string inputPath, string outputPath, IHasImages item, ImageType imageType, int imageIndex)
{
- var result = originalImage;
-
// Run the enhancers sequentially in order of priority
foreach (var enhancer in imageEnhancers)
{
@@ -868,7 +743,7 @@ namespace MediaBrowser.Server.Implementations.Drawing
try
{
- result = await enhancer.EnhanceImageAsync(item, result, imageType, imageIndex).ConfigureAwait(false);
+ await enhancer.EnhanceImageAsync(item, inputPath, outputPath, imageType, imageIndex).ConfigureAwait(false);
}
catch (Exception ex)
{
@@ -876,9 +751,10 @@ namespace MediaBrowser.Server.Implementations.Drawing
throw;
}
- }
- return result;
+ // Feed the output into the next enhancer as input
+ inputPath = outputPath;
+ }
}
/// <summary>
@@ -978,9 +854,20 @@ namespace MediaBrowser.Server.Implementations.Drawing
});
}
+ private bool _disposed;
public void Dispose()
{
+ _disposed = true;
+ Wand.CloseEnvironment();
_saveImageSizeTimer.Dispose();
}
+
+ private void CheckDisposed()
+ {
+ if (_disposed)
+ {
+ throw new ObjectDisposedException(GetType().Name);
+ }
+ }
}
}