From: Paul Cercueil Date: Sat, 21 May 2022 17:58:14 +0000 (+0100) Subject: frontend: Fix colorspace conversion routines on big-endian X-Git-Tag: r24l~454^2~2 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1318072afcc5d037c250e671af32f8d695ba2785;p=pcsx_rearmed.git frontend: Fix colorspace conversion routines on big-endian The bgr555_to_rgb565() and bgr888_to_rgb565() functions were only working correctly on little-endian systems. Signed-off-by: Paul Cercueil --- diff --git a/frontend/cspace.c b/frontend/cspace.c index 55d4ac62..557fe461 100644 --- a/frontend/cspace.c +++ b/frontend/cspace.c @@ -15,21 +15,30 @@ * in favor of NEON version or platform-specific conversion */ +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#define SWAP16(x) __builtin_bswap16(x) +#define LE16TOHx2(x) ((SWAP16((x) >> 16) << 16) | SWAP16(x)) +#else +#define LE16TOHx2(x) (x) +#endif + #ifndef __arm__ void bgr555_to_rgb565(void *dst_, const void *src_, int bytes) { - const unsigned int *src = src_; - unsigned int *dst = dst_; - unsigned int p; - int x; - - for (x = 0; x < bytes / 4; x++) { - p = src[x]; - p = ((p & 0x7c007c00) >> 10) | ((p & 0x03e003e0) << 1) - | ((p & 0x001f001f) << 11); - dst[x] = p; - } + const unsigned int *src = src_; + unsigned int *dst = dst_; + unsigned int x, p, r, g, b; + + for (x = 0; x < bytes / 4; x++) { + p = LE16TOHx2(src[x]); + + r = (p & 0x001f001f) << 11; + g = (p & 0x03e003e0) << 1; + b = (p & 0x7c007c00) >> 10; + + dst[x] = r | g | b; + } } #endif @@ -71,8 +80,13 @@ void bgr888_to_rgb565(void *dst_, const void *src_, int bytes) r2 = src[3] & 0xf8; g2 = src[4] & 0xfc; b2 = src[5] & 0xf8; +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + *dst = (r1 << 24) | (g1 << 19) | (b1 << 13) | + (r2 << 8) | (g2 << 3) | (b2 >> 3); +#else *dst = (r2 << 24) | (g2 << 19) | (b2 << 13) | (r1 << 8) | (g1 << 3) | (b1 >> 3); +#endif } }