update image encoding

This commit is contained in:
Luke Pulverenti
2015-11-12 14:26:02 -05:00
parent 4da6275de1
commit 90e06289dc
9 changed files with 177 additions and 120 deletions

View File

@@ -32,7 +32,7 @@ namespace Emby.Drawing.GDI
{
using (var img = Image.FromStream(stream))
{
}
}
_logger.Info("GDIImageEncoder started");
@@ -79,17 +79,17 @@ namespace Emby.Drawing.GDI
{
using (var croppedImage = image.CropWhitespace())
{
_fileSystem.CreateDirectory(Path.GetDirectoryName(outputPath));
_fileSystem.CreateDirectory(Path.GetDirectoryName(outputPath));
using (var outputStream = _fileSystem.GetFileStream(outputPath, FileMode.Create, FileAccess.Write, FileShare.Read, false))
{
croppedImage.Save(System.Drawing.Imaging.ImageFormat.Png, outputStream, 100);
}
}
}
}
}
public void EncodeImage(string inputPath, string cacheFilePath, int width, int height, int quality, ImageProcessingOptions options)
public void EncodeImage(string inputPath, string cacheFilePath, int width, int height, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat)
{
var hasPostProcessing = !string.IsNullOrEmpty(options.BackgroundColor) || options.UnplayedCount.HasValue || options.AddPlayedIndicator || options.PercentPlayed > 0;
@@ -98,8 +98,6 @@ namespace Emby.Drawing.GDI
var newWidth = Convert.ToInt32(width);
var newHeight = Convert.ToInt32(height);
var selectedOutputFormat = options.OutputFormat;
// 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 == ImageFormat.Webp
@@ -133,7 +131,7 @@ namespace Emby.Drawing.GDI
var outputFormat = GetOutputFormat(originalImage, selectedOutputFormat);
_fileSystem.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
_fileSystem.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
// Save to the cache location
using (var cacheFileStream = _fileSystem.GetFileStream(cacheFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, false))