Skip to content

Commit 7467adb

Browse files
committed
fixup! feat: Xplat support for image loading and saving from memory
1 parent 688a4eb commit 7467adb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

sources/engine/Stride/Graphics/StandardImageHelper.Desktop.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static unsafe Image LoadFromMemory(IntPtr pSource, int size, bool makeACo
3333
// Directly load image as RGBA instead of BGRA, because OpenGL ES devices don't support it out of the box (extension).
3434
//image.Description.Format = PixelFormat.R8G8B8A8_UNorm;
3535
//CopyMemoryBGRA(image.PixelBuffer[0].DataPointer, bitmapData.Scan0, image.PixelBuffer[0].BufferStride);
36-
Unsafe.CopyBlockUnaligned((void*)image.PixelBuffer[0].DataPointer, (void*)bitmapData.Scan0, (uint)bitmap.Width * 4);
36+
Unsafe.CopyBlockUnaligned((void*)image.PixelBuffer[0].DataPointer, (void*)bitmapData.Scan0, (uint)image.PixelBuffer[0].BufferStride);
3737
}
3838
finally
3939
{
@@ -94,17 +94,17 @@ private static unsafe void SaveFromMemory(PixelBuffer[] pixelBuffers, ImageDescr
9494
var format = description.Format;
9595
if (format is PixelFormat.R8G8B8A8_UNorm or PixelFormat.R8G8B8A8_UNorm_SRgb)
9696
{
97-
CopyMemoryBGRA(bitmapData.Scan0, pixelBuffers[0].DataPointer, bitmap.Width * 4);
97+
CopyMemoryBGRA(bitmapData.Scan0, pixelBuffers[0].DataPointer, pixelBuffers[0].BufferStride);
9898
}
9999
else if (format is PixelFormat.B8G8R8A8_UNorm or PixelFormat.B8G8R8A8_UNorm_SRgb)
100100
{
101-
Unsafe.CopyBlockUnaligned((void*)bitmapData.Scan0, (void*)pixelBuffers[0].DataPointer, (uint)bitmap.Width * 4);
101+
Unsafe.CopyBlockUnaligned((void*)bitmapData.Scan0, (void*)pixelBuffers[0].DataPointer, (uint)pixelBuffers[0].BufferStride);
102102
}
103103
else if (format is PixelFormat.R8_UNorm or PixelFormat.A8_UNorm)
104104
{
105105
// TODO Ideally we will want to support grayscale images, but the SpriteBatch can only render RGBA for now
106106
// so convert the grayscale image as an RGBA and save it
107-
CopyMemoryRRR1(bitmapData.Scan0, pixelBuffers[0].DataPointer, bitmap.Width * 4);
107+
CopyMemoryRRR1(bitmapData.Scan0, pixelBuffers[0].DataPointer, pixelBuffers[0].BufferStride);
108108
}
109109
else
110110
{

0 commit comments

Comments
 (0)