mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-05-24 02:02:29 -04:00
Reduce SKImage to SKBitmap conversion, high quality canvas (#5366)
This commit is contained in:
parent
5769c398c6
commit
2b742a5966
@ -557,20 +557,14 @@ public class SkiaEncoder : IImageEncoder
|
|||||||
canvas.Clear(SKColor.Parse(options.BackgroundColor));
|
canvas.Clear(SKColor.Parse(options.BackgroundColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using var paint = new SKPaint();
|
||||||
// Add blur if option is present
|
// Add blur if option is present
|
||||||
if (blur > 0)
|
using var filter = blur > 0 ? SKImageFilter.CreateBlur(blur, blur) : null;
|
||||||
{
|
paint.FilterQuality = SKFilterQuality.High;
|
||||||
// create image from resized bitmap to apply blur
|
paint.ImageFilter = filter;
|
||||||
using var paint = new SKPaint();
|
|
||||||
using var filter = SKImageFilter.CreateBlur(blur, blur);
|
// create image from resized bitmap to apply blur
|
||||||
paint.ImageFilter = filter;
|
canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height), paint);
|
||||||
canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height), paint);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// draw resized bitmap onto canvas
|
|
||||||
canvas.DrawBitmap(resizedBitmap, SKRect.Create(width, height));
|
|
||||||
}
|
|
||||||
|
|
||||||
// If foreground layer present then draw
|
// If foreground layer present then draw
|
||||||
if (hasForegroundColor)
|
if (hasForegroundColor)
|
||||||
|
@ -109,15 +109,18 @@ public partial class StripCollageBuilder
|
|||||||
|
|
||||||
// resize to the same aspect as the original
|
// resize to the same aspect as the original
|
||||||
var backdropHeight = Math.Abs(width * backdrop.Height / backdrop.Width);
|
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
|
// draw the backdrop
|
||||||
canvas.DrawImage(residedBackdrop, 0, 0);
|
canvas.DrawImage(resizedBackdrop, 0, 0, paint);
|
||||||
|
|
||||||
// draw shadow rectangle
|
// draw shadow rectangle
|
||||||
using var paintColor = new SKPaint
|
using var paintColor = new SKPaint
|
||||||
{
|
{
|
||||||
Color = SKColors.Black.WithAlpha(0x78),
|
Color = SKColors.Black.WithAlpha(0x78),
|
||||||
Style = SKPaintStyle.Fill
|
Style = SKPaintStyle.Fill,
|
||||||
|
FilterQuality = SKFilterQuality.High
|
||||||
};
|
};
|
||||||
canvas.DrawRect(0, 0, width, height, paintColor);
|
canvas.DrawRect(0, 0, width, height, paintColor);
|
||||||
|
|
||||||
@ -131,7 +134,8 @@ public partial class StripCollageBuilder
|
|||||||
TextSize = 112,
|
TextSize = 112,
|
||||||
TextAlign = SKTextAlign.Left,
|
TextAlign = SKTextAlign.Left,
|
||||||
Typeface = typeFace,
|
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
|
// 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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale image. The FromBitmap creates a copy
|
// Scale image
|
||||||
var imageInfo = new SKImageInfo(cellWidth, cellHeight, currentBitmap.ColorType, currentBitmap.AlphaType, currentBitmap.ColorSpace);
|
var imageInfo = new SKImageInfo(cellWidth, cellHeight, currentBitmap.ColorType, currentBitmap.AlphaType, currentBitmap.ColorSpace);
|
||||||
using var resizeImage = SkiaEncoder.ResizeImage(currentBitmap, imageInfo);
|
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
|
// draw this image into the strip at the next position
|
||||||
var xPos = x * cellWidth;
|
var xPos = x * cellWidth;
|
||||||
var yPos = y * cellHeight;
|
var yPos = y * cellHeight;
|
||||||
canvas.DrawImage(resizeImage, xPos, yPos);
|
canvas.DrawImage(resizeImage, xPos, yPos, paint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user