diff --git a/Source/Core/VideoCommon/Src/TextureDecoder.cpp b/Source/Core/VideoCommon/Src/TextureDecoder.cpp index dbb1bad211..9c2daa3f8e 100644 --- a/Source/Core/VideoCommon/Src/TextureDecoder.cpp +++ b/Source/Core/VideoCommon/Src/TextureDecoder.cpp @@ -165,7 +165,7 @@ inline u32 decode5A3(u16 val) g=lut5to8[(val>>5 ) & 0x1f]; b=lut5to8[(val ) & 0x1f]; a=0xFF; - } + } else { a=lut3to8[(val>>12) & 0x7]; @@ -274,13 +274,6 @@ inline void decodebytesIA4(u32 *dst, const u8 *src) } } -//inline void decodebytesIA8(u32 *dst, const u16 *src, int numpixels) -inline void decodebytesIA8(u32 *dst, const u16 *src) -{ - for (int x = 0; x < 4; x++) - dst[x] = decodeIA8(Common::swap16(src[x])); -} - //inline void decodebytesRGB5A3(u32 *dst, const u16 *src, int numpixels) inline void decodebytesRGB5A3(u32 *dst, const u16 *src) { @@ -412,13 +405,17 @@ PC_TexFormat TexDecoder_Decode(u8 *dst, const u8 *src, int width, int height, in return PC_TEX_FMT_BGRA32; case GX_TF_IA8: { - 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) - //decodebytesIA8((u32*)dst+(y+iy)*width+x, (u16*)src, 4); - decodebytesIA8((u32*)dst+(y+iy)*width+x, (u16*)src); + 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) { + u16 *ptr = (u16 *)dst+(y+iy)*width+x; + u16 *s = (u16 *)src; + for(int j = 0; j < 4; j++) + *ptr++ = Common::swap16(*s++); + } + } - return PC_TEX_FMT_BGRA32; + return PC_TEX_FMT_IA8; case GX_TF_C14X2: { for (int y = 0; y < height; y += 4) @@ -463,7 +460,7 @@ PC_TexFormat TexDecoder_Decode(u8 *dst, const u8 *src, int width, int height, in } return PC_TEX_FMT_BGRA32; case GX_TF_CMPR: // speed critical - { + { // TODO: Shuffle to PC S3TC (DXTC) format instead of converting // 11111111 22222222 55555555 66666666 // 33333333 44444444 77777777 88888888 diff --git a/Source/Core/VideoCommon/Src/TextureDecoder.h b/Source/Core/VideoCommon/Src/TextureDecoder.h index be37a08a24..87f9cdedb3 100644 --- a/Source/Core/VideoCommon/Src/TextureDecoder.h +++ b/Source/Core/VideoCommon/Src/TextureDecoder.h @@ -74,6 +74,7 @@ enum PC_TexFormat PC_TEX_FMT_NONE = 0, PC_TEX_FMT_BGRA32, 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 c28315b94a..13851a9896 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/D3DTexture.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/D3DTexture.cpp @@ -28,6 +28,12 @@ LPDIRECT3DTEXTURE9 CreateTexture2D(const u8* buffer, const int width, const int // crazy bitmagic, sorry :) bool isPow2 = !((width&(width-1)) || (height&(height-1))); + bool bExpand = false; + + if(fmt == D3DFMT_A8P8) { + fmt = D3DFMT_A8L8; + bExpand = true; + } HRESULT hr; // TODO(ector): allow mipmaps for non-pow textures on newer cards? @@ -71,17 +77,29 @@ LPDIRECT3DTEXTURE9 CreateTexture2D(const u8* buffer, const int width, const int break; case D3DFMT_A8L8: { - const u8 *pIn = buffer; - // TODO(XK): Find a better way that does not involve either unpacking - // or downsampling (i.e. A4L4) - for (int y = 0; y < height; y++) - { - u8* pBits = ((u8*)Lock.pBits + (y * Lock.Pitch)); - for(int i = 0; i < width * 2; i += 2) { - pBits[i] = pIn[i / 2]; - pBits[i + 1] = pIn[i / 2]; + if(bExpand) { // I8 + const u8 *pIn = buffer; + + // TODO(XK): Find a better way that does not involve either unpacking + // or downsampling (i.e. A4L4) + for (int y = 0; y < height; y++) + { + u8* pBits = ((u8*)Lock.pBits + (y * Lock.Pitch)); + for(int i = 0; i < width * 2; i += 2) { + pBits[i] = pIn[i / 2]; + pBits[i + 1] = pIn[i / 2]; + } + pIn += pitch; + } + } else { // IA8 + const u16 *pIn = (u16*)buffer; + + for (int y = 0; y < height; y++) + { + u16* pBits = (u16*)((u8*)Lock.pBits + (y * Lock.Pitch)); + memcpy(pBits, pIn, width * 2); + pIn += pitch; } - pIn += pitch; } } break; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp index fe8b446780..964f9be933 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/TextureCache.cpp @@ -180,6 +180,9 @@ void TextureCache::Load(int stage, u32 address, int width, int height, int forma d3d_fmt = D3DFMT_R5G6B5; break; case PC_TEX_FMT_I8: + d3d_fmt = D3DFMT_A8P8; + break; + case PC_TEX_FMT_IA8: d3d_fmt = D3DFMT_A8L8; break; } diff --git a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp index c1075d2258..5ebec56271 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/TextureMngr.cpp @@ -346,6 +346,7 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width int gl_iformat; int gl_type; switch (dfmt) { + default: case PC_TEX_FMT_NONE: PanicAlert("Invalid PC texture format %i", dfmt); case PC_TEX_FMT_BGRA32: @@ -358,23 +359,29 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width gl_iformat = GL_INTENSITY; gl_type = GL_UNSIGNED_BYTE; break; + case PC_TEX_FMT_IA8: + gl_format = GL_LUMINANCE_ALPHA; + gl_iformat = GL_LUMINANCE8_ALPHA8; + gl_type = GL_UNSIGNED_BYTE; + break; case PC_TEX_FMT_RGB565: gl_format = GL_RGB; gl_iformat = GL_RGB; gl_type = GL_UNSIGNED_SHORT_5_6_5; break; } - if (!entry.isNonPow2 && ((tm0.min_filter & 3) == 1 || (tm0.min_filter & 3) == 2)) { - glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - glTexImage2D(GL_TEXTURE_2D, 0, gl_iformat, width, height, 0, gl_format, gl_type, temp); - glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE); - entry.bHaveMipMaps = true; - } - else - glTexImage2D(target, 0, gl_iformat, width, height, 0, gl_format, gl_type, temp); + if (!entry.isNonPow2 && ((tm0.min_filter & 3) == 1 || (tm0.min_filter & 3) == 2)) { + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + glTexImage2D(GL_TEXTURE_2D, 0, gl_iformat, width, height, 0, gl_format, gl_type, temp); - if (expandedWidth != width) // reset - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE); + entry.bHaveMipMaps = true; + } + else + glTexImage2D(target, 0, gl_iformat, width, height, 0, gl_format, gl_type, temp); + + if (expandedWidth != width) // reset + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); entry.frameCount = frameCount; entry.w = width;