mirror of
https://github.com/DarthAffe/StableDiffusion.NET.git
synced 2025-12-12 13:28:35 +00:00
Fixed wrong free of upscaled images
This commit is contained in:
parent
eea9a9afe8
commit
46bba39c4a
@ -8,21 +8,29 @@ internal static class ImageHelper
|
||||
{
|
||||
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 = ToImage(*sdImage);
|
||||
|
||||
Image<ColorRGB> image = Image<ColorRGB>.Create(new ReadOnlySpan<byte>(sdImage->data, width * height * bpp), width, height, width * bpp);
|
||||
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);
|
||||
|
||||
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);
|
||||
Marshal.FreeHGlobal((nint)image.data);
|
||||
}
|
||||
|
||||
public static unsafe Native.sd_image_t ToSdImage(this IImage<ColorRGB> image, byte* pinnedReference)
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user