From 66609852104f0d7dc47d3fd8dd56972b656c0493 Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Wed, 8 Apr 2015 20:21:48 +0200 Subject: [PATCH] Extract a bunch more color conversion loops. --- Common/ColorConv.cpp | 66 +++++++++++++++++++++++++++++++++ Common/ColorConv.h | 23 ++++++------ Core/HW/MediaEngine.cpp | 6 +-- GPU/Directx9/FramebufferDX9.cpp | 19 ++-------- GPU/GLES/Framebuffer.cpp | 27 ++------------ 5 files changed, 86 insertions(+), 55 deletions(-) diff --git a/Common/ColorConv.cpp b/Common/ColorConv.cpp index 14def97a3d..eafd2afe96 100644 --- a/Common/ColorConv.cpp +++ b/Common/ColorConv.cpp @@ -243,3 +243,69 @@ void ConvertRGBA8888ToRGBA4444(u16 *dst, const u32 *src, const u32 numPixels) { dst[x] = RGBA8888toRGBA4444(src[x]); } } + +void ConvertRGBA565ToRGBA8888(u32 *dst32, const u16 *src, const u32 numPixels) { + u8 *dst = (u8 *)dst32; + for (u32 x = 0; x < numPixels; x++) { + u16 col = src[x]; + dst[x * 4] = Convert5To8((col) & 0x1f); + dst[x * 4 + 1] = Convert6To8((col >> 5) & 0x3f); + dst[x * 4 + 2] = Convert5To8((col >> 11) & 0x1f); + dst[x * 4 + 3] = 255; + } +} + +void ConvertRGBA5551ToRGBA8888(u32 *dst32, const u16 *src, const u32 numPixels) { + u8 *dst = (u8 *)dst32; + for (u32 x = 0; x < numPixels; x++) { + u16 col = src[x]; + dst[x * 4] = Convert5To8((col) & 0x1f); + dst[x * 4 + 1] = Convert5To8((col >> 5) & 0x1f); + dst[x * 4 + 2] = Convert5To8((col >> 10) & 0x1f); + dst[x * 4 + 3] = (col >> 15) ? 255 : 0; + } +} + +void ConvertRGBA4444ToRGBA8888(u32 *dst32, const u16 *src, const u32 numPixels) { + u8 *dst = (u8 *)dst32; + for (u32 x = 0; x < numPixels; x++) { + u16 col = src[x]; + dst[x * 4] = Convert4To8((col >> 8) & 0xf); + dst[x * 4 + 1] = Convert4To8((col >> 4) & 0xf); + dst[x * 4 + 2] = Convert4To8(col & 0xf); + dst[x * 4 + 3] = Convert4To8(col >> 12); + } +} + +void ConvertBGRA4444ToRGBA8888(u32 *dst32, const u16 *src, const u32 numPixels) { + u8 *dst = (u8 *)dst32; + for (u32 x = 0; x < numPixels; x++) { + u16 col = src[x]; + dst[x * 4 + 0] = (col >> 12) << 4; + dst[x * 4 + 1] = ((col >> 8) & 0xf) << 4; + dst[x * 4 + 2] = ((col >> 4) & 0xf) << 4; + dst[x * 4 + 3] = (col & 0xf) << 4; + } +} + +inline void ARGB8From565(u16 c, u32 * dst) { + *dst = ((c & 0x001f) << 19) | (((c >> 5) & 0x003f) << 11) | ((((c >> 10) & 0x001f) << 3)) | 0xFF000000; +} + +inline void ARGB8From5551(u16 c, u32 * dst) { + *dst = ((c & 0x001f) << 19) | (((c >> 5) & 0x001f) << 11) | ((((c >> 10) & 0x001f) << 3)) | 0xFF000000; +} + +void ConvertBGRA5551ToRGBA8888(u32 *dst, const u16 *src, const u32 numPixels) { + for (u32 x = 0; x < numPixels; x++) { + u16 col0 = src[x]; + ARGB8From5551(col0, &dst[x]); + } +} + +void ConvertBGR565ToRGBA8888(u32 *dst, const u16 *src, const u32 numPixels) { + for (u32 x = 0; x < numPixels; x++) { + u16 col0 = src[x]; + ARGB8From565(col0, &dst[x]); + } +} \ No newline at end of file diff --git a/Common/ColorConv.h b/Common/ColorConv.h index e2941deebc..2161b3b07e 100644 --- a/Common/ColorConv.h +++ b/Common/ColorConv.h @@ -59,18 +59,6 @@ inline u16 RGBA8888toRGBA5551(u32 px) { return ((px >> 3) & 0x001F) | ((px >> 6) & 0x03E0) | ((px >> 9) & 0x7C00) | ((px >> 16) & 0x8000); } -inline void ARGB8From4444(u16 c, u32 * dst) { - *dst = ((c & 0xf) << 4) | (((c >> 4) & 0xf) << 12) | (((c >> 8) & 0xf) << 20) | ((c >> 12) << 28); -} - -inline void ARGB8From565(u16 c, u32 * dst) { - *dst = ((c & 0x001f) << 19) | (((c >> 5) & 0x003f) << 11) | ((((c >> 10) & 0x001f) << 3)) | 0xFF000000; -} - -inline void ARGB8From5551(u16 c, u32 * dst) { - *dst = ((c & 0x001f) << 19) | (((c >> 5) & 0x001f) << 11) | ((((c >> 10) & 0x001f) << 3)) | 0xFF000000; -} - inline u32 RGBA2BGRA(u32 src) { const u32 r = (src & 0x000000FF) << 16; const u32 ga = src & 0xFF00FF00; @@ -150,6 +138,7 @@ inline u16 RGBA8888To4444(u32 value) { } // convert image to 8888, parallelizable +// TODO: Implement these in terms of the conversion functions below. void convert4444_gl(u16* data, u32* out, int width, int l, int u); void convert565_gl(u16* data, u32* out, int width, int l, int u); void convert5551_gl(u16* data, u32* out, int width, int l, int u); @@ -157,6 +146,8 @@ void convert4444_dx9(u16* data, u32* out, int width, int l, int u); void convert565_dx9(u16* data, u32* out, int width, int l, int u); void convert5551_dx9(u16* data, u32* out, int width, int l, int u); +// "Complete" set of color conversion functions between the usual formats. + void ConvertBGRA8888ToRGBA8888(u32 *dst, const u32 *src, const u32 numPixels); void ConvertRGBA8888ToRGBA5551(u16 *dst, const u32 *src, const u32 numPixels); @@ -166,3 +157,11 @@ void ConvertRGBA8888ToRGBA4444(u16 *dst, const u32 *src, const u32 numPixels); void ConvertBGRA8888ToRGBA5551(u16 *dst, const u32 *src, const u32 numPixels); void ConvertBGRA8888ToRGB565(u16 *dst, const u32 *src, const u32 numPixels); void ConvertBGRA8888ToRGBA4444(u16 *dst, const u32 *src, const u32 numPixels); + +void ConvertRGBA565ToRGBA8888(u32 *dst, const u16 *src, const u32 numPixels); +void ConvertRGBA5551ToRGBA8888(u32 *dst, const u16 *src, const u32 numPixels); +void ConvertRGBA4444ToRGBA8888(u32 *dst, const u16 *src, const u32 numPixels); + +void ConvertBGRA4444ToRGBA8888(u32 *dst, const u16 *src, const u32 numPixels); +void ConvertBGRA5551ToRGBA8888(u32 *dst, const u16 *src, const u32 numPixels); +void ConvertBGR565ToRGBA8888(u32 *dst, const u16 *src, const u32 numPixels); diff --git a/Core/HW/MediaEngine.cpp b/Core/HW/MediaEngine.cpp index 84f6716ee9..d63300241d 100644 --- a/Core/HW/MediaEngine.cpp +++ b/Core/HW/MediaEngine.cpp @@ -566,7 +566,7 @@ inline void writeVideoLineRGBA(void *destp, const void *srcp, int width) { u32_le *dest = (u32_le *)destp; const u32_le *src = (u32_le *)srcp; - u32 mask = 0x00FFFFFF; + const u32 mask = 0x00FFFFFF; for (int i = 0; i < width; ++i) { dest[i] = src[i] & mask; } @@ -581,7 +581,7 @@ inline void writeVideoLineABGR5551(void *destp, const void *srcp, int width) { u16_le *dest = (u16_le *)destp; const u16_le *src = (u16_le *)srcp; - u16 mask = 0x7FFF; + const u16 mask = 0x7FFF; for (int i = 0; i < width; ++i) { dest[i] = src[i] & mask; } @@ -592,7 +592,7 @@ inline void writeVideoLineABGR4444(void *destp, const void *srcp, int width) { u16_le *dest = (u16_le *)destp; const u16_le *src = (u16_le *)srcp; - u16 mask = 0x0FFF; + const u16 mask = 0x0FFF; for (int i = 0; i < width; ++i) { dest[i] = src[i] & mask; } diff --git a/GPU/Directx9/FramebufferDX9.cpp b/GPU/Directx9/FramebufferDX9.cpp index 3f21af445d..ad1b863982 100644 --- a/GPU/Directx9/FramebufferDX9.cpp +++ b/GPU/Directx9/FramebufferDX9.cpp @@ -169,15 +169,11 @@ namespace DX9 { if (srcPixelFormat != GE_FORMAT_8888 || srcStride != 512) { for (int y = 0; y < height; y++) { switch (srcPixelFormat) { - // not tested case GE_FORMAT_565: { const u16_le *src = (const u16_le *)srcPixels + srcStride * y; u32 *dst = (u32 *)(convBuf + rect.Pitch * y); - for (int x = 0; x < width; x++) { - u16_le col0 = src[x+0]; - ARGB8From565(col0, &dst[x + 0]); - } + ConvertBGR565ToRGBA8888(dst, src, width); } break; // faster @@ -185,23 +181,14 @@ namespace DX9 { { const u16_le *src = (const u16_le *)srcPixels + srcStride * y; u32 *dst = (u32 *)(convBuf + rect.Pitch * y); - for (int x = 0; x < width; x++) { - u16_le col0 = src[x+0]; - ARGB8From5551(col0, &dst[x + 0]); - } + ConvertBGRA5551ToRGBA8888(dst, src, width); } break; case GE_FORMAT_4444: { const u16_le *src = (const u16_le *)srcPixels + srcStride * y; u8 *dst = (u8 *)(convBuf + rect.Pitch * y); - for (int x = 0; x < width; x++) { - u16_le col = src[x]; - dst[x * 4 + 0] = (col >> 12) << 4; - dst[x * 4 + 1] = ((col >> 8) & 0xf) << 4; - dst[x * 4 + 2] = ((col >> 4) & 0xf) << 4; - dst[x * 4 + 3] = (col & 0xf) << 4; - } + ConvertBGRA4444ToRGBA8888((u32 *)dst, src, width); } break; diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index 4d193d55da..b1f502c42f 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -405,14 +405,7 @@ void FramebufferManager::MakePixelTexture(const u8 *srcPixels, GEBufferFormat sr { const u16 *src = (const u16 *)srcPixels + srcStride * y; u8 *dst = convBuf_ + 4 * width * y; - for (int x = 0; x < width; x++) - { - u16 col = src[x]; - dst[x * 4] = Convert5To8((col) & 0x1f); - dst[x * 4 + 1] = Convert6To8((col >> 5) & 0x3f); - dst[x * 4 + 2] = Convert5To8((col >> 11) & 0x1f); - dst[x * 4 + 3] = 255; - } + ConvertRGBA565ToRGBA8888((u32 *)dst, src, width); } break; @@ -420,14 +413,7 @@ void FramebufferManager::MakePixelTexture(const u8 *srcPixels, GEBufferFormat sr { const u16 *src = (const u16 *)srcPixels + srcStride * y; u8 *dst = convBuf_ + 4 * width * y; - for (int x = 0; x < width; x++) - { - u16 col = src[x]; - dst[x * 4] = Convert5To8((col) & 0x1f); - dst[x * 4 + 1] = Convert5To8((col >> 5) & 0x1f); - dst[x * 4 + 2] = Convert5To8((col >> 10) & 0x1f); - dst[x * 4 + 3] = (col >> 15) ? 255 : 0; - } + ConvertRGBA5551ToRGBA8888((u32 *)dst, src, width); } break; @@ -435,14 +421,7 @@ void FramebufferManager::MakePixelTexture(const u8 *srcPixels, GEBufferFormat sr { const u16 *src = (const u16 *)srcPixels + srcStride * y; u8 *dst = convBuf_ + 4 * width * y; - for (int x = 0; x < width; x++) - { - u16 col = src[x]; - dst[x * 4] = Convert4To8((col >> 8) & 0xf); - dst[x * 4 + 1] = Convert4To8((col >> 4) & 0xf); - dst[x * 4 + 2] = Convert4To8(col & 0xf); - dst[x * 4 + 3] = Convert4To8(col >> 12); - } + ConvertRGBA4444ToRGBA8888((u32 *)dst, src, width); } break;