excessively large commit: use RageSurface
This commit is contained in:
@@ -11,10 +11,11 @@
|
||||
#include "SDL_utils.h"
|
||||
#include "SDL_dither.h"
|
||||
#include "SDL_rotozoom.h"
|
||||
#include "SDL_utils.h"
|
||||
#include "RageDisplay.h"
|
||||
#include "RageTexture.h"
|
||||
#include "RageTextureManager.h"
|
||||
#include "RageSurface.h"
|
||||
#include "RageSurfaceUtils.h"
|
||||
|
||||
#include "Banner.h"
|
||||
|
||||
@@ -44,7 +45,7 @@
|
||||
BannerCache *BANNERCACHE;
|
||||
|
||||
|
||||
static map<CString,SDL_Surface *> m_BannerPathToImage;
|
||||
static map<CString,RageSurface *> g_BannerPathToImage;
|
||||
|
||||
CString BannerCache::GetBannerCachePath( CString BannerPath )
|
||||
{
|
||||
@@ -63,11 +64,11 @@ void BannerCache::LoadBanner( CString BannerPath )
|
||||
|
||||
for( int tries = 0; tries < 2; ++tries )
|
||||
{
|
||||
if( m_BannerPathToImage.find(BannerPath) != m_BannerPathToImage.end() )
|
||||
if( g_BannerPathToImage.find(BannerPath) != g_BannerPathToImage.end() )
|
||||
return; /* already loaded */
|
||||
|
||||
CHECKPOINT_M( ssprintf( "BannerCache::LoadBanner: %s", CachePath.c_str() ) );
|
||||
SDL_Surface *img = mySDL_LoadSurface( CachePath );
|
||||
RageSurface *img = RageSurfaceUtils::LoadSurface( CachePath );
|
||||
if( img == NULL )
|
||||
{
|
||||
if(tries == 0)
|
||||
@@ -87,17 +88,17 @@ void BannerCache::LoadBanner( CString BannerPath )
|
||||
}
|
||||
}
|
||||
|
||||
m_BannerPathToImage[BannerPath] = img;
|
||||
g_BannerPathToImage[BannerPath] = img;
|
||||
}
|
||||
}
|
||||
|
||||
void BannerCache::OutputStats() const
|
||||
{
|
||||
map<CString,SDL_Surface *>::const_iterator ban;
|
||||
map<CString,RageSurface *>::const_iterator ban;
|
||||
int total_size = 0;
|
||||
for( ban = m_BannerPathToImage.begin(); ban != m_BannerPathToImage.end(); ++ban )
|
||||
for( ban = g_BannerPathToImage.begin(); ban != g_BannerPathToImage.end(); ++ban )
|
||||
{
|
||||
SDL_Surface * const &img = ban->second;
|
||||
RageSurface * const &img = ban->second;
|
||||
const int size = img->pitch * img->h;
|
||||
total_size += size;
|
||||
}
|
||||
@@ -106,11 +107,11 @@ void BannerCache::OutputStats() const
|
||||
|
||||
void BannerCache::UnloadAllBanners()
|
||||
{
|
||||
map<CString,SDL_Surface *>::iterator it;
|
||||
for( it = m_BannerPathToImage.begin(); it != m_BannerPathToImage.end(); ++it )
|
||||
SDL_FreeSurface(it->second);
|
||||
map<CString,RageSurface *>::iterator it;
|
||||
for( it = g_BannerPathToImage.begin(); it != g_BannerPathToImage.end(); ++it )
|
||||
delete it->second;
|
||||
|
||||
m_BannerPathToImage.clear();
|
||||
g_BannerPathToImage.clear();
|
||||
}
|
||||
|
||||
BannerCache::BannerCache()
|
||||
@@ -127,11 +128,11 @@ struct BannerTexture: public RageTexture
|
||||
{
|
||||
unsigned m_uTexHandle;
|
||||
unsigned GetTexHandle() const { return m_uTexHandle; }; // accessed by RageDisplay
|
||||
/* This is a reference to a pointer in m_BannerPathToImage. */
|
||||
SDL_Surface *&img;
|
||||
/* This is a reference to a pointer in g_BannerPathToImage. */
|
||||
RageSurface *&img;
|
||||
int width, height;
|
||||
|
||||
BannerTexture( RageTextureID name, SDL_Surface *&img_, int width_, int height_ ):
|
||||
BannerTexture( RageTextureID name, RageSurface *&img_, int width_, int height_ ):
|
||||
RageTexture(name), img(img_), width(width_), height(height_)
|
||||
{
|
||||
Create();
|
||||
@@ -159,7 +160,7 @@ struct BannerTexture: public RageTexture
|
||||
img->h > DISPLAY->GetMaxTextureSize() )
|
||||
{
|
||||
LOG->Warn("Converted %s at runtime", GetID().filename.c_str() );
|
||||
ConvertSDLSurface(img, img->w, img->h, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
|
||||
RageSurfaceUtils::ConvertSurface(img, img->w, img->h, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
|
||||
zoomSurface(img, min( img->w, DISPLAY->GetMaxTextureSize() ),
|
||||
min( img->h, DISPLAY->GetMaxTextureSize() ));
|
||||
}
|
||||
@@ -218,7 +219,7 @@ RageTextureID BannerCache::LoadCachedBanner( CString BannerPath )
|
||||
ID = Sprite::SongBannerTexture(ID);
|
||||
|
||||
/* It's not in a texture. Do we have it loaded? */
|
||||
if( m_BannerPathToImage.find(BannerPath) == m_BannerPathToImage.end() )
|
||||
if( g_BannerPathToImage.find(BannerPath) == g_BannerPathToImage.end() )
|
||||
{
|
||||
/* Oops, the image is missing. Warn and continue. */
|
||||
LOG->Warn( "Banner cache for '%s' wasn't loaded", BannerPath.c_str() );
|
||||
@@ -228,7 +229,7 @@ RageTextureID BannerCache::LoadCachedBanner( CString BannerPath )
|
||||
/* This is a reference to a pointer. BannerTexture's ctor may change it
|
||||
* when converting; this way, the conversion will end up in the map so we
|
||||
* only have to convert once. */
|
||||
SDL_Surface *&img = m_BannerPathToImage[BannerPath];
|
||||
RageSurface *&img = g_BannerPathToImage[BannerPath];
|
||||
ASSERT( img );
|
||||
|
||||
int src_width = 0, src_height = 0;
|
||||
@@ -300,7 +301,7 @@ void BannerCache::CacheBanner( CString BannerPath )
|
||||
|
||||
void BannerCache::CacheBannerInternal( CString BannerPath )
|
||||
{
|
||||
SDL_Surface *img = RageSurface::LoadFile( BannerPath );
|
||||
RageSurface *img = RageSurfaceUtils::LoadFile( BannerPath );
|
||||
if( img == NULL )
|
||||
{
|
||||
LOG->Warn( "BannerCache::CacheBanner: Couldn't load %s: %s", BannerPath.c_str(), SDL_GetError() );
|
||||
@@ -322,18 +323,18 @@ void BannerCache::CacheBannerInternal( CString BannerPath )
|
||||
* This also makes the banner take less memory, though that could also be
|
||||
* done by RLEing the surface.
|
||||
*/
|
||||
ApplyHotPinkColorKey( img );
|
||||
RageSurfaceUtils::ApplyHotPinkColorKey( img );
|
||||
|
||||
ConvertSDLSurface(img, img->w, img->h, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
|
||||
RageSurfaceUtils::ConvertSurface(img, img->w, img->h, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
|
||||
|
||||
SDL_Surface *dst = SDL_CreateRGBSurface(
|
||||
SDL_SWSURFACE, 256, 64, img->format->BitsPerPixel,
|
||||
RageSurface *dst = CreateSurface(
|
||||
256, 64, img->format->BitsPerPixel,
|
||||
img->format->Rmask, img->format->Gmask, img->format->Bmask, img->format->Amask );
|
||||
|
||||
if( img->format->BitsPerPixel == 8 )
|
||||
{
|
||||
ASSERT( img->format->palette );
|
||||
mySDL_SetPalette(dst, img->format->palette->colors, 0, 256);
|
||||
dst->fmt.palette = img->fmt.palette;
|
||||
}
|
||||
|
||||
const float fCustomImageCoords[8] = {
|
||||
@@ -343,10 +344,10 @@ void BannerCache::CacheBannerInternal( CString BannerPath )
|
||||
0.78f, 0.02f, // top right
|
||||
};
|
||||
|
||||
mySDL_BlitTransform( img, dst, fCustomImageCoords );
|
||||
RageSurfaceUtils::BlitTransform( img, dst, fCustomImageCoords );
|
||||
|
||||
// SDL_SaveBMP( dst, BannerPath + "-test.bmp" );
|
||||
SDL_FreeSurface( img );
|
||||
delete img;
|
||||
img = dst;
|
||||
|
||||
WasRotatedBanner = true;
|
||||
@@ -368,42 +369,42 @@ void BannerCache::CacheBannerInternal( CString BannerPath )
|
||||
width = max( width, min(32, power_of_two(src_width)) );
|
||||
height = max( height, min(32, power_of_two(src_height)) );
|
||||
|
||||
ApplyHotPinkColorKey( img );
|
||||
RageSurfaceUtils::ApplyHotPinkColorKey( img );
|
||||
|
||||
{
|
||||
ConvertSDLSurface(img, img->w, img->h, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
|
||||
RageSurfaceUtils::ConvertSurface(img, img->w, img->h, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
|
||||
zoomSurface(img, width, height);
|
||||
|
||||
/* Dither to the final format. We use A1RGB5, since that's usually supported
|
||||
* natively by both OpenGL and D3D. */
|
||||
SDL_Surface *dst = SDL_CreateRGBSurfaceSane(SDL_SWSURFACE, img->w, img->h,
|
||||
16, 0x7C00, 0x03E0, 0x001F, 0x8000 );
|
||||
RageSurface *dst = CreateSurface( img->w, img->h, 16,
|
||||
0x7C00, 0x03E0, 0x001F, 0x8000 );
|
||||
|
||||
/* SM_SDL_OrderedDither is still faster than SM_SDL_ErrorDiffusionDither, and
|
||||
* these images are very small and only displayed briefly. */
|
||||
SM_SDL_OrderedDither(img, dst);
|
||||
SDL_FreeSurface( img );
|
||||
delete img;
|
||||
img = dst;
|
||||
}
|
||||
|
||||
const CString CachePath = GetBannerCachePath(BannerPath);
|
||||
mySDL_SaveSurface( img, CachePath );
|
||||
RageSurfaceUtils::SaveSurface( img, CachePath );
|
||||
|
||||
if( PREFSMAN->m_BannerCache == PrefsManager::BNCACHE_LOW_RES )
|
||||
{
|
||||
/* If an old image is loaded, free it. */
|
||||
if( m_BannerPathToImage.find(BannerPath) != m_BannerPathToImage.end() )
|
||||
if( g_BannerPathToImage.find(BannerPath) != g_BannerPathToImage.end() )
|
||||
{
|
||||
SDL_Surface *oldimg = m_BannerPathToImage[BannerPath];
|
||||
SDL_FreeSurface( oldimg );
|
||||
m_BannerPathToImage.erase(BannerPath);
|
||||
RageSurface *oldimg = g_BannerPathToImage[BannerPath];
|
||||
delete oldimg;
|
||||
g_BannerPathToImage.erase(BannerPath);
|
||||
}
|
||||
|
||||
/* Keep it; we're just going to load it anyway. */
|
||||
m_BannerPathToImage[BannerPath] = img;
|
||||
g_BannerPathToImage[BannerPath] = img;
|
||||
}
|
||||
else
|
||||
SDL_FreeSurface(img);
|
||||
delete img;
|
||||
|
||||
/* Remember the original size. */
|
||||
BannerData.SetValue( BannerPath, "Path", CachePath );
|
||||
|
||||
Reference in New Issue
Block a user