Compare commits

..

No commits in common. "d25eb9716854c0a550e572746b81a841726eab90" and "eea9a9afe8bdd61b060b252c8e5a84d56b2fd5f1" have entirely different histories.

2 changed files with 9 additions and 17 deletions

View File

@ -8,29 +8,21 @@ internal static class ImageHelper
{
public static unsafe Image<ColorRGB> ToImage(Native.sd_image_t* sdImage)
{
Image<ColorRGB> image = ToImage(*sdImage);
int width = (int)sdImage->width;
int height = (int)sdImage->height;
int bpp = (int)sdImage->channel;
Marshal.FreeHGlobal((nint)sdImage);
return image;
}
public static unsafe Image<ColorRGB> ToImage(Native.sd_image_t sdImage)
{
int width = (int)sdImage.width;
int height = (int)sdImage.height;
int bpp = (int)sdImage.channel;
Image<ColorRGB> image = Image<ColorRGB>.Create(new ReadOnlySpan<byte>(sdImage.data, width * height * bpp), width, height, width * bpp);
Image<ColorRGB> image = Image<ColorRGB>.Create(new ReadOnlySpan<byte>(sdImage->data, width * height * bpp), width, height, width * bpp);
Dispose(sdImage);
return image;
}
public static unsafe void Dispose(Native.sd_image_t image)
public static unsafe void Dispose(Native.sd_image_t* image)
{
Marshal.FreeHGlobal((nint)image.data);
Marshal.FreeHGlobal((nint)image->data);
Marshal.FreeHGlobal((nint)image);
}
public static unsafe Native.sd_image_t ToSdImage(this IImage<ColorRGB> image, byte* pinnedReference)

View File

@ -58,14 +58,14 @@ public sealed unsafe class UpscaleModel : IDisposable
fixed (byte* imagePtr = sourceImage.AsRefImage())
{
Native.sd_image_t result = Native.upscale(_ctx, sourceImage.ToSdImage(imagePtr), upscaleFactor);
return ImageHelper.ToImage(result);
return ImageHelper.ToImage(&result);
}
}
private IImage<ColorRGB> Upscale(Native.sd_image_t image, int upscaleFactor)
{
Native.sd_image_t result = Native.upscale(_ctx, image, upscaleFactor);
return ImageHelper.ToImage(result);
return ImageHelper.ToImage(&result);
}
public void Dispose()