From 76b4dbdf2895e36e7bc993728b01f20711d5b111 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sun, 10 Aug 2014 16:22:44 -0400 Subject: [PATCH] TextureDecoder: Clean up the code style For a long time, we've had ugly and inconsistent function names here as helpers, names like "decodebytesRGB5A3rgba" which are absolutely incomprehensible to understand. Fix this by introducing a new consistent naming scheme, where the above function now becomes "DecodeBytes_RGB5A3". --- .../VideoCommon/TextureDecoder_Common.cpp | 64 +++---- .../VideoCommon/TextureDecoder_Generic.cpp | 142 +++++++-------- .../Core/VideoCommon/TextureDecoder_x64.cpp | 166 +++++++++--------- 3 files changed, 184 insertions(+), 188 deletions(-) diff --git a/Source/Core/VideoCommon/TextureDecoder_Common.cpp b/Source/Core/VideoCommon/TextureDecoder_Common.cpp index 1fd09fc1f9..eb9089a33f 100644 --- a/Source/Core/VideoCommon/TextureDecoder_Common.cpp +++ b/Source/Core/VideoCommon/TextureDecoder_Common.cpp @@ -252,19 +252,14 @@ PC_TexFormat TexDecoder_Decode(u8 *dst, const u8 *src, int width, int height, in return pc_texformat; } -static inline u32 makeRGBA(int r, int g, int b, int a) -{ - return (a<<24)|(b<<16)|(g<<8)|r; -} - -static inline u32 decodeIA8Swapped(u16 val) +static inline u32 DecodePixel_IA8(u16 val) { int a = val & 0xFF; int i = val >> 8; return i | (i<<8) | (i<<16) | (a<<24); } -static inline u32 decode565RGBA(u16 val) +static inline u32 DecodePixel_RGB565(u16 val) { int r,g,b,a; r=Convert5To8((val>>11) & 0x1f); @@ -274,7 +269,7 @@ static inline u32 decode565RGBA(u16 val) return r | (g<<8) | (b << 16) | (a << 24); } -static inline u32 decode5A3RGBA(u16 val) +static inline u32 DecodePixel_RGB5A3(u16 val) { int r,g,b,a; if ((val&0x8000)) @@ -294,6 +289,21 @@ static inline u32 decode5A3RGBA(u16 val) return r | (g<<8) | (b << 16) | (a << 24); } +static inline u32 DecodePixel_Paletted(u16 pixel, TlutFormat tlutfmt) +{ + switch (tlutfmt) + { + case GX_TL_IA8: + return DecodePixel_IA8(pixel); + case GX_TL_RGB565: + return DecodePixel_RGB565(Common::swap16(pixel)); + case GX_TL_RGB5A3: + return DecodePixel_RGB5A3(Common::swap16(pixel)); + default: + return 0; + } +} + struct DXTBlock { u16 color1; @@ -301,19 +311,9 @@ struct DXTBlock u8 lines[4]; }; -static inline u32 decodePalettedPixel(u16 pixel, TlutFormat tlutfmt) +static inline u32 MakeRGBA(int r, int g, int b, int a) { - switch (tlutfmt) - { - case GX_TL_IA8: - return decodeIA8Swapped(pixel); - case GX_TL_RGB565: - return decode565RGBA(Common::swap16(pixel)); - case GX_TL_RGB5A3: - return decode5A3RGBA(Common::swap16(pixel)); - default: - return 0; - } + return (a<<24)|(b<<16)|(g<<8)|r; } void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth, int texformat, const u8* tlut_, TlutFormat tlutfmt) @@ -347,7 +347,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth u8 val = (*(src + offset) >> rs) & 0xF; u16 *tlut = (u16*) tlut_; - *((u32*)dst) = decodePalettedPixel(tlut[val], tlutfmt); + *((u32*)dst) = DecodePixel_Paletted(tlut[val], tlutfmt); } break; case GX_TF_I4: @@ -401,7 +401,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth u8 val = *(src + base + blkOff); u16 *tlut = (u16*) tlut_; - *((u32*)dst) = decodePalettedPixel(tlut[val], tlutfmt); + *((u32*)dst) = DecodePixel_Paletted(tlut[val], tlutfmt); } break; case GX_TF_IA4: @@ -436,7 +436,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth u32 offset = (base + blkOff) << 1; const u16* valAddr = (u16*)(src + offset); - *((u32*)dst) = decodeIA8Swapped(*valAddr); + *((u32*)dst) = DecodePixel_IA8(*valAddr); } break; case GX_TF_C14X2: @@ -455,7 +455,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth u16 val = Common::swap16(*valAddr) & 0x3FFF; u16 *tlut = (u16*) tlut_; - *((u32*)dst) = decodePalettedPixel(tlut[val], tlutfmt); + *((u32*)dst) = DecodePixel_Paletted(tlut[val], tlutfmt); } break; case GX_TF_RGB565: @@ -471,7 +471,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth u32 offset = (base + blkOff) << 1; const u16* valAddr = (u16*)(src + offset); - *((u32*)dst) = decode565RGBA(Common::swap16(*valAddr)); + *((u32*)dst) = DecodePixel_RGB565(Common::swap16(*valAddr)); } break; case GX_TF_RGB5A3: @@ -487,7 +487,7 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth u32 offset = (base + blkOff) << 1; const u16* valAddr = (u16*)(src + offset); - *((u32*)dst) = decode5A3RGBA(Common::swap16(*valAddr)); + *((u32*)dst) = DecodePixel_RGB5A3(Common::swap16(*valAddr)); } break; case GX_TF_RGBA8: @@ -549,23 +549,23 @@ void TexDecoder_DecodeTexel(u8 *dst, const u8 *src, int s, int t, int imageWidth { case 0: case 4: - color = makeRGBA(red1, green1, blue1, 255); + color = MakeRGBA(red1, green1, blue1, 255); break; case 1: case 5: - color = makeRGBA(red2, green2, blue2, 255); + color = MakeRGBA(red2, green2, blue2, 255); break; case 2: - color = makeRGBA(red1+(red2-red1)/3, green1+(green2-green1)/3, blue1+(blue2-blue1)/3, 255); + color = MakeRGBA(red1+(red2-red1)/3, green1+(green2-green1)/3, blue1+(blue2-blue1)/3, 255); break; case 3: - color = makeRGBA(red2+(red1-red2)/3, green2+(green1-green2)/3, blue2+(blue1-blue2)/3, 255); + color = MakeRGBA(red2+(red1-red2)/3, green2+(green1-green2)/3, blue2+(blue1-blue2)/3, 255); break; case 6: - color = makeRGBA((int)ceil((float)(red1+red2)/2), (int)ceil((float)(green1+green2)/2), (int)ceil((float)(blue1+blue2)/2), 255); + color = MakeRGBA((int)ceil((float)(red1+red2)/2), (int)ceil((float)(green1+green2)/2), (int)ceil((float)(blue1+blue2)/2), 255); break; case 7: - color = makeRGBA(red2, green2, blue2, 0); + color = MakeRGBA(red2, green2, blue2, 0); break; } diff --git a/Source/Core/VideoCommon/TextureDecoder_Generic.cpp b/Source/Core/VideoCommon/TextureDecoder_Generic.cpp index 92a7687f4e..663e73f756 100644 --- a/Source/Core/VideoCommon/TextureDecoder_Generic.cpp +++ b/Source/Core/VideoCommon/TextureDecoder_Generic.cpp @@ -17,7 +17,24 @@ // Decodes all known GameCube/Wii texture formats. // by ector -static inline u32 decode5A3RGBA(u16 val) +static inline u32 DecodePixel_IA8(u16 val) +{ + int a = val & 0xFF; + int i = val >> 8; + return i | (i<<8) | (i<<16) | (a<<24); +} + +static inline u32 DecodePixel_RGB565(u16 val) +{ + int r,g,b,a; + r=Convert5To8((val>>11) & 0x1f); + g=Convert6To8((val>>5 ) & 0x3f); + b=Convert5To8((val ) & 0x1f); + a=0xFF; + return r | (g<<8) | (b << 16) | (a << 24); +} + +static inline u32 DecodePixel_RGB5A3(u16 val) { int r,g,b,a; if ((val&0x8000)) @@ -37,76 +54,53 @@ static inline u32 decode5A3RGBA(u16 val) return r | (g<<8) | (b << 16) | (a << 24); } -static inline u32 decode565RGBA(u16 val) -{ - int r,g,b,a; - r=Convert5To8((val>>11) & 0x1f); - g=Convert6To8((val>>5 ) & 0x3f); - b=Convert5To8((val ) & 0x1f); - a=0xFF; - return r | (g<<8) | (b << 16) | (a << 24); -} -static inline u32 decodeIA8Swapped(u16 val) -{ - int a = val & 0xFF; - int i = val >> 8; - return i | (i<<8) | (i<<16) | (a<<24); -} - -struct DXTBlock -{ - u16 color1; - u16 color2; - u8 lines[4]; -}; - -static inline u32 decodePalettedPixel(u16 pixel, TlutFormat tlutfmt) +static inline u32 DecodePixel_Paletted(u16 pixel, TlutFormat tlutfmt) { switch (tlutfmt) { case GX_TL_IA8: - return decodeIA8Swapped(pixel); + return DecodePixel_IA8(pixel); case GX_TL_RGB565: - return decode565RGBA(Common::swap16(pixel)); + return DecodePixel_RGB565(Common::swap16(pixel)); case GX_TL_RGB5A3: - return decode5A3RGBA(Common::swap16(pixel)); + return DecodePixel_RGB5A3(Common::swap16(pixel)); default: return 0; } } -static inline void decodeC4(u32 *dst, const u8 *src, const u8* tlut_, TlutFormat tlutfmt) +static inline void DecodeBytes_C4(u32 *dst, const u8 *src, const u8* tlut_, TlutFormat tlutfmt) { const u16* tlut = (u16*) tlut_; for (int x = 0; x < 4; x++) { u8 val = src[x]; - *dst++ = decodePalettedPixel(tlut[val >> 4], tlutfmt); - *dst++ = decodePalettedPixel(tlut[val & 0xF], tlutfmt); + *dst++ = DecodePixel_Paletted(tlut[val >> 4], tlutfmt); + *dst++ = DecodePixel_Paletted(tlut[val & 0xF], tlutfmt); } } -static inline void decodeC8(u32 *dst, const u8 *src, const u8* tlut_, TlutFormat tlutfmt) +static inline void DecodeBytes_C8(u32 *dst, const u8 *src, const u8* tlut_, TlutFormat tlutfmt) { const u16* tlut = (u16*) tlut_; for (int x = 0; x < 8; x++) { u8 val = src[x]; - *dst++ = decodePalettedPixel(tlut[val], tlutfmt); + *dst++ = DecodePixel_Paletted(tlut[val], tlutfmt); } } -static inline void decodeC14X2(u32 *dst, const u16 *src, const u8* tlut_, TlutFormat tlutfmt) +static inline void DecodeBytes_C14X2(u32 *dst, const u16 *src, const u8* tlut_, TlutFormat tlutfmt) { const u16* tlut = (u16*) tlut_; for (int x = 0; x < 4; x++) { u16 val = Common::swap16(src[x]); - *dst++ = decodePalettedPixel(tlut[(val & 0x3FFF)], tlutfmt); + *dst++ = DecodePixel_Paletted(tlut[(val & 0x3FFF)], tlutfmt); } } -static inline void decodebytesIA4RGBA(u32 *dst, const u8 *src) +static inline void DecodeBytes_IA4(u32 *dst, const u8 *src) { for (int x = 0; x < 8; x++) { @@ -117,20 +111,20 @@ static inline void decodebytesIA4RGBA(u32 *dst, const u8 *src) } } -static inline void decodebytesRGB5A3rgba(u32 *dst, const u16 *src) +static inline void DecodeBytes_RGB5A3(u32 *dst, const u16 *src) { #if 0 for (int x = 0; x < 4; x++) - dst[x] = decode5A3RGBA(Common::swap16(src[x])); + dst[x] = DecodePixel_RGB5A3(Common::swap16(src[x])); #else - dst[0] = decode5A3RGBA(Common::swap16(src[0])); - dst[1] = decode5A3RGBA(Common::swap16(src[1])); - dst[2] = decode5A3RGBA(Common::swap16(src[2])); - dst[3] = decode5A3RGBA(Common::swap16(src[3])); + dst[0] = DecodePixel_RGB5A3(Common::swap16(src[0])); + dst[1] = DecodePixel_RGB5A3(Common::swap16(src[1])); + dst[2] = DecodePixel_RGB5A3(Common::swap16(src[2])); + dst[3] = DecodePixel_RGB5A3(Common::swap16(src[3])); #endif } -static inline void decodebytesARGB8_4ToRgba(u32 *dst, const u16 *src, const u16 * src2) +static inline void DecodeBytes_RGBA8(u32 *dst, const u16 *src, const u16 * src2) { #if 0 for (int x = 0; x < 4; x++) @@ -145,12 +139,19 @@ static inline void decodebytesARGB8_4ToRgba(u32 *dst, const u16 *src, const u16 #endif } -static inline u32 makeRGBA(int r, int g, int b, int a) +struct DXTBlock +{ + u16 color1; + u16 color2; + u8 lines[4]; +}; + +static inline u32 MakeRGBA(int r, int g, int b, int a) { return (a<<24)|(b<<16)|(g<<8)|r; } -static void decodeDXTBlockRGBA(u32 *dst, const DXTBlock *src, int pitch) +static void DecodeDXTBlock(u32 *dst, const DXTBlock *src, int pitch) { // S3TC Decoder (Note: GCN decodes differently from PC so we can't use native support) // Needs more speed. @@ -163,22 +164,22 @@ static void decodeDXTBlockRGBA(u32 *dst, const DXTBlock *src, int pitch) int red1 = Convert5To8((c1 >> 11) & 0x1F); int red2 = Convert5To8((c2 >> 11) & 0x1F); int colors[4]; - colors[0] = makeRGBA(red1, green1, blue1, 255); - colors[1] = makeRGBA(red2, green2, blue2, 255); + colors[0] = MakeRGBA(red1, green1, blue1, 255); + colors[1] = MakeRGBA(red2, green2, blue2, 255); if (c1 > c2) { int blue3 = ((blue2 - blue1) >> 1) - ((blue2 - blue1) >> 3); int green3 = ((green2 - green1) >> 1) - ((green2 - green1) >> 3); int red3 = ((red2 - red1) >> 1) - ((red2 - red1) >> 3); - colors[2] = makeRGBA(red1 + red3, green1 + green3, blue1 + blue3, 255); - colors[3] = makeRGBA(red2 - red3, green2 - green3, blue2 - blue3, 255); + colors[2] = MakeRGBA(red1 + red3, green1 + green3, blue1 + blue3, 255); + colors[3] = MakeRGBA(red2 - red3, green2 - green3, blue2 - blue3, 255); } else { - colors[2] = makeRGBA((red1 + red2 + 1) / 2, // Average + colors[2] = MakeRGBA((red1 + red2 + 1) / 2, // Average (green1 + green2 + 1) / 2, (blue1 + blue2 + 1) / 2, 255); - colors[3] = makeRGBA(red2, green2, blue2, 0); // Color2 but transparent + colors[3] = MakeRGBA(red2, green2, blue2, 0); // Color2 but transparent } for (int y = 0; y < 4; y++) @@ -203,7 +204,6 @@ static void decodeDXTBlockRGBA(u32 *dst, const DXTBlock *src, int pitch) PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int height, int texformat, const u8* tlut, TlutFormat tlutfmt) { - const int Wsteps4 = (width + 3) / 4; const int Wsteps8 = (width + 7) / 8; @@ -213,7 +213,7 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he for (int y = 0; y < height; y += 8) for (int x = 0, yStep = (y / 8) * Wsteps8; x < width; x += 8,yStep++) for (int iy = 0, xStep = 8 * yStep; iy < 8; iy++,xStep++) - decodeC4(dst + (y + iy) * width + x, src + 4 * xStep, tlut, tlutfmt); + DecodeBytes_C4(dst + (y + iy) * width + x, src + 4 * xStep, tlut, tlutfmt); break; case GX_TF_I4: { @@ -257,14 +257,14 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he for (int y = 0; y < height; y += 4) for (int x = 0, yStep = (y / 4) * Wsteps8; x < width; x += 8, yStep++) for (int iy = 0, xStep = 4 * yStep; iy < 4; iy++, xStep++) - decodeC8((u32*)dst + (y + iy) * width + x, src + 8 * xStep, tlut, tlutfmt); + DecodeBytes_C8((u32*)dst + (y + iy) * width + x, src + 8 * xStep, tlut, tlutfmt); break; case GX_TF_IA4: { for (int y = 0; y < height; y += 4) for (int x = 0, yStep = (y / 4) * Wsteps8; x < width; x += 8, yStep++) for (int iy = 0, xStep = 4 * yStep; iy < 4; iy++, xStep++) - decodebytesIA4RGBA(dst + (y + iy) * width + x, src + 8 * xStep); + DecodeBytes_IA4(dst + (y + iy) * width + x, src + 8 * xStep); } break; case GX_TF_IA8: @@ -276,10 +276,10 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he { u32 *ptr = dst + (y + iy) * width + x; u16 *s = (u16 *)src; - ptr[0] = decodeIA8Swapped(s[0]); - ptr[1] = decodeIA8Swapped(s[1]); - ptr[2] = decodeIA8Swapped(s[2]); - ptr[3] = decodeIA8Swapped(s[3]); + ptr[0] = DecodePixel_IA8(s[0]); + ptr[1] = DecodePixel_IA8(s[1]); + ptr[2] = DecodePixel_IA8(s[2]); + ptr[3] = DecodePixel_IA8(s[3]); } } break; @@ -287,7 +287,7 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he for (int y = 0; y < height; y += 4) for (int x = 0, yStep = (y / 4) * Wsteps4; x < width; x += 4, yStep++) for (int iy = 0, xStep = 4 * yStep; iy < 4; iy++, xStep++) - decodeC14X2(dst + (y + iy) * width + x, (u16*)(src + 8 * xStep), tlut, tlutfmt); + DecodeBytes_C14X2(dst + (y + iy) * width + x, (u16*)(src + 8 * xStep), tlut, tlutfmt); break; case GX_TF_RGB565: { @@ -299,7 +299,7 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he u32 *ptr = dst + (y + iy) * width + x; u16 *s = (u16 *)src; for (int j = 0; j < 4; j++) - *ptr++ = decode565RGBA(Common::swap16(*s++)); + *ptr++ = DecodePixel_RGB565(Common::swap16(*s++)); } } break; @@ -309,7 +309,7 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he for (int y = 0; y < height; y += 4) for (int x = 0; x < width; x += 4) for (int iy = 0; iy < 4; iy++, src += 8) - decodebytesRGB5A3rgba(dst+(y+iy)*width+x, (u16*)src); + DecodeBytes_RGB5A3(dst+(y+iy)*width+x, (u16*)src); } break; case GX_TF_RGBA8: // speed critical @@ -319,7 +319,7 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he for (int x = 0; x < width; x += 4) { for (int iy = 0; iy < 4; iy++) - decodebytesARGB8_4ToRgba(dst + (y+iy)*width + x, (u16*)src + 4 * iy, (u16*)src + 4 * iy + 16); + DecodeBytes_RGBA8(dst + (y+iy)*width + x, (u16*)src + 4 * iy, (u16*)src + 4 * iy + 16); src += 64; } } @@ -331,14 +331,14 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he { for (int x = 0; x < width; x += 8) { - decodeDXTBlockRGBA((u32*)dst + y * width + x, (DXTBlock*)src, width); - src += sizeof(DXTBlock); - decodeDXTBlockRGBA((u32*)dst + y * width + x + 4, (DXTBlock*)src, width); - src += sizeof(DXTBlock); - decodeDXTBlockRGBA((u32*)dst + (y + 4) * width + x, (DXTBlock*)src, width); - src += sizeof(DXTBlock); - decodeDXTBlockRGBA((u32*)dst + (y + 4) * width + x + 4, (DXTBlock*)src, width); - src += sizeof(DXTBlock); + DecodeDXTBlock((u32*)dst + y * width + x, (DXTBlock*)src, width); + src += sizeof(DXTBlock); + DecodeDXTBlock((u32*)dst + y * width + x + 4, (DXTBlock*)src, width); + src += sizeof(DXTBlock); + DecodeDXTBlock((u32*)dst + (y + 4) * width + x, (DXTBlock*)src, width); + src += sizeof(DXTBlock); + DecodeDXTBlock((u32*)dst + (y + 4) * width + x + 4, (DXTBlock*)src, width); + src += sizeof(DXTBlock); } } break; diff --git a/Source/Core/VideoCommon/TextureDecoder_x64.cpp b/Source/Core/VideoCommon/TextureDecoder_x64.cpp index 9603ec1695..50458016fa 100644 --- a/Source/Core/VideoCommon/TextureDecoder_x64.cpp +++ b/Source/Core/VideoCommon/TextureDecoder_x64.cpp @@ -37,7 +37,24 @@ // Decodes all known GameCube/Wii texture formats. // by ector -static inline u32 decode5A3RGBA(u16 val) +static inline u32 DecodePixel_IA8(u16 val) +{ + int a = val & 0xFF; + int i = val >> 8; + return i | (i<<8) | (i<<16) | (a<<24); +} + +static inline u32 DecodePixel_RGB565(u16 val) +{ + int r,g,b,a; + r=Convert5To8((val>>11) & 0x1f); + g=Convert6To8((val>>5 ) & 0x3f); + b=Convert5To8((val ) & 0x1f); + a=0xFF; + return r | (g<<8) | (b << 16) | (a << 24); +} + +static inline u32 DecodePixel_RGB5A3(u16 val) { int r,g,b,a; if ((val&0x8000)) @@ -57,25 +74,6 @@ static inline u32 decode5A3RGBA(u16 val) return r | (g<<8) | (b << 16) | (a << 24); } -static inline u32 decode565RGBA(u16 val) -{ - int r,g,b,a; - r=Convert5To8((val>>11) & 0x1f); - g=Convert6To8((val>>5 ) & 0x3f); - b=Convert5To8((val ) & 0x1f); - a=0xFF; - return r | (g<<8) | (b << 16) | (a << 24); -} - -static inline u32 decodeIA8Swapped(u16 val) -{ - int a = val & 0xFF; - int i = val >> 8; - return i | (i<<8) | (i<<16) | (a<<24); -} - - - struct DXTBlock { u16 color1; @@ -83,98 +81,99 @@ struct DXTBlock u8 lines[4]; }; -static inline void decodebytesC4_5A3_To_rgba32(u32 *dst, const u8 *src, const u8* tlut_) +static inline void DecodeBytes_C4_IA8(u32* dst, const u8* src, const u8* tlut_) { const u16* tlut = (u16*) tlut_; for (int x = 0; x < 4; x++) { u8 val = src[x]; - *dst++ = decode5A3RGBA(Common::swap16(tlut[val >> 4])); - *dst++ = decode5A3RGBA(Common::swap16(tlut[val & 0xF])); + *dst++ = DecodePixel_IA8(tlut[val >> 4]); + *dst++ = DecodePixel_IA8(tlut[val & 0xF]); } } -static inline void decodebytesC4IA8_To_RGBA(u32* dst, const u8* src, const u8* tlut_) +static inline void DecodeBytes_C4_RGB565(u32* dst, const u8* src, const u8* tlut_) { const u16* tlut = (u16*) tlut_; for (int x = 0; x < 4; x++) { u8 val = src[x]; - *dst++ = decodeIA8Swapped(tlut[val >> 4]); - *dst++ = decodeIA8Swapped(tlut[val & 0xF]); + *dst++ = DecodePixel_RGB565(Common::swap16(tlut[val >> 4])); + *dst++ = DecodePixel_RGB565(Common::swap16(tlut[val & 0xF])); } } -static inline void decodebytesC4RGB565_To_RGBA(u32* dst, const u8* src, const u8* tlut_) +static inline void DecodeBytes_C4_RGB5A3(u32 *dst, const u8 *src, const u8* tlut_) { const u16* tlut = (u16*) tlut_; for (int x = 0; x < 4; x++) { u8 val = src[x]; - *dst++ = decode565RGBA(Common::swap16(tlut[val >> 4])); - *dst++ = decode565RGBA(Common::swap16(tlut[val & 0xF])); + *dst++ = DecodePixel_RGB5A3(Common::swap16(tlut[val >> 4])); + *dst++ = DecodePixel_RGB5A3(Common::swap16(tlut[val & 0xF])); } } -static inline void decodebytesC8_5A3_To_RGBA32(u32 *dst, const u8 *src, const u8* tlut_) +static inline void DecodeBytes_C8_IA8(u32* dst, const u8* src, const u8* tlut_) +{ + const u16* tlut = (u16*) tlut_; + for (int x = 0; x < 8; x++) + { + *dst++ = DecodePixel_IA8(tlut[src[x]]); + } +} + +static inline void DecodeBytes_C8_RGB565(u32* dst, const u8* src, const u8* tlut_) { const u16* tlut = (u16*) tlut_; for (int x = 0; x < 8; x++) { u8 val = src[x]; - *dst++ = decode5A3RGBA(Common::swap16(tlut[val])); + *dst++ = DecodePixel_RGB565(Common::swap16(tlut[val])); } } -static inline void decodebytesC8IA8_To_RGBA(u32* dst, const u8* src, const u8* tlut_) +static inline void DecodeBytes_C8_RGB5A3(u32 *dst, const u8 *src, const u8* tlut_) { const u16* tlut = (u16*) tlut_; for (int x = 0; x < 8; x++) { - *dst++ = decodeIA8Swapped(tlut[src[x]]); + u8 val = src[x]; + *dst++ = DecodePixel_RGB5A3(Common::swap16(tlut[val])); } } -static inline void decodebytesC8RGB565_To_RGBA(u32* dst, const u8* src, const u8* tlut_) -{ - const u16* tlut = (u16*) tlut_; - for (int x = 0; x < 8; x++) - { - *dst++ = decode565RGBA(Common::swap16(tlut[src[x]])); - } -} - -static inline void decodebytesC14X2_5A3_To_RGBA(u32 *dst, const u16 *src, const u8* tlut_) +static inline void DecodeBytes_C14X2_IA8(u32* dst, const u16* src, const u8* tlut_) { const u16* tlut = (u16*) tlut_; for (int x = 0; x < 4; x++) { u16 val = Common::swap16(src[x]); - *dst++ = decode5A3RGBA(Common::swap16(tlut[(val & 0x3FFF)])); + *dst++ = DecodePixel_IA8(tlut[(val & 0x3FFF)]); } } -static inline void decodebytesC14X2IA8_To_RGBA(u32* dst, const u16* src, const u8* tlut_) +static inline void DecodeBytes_C14X2_RGB565(u32* dst, const u16* src, const u8* tlut_) { const u16* tlut = (u16*) tlut_; for (int x = 0; x < 4; x++) { u16 val = Common::swap16(src[x]); - *dst++ = decodeIA8Swapped(tlut[(val & 0x3FFF)]); + *dst++ = DecodePixel_RGB565(Common::swap16(tlut[(val & 0x3FFF)])); } } -static inline void decodebytesC14X2rgb565_To_RGBA(u32* dst, const u16* src, const u8* tlut_) +static inline void DecodeBytes_C14X2_RGB5A3(u32 *dst, const u16 *src, const u8* tlut_) { const u16* tlut = (u16*) tlut_; for (int x = 0; x < 4; x++) { u16 val = Common::swap16(src[x]); - *dst++ = decode565RGBA(Common::swap16(tlut[(val & 0x3FFF)])); + *dst++ = DecodePixel_RGB5A3(Common::swap16(tlut[(val & 0x3FFF)])); } } -static inline void decodebytesIA4RGBA(u32 *dst, const u8 *src) +static inline void DecodeBytes_IA4(u32 *dst, const u8 *src) { for (int x = 0; x < 8; x++) { @@ -185,20 +184,20 @@ static inline void decodebytesIA4RGBA(u32 *dst, const u8 *src) } } -static inline void decodebytesRGB5A3rgba(u32 *dst, const u16 *src) +static inline void DecodeBytes_RGB5A3(u32 *dst, const u16 *src) { #if 0 for (int x = 0; x < 4; x++) - dst[x] = decode5A3RGBA(Common::swap16(src[x])); + dst[x] = DecodePixel_RGB5A3(Common::swap16(src[x])); #else - dst[0] = decode5A3RGBA(Common::swap16(src[0])); - dst[1] = decode5A3RGBA(Common::swap16(src[1])); - dst[2] = decode5A3RGBA(Common::swap16(src[2])); - dst[3] = decode5A3RGBA(Common::swap16(src[3])); + dst[0] = DecodePixel_RGB5A3(Common::swap16(src[0])); + dst[1] = DecodePixel_RGB5A3(Common::swap16(src[1])); + dst[2] = DecodePixel_RGB5A3(Common::swap16(src[2])); + dst[3] = DecodePixel_RGB5A3(Common::swap16(src[3])); #endif } -static inline void decodebytesARGB8_4ToRgba(u32 *dst, const u16 *src, const u16 * src2) +static inline void DecodeBytes_RGBA8(u32 *dst, const u16 *src, const u16 * src2) { #if 0 for (int x = 0; x < 4; x++) @@ -213,13 +212,13 @@ static inline void decodebytesARGB8_4ToRgba(u32 *dst, const u16 *src, const u16 #endif } +#ifdef CHECK static inline u32 makeRGBA(int r, int g, int b, int a) { return (a<<24)|(b<<16)|(g<<8)|r; } -#ifdef CHECK -static void decodeDXTBlockRGBA(u32 *dst, const DXTBlock *src, int pitch) +static void DecodeDXTBlock(u32 *dst, const DXTBlock *src, int pitch) { // S3TC Decoder (Note: GCN decodes differently from PC so we can't use native support) // Needs more speed. @@ -232,22 +231,22 @@ static void decodeDXTBlockRGBA(u32 *dst, const DXTBlock *src, int pitch) int red1 = Convert5To8((c1 >> 11) & 0x1F); int red2 = Convert5To8((c2 >> 11) & 0x1F); int colors[4]; - colors[0] = makeRGBA(red1, green1, blue1, 255); - colors[1] = makeRGBA(red2, green2, blue2, 255); + colors[0] = MakeRGBA(red1, green1, blue1, 255); + colors[1] = MakeRGBA(red2, green2, blue2, 255); if (c1 > c2) { int blue3 = ((blue2 - blue1) >> 1) - ((blue2 - blue1) >> 3); int green3 = ((green2 - green1) >> 1) - ((green2 - green1) >> 3); int red3 = ((red2 - red1) >> 1) - ((red2 - red1) >> 3); - colors[2] = makeRGBA(red1 + red3, green1 + green3, blue1 + blue3, 255); - colors[3] = makeRGBA(red2 - red3, green2 - green3, blue2 - blue3, 255); + colors[2] = MakeRGBA(red1 + red3, green1 + green3, blue1 + blue3, 255); + colors[3] = MakeRGBA(red2 - red3, green2 - green3, blue2 - blue3, 255); } else { - colors[2] = makeRGBA((red1 + red2 + 1) / 2, // Average + colors[2] = MakeRGBA((red1 + red2 + 1) / 2, // Average (green1 + green2 + 1) / 2, (blue1 + blue2 + 1) / 2, 255); - colors[3] = makeRGBA(red2, green2, blue2, 0); // Color2 but transparent + colors[3] = MakeRGBA(red2, green2, blue2, 0); // Color2 but transparent } for (int y = 0; y < 4; y++) @@ -299,12 +298,11 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he case GX_TF_C4: if (tlutfmt == GX_TL_RGB5A3) { - // Special decoding is required for TLUT format 5A3 #pragma omp parallel for for (int y = 0; y < height; y += 8) for (int x = 0, yStep = (y / 8) * Wsteps8; x < width; x += 8,yStep++) for (int iy = 0, xStep = 8 * yStep; iy < 8; iy++,xStep++) - decodebytesC4_5A3_To_rgba32(dst + (y + iy) * width + x, src + 4 * xStep, tlut); + DecodeBytes_C4_RGB5A3(dst + (y + iy) * width + x, src + 4 * xStep, tlut); } else if (tlutfmt == GX_TL_IA8) { @@ -312,7 +310,7 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he for (int y = 0; y < height; y += 8) for (int x = 0, yStep = (y / 8) * Wsteps8; x < width; x += 8,yStep++) for (int iy = 0, xStep = 8 * yStep; iy < 8; iy++,xStep++) - decodebytesC4IA8_To_RGBA(dst + (y + iy) * width + x, src + 4 * xStep, tlut); + DecodeBytes_C4_IA8(dst + (y + iy) * width + x, src + 4 * xStep, tlut); } else if (tlutfmt == GX_TL_RGB565) @@ -321,7 +319,7 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he for (int y = 0; y < height; y += 8) for (int x = 0, yStep = (y / 8) * Wsteps8; x < width; x += 8,yStep++) for (int iy = 0, xStep = 8 * yStep; iy < 8; iy++,xStep++) - decodebytesC4RGB565_To_RGBA(dst + (y + iy) * width + x, src + 4 * xStep, tlut); + DecodeBytes_C4_RGB565(dst + (y + iy) * width + x, src + 4 * xStep, tlut); } break; case GX_TF_I4: @@ -557,29 +555,28 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he case GX_TF_C8: if (tlutfmt == GX_TL_RGB5A3) { - // Special decoding is required for TLUT format 5A3 #pragma omp parallel for for (int y = 0; y < height; y += 4) for (int x = 0, yStep = (y / 4) * Wsteps8; x < width; x += 8, yStep++) for (int iy = 0, xStep = 4 * yStep; iy < 4; iy++, xStep++) - decodebytesC8_5A3_To_RGBA32((u32*)dst + (y + iy) * width + x, src + 8 * xStep, tlut); + DecodeBytes_C8_RGB5A3((u32*)dst + (y + iy) * width + x, src + 8 * xStep, tlut); } else if (tlutfmt == GX_TL_IA8) { #pragma omp parallel for for (int y = 0; y < height; y += 4) - for (int x = 0, yStep = (y / 4) * Wsteps8; x < width; x += 8, yStep++) - for (int iy = 0, xStep = 4 * yStep; iy < 4; iy++, xStep++) - decodebytesC8IA8_To_RGBA(dst + (y + iy) * width + x, src + 8 * xStep, tlut); + for (int x = 0, yStep = (y / 4) * Wsteps8; x < width; x += 8, yStep++) + for (int iy = 0, xStep = 4 * yStep; iy < 4; iy++, xStep++) + DecodeBytes_C8_IA8(dst + (y + iy) * width + x, src + 8 * xStep, tlut); } else if (tlutfmt == GX_TL_RGB565) { #pragma omp parallel for for (int y = 0; y < height; y += 4) - for (int x = 0, yStep = (y / 4) * Wsteps8; x < width; x += 8, yStep++) - for (int iy = 0, xStep = 4 * yStep; iy < 4; iy++, xStep++) - decodebytesC8RGB565_To_RGBA(dst + (y + iy) * width + x, src + 8 * xStep, tlut); + for (int x = 0, yStep = (y / 4) * Wsteps8; x < width; x += 8, yStep++) + for (int iy = 0, xStep = 4 * yStep; iy < 4; iy++, xStep++) + DecodeBytes_C8_RGB565(dst + (y + iy) * width + x, src + 8 * xStep, tlut); } break; @@ -587,9 +584,9 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he { #pragma omp parallel for for (int y = 0; y < height; y += 4) - for (int x = 0, yStep = (y / 4) * Wsteps8; x < width; x += 8, yStep++) - for (int iy = 0, xStep = 4 * yStep; iy < 4; iy++, xStep++) - decodebytesIA4RGBA(dst + (y + iy) * width + x, src + 8 * xStep); + for (int x = 0, yStep = (y / 4) * Wsteps8; x < width; x += 8, yStep++) + for (int iy = 0, xStep = 4 * yStep; iy < 4; iy++, xStep++) + DecodeBytes_IA4(dst + (y + iy) * width + x, src + 8 * xStep); } break; case GX_TF_IA8: @@ -670,12 +667,11 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he case GX_TF_C14X2: if (tlutfmt == GX_TL_RGB5A3) { - // Special decoding is required for TLUT format 5A3 #pragma omp parallel for for (int y = 0; y < height; y += 4) for (int x = 0, yStep = (y / 4) * Wsteps4; x < width; x += 4, yStep++) for (int iy = 0, xStep = 4 * yStep; iy < 4; iy++, xStep++) - decodebytesC14X2_5A3_To_RGBA(dst + (y + iy) * width + x, (u16*)(src + 8 * xStep), tlut); + DecodeBytes_C14X2_RGB5A3(dst + (y + iy) * width + x, (u16*)(src + 8 * xStep), tlut); } else if (tlutfmt == GX_TL_IA8) { @@ -683,7 +679,7 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he for (int y = 0; y < height; y += 4) for (int x = 0, yStep = (y / 4) * Wsteps4; x < width; x += 4, yStep++) for (int iy = 0, xStep = 4 * yStep; iy < 4; iy++, xStep++) - decodebytesC14X2IA8_To_RGBA(dst + (y + iy) * width + x, (u16*)(src + 8 * xStep), tlut); + DecodeBytes_C14X2_IA8(dst + (y + iy) * width + x, (u16*)(src + 8 * xStep), tlut); } else if (tlutfmt == GX_TL_RGB565) { @@ -691,7 +687,7 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he for (int y = 0; y < height; y += 4) for (int x = 0, yStep = (y / 4) * Wsteps4; x < width; x += 4, yStep++) for (int iy = 0, xStep = 4 * yStep; iy < 4; iy++, xStep++) - decodebytesC14X2rgb565_To_RGBA(dst + (y + iy) * width + x, (u16*)(src + 8 * xStep), tlut); + DecodeBytes_C14X2_RGB565(dst + (y + iy) * width + x, (u16*)(src + 8 * xStep), tlut); } break; case GX_TF_RGB565: @@ -1281,8 +1277,8 @@ PC_TexFormat _TexDecoder_DecodeImpl(u32 * dst, const u8 * src, int width, int he // REFERENCE: u32 tmp0[4][4], tmp1[4][4]; - decodeDXTBlockRGBA(&(tmp0[0][0]), (const DXTBlock *)src, 4); - decodeDXTBlockRGBA(&(tmp1[0][0]), (const DXTBlock *)(src + 8), 4); + DecodeDXTBlock(&(tmp0[0][0]), (const DXTBlock *)src, 4); + DecodeDXTBlock(&(tmp1[0][0]), (const DXTBlock *)(src + 8), 4); #endif u32 *dst32 = ( dst + (y + z*4) * width + x );