aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFernando Fernández <ferferga@hotmail.com>2025-04-01 01:45:03 +0200
committerGitHub <noreply@github.com>2025-03-31 17:45:03 -0600
commit2b742a59665e5579c4ac4d38a62f95aa9ff5365a (patch)
tree11fc50235053777693a83fff15525d1f1add3107
parent5769c398c6bf5e23bac4063cdb17859b10fe37c7 (diff)
Reduce SKImage to SKBitmap conversion, high quality canvas (#5366)
-rw-r--r--src/Jellyfin.Drawing.Skia/SkiaEncoder.cs20
-rw-r--r--src/Jellyfin.Drawing.Skia/StripCollageBuilder.cs18
2 files changed, 19 insertions, 19 deletions
diff --git a/src/Jellyfin.Drawing.Skia/SkiaEncoder.cs b/src/Jellyfin.Drawing.Skia/SkiaEncoder.cs
index 99f7fa7f9..73c8c3966 100644
--- a/src/Jellyfin.Drawing.Skia/SkiaEncoder.cs
+++ b/src/Jellyfin.Drawing.Skia/SkiaEncoder.cs
@@ -557,20 +557,14 @@ public class SkiaEncoder : IImageEncoder
canvas.Clear(SKColor.Parse(options.BackgroundColor));
}
+ using var paint = new SKPaint();
// Add blur if option is present
- if (blur > 0)
- {
- // create image from resized bitmap to apply blur
- using var paint = new SKPaint();
- using var filter = SKImageFilter.CreateBlur(blur, blur);
- paint.ImageFilter = filter;
- canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height), paint);
- }
- else
- {
- // draw resized bitmap onto canvas
- canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height));
- }
+ using var filter = blur > 0 ? SKImageFilter.CreateBlur(blur, blur) : null;
+ paint.FilterQuality = SKFilterQuality.High;
+ paint.ImageFilter = filter;
+
+ // create image from resized bitmap to apply blur
+ canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height), paint);
// If foreground layer present then draw
if (hasForegroundColor)
diff --git a/src/Jellyfin.Drawing.Skia/StripCollageBuilder.cs b/src/Jellyfin.Drawing.Skia/StripCollageBuilder.cs
index b0c9c0b3c..03e202e5a 100644
--- a/src/Jellyfin.Drawing.Skia/StripCollageBuilder.cs
+++ b/src/Jellyfin.Drawing.Skia/StripCollageBuilder.cs
@@ -109,15 +109,18 @@ public partial class StripCollageBuilder
// resize to the same aspect as the original
var backdropHeight = Math.Abs(width * backdrop.Height / backdrop.Width);
- using var residedBackdrop = SkiaEncoder.ResizeImage(backdrop, new SKImageInfo(width, backdropHeight, backdrop.ColorType, backdrop.AlphaType, backdrop.ColorSpace));
+ using var resizedBackdrop = SkiaEncoder.ResizeImage(backdrop, new SKImageInfo(width, backdropHeight, backdrop.ColorType, backdrop.AlphaType, backdrop.ColorSpace));
+ using var paint = new SKPaint();
+ paint.FilterQuality = SKFilterQuality.High;
// draw the backdrop
- canvas.DrawImage(residedBackdrop, 0, 0);
+ canvas.DrawImage(resizedBackdrop, 0, 0, paint);
// draw shadow rectangle
using var paintColor = new SKPaint
{
Color = SKColors.Black.WithAlpha(0x78),
- Style = SKPaintStyle.Fill
+ Style = SKPaintStyle.Fill,
+ FilterQuality = SKFilterQuality.High
};
canvas.DrawRect(0, 0, width, height, paintColor);
@@ -131,7 +134,8 @@ public partial class StripCollageBuilder
TextSize = 112,
TextAlign = SKTextAlign.Left,
Typeface = typeFace,
- IsAntialias = true
+ IsAntialias = true,
+ FilterQuality = SKFilterQuality.High
};
// scale down text to 90% of the width if text is larger than 95% of the width
@@ -188,14 +192,16 @@ public partial class StripCollageBuilder
continue;
}
- // Scale image. The FromBitmap creates a copy
+ // Scale image
var imageInfo = new SKImageInfo(cellWidth, cellHeight, currentBitmap.ColorType, currentBitmap.AlphaType, currentBitmap.ColorSpace);
using var resizeImage = SkiaEncoder.ResizeImage(currentBitmap, imageInfo);
+ using var paint = new SKPaint();
+ paint.FilterQuality = SKFilterQuality.High;
// draw this image into the strip at the next position
var xPos = x * cellWidth;
var yPos = y * cellHeight;
- canvas.DrawImage(resizeImage, xPos, yPos);
+ canvas.DrawImage(resizeImage, xPos, yPos, paint);
}
}