From 5e1cde48fbf809b1e39e4ca6d19fd4631f3262a4 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 16 Jun 2003 18:26:24 +0000 Subject: [PATCH] detect square (diagonal) banners, and give a small margin of error --- stepmania/src/BannerCache.cpp | 3 ++- stepmania/src/CroppedSprite.cpp | 9 ++++++++- stepmania/src/CroppedSprite.h | 2 ++ stepmania/src/Song.cpp | 8 ++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/stepmania/src/BannerCache.cpp b/stepmania/src/BannerCache.cpp index bdec2ed850..042e583eb3 100644 --- a/stepmania/src/BannerCache.cpp +++ b/stepmania/src/BannerCache.cpp @@ -10,6 +10,7 @@ #include "RageUtil.h" #include "RageLog.h" #include "BannerCache.h" +#include "CroppedSprite.h" #include "PrefsManager.h" #include "SDL_utils.h" #include "SDL_dither.h" @@ -304,7 +305,7 @@ void BannerCache::CacheBannerInternal( CString BannerPath ) bool WasRotatedBanner = false; - if( img->w == img->h ) + if( CroppedSprite::IsDiagonalBanner(img->w , img->h) ) { /* Ack. It's a diagonal banner. Problem: if we resize a diagonal banner, we * get ugly checker patterns. We need to un-rotate it. diff --git a/stepmania/src/CroppedSprite.cpp b/stepmania/src/CroppedSprite.cpp index b6536d8418..3801d259d9 100644 --- a/stepmania/src/CroppedSprite.cpp +++ b/stepmania/src/CroppedSprite.cpp @@ -56,7 +56,7 @@ void CroppedSprite::CropToSize( float fWidth, float fHeight ) float fOriginalX = GetX(); float fOriginalY = GetY(); - if( iSourceWidth == iSourceHeight ) // this is a SSR/DWI CroppedSprite + if( IsDiagonalBanner(iSourceWidth, iSourceHeight) ) // this is a SSR/DWI CroppedSprite { float fCustomImageCoords[8] = { 0.02f, 0.78f, // top left @@ -137,3 +137,10 @@ void CroppedSprite::CropToSize( float fWidth, float fHeight ) // restore original XY SetXY( fOriginalX, fOriginalY ); } + +bool CroppedSprite::IsDiagonalBanner( int iWidth, int iHeight ) +{ + /* A diagonal banner is a square. Give a couple pixels of leeway. */ + return iWidth >= 100 && abs(iWidth - iHeight) < 2; +} + diff --git a/stepmania/src/CroppedSprite.h b/stepmania/src/CroppedSprite.h index fc86fbff05..c27cbcc3d7 100644 --- a/stepmania/src/CroppedSprite.h +++ b/stepmania/src/CroppedSprite.h @@ -25,6 +25,8 @@ public: void SetCroppedSize( float fWidth, float fHeight ); void SetWH(float fWidth, float fHeight); + static bool IsDiagonalBanner( int iWidth, int iHeight ); + protected: void CropToSize( float fWidth, float fHeight ); diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 6e0c4e5bb8..92ecc18044 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -27,6 +27,7 @@ #include "FontCharAliases.h" #include "TitleSubstitution.h" #include "BannerCache.h" +#include "CroppedSprite.h" #include "NotesLoaderSM.h" #include "NotesLoaderDWI.h" @@ -670,6 +671,13 @@ void Song::TidyUpData() m_sBackgroundFile = arrayImages[i]; continue; } + + if( CroppedSprite::IsDiagonalBanner(width, height) ) + { + m_sBannerFile = arrayImages[i]; + continue; + } + if( !HasBanner() && 100<=width && width<=320 && 50<=height && height<=240 ) { m_sBannerFile = arrayImages[i];