diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-05-17 14:19:13 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-17 14:19:13 -0400 |
| commit | 53ca77ed3136ef0e42486f74b3c8b58a66e4ac5c (patch) | |
| tree | 6509b8adf32de2be823ff55de538ce9df0c4b0e7 /Emby.Drawing.Skia/SkiaEncoder.cs | |
| parent | 3d44783da9c01580aa4bde8a7a83215a3467e10f (diff) | |
| parent | 9695430d9d37c27ed0385b5ad29ab9888d712f39 (diff) | |
Merge pull request #2644 from MediaBrowser/dev
Dev
Diffstat (limited to 'Emby.Drawing.Skia/SkiaEncoder.cs')
| -rw-r--r-- | Emby.Drawing.Skia/SkiaEncoder.cs | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/Emby.Drawing.Skia/SkiaEncoder.cs b/Emby.Drawing.Skia/SkiaEncoder.cs index 018de5bc9..d74279952 100644 --- a/Emby.Drawing.Skia/SkiaEncoder.cs +++ b/Emby.Drawing.Skia/SkiaEncoder.cs @@ -191,18 +191,18 @@ namespace Emby.Drawing.Skia } private string[] TransparentImageTypes = new string[] { ".png", ".gif", ".webp" }; - private SKBitmap Decode(string path) + private SKBitmap Decode(string path, bool forceCleanBitmap = false) { var requiresTransparencyHack = TransparentImageTypes.Contains(Path.GetExtension(path) ?? string.Empty); - if (requiresTransparencyHack) + if (requiresTransparencyHack || forceCleanBitmap) { using (var stream = new SKFileStream(path)) { var codec = SKCodec.Create(stream); // create the bitmap - var bitmap = new SKBitmap(codec.Info.Width, codec.Info.Height); + var bitmap = new SKBitmap(codec.Info.Width, codec.Info.Height, !requiresTransparencyHack); // decode codec.GetPixels(bitmap.Info, bitmap.GetPixels()); @@ -210,7 +210,18 @@ namespace Emby.Drawing.Skia } } - return SKBitmap.Decode(path); + var resultBitmap = SKBitmap.Decode(path); + + // If we have to resize these they often end up distorted + if (resultBitmap.ColorType == SKColorType.Gray8) + { + using (resultBitmap) + { + return Decode(path, true); + } + } + + return resultBitmap; } private SKBitmap GetBitmap(string path, bool cropWhitespace) @@ -226,7 +237,7 @@ namespace Emby.Drawing.Skia return Decode(path); } - public void EncodeImage(string inputPath, ImageSize? originalImageSize, string outputPath, bool autoOrient, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat) + public string EncodeImage(string inputPath, DateTime dateModified, string outputPath, bool autoOrient, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat) { if (string.IsNullOrWhiteSpace(inputPath)) { @@ -246,9 +257,20 @@ namespace Emby.Drawing.Skia using (var bitmap = GetBitmap(inputPath, options.CropWhiteSpace)) { - if (options.CropWhiteSpace || !originalImageSize.HasValue) + if (bitmap == null) + { + throw new Exception(string.Format("Skia unable to read image {0}", inputPath)); + } + + //_logger.Info("Color type {0}", bitmap.Info.ColorType); + + var originalImageSize = new ImageSize(bitmap.Width, bitmap.Height); + ImageHelper.SaveImageSize(inputPath, dateModified, originalImageSize); + + if (!options.CropWhiteSpace && options.HasDefaultOptions(inputPath, originalImageSize)) { - originalImageSize = new ImageSize(bitmap.Width, bitmap.Height); + // Just spit out the original file if all the options are default + return inputPath; } var newImageSize = ImageHelper.GetNewImageSize(options, originalImageSize); @@ -269,7 +291,7 @@ namespace Emby.Drawing.Skia using (var outputStream = new SKFileWStream(outputPath)) { resizedBitmap.Encode(outputStream, skiaOutputFormat, quality); - return; + return outputPath; } } @@ -326,6 +348,7 @@ namespace Emby.Drawing.Skia } } } + return outputPath; } public void CreateImageCollage(ImageCollageOptions options) |
