add byteswap support to read framebuffer (#512)

This commit is contained in:
Archez
2024-04-25 18:00:27 -04:00
committed by GitHub
parent 1d70eb42b1
commit dedff4fd92
2 changed files with 19 additions and 8 deletions
+8 -8
View File
@@ -2680,14 +2680,14 @@ typedef union {
}
// Read the framebuffer's texture to a cpu memory location as RGBA16
#define gDPReadFB(pkt, src, rgba16buf, ulx, uly, width, height) \
{ \
Gfx *_g0 = (Gfx*)(pkt), *_g1 = (Gfx*)(pkt); \
\
_g0->words.w0 = _SHIFTL(G_READFB, 24, 8) | _SHIFTL(src, 0, 8); \
_g0->words.w1 = (uintptr_t)rgba16buf; \
_g1->words.w0 = _SHIFTL(uly, 16, 16) | _SHIFTL(ulx, 0, 16); \
_g1->words.w1 = _SHIFTL(height, 16, 16) | _SHIFTL(width, 0, 16); \
#define gDPReadFB(pkt, src, rgba16buf, ulx, uly, width, height, bswap) \
{ \
Gfx *_g0 = (Gfx*)(pkt), *_g1 = (Gfx*)(pkt); \
\
_g0->words.w0 = _SHIFTL(G_READFB, 24, 8) | _SHIFTL(bswap, 8, 1) | _SHIFTL(src, 0, 8); \
_g0->words.w1 = (uintptr_t)rgba16buf; \
_g1->words.w0 = _SHIFTL(uly, 16, 16) | _SHIFTL(ulx, 0, 16); \
_g1->words.w1 = _SHIFTL(height, 16, 16) | _SHIFTL(width, 0, 16); \
}
#define gDPImageRectangle(pkt, x0, y0, s0, t0, x1, y1, s1, t1, tile, iw, ih) \
+11
View File
@@ -3306,6 +3306,7 @@ bool gfx_read_fb_handler_custom(Gfx** cmd0) {
int32_t width, height, ulx, uly;
uint16_t* rgba16Buffer = (uint16_t*)cmd->words.w1;
int fbId = C0(0, 8);
bool bswap = C0(8, 1);
++(*cmd0);
cmd = *cmd0;
// Specifying the upper left origin value is unused and unsupported at the renderer level
@@ -3316,6 +3317,16 @@ bool gfx_read_fb_handler_custom(Gfx** cmd0) {
gfx_flush();
gfx_rapi->read_framebuffer_to_cpu(fbId, width, height, rgba16Buffer);
#ifndef IS_BIGENDIAN
// byteswap the output to BE
if (bswap) {
for (size_t i = 0; i < width * height; i++) {
rgba16Buffer[i] = BE16SWAP(rgba16Buffer[i]);
}
}
#endif
return false;
}