mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 03:26:07 +02:00
refactor: cache the resize image filter
This commit is contained in:
parent
42a7e4cf1a
commit
0a284dc0ab
1 changed files with 25 additions and 19 deletions
|
@ -27,6 +27,30 @@ public class SkiaEncoder : IImageEncoder
|
||||||
|
|
||||||
private readonly ILogger<SkiaEncoder> _logger;
|
private readonly ILogger<SkiaEncoder> _logger;
|
||||||
private readonly IApplicationPaths _appPaths;
|
private readonly IApplicationPaths _appPaths;
|
||||||
|
private static readonly SKImageFilter _imageFilter;
|
||||||
|
|
||||||
|
#pragma warning disable CA1810
|
||||||
|
static SkiaEncoder()
|
||||||
|
#pragma warning restore CA1810
|
||||||
|
{
|
||||||
|
var kernel = new[]
|
||||||
|
{
|
||||||
|
0, -.1f, 0,
|
||||||
|
-.1f, 1.4f, -.1f,
|
||||||
|
0, -.1f, 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
var kernelSize = new SKSizeI(3, 3);
|
||||||
|
var kernelOffset = new SKPointI(1, 1);
|
||||||
|
_imageFilter = SKImageFilter.CreateMatrixConvolution(
|
||||||
|
kernelSize,
|
||||||
|
kernel,
|
||||||
|
1f,
|
||||||
|
0f,
|
||||||
|
kernelOffset,
|
||||||
|
SKShaderTileMode.Clamp,
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SkiaEncoder"/> class.
|
/// Initializes a new instance of the <see cref="SkiaEncoder"/> class.
|
||||||
|
@ -357,25 +381,7 @@ public class SkiaEncoder : IImageEncoder
|
||||||
IsDither = isDither
|
IsDither = isDither
|
||||||
};
|
};
|
||||||
|
|
||||||
var kernel = new float[9]
|
paint.ImageFilter = _imageFilter;
|
||||||
{
|
|
||||||
0, -.1f, 0,
|
|
||||||
-.1f, 1.4f, -.1f,
|
|
||||||
0, -.1f, 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
var kernelSize = new SKSizeI(3, 3);
|
|
||||||
var kernelOffset = new SKPointI(1, 1);
|
|
||||||
|
|
||||||
paint.ImageFilter = SKImageFilter.CreateMatrixConvolution(
|
|
||||||
kernelSize,
|
|
||||||
kernel,
|
|
||||||
1f,
|
|
||||||
0f,
|
|
||||||
kernelOffset,
|
|
||||||
SKShaderTileMode.Clamp,
|
|
||||||
true);
|
|
||||||
|
|
||||||
canvas.DrawBitmap(
|
canvas.DrawBitmap(
|
||||||
source,
|
source,
|
||||||
SKRect.Create(0, 0, source.Width, source.Height),
|
SKRect.Create(0, 0, source.Width, source.Height),
|
||||||
|
|
Loading…
Reference in a new issue