Skip to content

Commit

Permalink
Don't use .copy, it's evil and mean
Browse files Browse the repository at this point in the history
  • Loading branch information
PassiveModding committed Oct 3, 2024
1 parent ee8745f commit c3190b1
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Meddle/Meddle.Utils/Helpers/ImageUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,18 @@ public static unsafe SKBitmap ToBitmap(this TextureResource resource)
{
bitmap.InstallPixels(bitmap.Info, (nint)data, rgba.Meta.Width * 4);
}
bitmap.SetImmutable();

return bitmap.Copy() ?? throw new InvalidOperationException("Failed to copy bitmap.");
// bitmap.SetImmutable();
//
// return bitmap.Copy() ?? throw new InvalidOperationException("Failed to copy bitmap.");
var copy = new SKBitmap(rgba.Meta.Width, rgba.Meta.Height, SKColorType.Rgba8888, SKAlphaType.Unpremul);
var pixelBuf = copy.GetPixelSpan().ToArray();
bitmap.GetPixelSpan().CopyTo(pixelBuf);
fixed (byte* data = pixelBuf)
{
copy.InstallPixels(copy.Info, (nint)data, copy.Info.RowBytes);
}

return copy;
}

public static TexMeta FromResource(TextureResource resource)
Expand Down

0 comments on commit c3190b1

Please sign in to comment.