Skip to content

Commit 988ec17

Browse files
committed
Screenshots: when dealing with 800px mode, produce 800x480 instead of 800x240 images for more faithful output
Each line is duplicated in this case (integer scaling 2)
1 parent 52a1f4a commit 988ec17

3 files changed

Lines changed: 23 additions & 14 deletions

File tree

sysmodules/rosalina/include/draw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ u32 Draw_GetCurrentFramebufferAddress(bool top, bool left);
108108
void Draw_GetCurrentScreenInfo(u32 *width, bool *is3d, bool top);
109109

110110
void Draw_CreateBitmapHeader(u8 *dst, u32 width, u32 heigth);
111-
void Draw_ConvertFrameBufferLines(u8 *buf, u32 width, u32 startingLine, u32 numLines, bool top, bool left);
111+
void Draw_ConvertFrameBufferLines(u8 *buf, u32 width, u32 startingLine, u32 numLines, u32 scaleFactorY, bool top, bool left);

sysmodules/rosalina/source/draw.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ u32 Draw_SetupFramebuffer(void)
203203
GPU_FB_BOTTOM_ADDR_1 = GPU_FB_BOTTOM_ADDR_2 = FB_BOTTOM_VRAM_PA;
204204
GPU_FB_BOTTOM_FMT = format;
205205
GPU_FB_BOTTOM_STRIDE = 240 * 2;
206-
206+
207207
gpuSavedFillColor = LCD_BOT_FILLCOLOR;
208208
LCD_BOT_FILLCOLOR = 0;
209209

@@ -214,7 +214,7 @@ void Draw_RestoreFramebuffer(void)
214214
{
215215
memcpy(FB_BOTTOM_VRAM_ADDR, framebufferCache, FB_BOTTOM_SIZE);
216216
Draw_FlushFramebuffer();
217-
217+
218218
LCD_BOT_FILLCOLOR = gpuSavedFillColor;
219219
GPU_FB_BOTTOM_ADDR_1 = gpuSavedFramebufferAddr1;
220220
GPU_FB_BOTTOM_ADDR_2 = gpuSavedFramebufferAddr2;
@@ -350,6 +350,7 @@ typedef struct FrameBufferConvertArgs {
350350
u32 width;
351351
u8 startingLine;
352352
u8 numLines;
353+
u8 scaleFactorY;
353354
bool top;
354355
bool left;
355356
} FrameBufferConvertArgs;
@@ -367,16 +368,19 @@ static void Draw_ConvertFrameBufferLinesKernel(const FrameBufferConvertArgs *arg
367368

368369
for (u32 y = args->startingLine; y < args->startingLine + args->numLines; y++)
369370
{
370-
for(u32 x = 0; x < width; x++)
371+
for (u8 i = 0; i < args->scaleFactorY; i++)
371372
{
372-
__builtin_prefetch(addr + x * stride + y * formatSizes[fmt], 0, 3);
373-
Draw_ConvertPixelToBGR8(args->buf + (x + width * y) * 3 , addr + x * stride + y * formatSizes[fmt], fmt);
373+
for(u32 x = 0; x < width; x++)
374+
{
375+
__builtin_prefetch(addr + x * stride + y * formatSizes[fmt], 0, 3);
376+
Draw_ConvertPixelToBGR8(args->buf + (x + width * (args->scaleFactorY * y + i)) * 3 , addr + x * stride + y * formatSizes[fmt], fmt);
377+
}
374378
}
375379
}
376380
}
377381

378-
void Draw_ConvertFrameBufferLines(u8 *buf, u32 width, u32 startingLine, u32 numLines, bool top, bool left)
382+
void Draw_ConvertFrameBufferLines(u8 *buf, u32 width, u32 startingLine, u32 numLines, u32 scaleFactorY, bool top, bool left)
379383
{
380-
FrameBufferConvertArgs args = { buf, width, (u8)startingLine, (u8)numLines, top, left };
384+
FrameBufferConvertArgs args = { buf, width, (u8)startingLine, (u8)numLines, (u8)scaleFactorY, top, left };
381385
svcCustomBackdoor(Draw_ConvertFrameBufferLinesKernel, &args);
382386
}

sysmodules/rosalina/source/menus.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,20 @@ static Result RosalinaMenu_WriteScreenshot(IFile *file, u32 width, bool top, boo
362362
u64 total;
363363
Result res = 0;
364364
u32 lineSize = 3 * width;
365-
u32 remaining = lineSize * 240;
365+
366+
// When dealing with 800px mode (800x240 with half-width pixels), duplicate each line
367+
// to restore aspect ratio and obtain faithful 800x480 screenshots
368+
u32 scaleFactorY = width > 400 ? 2 : 1;
369+
u32 numLinesScaled = 240 * scaleFactorY;
370+
u32 remaining = lineSize * numLinesScaled;
366371

367372
TRY(Draw_AllocateFramebufferCacheForScreenshot(remaining));
368373

369374
u8 *framebufferCache = (u8 *)Draw_GetFramebufferCache();
370375
u8 *framebufferCacheEnd = framebufferCache + Draw_GetFramebufferCacheSize();
371376

372377
u8 *buf = framebufferCache;
373-
Draw_CreateBitmapHeader(framebufferCache, width, 240);
378+
Draw_CreateBitmapHeader(framebufferCache, width, numLinesScaled);
374379
buf += 54;
375380

376381
u32 y = 0;
@@ -380,16 +385,16 @@ static Result RosalinaMenu_WriteScreenshot(IFile *file, u32 width, bool top, boo
380385
s64 t0 = svcGetSystemTick();
381386
u32 available = (u32)(framebufferCacheEnd - buf);
382387
u32 size = available < remaining ? available : remaining;
383-
u32 nlines = size / lineSize;
384-
Draw_ConvertFrameBufferLines(buf, width, y, nlines, top, left);
388+
u32 nlines = size / (lineSize * scaleFactorY);
389+
Draw_ConvertFrameBufferLines(buf, width, y, nlines, scaleFactorY, top, left);
385390

386391
s64 t1 = svcGetSystemTick();
387392
timeSpentConvertingScreenshot += t1 - t0;
388-
TRY(IFile_Write(file, &total, framebufferCache, (y == 0 ? 54 : 0) + lineSize * nlines, 0)); // don't forget to write the header
393+
TRY(IFile_Write(file, &total, framebufferCache, (y == 0 ? 54 : 0) + lineSize * nlines * scaleFactorY, 0)); // don't forget to write the header
389394
timeSpentWritingScreenshot += svcGetSystemTick() - t1;
390395

391396
y += nlines;
392-
remaining -= lineSize * nlines;
397+
remaining -= lineSize * nlines * scaleFactorY;
393398
buf = framebufferCache;
394399
}
395400
end:

0 commit comments

Comments
 (0)