2008-12-08 05:30:24 +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"
|
2009-02-22 12:43:25 +00:00
|
|
|
#include "ColorUtil.h"
|
2008-12-08 05:30:24 +00:00
|
|
|
#include "BannerLoaderWii.h"
|
|
|
|
#include "FileUtil.h"
|
|
|
|
|
|
|
|
namespace DiscIO
|
|
|
|
{
|
2009-03-20 18:13:31 +00:00
|
|
|
|
2008-12-08 05:30:24 +00:00
|
|
|
CBannerLoaderWii::CBannerLoaderWii(DiscIO::IFileSystem& _rFileSystem)
|
|
|
|
: m_pBannerFile(NULL)
|
|
|
|
, m_IsValid(false)
|
|
|
|
{
|
|
|
|
char Filename[260];
|
|
|
|
char TitleID[4];
|
|
|
|
|
|
|
|
_rFileSystem.GetVolume()->Read(0, 4, (u8*)TitleID);
|
2009-03-20 18:13:31 +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]);
|
|
|
|
|
|
|
|
if (!File::Exists(Filename))
|
|
|
|
{
|
|
|
|
m_IsValid = false;
|
|
|
|
return;
|
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
// load the opening.bnr
|
2008-12-20 18:46:49 +00:00
|
|
|
size_t FileSize = (size_t) File::GetSize(Filename);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
|
|
|
if (FileSize > 0)
|
|
|
|
{
|
|
|
|
m_pBannerFile = new u8[FileSize];
|
|
|
|
FILE* pFile = fopen(Filename, "rb");
|
2009-03-20 18:13:31 +00:00
|
|
|
if (pFile)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
|
|
|
fread(m_pBannerFile, FileSize, 1, pFile);
|
|
|
|
fclose(pFile);
|
|
|
|
m_IsValid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CBannerLoaderWii::~CBannerLoaderWii()
|
|
|
|
{
|
|
|
|
if (m_pBannerFile)
|
|
|
|
{
|
|
|
|
delete [] m_pBannerFile;
|
|
|
|
m_pBannerFile = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-20 18:13:31 +00:00
|
|
|
bool CBannerLoaderWii::IsValid()
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2009-03-20 18:13:31 +00:00
|
|
|
return m_IsValid;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2009-03-20 18:13:31 +00:00
|
|
|
bool CBannerLoaderWii::GetBanner(u32* _pBannerImage)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2009-02-07 17:31:35 +00:00
|
|
|
if (IsValid())
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2009-02-07 17:31:35 +00:00
|
|
|
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2009-03-20 18:13:31 +00:00
|
|
|
u32 Buffer[192 * 64];
|
2009-02-07 17:31:35 +00:00
|
|
|
decode5A3image(Buffer, (u16*)pBanner->m_BannerTexture, 192, 64);
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2009-03-20 18:13:31 +00:00
|
|
|
// ugly scaling :) TODO: at least a 2x2 box filter, preferably a 3x3 gaussian :)
|
|
|
|
for (int y = 0; y < 32; y++)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2009-03-20 18:13:31 +00:00
|
|
|
for (int x = 0; x < 96; x++)
|
2009-02-07 17:31:35 +00:00
|
|
|
{
|
2009-03-20 18:13:31 +00:00
|
|
|
_pBannerImage[y*96+x] = Buffer[(y*192*2) + (x*2)];
|
2009-02-07 17:31:35 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-03-20 18:13:31 +00:00
|
|
|
bool CBannerLoaderWii::GetName(std::string* _rName)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2009-02-07 17:31:35 +00:00
|
|
|
if (IsValid())
|
2009-02-03 15:03:34 +00:00
|
|
|
{
|
2009-02-07 17:31:35 +00:00
|
|
|
// find Banner type
|
|
|
|
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
2008-12-08 05:30:24 +00:00
|
|
|
|
2009-02-07 17:31:35 +00:00
|
|
|
std::string name;
|
|
|
|
if (CopyBeUnicodeToString(name, pBanner->m_Comment[0], WII_BANNER_COMMENT_SIZE))
|
2009-02-03 15:03:34 +00:00
|
|
|
{
|
2009-02-07 17:31:35 +00:00
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
_rName[i] = name;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
2009-02-03 15:03:34 +00:00
|
|
|
return false;
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
|
2009-03-20 18:13:31 +00:00
|
|
|
bool CBannerLoaderWii::GetCompany(std::string& _rCompany)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
|
|
|
_rCompany = "N/A";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-03-20 18:13:31 +00:00
|
|
|
bool CBannerLoaderWii::GetDescription(std::string* _rDescription)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
2009-02-07 17:31:35 +00:00
|
|
|
if (IsValid())
|
2009-02-03 15:03:34 +00:00
|
|
|
{
|
2009-02-07 17:31:35 +00:00
|
|
|
// find Banner type
|
|
|
|
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;
|
2009-01-21 16:31:44 +00:00
|
|
|
|
2009-02-07 17:31:35 +00:00
|
|
|
std::string description;
|
|
|
|
if (CopyBeUnicodeToString(description, pBanner->m_Comment[1], WII_BANNER_COMMENT_SIZE))
|
2009-02-03 15:03:34 +00:00
|
|
|
{
|
2009-02-07 17:31:35 +00:00
|
|
|
for (int i = 0; i< 6; i++)
|
|
|
|
{
|
|
|
|
_rDescription[i] = description;
|
|
|
|
}
|
|
|
|
return true;
|
2009-02-03 15:03:34 +00:00
|
|
|
}
|
2008-12-08 05:30:24 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-03-20 18:13:31 +00:00
|
|
|
void CBannerLoaderWii::decode5A3image(u32* dst, u16* src, int width, int height)
|
2008-12-08 05:30:24 +00:00
|
|
|
{
|
|
|
|
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++)
|
|
|
|
{
|
2009-02-22 12:43:25 +00:00
|
|
|
u32 RGBA = ColorUtil::Decode5A3(Common::swap16(src[ix]));
|
2008-12-08 05:30:24 +00:00
|
|
|
dst[(y + iy) * width + (x + ix)] = RGBA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|