From efa5fe5eb71b132f951d92e738deed62fbd67dc4 Mon Sep 17 00:00:00 2001 From: "XTra.KrazzY" Date: Sat, 14 Feb 2009 09:04:40 +0000 Subject: [PATCH] New compact texture type for OGL/D3D: IA4. Thanks for the IA4->IA8 unpacker hyperiris! Too bad that D3D supports IA4 natively while OGL is a bit buggy (treats LUM4_ALPHA4 as LUM8_ALPHA8). git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2238 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Core/VideoCommon/Src/TextureDecoder.cpp | 19 ++++++++++--------- Source/Core/VideoCommon/Src/TextureDecoder.h | 1 + .../Plugin_VideoDX9/Src/D3DTexture.cpp | 1 + .../Plugin_VideoDX9/Src/TextureCache.cpp | 3 +++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Source/Core/VideoCommon/Src/TextureDecoder.cpp b/Source/Core/VideoCommon/Src/TextureDecoder.cpp index 9c2daa3f8e..252f1843a1 100644 --- a/Source/Core/VideoCommon/Src/TextureDecoder.cpp +++ b/Source/Core/VideoCommon/Src/TextureDecoder.cpp @@ -262,15 +262,15 @@ inline void decodebytesC14X2(u32 *dst, const u16 *src, int tlutaddr, int tlutfmt } } -//inline void decodebytesIA4(u32 *dst, const u8 *src, int numbytes) -inline void decodebytesIA4(u32 *dst, const u8 *src) +//inline void decodebytesIA4(u16 *dst, const u8 *src, int numbytes) +inline void decodebytesIA4(u16 *dst, const u8 *src) { for (int x = 0; x < 8; x++) { - int val = src[x]; - int a = lut4to8[val>>4]; - int r = lut4to8[val&15]; - dst[x] = (a<<24) | (r<<16) | (r<<8) | r; + const u8 val = src[x]; + const u8 a = lut4to8[val>>4]; + const u8 l = lut4to8[val&0xF]; + dst[x] = (a<<8) | l; } } @@ -398,11 +398,12 @@ PC_TexFormat TexDecoder_Decode(u8 *dst, const u8 *src, int width, int height, in { 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) + for (int iy = 0; iy < 4; iy++, src += 8) { //decodebytesIA4((u32*)dst+(y+iy)*width+x, src, 8); - decodebytesIA4((u32*)dst+(y+iy)*width+x, src); + decodebytesIA4((u16*)dst+(y+iy)*width+x, src); + } } - return PC_TEX_FMT_BGRA32; + return PC_TEX_FMT_IA8; case GX_TF_IA8: { for (int y = 0; y < height; y += 4) diff --git a/Source/Core/VideoCommon/Src/TextureDecoder.h b/Source/Core/VideoCommon/Src/TextureDecoder.h index 87f9cdedb3..ff7a3fe568 100644 --- a/Source/Core/VideoCommon/Src/TextureDecoder.h +++ b/Source/Core/VideoCommon/Src/TextureDecoder.h @@ -73,6 +73,7 @@ enum PC_TexFormat { PC_TEX_FMT_NONE = 0, PC_TEX_FMT_BGRA32, + PC_TEX_FMT_IA4, PC_TEX_FMT_I8, PC_TEX_FMT_IA8, PC_TEX_FMT_RGB565, diff --git a/Source/Plugins/Plugin_VideoDX9/Src/D3DTexture.cpp b/Source/Plugins/Plugin_VideoDX9/Src/D3DTexture.cpp index 13851a9896..be63f3cff9 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/D3DTexture.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/D3DTexture.cpp @@ -54,6 +54,7 @@ LPDIRECT3DTEXTURE9 CreateTexture2D(const u8* buffer, const int width, const int { case D3DFMT_L8: case D3DFMT_A8: + case D3DFMT_A4L4: { const u8 *pIn = buffer; for (int y = 0; y < height; y++) diff --git a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp index 964f9be933..938b68ec4f 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp @@ -179,6 +179,9 @@ void TextureCache::Load(int stage, u32 address, int width, int height, int forma case PC_TEX_FMT_RGB565: d3d_fmt = D3DFMT_R5G6B5; break; + case PC_TEX_FMT_IA4: + d3d_fmt = D3DFMT_A4L4; + break; case PC_TEX_FMT_I8: d3d_fmt = D3DFMT_A8P8; break;