From 12b15812f294907c5aa9b2616087817e400c7869 Mon Sep 17 00:00:00 2001 From: TuxSH <1922548+TuxSH@users.noreply.github.com> Date: Wed, 30 Jul 2025 12:53:46 +0200 Subject: [PATCH] rosalina: make sure pixel data is aligned in screenshots --- sysmodules/rosalina/source/draw.c | 12 ++++++++---- sysmodules/rosalina/source/menus.c | 5 +++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sysmodules/rosalina/source/draw.c b/sysmodules/rosalina/source/draw.c index 84d8d811..ed1d9982 100644 --- a/sysmodules/rosalina/source/draw.c +++ b/sysmodules/rosalina/source/draw.c @@ -268,14 +268,18 @@ static inline void Draw_WriteUnaligned(u8 *dst, u32 tmp, u32 size) void Draw_CreateBitmapHeader(u8 *dst, u32 width, u32 heigth) { static const u8 bmpHeaderTemplate[54] = { - 0x42, 0x4D, 0xCC, 0xCC, 0xCC, 0xCC, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, - 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, - 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x00, 0x00, + // BITMAPFILEHEADER + 0x42, 0x4D, 0xCC, 0xCC, 0xCC, 0xCC, 0x00, 0x00, 0x00, 0x00, 0x40 /* data offset */, 0x00, 0x00, 0x00, + + // BITMAPINFOHEADER + 0x28, 0x00, 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x01, 0x00, 0x18, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xCC, 0xCC, 0xCC, 0xCC, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; memcpy(dst, bmpHeaderTemplate, 54); - Draw_WriteUnaligned(dst + 2, 54 + 3 * width * heigth, 4); + memset(dst + 54, 0, 64 - 54); + Draw_WriteUnaligned(dst + 2, 64 + 3 * width * heigth, 4); Draw_WriteUnaligned(dst + 0x12, width, 4); Draw_WriteUnaligned(dst + 0x16, heigth, 4); Draw_WriteUnaligned(dst + 0x22, 3 * width * heigth, 4); diff --git a/sysmodules/rosalina/source/menus.c b/sysmodules/rosalina/source/menus.c index 569cf22d..4f45492d 100644 --- a/sysmodules/rosalina/source/menus.c +++ b/sysmodules/rosalina/source/menus.c @@ -273,7 +273,8 @@ static Result RosalinaMenu_WriteScreenshot(IFile *file, u32 width, bool top, boo u8 *buf = framebufferCache; Draw_CreateBitmapHeader(framebufferCache, width, numLinesScaled); - buf += 54; + const u32 headerSize = 0x40; + buf += headerSize; u32 y = 0; // Our buffer might be smaller than the size of the screenshot... @@ -287,7 +288,7 @@ static Result RosalinaMenu_WriteScreenshot(IFile *file, u32 width, bool top, boo s64 t1 = svcGetSystemTick(); timeSpentConvertingScreenshot += t1 - t0; - TRY(IFile_Write(file, &total, framebufferCache, (y == 0 ? 54 : 0) + lineSize * nlines * scaleFactorY, 0)); // don't forget to write the header + TRY(IFile_Write(file, &total, framebufferCache, (y == 0 ? headerSize : 0) + lineSize * nlines * scaleFactorY, 0)); // don't forget to write the header timeSpentWritingScreenshot += svcGetSystemTick() - t1; y += nlines;