From f931ce76061018a7cc7d43be97a4cbee06a0a9e5 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 10 May 2016 06:02:00 +0200 Subject: [PATCH] Adds conversion when color shifts are BGRA --- libretro-common/formats/jpeg/rjpeg.c | 37 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/libretro-common/formats/jpeg/rjpeg.c b/libretro-common/formats/jpeg/rjpeg.c index 44be7d75ad..341cdc43f8 100644 --- a/libretro-common/formats/jpeg/rjpeg.c +++ b/libretro-common/formats/jpeg/rjpeg.c @@ -2361,6 +2361,24 @@ static int stbi__jpeg_test(stbi__context *s) } #endif +static INLINE void video_frame_convert_rgba_to_bgra( + const void *src_data, + void *dst_data, + unsigned width) +{ + unsigned x; + uint8_t *dst = (uint8_t*)dst_data; + const uint8_t *src = (const uint8_t*)src_data; + + for (x = 0; x < width; x++, dst += 4, src += 4) + { + dst[3] = src[3]; + dst[0] = src[2]; + dst[1] = src[1]; + dst[2] = src[0]; + } +} + bool rjpeg_image_load(uint8_t *_buf, void *data, size_t size, unsigned a_shift, unsigned r_shift, unsigned g_shift, unsigned b_shift) @@ -2369,25 +2387,14 @@ bool rjpeg_image_load(uint8_t *_buf, void *data, size_t size, int x, y, comp; struct texture_image *out_img = (struct texture_image*)data; - out_img->pixels = stbi_load_from_memory(_buf, size, &x, &y, &comp, 4); + out_img->pixels = (uint32_t*)stbi_load_from_memory(_buf, size, &x, &y, &comp, 4); out_img->width = x; out_img->height = y; -#if 0 - for (i = 0; i < (x * y); i++) - { - uint32_t r = (_buf[i] & 0xff00ff00); - uint32_t g = ((_buf[i] << 16) & 0x00ff0000); - uint32_t b = ((_buf[i] >> 16) & 0xff); - - if (r_shift == 0 && b_shift == 16) - out_img->pixels[i] = _buf[i]; - else - out_img->pixels[i] = r | g | b; - //out_img->pixels[i] = (r << r_shift) | (g << g_shift) || (b << b_shift); - } -#endif + if (r_shift == 0 && b_shift == 16) { } /* RGBA, doesn't need conversion */ + else + video_frame_convert_rgba_to_bgra(_buf, out_img->pixels, x); return true; }