aboutsummaryrefslogtreecommitdiff
path: root/Emby.Drawing.Skia/SkiaEncoder.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Drawing.Skia/SkiaEncoder.cs')
-rw-r--r--Emby.Drawing.Skia/SkiaEncoder.cs39
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)