2008-07-12 17:40:22 +00:00
|
|
|
// Copyright (C) 2003-2008 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "Common.h"
|
|
|
|
#include "BannerLoaderWii.h"
|
2008-11-01 15:59:06 +00:00
|
|
|
#include "FileUtil.h"
|
2008-07-12 17:40:22 +00:00
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
2008-11-01 15:59:06 +00:00
|
|
|
CBannerLoaderWii::CBannerLoaderWii(DiscIO::IFileSystem& _rFileSystem)
|
|
|
|
: m_pBannerFile(NULL)
|
|
|
|
, m_IsValid(false)
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
2008-11-01 15:59:06 +00:00
|
|
|
InitLUTTable();
|
|
|
|
|
|
|
|
char Filename[260];
|
|
|
|
char TitleID[4];
|
|
|
|
|
|
|
|
_rFileSystem.GetVolume()->Read(0, 4, (u8*)TitleID);
|
2008-11-12 08:16:09 +00:00
|
|
|
sprintf(Filename, FULL_WII_USER_DIR "title/00010000/%02x%02x%02x%02x/data/banner.bin", (u8)TitleID[0], (u8)TitleID[1], (u8)TitleID[2], (u8)TitleID[3]);
|
2008-11-01 15:59:06 +00:00
|
|
|
|
|
|
|
// load the opening.bnr
|
|
|
|
size_t FileSize = File::GetSize(Filename);
|
|
|
|
|
|
|
|
if (FileSize > 0)
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
2008-11-01 15:59:06 +00:00
|
|
|
m_pBannerFile = new u8[FileSize];
|
|
|
|
FILE* pFile = fopen(Filename, "rb");
|
|
|
|
if (pFile != NULL)
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
2008-11-01 15:59:06 +00:00
|
|
|
fread(m_pBannerFile, FileSize, 1, pFile);
|
|
|
|
fclose(pFile);
|
|
|
|
m_IsValid = true;
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CBannerLoaderWii::~CBannerLoaderWii()
|
|
|
|
{
|
2008-11-01 15:59:06 +00:00
|
|
|
if (m_pBannerFile)
|
|
|
|
{
|
|
|
|
delete [] m_pBannerFile;
|
|
|
|
m_pBannerFile = NULL;
|
|
|
|
}
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
CBannerLoaderWii::IsValid()
|
|
|
|
{
|
2008-11-01 15:59:06 +00:00
|
|
|
return (m_IsValid);
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
CBannerLoaderWii::GetBanner(u32* _pBannerImage)
|
|
|
|
{
|
2008-11-01 15:59:06 +00:00
|
|
|
if (!IsValid())
|
|
|
|
{
|
2008-11-26 17:16:54 +00:00
|
|
|
return false;
|
2008-11-01 15:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
|
|
|
|
|
|
|
static u32 Buffer[192 * 64];
|
|
|
|
decode5A3image(Buffer, (u16*)pBanner->m_BannerTexture, 192, 64);
|
|
|
|
|
2008-11-01 18:33:37 +00:00
|
|
|
// ugly scaling :)
|
2008-11-01 15:59:06 +00:00
|
|
|
for (int y=0; y<32; y++)
|
|
|
|
{
|
|
|
|
for (int x=0; x<96; x++)
|
|
|
|
{
|
2008-11-05 21:05:04 +00:00
|
|
|
_pBannerImage[y*96+x] = Buffer[(y*192*2)+(x*2)];
|
2008-11-01 15:59:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-26 17:16:54 +00:00
|
|
|
return true;
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
|
|
|
|
2008-11-01 15:59:06 +00:00
|
|
|
std::string
|
|
|
|
CBannerLoaderWii::StupidWideCharToString(u16* _pSrc, size_t _max)
|
|
|
|
{
|
|
|
|
std::string temp;
|
|
|
|
|
|
|
|
int offset = 0;
|
|
|
|
while (_pSrc[offset] != 0x0000)
|
|
|
|
{
|
|
|
|
temp += (char)(_pSrc[offset] >> 8);
|
|
|
|
offset ++;
|
|
|
|
|
|
|
|
if (offset >= _max)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
}
|
2008-07-12 17:40:22 +00:00
|
|
|
|
|
|
|
bool
|
2008-07-20 12:26:32 +00:00
|
|
|
CBannerLoaderWii::GetName(std::string& _rName, int language)
|
2008-07-12 17:40:22 +00:00
|
|
|
{
|
2008-11-01 15:59:06 +00:00
|
|
|
if (IsValid())
|
|
|
|
{
|
|
|
|
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
|
|
|
|
|
|
|
// very stupid
|
|
|
|
_rName = StupidWideCharToString(pBanner->m_Comment[0], WII_BANNER_COMMENT_SIZE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-11-26 17:16:54 +00:00
|
|
|
return true;
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
CBannerLoaderWii::GetCompany(std::string& _rCompany)
|
|
|
|
{
|
2008-11-26 17:16:54 +00:00
|
|
|
_rCompany = "N/A";
|
|
|
|
return true;
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
CBannerLoaderWii::GetDescription(std::string& _rDescription)
|
|
|
|
{
|
2008-11-01 15:59:06 +00:00
|
|
|
if (IsValid())
|
|
|
|
{
|
|
|
|
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
|
|
|
|
|
|
|
// very stupid
|
|
|
|
_rDescription = StupidWideCharToString(pBanner->m_Comment[1], WII_BANNER_COMMENT_SIZE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-11-26 17:16:54 +00:00
|
|
|
return false;
|
2008-07-12 17:40:22 +00:00
|
|
|
}
|
2008-11-01 15:59:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CBannerLoaderWii::InitLUTTable()
|
|
|
|
{
|
|
|
|
// build LUT Table
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
lut3to8[i] = (i * 255) / 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
lut4to8[i] = (i * 255) / 15;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 32; i++)
|
|
|
|
{
|
|
|
|
lut5to8[i] = (i * 255) / 31;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u32
|
|
|
|
CBannerLoaderWii::decode5A3(u16 val)
|
|
|
|
{
|
|
|
|
u32 bannerBGColor = 0x00000000;
|
|
|
|
|
|
|
|
int r, g, b, a;
|
|
|
|
|
|
|
|
if ((val & 0x8000))
|
|
|
|
{
|
|
|
|
r = lut5to8[(val >> 10) & 0x1f];
|
|
|
|
g = lut5to8[(val >> 5) & 0x1f];
|
|
|
|
b = lut5to8[(val) & 0x1f];
|
|
|
|
a = 0xFF;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
a = lut3to8[(val >> 12) & 0x7];
|
|
|
|
r = (lut4to8[(val >> 8) & 0xf] * a + (bannerBGColor & 0xFF) * (255 - a)) / 255;
|
|
|
|
g = (lut4to8[(val >> 4) & 0xf] * a + ((bannerBGColor >> 8) & 0xFF) * (255 - a)) / 255;
|
|
|
|
b = (lut4to8[(val) & 0xf] * a + ((bannerBGColor >> 16) & 0xFF) * (255 - a)) / 255;
|
|
|
|
a = 0xFF;
|
|
|
|
}
|
|
|
|
|
2008-11-26 17:16:54 +00:00
|
|
|
return ((a << 24) | (r << 16) | (g << 8) | b);
|
2008-11-01 15:59:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 = decode5A3(Common::swap16(src[ix]));
|
|
|
|
dst[(y + iy) * width + (x + ix)] = RGBA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-12 17:40:22 +00:00
|
|
|
} // namespace
|
|
|
|
|