update skia

pull/1154/head
Luke Pulverenti 7 years ago
parent e915ceda1b
commit 3feeb04ffc

@ -6,6 +6,8 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using SkiaSharp; using SkiaSharp;
using System; using System;
using System.IO;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -120,8 +122,6 @@ namespace Emby.Drawing.Skia
private SKBitmap CropWhiteSpace(SKBitmap bitmap) private SKBitmap CropWhiteSpace(SKBitmap bitmap)
{ {
CheckDisposed();
var topmost = 0; var topmost = 0;
for (int row = 0; row < bitmap.Height; ++row) for (int row = 0; row < bitmap.Height; ++row)
{ {
@ -175,8 +175,6 @@ namespace Emby.Drawing.Skia
public ImageSize GetImageSize(string path) public ImageSize GetImageSize(string path)
{ {
CheckDisposed();
using (var s = new SKFileStream(path)) using (var s = new SKFileStream(path))
{ {
using (var codec = SKCodec.Create(s)) using (var codec = SKCodec.Create(s))
@ -192,19 +190,27 @@ namespace Emby.Drawing.Skia
} }
} }
private string[] TransparentImageTypes = new string[] { ".png", ".gif", ".webp" };
private SKBitmap Decode(string path) private SKBitmap Decode(string path)
{ {
using (var stream = new SKFileStream(path)) var requiresTransparencyHack = TransparentImageTypes.Contains(Path.GetExtension(path) ?? string.Empty);
if (requiresTransparencyHack)
{ {
var codec = SKCodec.Create(stream); using (var stream = new SKFileStream(path))
{
var codec = SKCodec.Create(stream);
// create the bitmap // create the bitmap
var bitmap = new SKBitmap(codec.Info.Width, codec.Info.Height); var bitmap = new SKBitmap(codec.Info.Width, codec.Info.Height);
// decode // decode
codec.GetPixels(bitmap.Info, bitmap.GetPixels()); codec.GetPixels(bitmap.Info, bitmap.GetPixels());
return bitmap; return bitmap;
}
} }
return SKBitmap.Decode(path);
} }
private SKBitmap GetBitmap(string path, bool cropWhitespace) private SKBitmap GetBitmap(string path, bool cropWhitespace)
@ -236,11 +242,11 @@ namespace Emby.Drawing.Skia
var hasBackgroundColor = !string.IsNullOrWhiteSpace(options.BackgroundColor); var hasBackgroundColor = !string.IsNullOrWhiteSpace(options.BackgroundColor);
var hasForegroundColor = !string.IsNullOrWhiteSpace(options.ForegroundLayer); var hasForegroundColor = !string.IsNullOrWhiteSpace(options.ForegroundLayer);
var blur = options.Blur ?? 0; 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 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 // scale image
var resizeMethod = SKBitmapResizeMethod.Lanczos3; var resizeMethod = SKBitmapResizeMethod.Lanczos3;
@ -258,7 +264,7 @@ namespace Emby.Drawing.Skia
} }
// create bitmap to use for canvas drawing // 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 // create canvas used to draw into bitmap
using (var canvas = new SKCanvas(saveBitmap)) using (var canvas = new SKCanvas(saveBitmap))
@ -275,7 +281,7 @@ namespace Emby.Drawing.Skia
using (var paint = new SKPaint()) using (var paint = new SKPaint())
{ {
// create image from resized bitmap to apply blur // 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; paint.ImageFilter = filter;
canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height), paint); canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height), paint);
@ -294,8 +300,7 @@ namespace Emby.Drawing.Skia
Double opacity; Double opacity;
if (!Double.TryParse(options.ForegroundLayer, out opacity)) opacity = .4; if (!Double.TryParse(options.ForegroundLayer, out opacity)) opacity = .4;
var foregroundColor = String.Format("#{0:X2}000000", (Byte)((1 - opacity) * 0xFF)); canvas.DrawColor(new SKColor(0, 0, 0, (Byte)((1 - opacity) * 0xFF)), SKBlendMode.SrcOver);
canvas.DrawColor(SKColor.Parse(foregroundColor), SKBlendMode.SrcOver);
} }
if (hasIndicator) if (hasIndicator)
@ -365,18 +370,8 @@ namespace Emby.Drawing.Skia
get { return "Skia"; } get { return "Skia"; }
} }
private bool _disposed;
public void Dispose() public void Dispose()
{ {
_disposed = true;
}
private void CheckDisposed()
{
if (_disposed)
{
throw new ObjectDisposedException(GetType().Name);
}
} }
public bool SupportsImageCollageCreation public bool SupportsImageCollageCreation

Loading…
Cancel
Save