|
|
|
@ -6,6 +6,8 @@ using MediaBrowser.Model.IO;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using SkiaSharp;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
@ -120,8 +122,6 @@ namespace Emby.Drawing.Skia
|
|
|
|
|
|
|
|
|
|
private SKBitmap CropWhiteSpace(SKBitmap bitmap)
|
|
|
|
|
{
|
|
|
|
|
CheckDisposed();
|
|
|
|
|
|
|
|
|
|
var topmost = 0;
|
|
|
|
|
for (int row = 0; row < bitmap.Height; ++row)
|
|
|
|
|
{
|
|
|
|
@ -175,8 +175,6 @@ namespace Emby.Drawing.Skia
|
|
|
|
|
|
|
|
|
|
public ImageSize GetImageSize(string path)
|
|
|
|
|
{
|
|
|
|
|
CheckDisposed();
|
|
|
|
|
|
|
|
|
|
using (var s = new SKFileStream(path))
|
|
|
|
|
{
|
|
|
|
|
using (var codec = SKCodec.Create(s))
|
|
|
|
@ -192,17 +190,40 @@ namespace Emby.Drawing.Skia
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string[] TransparentImageTypes = new string[] { ".png", ".gif", ".webp" };
|
|
|
|
|
private SKBitmap Decode(string path)
|
|
|
|
|
{
|
|
|
|
|
var requiresTransparencyHack = TransparentImageTypes.Contains(Path.GetExtension(path) ?? string.Empty);
|
|
|
|
|
|
|
|
|
|
if (requiresTransparencyHack)
|
|
|
|
|
{
|
|
|
|
|
using (var stream = new SKFileStream(path))
|
|
|
|
|
{
|
|
|
|
|
var codec = SKCodec.Create(stream);
|
|
|
|
|
|
|
|
|
|
// create the bitmap
|
|
|
|
|
var bitmap = new SKBitmap(codec.Info.Width, codec.Info.Height);
|
|
|
|
|
// decode
|
|
|
|
|
codec.GetPixels(bitmap.Info, bitmap.GetPixels());
|
|
|
|
|
|
|
|
|
|
return bitmap;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SKBitmap.Decode(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SKBitmap GetBitmap(string path, bool cropWhitespace)
|
|
|
|
|
{
|
|
|
|
|
if (cropWhitespace)
|
|
|
|
|
{
|
|
|
|
|
using (var bitmap = SKBitmap.Decode(path))
|
|
|
|
|
using (var bitmap = Decode(path))
|
|
|
|
|
{
|
|
|
|
|
return CropWhiteSpace(bitmap);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SKBitmap.Decode(path);
|
|
|
|
|
return Decode(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EncodeImage(string inputPath, string outputPath, bool autoOrient, int width, int height, int quality, ImageProcessingOptions options, ImageFormat selectedOutputFormat)
|
|
|
|
@ -221,17 +242,14 @@ namespace Emby.Drawing.Skia
|
|
|
|
|
var hasBackgroundColor = !string.IsNullOrWhiteSpace(options.BackgroundColor);
|
|
|
|
|
var hasForegroundColor = !string.IsNullOrWhiteSpace(options.ForegroundLayer);
|
|
|
|
|
var blur = options.Blur ?? 0;
|
|
|
|
|
var hasIndicator = !options.AddPlayedIndicator && !options.UnplayedCount.HasValue && options.PercentPlayed.Equals(0);
|
|
|
|
|
var hasIndicator = options.AddPlayedIndicator || options.UnplayedCount.HasValue || !options.PercentPlayed.Equals(0);
|
|
|
|
|
|
|
|
|
|
using (var bitmap = GetBitmap(inputPath, options.CropWhiteSpace))
|
|
|
|
|
{
|
|
|
|
|
using (var resizedBitmap = new SKBitmap(width, height, bitmap.ColorType, bitmap.AlphaType))
|
|
|
|
|
using (var resizedBitmap = new SKBitmap(width, height))//, bitmap.ColorType, bitmap.AlphaType))
|
|
|
|
|
{
|
|
|
|
|
// scale image
|
|
|
|
|
var resizeMethod = options.Image.Type == MediaBrowser.Model.Entities.ImageType.Logo ||
|
|
|
|
|
options.Image.Type == MediaBrowser.Model.Entities.ImageType.Art
|
|
|
|
|
? SKBitmapResizeMethod.Lanczos3
|
|
|
|
|
: SKBitmapResizeMethod.Lanczos3;
|
|
|
|
|
var resizeMethod = SKBitmapResizeMethod.Lanczos3;
|
|
|
|
|
|
|
|
|
|
bitmap.Resize(resizedBitmap, resizeMethod);
|
|
|
|
|
|
|
|
|
@ -246,7 +264,7 @@ namespace Emby.Drawing.Skia
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// create bitmap to use for canvas drawing
|
|
|
|
|
using (var saveBitmap = new SKBitmap(width, height, bitmap.ColorType, bitmap.AlphaType))
|
|
|
|
|
using (var saveBitmap = new SKBitmap(width, height))//, bitmap.ColorType, bitmap.AlphaType))
|
|
|
|
|
{
|
|
|
|
|
// create canvas used to draw into bitmap
|
|
|
|
|
using (var canvas = new SKCanvas(saveBitmap))
|
|
|
|
@ -263,7 +281,7 @@ namespace Emby.Drawing.Skia
|
|
|
|
|
using (var paint = new SKPaint())
|
|
|
|
|
{
|
|
|
|
|
// create image from resized bitmap to apply blur
|
|
|
|
|
using (var filter = SKImageFilter.CreateBlur(5, 5))
|
|
|
|
|
using (var filter = SKImageFilter.CreateBlur(blur, blur))
|
|
|
|
|
{
|
|
|
|
|
paint.ImageFilter = filter;
|
|
|
|
|
canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height), paint);
|
|
|
|
@ -282,8 +300,7 @@ namespace Emby.Drawing.Skia
|
|
|
|
|
Double opacity;
|
|
|
|
|
if (!Double.TryParse(options.ForegroundLayer, out opacity)) opacity = .4;
|
|
|
|
|
|
|
|
|
|
var foregroundColor = String.Format("#{0:X2}000000", (Byte)((1 - opacity) * 0xFF));
|
|
|
|
|
canvas.DrawColor(SKColor.Parse(foregroundColor), SKBlendMode.SrcOver);
|
|
|
|
|
canvas.DrawColor(new SKColor(0, 0, 0, (Byte)((1 - opacity) * 0xFF)), SKBlendMode.SrcOver);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasIndicator)
|
|
|
|
@ -353,18 +370,8 @@ namespace Emby.Drawing.Skia
|
|
|
|
|
get { return "Skia"; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _disposed;
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_disposed = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckDisposed()
|
|
|
|
|
{
|
|
|
|
|
if (_disposed)
|
|
|
|
|
{
|
|
|
|
|
throw new ObjectDisposedException(GetType().Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SupportsImageCollageCreation
|
|
|
|
|