mirror of
https://github.com/DarthAffe/HPPH.git
synced 2026-11-09 18:36:34 +00:00
Reduced allocations on image-conversion if the source iamge is already in the correct color-format
This commit is contained in:
1 parent
b66fc3c9e9
commit
ca4e7e7af5
2 files changed
+8
-7
No files matched your search
@@ -21,7 +21,8 @@ public static class ImageExtension
|
||||
|
||||
SKBitmap bitmap = new(image.Width, image.Height, SKColorType.Bgra8888, SKAlphaType.Unpremul);
|
||||
nint pixelPtr = bitmap.GetPixels(out nint length);
|
||||
image.ConvertTo<ColorBGRA>().CopyTo(new Span<byte>((void*)pixelPtr, (int)length));
|
||||
|
||||
(image as IImage<ColorBGRA> ?? image.ConvertTo<ColorBGRA>()).CopyTo(new Span<byte>((void*)pixelPtr, (int)length));
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
@@ -32,9 +33,9 @@ public static class ImageExtension
|
||||
return skImage.Encode(SKEncodedImageFormat.Png, 100).ToArray();
|
||||
}
|
||||
|
||||
public static IImage ToImage(this SKImage skImage) => SKBitmap.FromImage(skImage).ToImage();
|
||||
public static IImage<ColorBGRA> ToImage(this SKImage skImage) => SKBitmap.FromImage(skImage).ToImage();
|
||||
|
||||
public static IImage ToImage(this SKBitmap bitmap)
|
||||
public static IImage<ColorBGRA> ToImage(this SKBitmap bitmap)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(bitmap, nameof(bitmap));
|
||||
|
||||
|
||||
Reference in new issue
Block a user