From 0a3862ff8040bc7bd5803bb259842da302a282d1 Mon Sep 17 00:00:00 2001 From: Erwin de Haan Date: Thu, 3 Jan 2019 18:59:12 +0100 Subject: [PATCH 1/2] Moved Emby.Drawing.Skia off of deprecated functions. Cleaned up some other declarations along the way. --- Emby.Drawing.Skia/SkiaEncoder.cs | 15 ++++++++------- Emby.Drawing.Skia/StripCollageBuilder.cs | 23 ++++++++++++----------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/Emby.Drawing.Skia/SkiaEncoder.cs b/Emby.Drawing.Skia/SkiaEncoder.cs index 7a445a09ce..b96d46832d 100644 --- a/Emby.Drawing.Skia/SkiaEncoder.cs +++ b/Emby.Drawing.Skia/SkiaEncoder.cs @@ -548,9 +548,7 @@ namespace Emby.Drawing.Skia using (var resizedBitmap = new SKBitmap(width, height))//, bitmap.ColorType, bitmap.AlphaType)) { // scale image - var resizeMethod = SKBitmapResizeMethod.Lanczos3; - - bitmap.Resize(resizedBitmap, resizeMethod); + bitmap.ScalePixels(resizedBitmap, SKFilterQuality.High); // If all we're doing is resizing then we can stop now if (!hasBackgroundColor && !hasForegroundColor && blur == 0 && !hasIndicator) @@ -558,7 +556,9 @@ namespace Emby.Drawing.Skia _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(outputPath)); using (var outputStream = new SKFileWStream(outputPath)) { - resizedBitmap.Encode(outputStream, skiaOutputFormat, quality); + SKImageInfo imageInfo = new SKImageInfo(width,height); + var pixmap = new SKPixmap(new SKImageInfo(width, height), resizedBitmap.GetPixels()); + pixmap.Encode(outputStream, skiaOutputFormat, quality); return outputPath; } } @@ -593,8 +593,7 @@ namespace Emby.Drawing.Skia // If foreground layer present then draw if (hasForegroundColor) { - Double opacity; - if (!Double.TryParse(options.ForegroundLayer, out opacity)) + if (!Double.TryParse(options.ForegroundLayer, out double opacity)) { opacity = .4; } @@ -610,7 +609,9 @@ namespace Emby.Drawing.Skia _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(outputPath)); using (var outputStream = new SKFileWStream(outputPath)) { - saveBitmap.Encode(outputStream, skiaOutputFormat, quality); + SKImageInfo imageInfo = new SKImageInfo(width, height); + var pixmap = new SKPixmap(new SKImageInfo(width, height), saveBitmap.GetPixels()); + pixmap.Encode(outputStream, skiaOutputFormat, quality); } } } diff --git a/Emby.Drawing.Skia/StripCollageBuilder.cs b/Emby.Drawing.Skia/StripCollageBuilder.cs index 32f0b65857..2528fbc567 100644 --- a/Emby.Drawing.Skia/StripCollageBuilder.cs +++ b/Emby.Drawing.Skia/StripCollageBuilder.cs @@ -49,7 +49,9 @@ namespace Emby.Drawing.Skia { using (var outputStream = new SKFileWStream(outputPath)) { - bitmap.Encode(outputStream, GetEncodedFormat(outputPath), 90); + SKImageInfo imageInfo = new SKImageInfo(width, height); + var pixmap = new SKPixmap(new SKImageInfo(width, height), bitmap.GetPixels()); + pixmap.Encode(outputStream, GetEncodedFormat(outputPath), 90); } } } @@ -60,7 +62,9 @@ namespace Emby.Drawing.Skia { using (var outputStream = new SKFileWStream(outputPath)) { - bitmap.Encode(outputStream, GetEncodedFormat(outputPath), 90); + SKImageInfo imageInfo = new SKImageInfo(width, height); + var pixmap = new SKPixmap(new SKImageInfo(width, height), bitmap.GetPixels()); + pixmap.Encode(outputStream, GetEncodedFormat(outputPath), 90); } } } @@ -83,9 +87,8 @@ namespace Emby.Drawing.Skia for (int i = 0; i < 4; i++) { - int newIndex; - using (var currentBitmap = GetNextValidImage(paths, imageIndex, out newIndex)) + using (var currentBitmap = GetNextValidImage(paths, imageIndex, out int newIndex)) { imageIndex = newIndex; @@ -98,7 +101,7 @@ namespace Emby.Drawing.Skia int iWidth = (int)Math.Abs(iHeight * currentBitmap.Width / currentBitmap.Height); using (var resizeBitmap = new SKBitmap(iWidth, iHeight, currentBitmap.ColorType, currentBitmap.AlphaType)) { - currentBitmap.Resize(resizeBitmap, SKBitmapResizeMethod.Lanczos3); + currentBitmap.ScalePixels(resizeBitmap, SKFilterQuality.High); // crop image int ix = (int)Math.Abs((iWidth - iSlice) / 2); using (var image = SKImage.FromBitmap(resizeBitmap)) @@ -116,7 +119,7 @@ namespace Emby.Drawing.Skia using (var reflectionBitmap = new SKBitmap(croppedBitmap.Width, croppedBitmap.Height / 2, croppedBitmap.ColorType, croppedBitmap.AlphaType)) { // resize to half height - croppedBitmap.Resize(reflectionBitmap, SKBitmapResizeMethod.Lanczos3); + currentBitmap.ScalePixels(reflectionBitmap, SKFilterQuality.High); using (var flippedBitmap = new SKBitmap(reflectionBitmap.Width, reflectionBitmap.Height, reflectionBitmap.ColorType, reflectionBitmap.AlphaType)) using (var flippedCanvas = new SKCanvas(flippedBitmap)) @@ -164,8 +167,7 @@ namespace Emby.Drawing.Skia currentIndex = 0; } - SKEncodedOrigin origin; - bitmap = SkiaEncoder.Decode(paths[currentIndex], false, _fileSystem, null, out origin); + bitmap = SkiaEncoder.Decode(paths[currentIndex], false, _fileSystem, null, out SKEncodedOrigin origin); imagesTested[currentIndex] = 0; @@ -194,9 +196,8 @@ namespace Emby.Drawing.Skia { for (var y = 0; y < 2; y++) { - int newIndex; - using (var currentBitmap = GetNextValidImage(paths, imageIndex, out newIndex)) + using (var currentBitmap = GetNextValidImage(paths, imageIndex, out int newIndex)) { imageIndex = newIndex; @@ -208,7 +209,7 @@ namespace Emby.Drawing.Skia using (var resizedBitmap = new SKBitmap(cellWidth, cellHeight, currentBitmap.ColorType, currentBitmap.AlphaType)) { // scale image - currentBitmap.Resize(resizedBitmap, SKBitmapResizeMethod.Lanczos3); + currentBitmap.ScalePixels(resizedBitmap, SKFilterQuality.High); // draw this image into the strip at the next position var xPos = x * cellWidth; From 635dd36727f3c779cad8a3b56625bcfbea8ee286 Mon Sep 17 00:00:00 2001 From: Erwin de Haan Date: Thu, 3 Jan 2019 19:11:18 +0100 Subject: [PATCH 2/2] Put all pixmap constructors in `using` statements. Cleanup extra ImageInfo as well --- Emby.Drawing.Skia/SkiaEncoder.cs | 16 +++++++++------- Emby.Drawing.Skia/StripCollageBuilder.cs | 14 ++++++++------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Emby.Drawing.Skia/SkiaEncoder.cs b/Emby.Drawing.Skia/SkiaEncoder.cs index b96d46832d..0467794dc9 100644 --- a/Emby.Drawing.Skia/SkiaEncoder.cs +++ b/Emby.Drawing.Skia/SkiaEncoder.cs @@ -556,10 +556,11 @@ namespace Emby.Drawing.Skia _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(outputPath)); using (var outputStream = new SKFileWStream(outputPath)) { - SKImageInfo imageInfo = new SKImageInfo(width,height); - var pixmap = new SKPixmap(new SKImageInfo(width, height), resizedBitmap.GetPixels()); - pixmap.Encode(outputStream, skiaOutputFormat, quality); - return outputPath; + using (var pixmap = new SKPixmap(new SKImageInfo(width, height), resizedBitmap.GetPixels())) + { + pixmap.Encode(outputStream, skiaOutputFormat, quality); + return outputPath; + } } } @@ -609,9 +610,10 @@ namespace Emby.Drawing.Skia _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(outputPath)); using (var outputStream = new SKFileWStream(outputPath)) { - SKImageInfo imageInfo = new SKImageInfo(width, height); - var pixmap = new SKPixmap(new SKImageInfo(width, height), saveBitmap.GetPixels()); - pixmap.Encode(outputStream, skiaOutputFormat, quality); + using (var pixmap = new SKPixmap(new SKImageInfo(width, height), saveBitmap.GetPixels())) + { + pixmap.Encode(outputStream, skiaOutputFormat, quality); + } } } } diff --git a/Emby.Drawing.Skia/StripCollageBuilder.cs b/Emby.Drawing.Skia/StripCollageBuilder.cs index 2528fbc567..a98450e08b 100644 --- a/Emby.Drawing.Skia/StripCollageBuilder.cs +++ b/Emby.Drawing.Skia/StripCollageBuilder.cs @@ -49,9 +49,10 @@ namespace Emby.Drawing.Skia { using (var outputStream = new SKFileWStream(outputPath)) { - SKImageInfo imageInfo = new SKImageInfo(width, height); - var pixmap = new SKPixmap(new SKImageInfo(width, height), bitmap.GetPixels()); - pixmap.Encode(outputStream, GetEncodedFormat(outputPath), 90); + using (var pixmap = new SKPixmap(new SKImageInfo(width, height), bitmap.GetPixels())) + { + pixmap.Encode(outputStream, GetEncodedFormat(outputPath), 90); + } } } } @@ -62,9 +63,10 @@ namespace Emby.Drawing.Skia { using (var outputStream = new SKFileWStream(outputPath)) { - SKImageInfo imageInfo = new SKImageInfo(width, height); - var pixmap = new SKPixmap(new SKImageInfo(width, height), bitmap.GetPixels()); - pixmap.Encode(outputStream, GetEncodedFormat(outputPath), 90); + using (var pixmap = new SKPixmap(new SKImageInfo(width, height), bitmap.GetPixels())) + { + pixmap.Encode(outputStream, GetEncodedFormat(outputPath), 90); + } } } }