From c840297615c8e291be5516502156a6755d6a58fa Mon Sep 17 00:00:00 2001 From: hrydgard Date: Mon, 11 Jan 2010 23:24:32 +0000 Subject: [PATCH] Better-quality downsizing of Wii banners (yeah yeah I know it's not important but it's been sitting on my harddrive for ages). git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4806 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/DiscIO/Src/BannerLoaderWii.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp index 305d262a72..c495fbff60 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp +++ b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp @@ -116,21 +116,33 @@ bool CBannerLoaderWii::IsValid() return m_IsValid; } +static inline u32 Average32(u32 a, u32 b) { + return ((a >> 1) & 0x7f7f7f7f) + ((b >> 1) & 0x7f7f7f7f); +} + +static inline u32 GetPixel(u32 *buffer, unsigned int x, unsigned int y) { + // thanks to unsignedness, these also check for <0 automatically. + if (x > 191) return 0; + if (y > 63) return 0; + return buffer[y * 192 + x]; +} + bool CBannerLoaderWii::GetBanner(u32* _pBannerImage) { if (IsValid()) { SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; - u32* Buffer = new u32[192 * 64]; decode5A3image(Buffer, (u16*)pBanner->m_BannerTexture, 192, 64); - - // ugly scaling :) TODO: at least a 2x2 box filter, preferably a 3x3 gaussian :) for (int y = 0; y < 32; y++) { for (int x = 0; x < 96; x++) { - _pBannerImage[y*96+x] = Buffer[(y*192*2) + (x*2)]; + // simplified plus-shaped "gaussian" + u32 surround = Average32( + Average32(GetPixel(Buffer, x*2 - 1, y*2), GetPixel(Buffer, x*2 + 1, y*2)), + Average32(GetPixel(Buffer, x*2, y*2 - 1), GetPixel(Buffer, x*2, y*2 + 1))); + _pBannerImage[y * 96 + x] = Average32(GetPixel(Buffer, x*2, y*2), surround); } } delete[] Buffer;