From dcad8a779daf58ea748369547a965e96b7912473 Mon Sep 17 00:00:00 2001 From: Nolan Check Date: Wed, 13 May 2009 02:06:02 +0000 Subject: [PATCH] TextureDecoder now indicates I4 and IA4 texture formats. It also decodes paletted textures more efficiently. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@3213 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Core/VideoCommon/Src/TextureDecoder.cpp | 153 ++++++++++-------- Source/Core/VideoCommon/Src/TextureDecoder.h | 3 +- .../Plugin_VideoDX9/Src/TextureCache.cpp | 2 +- .../Plugin_VideoOGL/Src/TextureMngr.cpp | 10 ++ 4 files changed, 102 insertions(+), 66 deletions(-) diff --git a/Source/Core/VideoCommon/Src/TextureDecoder.cpp b/Source/Core/VideoCommon/Src/TextureDecoder.cpp index 37a0aef0d9..be08055807 100644 --- a/Source/Core/VideoCommon/Src/TextureDecoder.cpp +++ b/Source/Core/VideoCommon/Src/TextureDecoder.cpp @@ -185,82 +185,71 @@ struct DXTBlock }; //inline void decodebytesC4(u32 *dst, const u8 *src, int numbytes, int tlutaddr, int tlutfmt) -inline void decodebytesC4(u32 *dst, const u8 *src, int tlutaddr, int tlutfmt) +inline void decodebytesC4_5A3_To_BGRA32(u32 *dst, const u8 *src, int tlutaddr) { u16 *tlut = (u16*)(texMem + tlutaddr); for (int x = 0; x < 4; x++) { - int val = src[x]; - switch (tlutfmt) { - case 0: - *dst++ = decodeIA8(Common::swap16(tlut[val >> 4])); - *dst++ = decodeIA8(Common::swap16(tlut[val & 15])); - break; - case 1: - *dst++ = decode565(Common::swap16(tlut[val >> 4])); - *dst++ = decode565(Common::swap16(tlut[val & 15])); - break; - case 2: - *dst++ = decode5A3(Common::swap16(tlut[val >> 4])); - *dst++ = decode5A3(Common::swap16(tlut[val & 15])); - break; - case 3: //ERROR - *dst++ = 0xFFFF00FF; - *dst++ = 0xFFFF00FF; - break; - } + u8 val = src[x]; + *dst++ = decode5A3(Common::swap16(tlut[val >> 4])); + *dst++ = decode5A3(Common::swap16(tlut[val & 0xF])); } } +inline void decodebytesC4_To_Raw16(u16* dst, const u8* src, int tlutaddr) +{ + u16* tlut = (u16*)(texMem+tlutaddr); + for (int x = 0; x < 4; x++) + { + u8 val = src[x]; + *dst++ = Common::swap16(tlut[val >> 4]); + *dst++ = Common::swap16(tlut[val & 0xF]); + } +} + //inline void decodebytesC8(u32 *dst, const u8 *src, int numbytes, int tlutaddr, int tlutfmt) -inline void decodebytesC8(u32 *dst, const u8 *src, int tlutaddr, int tlutfmt) +inline void decodebytesC8_5A3_To_BGRA32(u32 *dst, const u8 *src, int tlutaddr) { u16 *tlut = (u16*)(texMem+tlutaddr); for (int x = 0; x < 8; x++) { - int val = src[x]; - switch (tlutfmt) { - case 0: - *dst++ = decodeIA8(Common::swap16(tlut[val])); - break; - case 1: - *dst++ = decode565(Common::swap16(tlut[val])); - break; - case 2: - *dst++ = decode5A3(Common::swap16(tlut[val])); - break; - case 3: //ERROR - *dst++ = 0xFFFF00FF; - break; - } + u8 val = src[x]; + *dst++ = decode5A3(Common::swap16(tlut[val])); } } +inline void decodebytesC8_To_Raw16(u16* dst, const u8* src, int tlutaddr) +{ + u16* tlut = (u16*)(texMem+tlutaddr); + for (int x = 0; x < 8; x++) + { + u8 val = src[x]; + *dst++ = Common::swap16(tlut[val]); + } +} + //inline void decodebytesC14X2(u32 *dst, const u16 *src, int numpixels, int tlutaddr, int tlutfmt) -inline void decodebytesC14X2(u32 *dst, const u16 *src, int tlutaddr, int tlutfmt) +inline void decodebytesC14X2_5A3_To_BGRA32(u32 *dst, const u16 *src, int tlutaddr) { u16 *tlut = (u16*)(texMem+tlutaddr); for (int x = 0; x < 4; x++) { - int val = Common::swap16(src[x]); - switch (tlutfmt) { - case 0: - *dst++ = decodeIA8(Common::swap16(tlut[(val&0x3FFF)])); - break; - case 1: - *dst++ = decode565(Common::swap16(tlut[(val&0x3FFF)])); - break; - case 2: - *dst++ = decode5A3(Common::swap16(tlut[(val&0x3FFF)])); - break; - case 3: //ERROR - *dst++ = 0xFFFF00FF; - break; - } + u16 val = Common::swap16(src[x]); + *dst++ = decode5A3(Common::swap16(tlut[(val&0x3FFF)])); } } +inline void decodebytesC14X2_To_Raw16(u16* dst, const u16* src, int tlutaddr) +{ + u16* tlut = (u16*)(texMem+tlutaddr); + for (int x = 0; x < 4; x++) + { + u16 val = Common::swap16(src[x]); + *dst++ = Common::swap16(tlut[(val&0x3FFF)]); + } +} + //inline void decodebytesIA4(u16 *dst, const u8 *src, int numbytes) inline void decodebytesIA4(u16 *dst, const u8 *src) { @@ -355,6 +344,18 @@ static void copyDXTBlock(u8* dst, const u8* src) ((u32*)dst)[1] = pixels; } +static PC_TexFormat GetPCFormatFromTLUTFormat(int tlutfmt) +{ + switch (tlutfmt) + { + case 0: return PC_TEX_FMT_IA8; // IA8 + case 1: return PC_TEX_FMT_RGB565; // RGB565 + case 2: return PC_TEX_FMT_BGRA32; // RGB5A3: This TLUT format requires + // extra work to decode. + } + return PC_TEX_FMT_NONE; // Error +} + //switch endianness, unswizzle //TODO: to save memory, don't blindly convert everything to argb8888 @@ -365,14 +366,22 @@ PC_TexFormat TexDecoder_Decode_real(u8 *dst, const u8 *src, int width, int heigh switch (texformat) { case GX_TF_C4: + if (tlutfmt == 2) { + // Special decoding is required for TLUT format 5A3 for (int y = 0; y < height; y += 8) for (int x = 0; x < width; x += 8) for (int iy = 0; iy < 8; iy++, src += 4) - //decodebytesC4((u32*)dst+(y+iy)*width+x, src, 4, tlutaddr, tlutfmt); - decodebytesC4((u32*)dst+(y+iy)*width+x, src, tlutaddr, tlutfmt); + decodebytesC4_5A3_To_BGRA32((u32*)dst+(y+iy)*width+x, src, tlutaddr); } - return PC_TEX_FMT_BGRA32; + else + { + for (int y = 0; y < height; y += 8) + for (int x = 0; x < width; x += 8) + for (int iy = 0; iy < 8; iy++, src += 4) + decodebytesC4_To_Raw16((u16*)dst+(y+iy)*width+x, src, tlutaddr); + } + return GetPCFormatFromTLUTFormat(tlutfmt); case GX_TF_I4: { for (int y = 0; y < height; y += 8) @@ -385,7 +394,7 @@ PC_TexFormat TexDecoder_Decode_real(u8 *dst, const u8 *src, int width, int heigh dst[(y+iy)*width+x+ix*2+1] = lut4to8[val&15]; } } - return PC_TEX_FMT_I8; + return PC_TEX_FMT_I4_AS_I8; case GX_TF_I8: // speed critical { for (int y = 0; y < height; y += 4) @@ -395,14 +404,22 @@ PC_TexFormat TexDecoder_Decode_real(u8 *dst, const u8 *src, int width, int heigh } return PC_TEX_FMT_I8; case GX_TF_C8: + if (tlutfmt == 2) { + // Special decoding is required for TLUT format 5A3 for (int y = 0; y < height; y += 4) for (int x = 0; x < width; x += 8) for (int iy = 0; iy < 4; iy++, src += 8) - //decodebytesC8((u32*)dst+(y+iy)*width+x, src, 8, tlutaddr, tlutfmt); - decodebytesC8((u32*)dst+(y+iy)*width+x, src, tlutaddr, tlutfmt); + decodebytesC8_5A3_To_BGRA32((u32*)dst+(y+iy)*width+x, src, tlutaddr); } - return PC_TEX_FMT_BGRA32; + else + { + for (int y = 0; y < height; y += 4) + for (int x = 0; x < width; x += 8) + for (int iy = 0; iy < 4; iy++, src += 8) + decodebytesC8_To_Raw16((u16*)dst+(y+iy)*width+x, src, tlutaddr); + } + return GetPCFormatFromTLUTFormat(tlutfmt); case GX_TF_IA4: { for (int y = 0; y < height; y += 4) @@ -412,7 +429,7 @@ PC_TexFormat TexDecoder_Decode_real(u8 *dst, const u8 *src, int width, int heigh decodebytesIA4((u16*)dst+(y+iy)*width+x, src); } } - return PC_TEX_FMT_IA8; + return PC_TEX_FMT_IA4_AS_IA8; case GX_TF_IA8: { for (int y = 0; y < height; y += 4) @@ -427,14 +444,22 @@ PC_TexFormat TexDecoder_Decode_real(u8 *dst, const u8 *src, int width, int heigh } return PC_TEX_FMT_IA8; case GX_TF_C14X2: + if (tlutfmt == 2) { + // Special decoding is required for TLUT format 5A3 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) - //decodebytesC14X2((u32*)dst+(y+iy)*width+x, (u16*)src, 4, tlutaddr, tlutfmt); - decodebytesC14X2((u32*)dst+(y+iy)*width+x, (u16*)src, tlutaddr, tlutfmt); + decodebytesC14X2_5A3_To_BGRA32((u32*)dst+(y+iy)*width+x, (u16*)src, tlutaddr); } - return PC_TEX_FMT_BGRA32; + else + { + 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) + decodebytesC14X2_To_Raw16((u16*)dst+(y+iy)*width+x, (u16*)src, tlutaddr); + } + return GetPCFormatFromTLUTFormat(tlutfmt); case GX_TF_RGB565: { for (int y = 0; y < height; y += 4) @@ -565,7 +590,7 @@ PC_TexFormat TexDecoder_Decode(u8 *dst, const u8 *src, int width, int height, in break; } case PC_TEX_FMT_IA8: - case PC_TEX_FMT_IA4: + case PC_TEX_FMT_IA4_AS_IA8: { u16 *dtp = (u16*)dst; dtp[(y+yoff)*width + x+xoff] = ptr[x]?0xFFFF:0xFF00; diff --git a/Source/Core/VideoCommon/Src/TextureDecoder.h b/Source/Core/VideoCommon/Src/TextureDecoder.h index 9acd3ebc22..f941da9c9c 100644 --- a/Source/Core/VideoCommon/Src/TextureDecoder.h +++ b/Source/Core/VideoCommon/Src/TextureDecoder.h @@ -75,7 +75,8 @@ enum PC_TexFormat PC_TEX_FMT_NONE = 0, PC_TEX_FMT_BGRA32, PC_TEX_FMT_RGBA32, - PC_TEX_FMT_IA4, + PC_TEX_FMT_I4_AS_I8, + PC_TEX_FMT_IA4_AS_IA8, PC_TEX_FMT_I8, PC_TEX_FMT_IA8, PC_TEX_FMT_RGB565, diff --git a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp index 69ee1bc914..f3e607ca39 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp @@ -179,7 +179,7 @@ TextureCache::TCacheEntry *TextureCache::Load(int stage, u32 address, int width, case PC_TEX_FMT_RGB565: d3d_fmt = D3DFMT_R5G6B5; break; - case PC_TEX_FMT_IA4: + case PC_TEX_FMT_IA4_AS_IA8: d3d_fmt = D3DFMT_A4L4; break; case PC_TEX_FMT_I8: diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp index 6e926767c5..db81ff5ff4 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp @@ -422,6 +422,16 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width gl_iformat = 4; gl_type = GL_UNSIGNED_BYTE; break; + case PC_TEX_FMT_I4_AS_I8: + gl_format = GL_LUMINANCE; + gl_iformat = GL_INTENSITY4; + gl_type = GL_UNSIGNED_BYTE; + break; + case PC_TEX_FMT_IA4_AS_IA8: + gl_format = GL_LUMINANCE_ALPHA; + gl_iformat = GL_LUMINANCE4_ALPHA4; + gl_type = GL_UNSIGNED_BYTE; + break; case PC_TEX_FMT_I8: gl_format = GL_LUMINANCE; gl_iformat = GL_INTENSITY;