[Common] Abstract out the decode5A3Image and decodeCI8Image functions in BannerLoaderGC, BannerLoaderWii, and GCMemcard into ColorUtil.cpp. Makes for less copied code and remains functionally the same.

This commit is contained in:
Lioncash 2013-10-02 18:18:54 -04:00
parent b1268bfcd2
commit 1ec4894bc5
7 changed files with 50 additions and 89 deletions

View File

@ -40,4 +40,41 @@ u32 Decode5A3(u16 val)
return (a << 24) | (r << 16) | (g << 8) | b; return (a << 24) | (r << 16) | (g << 8) | b;
} }
void decode5A3image(u32* dst, u16* src, int width, int height)
{
for (int y = 0; y < height; y += 4)
{
for (int x = 0; x < width; x += 4)
{
for (int iy = 0; iy < 4; iy++, src += 4)
{
for (int ix = 0; ix < 4; ix++)
{
u32 RGBA = Decode5A3(Common::swap16(src[ix]));
dst[(y + iy) * width + (x + ix)] = RGBA;
}
}
}
}
}
void decodeCI8image(u32* dst, u8* src, u16* pal, int width, int height)
{
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)
{
u32 *tdst = dst+(y+iy)*width+x;
for (int ix = 0; ix < 8; ix++)
{
// huh, this seems wrong. CI8, not 5A3, no?
tdst[ix] = ColorUtil::Decode5A3(Common::swap16(pal[src[ix]]));
}
}
}
}
}
} // namespace } // namespace

View File

@ -8,7 +8,8 @@
namespace ColorUtil namespace ColorUtil
{ {
u32 Decode5A3(u16 val); void decode5A3image(u32* dst, u16* src, int width, int height);
void decodeCI8image(u32* dst, u8* src, u16* pal, int width, int height);
} // namespace } // namespace

View File

@ -11,43 +11,6 @@ static void ByteSwap(u8 *valueA, u8 *valueB)
*valueB = tmp; *valueB = tmp;
} }
void decode5A3image(u32* dst, u16* src, int width, int height)
{
for (int y = 0; y < height; y += 4)
{
for (int x = 0; x < width; x += 4)
{
for (int iy = 0; iy < 4; iy++, src += 4)
{
for (int ix = 0; ix < 4; ix++)
{
u32 RGBA = ColorUtil::Decode5A3(Common::swap16(src[ix]));
dst[(y + iy) * width + (x + ix)] = RGBA;
}
}
}
}
}
void decodeCI8image(u32* dst, u8* src, u16* pal, int width, int height)
{
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)
{
u32 *tdst = dst+(y+iy)*width+x;
for (int ix = 0; ix < 8; ix++)
{
// huh, this seems wrong. CI8, not 5A3, no?
tdst[ix] = ColorUtil::Decode5A3(Common::swap16(pal[src[ix]]));
}
}
}
}
}
GCMemcard::GCMemcard(const char *filename, bool forceCreation, bool sjis) GCMemcard::GCMemcard(const char *filename, bool forceCreation, bool sjis)
: m_valid(false) : m_valid(false)
, m_fileName(filename) , m_fileName(filename)
@ -1083,13 +1046,13 @@ bool GCMemcard::ReadBannerRGBA8(u8 index, u32* buffer) const
u8 *pxdata = (u8* )(mc_data_blocks[DataBlock].block + DataOffset); u8 *pxdata = (u8* )(mc_data_blocks[DataBlock].block + DataOffset);
u16 *paldata = (u16*)(mc_data_blocks[DataBlock].block + DataOffset + pixels); u16 *paldata = (u16*)(mc_data_blocks[DataBlock].block + DataOffset + pixels);
decodeCI8image(buffer, pxdata, paldata, 96, 32); ColorUtil::decodeCI8image(buffer, pxdata, paldata, 96, 32);
} }
else else
{ {
u16 *pxdata = (u16*)(mc_data_blocks[DataBlock].block + DataOffset); u16 *pxdata = (u16*)(mc_data_blocks[DataBlock].block + DataOffset);
decode5A3image(buffer, pxdata, 96, 32); ColorUtil::decode5A3image(buffer, pxdata, 96, 32);
} }
return true; return true;
} }
@ -1185,16 +1148,16 @@ u32 GCMemcard::ReadAnimRGBA8(u8 index, u32* buffer, u8 *delays) const
switch (fmts[i]) switch (fmts[i])
{ {
case CI8SHARED: // CI8 with shared palette case CI8SHARED: // CI8 with shared palette
decodeCI8image(buffer,data[i],sharedPal,32,32); ColorUtil::decodeCI8image(buffer,data[i],sharedPal,32,32);
buffer += 32*32; buffer += 32*32;
break; break;
case RGB5A3: // RGB5A3 case RGB5A3: // RGB5A3
decode5A3image(buffer, (u16*)(data[i]), 32, 32); ColorUtil::decode5A3image(buffer, (u16*)(data[i]), 32, 32);
buffer += 32*32; buffer += 32*32;
break; break;
case CI8: // CI8 with own palette case CI8: // CI8 with own palette
u16 *paldata = (u16*)(data[i] + 32*32); u16 *paldata = (u16*)(data[i] + 32*32);
decodeCI8image(buffer, data[i], paldata, 32, 32); ColorUtil::decodeCI8image(buffer, data[i], paldata, 32, 32);
buffer += 32*32; buffer += 32*32;
break; break;
} }
@ -1211,15 +1174,15 @@ u32 GCMemcard::ReadAnimRGBA8(u8 index, u32* buffer, u8 *delays) const
switch (fmts[j]) switch (fmts[j])
{ {
case CI8SHARED: // CI8 with shared palette case CI8SHARED: // CI8 with shared palette
decodeCI8image(buffer,data[j],sharedPal,32,32); ColorUtil::decodeCI8image(buffer,data[j],sharedPal,32,32);
break; break;
case RGB5A3: // RGB5A3 case RGB5A3: // RGB5A3
decode5A3image(buffer, (u16*)(data[j]), 32, 32); ColorUtil::decode5A3image(buffer, (u16*)(data[j]), 32, 32);
buffer += 32*32; buffer += 32*32;
break; break;
case CI8: // CI8 with own palette case CI8: // CI8 with own palette
u16 *paldata = (u16*)(data[j] + 32*32); u16 *paldata = (u16*)(data[j] + 32*32);
decodeCI8image(buffer, data[j], paldata, 32, 32); ColorUtil::decodeCI8image(buffer, data[j], paldata, 32, 32);
buffer += 32*32; buffer += 32*32;
break; break;
} }

View File

@ -55,7 +55,7 @@ std::vector<u32> CBannerLoaderGC::GetBanner(int* pWidth, int* pHeight)
std::vector<u32> Buffer; std::vector<u32> Buffer;
Buffer.resize(DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT); Buffer.resize(DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT);
auto const pBanner = (DVDBanner*)m_pBannerFile; auto const pBanner = (DVDBanner*)m_pBannerFile;
decode5A3image(&Buffer[0], pBanner->image, DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT); ColorUtil::decode5A3image(&Buffer[0], pBanner->image, DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT);
*pWidth = DVD_BANNER_WIDTH; *pWidth = DVD_BANNER_WIDTH;
*pHeight = DVD_BANNER_HEIGHT; *pHeight = DVD_BANNER_HEIGHT;
return Buffer; return Buffer;
@ -163,25 +163,6 @@ std::vector<std::string> CBannerLoaderGC::GetDescriptions()
return descriptions; return descriptions;
} }
void CBannerLoaderGC::decode5A3image(u32* dst, u16* src, int width, int height)
{
for (int y = 0; y < height; y += 4)
{
for (int x = 0; x < width; x += 4)
{
for (int iy = 0; iy < 4; iy++, src += 4)
{
for (int ix = 0; ix < 4; ix++)
{
u32 RGBA = ColorUtil::Decode5A3(Common::swap16(src[ix]));
dst[(y + iy) * width + (x + ix)] = RGBA;
}
}
}
}
}
CBannerLoaderGC::BANNER_TYPE CBannerLoaderGC::getBannerType() CBannerLoaderGC::BANNER_TYPE CBannerLoaderGC::getBannerType()
{ {
u32 bannerSignature = *(u32*)m_pBannerFile; u32 bannerSignature = *(u32*)m_pBannerFile;

View File

@ -75,9 +75,8 @@ class CBannerLoaderGC
bool m_IsValid; bool m_IsValid;
BANNER_TYPE m_BNRType; BANNER_TYPE m_BNRType;
void decode5A3image(u32* dst, u16* src, int width, int height);
BANNER_TYPE getBannerType(); BANNER_TYPE getBannerType();
DiscIO::IVolume::ECountry const m_country; DiscIO::IVolume::ECountry const m_country;
}; };

View File

@ -103,7 +103,7 @@ std::vector<u32> CBannerLoaderWii::GetBanner(int* pWidth, int* pHeight)
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
std::vector<u32> Buffer; std::vector<u32> Buffer;
Buffer.resize(192 * 64); Buffer.resize(192 * 64);
decode5A3image(&Buffer[0], (u16*)pBanner->m_BannerTexture, 192, 64); ColorUtil::decode5A3image(&Buffer[0], (u16*)pBanner->m_BannerTexture, 192, 64);
*pWidth = 192; *pWidth = 192;
*pHeight = 64; *pHeight = 64;
return Buffer; return Buffer;
@ -153,22 +153,4 @@ std::vector<std::string> CBannerLoaderWii::GetDescriptions()
return result; return result;
} }
void CBannerLoaderWii::decode5A3image(u32* dst, u16* src, int width, int height)
{
for (int y = 0; y < height; y += 4)
{
for (int x = 0; x < width; x += 4)
{
for (int iy = 0; iy < 4; iy++, src += 4)
{
for (int ix = 0; ix < 4; ix++)
{
u32 RGBA = ColorUtil::Decode5A3(Common::swap16(src[ix]));
dst[(y + iy) * width + (x + ix)] = RGBA;
}
}
}
}
}
} // namespace } // namespace

View File

@ -59,8 +59,6 @@ class CBannerLoaderWii
bool m_IsValid; bool m_IsValid;
void decode5A3image(u32* dst, u16* src, int width, int height);
bool GetStringFromComments(const CommentIndex index, std::string& s); bool GetStringFromComments(const CommentIndex index, std::string& s);
}; };
} // namespace } // namespace