2003-02-16 04:01:45 +00:00
|
|
|
#include "global.h"
|
2001-11-04 19:34:28 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
2002-08-13 23:26:46 +00:00
|
|
|
Class: RageBitmapTexture
|
2001-11-04 19:34:28 +00:00
|
|
|
|
|
|
|
|
Desc: Holder for a static texture with metadata. Can load just about any image format.
|
|
|
|
|
|
2002-05-19 01:59:48 +00:00
|
|
|
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
|
2002-10-24 04:16:15 +00:00
|
|
|
Glenn Maynard
|
2002-11-14 01:26:19 +00:00
|
|
|
Chris Danford
|
2001-11-04 19:34:28 +00:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
#include "RageBitmapTexture.h"
|
|
|
|
|
#include "RageUtil.h"
|
2002-05-01 19:14:55 +00:00
|
|
|
#include "RageLog.h"
|
2003-07-09 20:27:02 +00:00
|
|
|
#include "RageTextureManager.h"
|
2002-07-27 19:29:51 +00:00
|
|
|
#include "RageException.h"
|
2002-11-14 01:26:19 +00:00
|
|
|
#include "RageDisplay.h"
|
2003-05-22 05:28:37 +00:00
|
|
|
#include "RageTypes.h"
|
2003-07-11 03:15:28 +00:00
|
|
|
#include "arch/ArchHooks/ArchHooks.h"
|
2004-04-24 07:54:18 +00:00
|
|
|
#include "PrefsManager.h"
|
2002-06-14 22:25:22 +00:00
|
|
|
|
2002-10-24 04:16:15 +00:00
|
|
|
#include "SDL.h"
|
|
|
|
|
#include "SDL_endian.h"
|
|
|
|
|
#include "SDL_rotozoom.h"
|
|
|
|
|
#include "SDL_utils.h"
|
|
|
|
|
#include "SDL_dither.h"
|
|
|
|
|
|
2003-05-05 03:14:47 +00:00
|
|
|
static void GetResolutionFromFileName( CString sPath, int &Width, int &Height )
|
|
|
|
|
{
|
|
|
|
|
/* Match:
|
2003-05-05 06:21:01 +00:00
|
|
|
* Foo (res 512x128).png
|
|
|
|
|
* Also allow, eg:
|
|
|
|
|
* Foo (dither, res 512x128).png
|
|
|
|
|
*
|
2003-05-05 03:14:47 +00:00
|
|
|
* Be careful that this doesn't get mixed up with frame dimensions. */
|
2003-05-05 06:21:01 +00:00
|
|
|
Regex re("\\([^\\)]*res ([0-9]+)x([0-9]+).*\\)");
|
2003-05-05 03:14:47 +00:00
|
|
|
|
|
|
|
|
vector<CString> matches;
|
|
|
|
|
if(!re.Compare(sPath, matches))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Width = atoi(matches[0].c_str());
|
|
|
|
|
Height = atoi(matches[1].c_str());
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// RageBitmapTexture constructor
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2002-12-30 02:43:52 +00:00
|
|
|
RageBitmapTexture::RageBitmapTexture( RageTextureID name ) :
|
|
|
|
|
RageTexture( name )
|
2001-11-03 10:52:42 +00:00
|
|
|
{
|
2002-07-31 19:40:40 +00:00
|
|
|
// LOG->Trace( "RageBitmapTexture::RageBitmapTexture()" );
|
2003-05-22 05:28:37 +00:00
|
|
|
Create();
|
2001-11-03 10:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RageBitmapTexture::~RageBitmapTexture()
|
|
|
|
|
{
|
2003-05-22 05:28:37 +00:00
|
|
|
Destroy();
|
2002-04-28 20:42:32 +00:00
|
|
|
}
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2003-01-26 00:56:13 +00:00
|
|
|
void RageBitmapTexture::Reload()
|
2002-11-14 01:26:19 +00:00
|
|
|
{
|
2003-05-22 05:28:37 +00:00
|
|
|
Destroy();
|
2002-11-14 01:26:19 +00:00
|
|
|
Create();
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-22 05:28:37 +00:00
|
|
|
/*
|
|
|
|
|
* Each dwMaxSize, dwTextureColorDepth and iAlphaBits are maximums; we may
|
|
|
|
|
* use less. iAlphaBits must be 0, 1 or 4.
|
|
|
|
|
*
|
|
|
|
|
* XXX: change iAlphaBits == 4 to iAlphaBits == 8 to indicate "as much alpha
|
|
|
|
|
* as needed", since that's what it really is; still only use 4 in 16-bit textures.
|
|
|
|
|
*
|
|
|
|
|
* Dither forces dithering when loading 16-bit textures.
|
|
|
|
|
* Stretch forces the loaded image to fill the texture completely.
|
2002-11-14 01:26:19 +00:00
|
|
|
*/
|
2003-05-22 05:28:37 +00:00
|
|
|
void RageBitmapTexture::Create()
|
2002-11-14 01:26:19 +00:00
|
|
|
{
|
2003-05-22 06:32:23 +00:00
|
|
|
RageTextureID actualID = GetID();
|
|
|
|
|
|
2003-05-22 05:28:37 +00:00
|
|
|
/* Create (and return) a surface ready to be loaded to OpenGL */
|
2002-10-24 04:16:15 +00:00
|
|
|
/* Load the image into an SDL surface. */
|
2003-12-04 20:43:22 +00:00
|
|
|
SDL_Surface *img = SDL_LoadImage( actualID.filename );
|
2003-06-05 19:29:27 +00:00
|
|
|
|
2004-02-20 05:11:12 +00:00
|
|
|
/* Tolerate corrupt/unknown images. */
|
|
|
|
|
if( img == NULL )
|
|
|
|
|
{
|
|
|
|
|
LOG->Warn( "RageBitmapTexture: Couldn't load %s: %s", actualID.filename.c_str(), SDL_GetError() );
|
|
|
|
|
img = mySDL_MakeDummySurface( 64, 64 );
|
|
|
|
|
ASSERT( img != NULL );
|
|
|
|
|
}
|
2002-11-14 01:26:19 +00:00
|
|
|
|
2003-05-22 06:32:23 +00:00
|
|
|
if(actualID.bHotPinkColorKey)
|
2003-01-22 04:18:02 +00:00
|
|
|
{
|
2003-06-09 19:22:04 +00:00
|
|
|
// HACK: Some Pump banners and DDR PC textures have (248,0,248) as the color key.
|
|
|
|
|
// Search the edge for (248,0,248). If we find it, use that as the color key.
|
|
|
|
|
// TODO: Get rid of this hack and save DDR PC textures in a format that supports alpha.
|
|
|
|
|
bool bUse248 = false;
|
|
|
|
|
{
|
|
|
|
|
const Uint8 *p = (Uint8*)img->pixels;
|
|
|
|
|
for( int i=0; i<img->w; i++ )
|
|
|
|
|
{
|
|
|
|
|
Uint8 color[4];
|
|
|
|
|
mySDL_GetRGBAV( p, img, color );
|
|
|
|
|
if( color[0]==248 && color[1]==0 && color[2]==248 )
|
|
|
|
|
{
|
|
|
|
|
bUse248 = true;
|
|
|
|
|
goto apply_color_key;
|
|
|
|
|
}
|
|
|
|
|
p += img->format->BytesPerPixel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
const Uint8 *p = (Uint8*)img->pixels;
|
|
|
|
|
p += img->pitch * (img->h-1);
|
|
|
|
|
for( int i=0; i<img->w; i++ )
|
|
|
|
|
{
|
|
|
|
|
Uint8 color[4];
|
|
|
|
|
mySDL_GetRGBAV( p, img, color );
|
|
|
|
|
if( color[0]==248 && color[1]==0 && color[2]==248 )
|
|
|
|
|
{
|
|
|
|
|
bUse248 = true;
|
|
|
|
|
goto apply_color_key;
|
|
|
|
|
}
|
|
|
|
|
p += img->format->BytesPerPixel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
apply_color_key:
|
|
|
|
|
int color = mySDL_MapRGBExact(img->format, bUse248 ? 248 : 0xFF, 0, bUse248 ? 248 : 0xFF);
|
2003-01-22 04:18:02 +00:00
|
|
|
if( color != -1 )
|
2003-06-04 20:16:16 +00:00
|
|
|
SDL_SetColorKey( img, SDL_SRCCOLORKEY, color );
|
2003-01-22 04:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
2003-03-27 06:01:43 +00:00
|
|
|
{
|
2003-10-08 02:52:51 +00:00
|
|
|
/* Do this after setting the color key for paletted images; it'll also return
|
2003-03-27 06:01:43 +00:00
|
|
|
* TRAIT_NO_TRANSPARENCY if the color key is never used. */
|
|
|
|
|
int traits = FindSurfaceTraits(img);
|
2003-04-01 07:47:19 +00:00
|
|
|
if(traits & TRAIT_NO_TRANSPARENCY)
|
2003-05-22 06:32:23 +00:00
|
|
|
actualID.iAlphaBits = 0;
|
2003-04-01 07:47:19 +00:00
|
|
|
else if(traits & TRAIT_BOOL_TRANSPARENCY)
|
2003-05-22 06:32:23 +00:00
|
|
|
actualID.iAlphaBits = 1;
|
2003-03-27 06:01:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// look in the file name for a format hints
|
2003-10-08 02:52:51 +00:00
|
|
|
CString HintString = GetID().filename + actualID.AdditionalTextureHints;
|
2003-03-27 06:01:43 +00:00
|
|
|
HintString.MakeLower();
|
|
|
|
|
|
2003-09-03 08:41:12 +00:00
|
|
|
if( HintString.Find("32bpp") != -1 ) actualID.iColorDepth = 32;
|
|
|
|
|
else if( HintString.Find("16bpp") != -1 ) actualID.iColorDepth = 16;
|
2003-05-22 06:32:23 +00:00
|
|
|
if( HintString.Find("dither") != -1 ) actualID.bDither = true;
|
2003-07-07 01:29:18 +00:00
|
|
|
if( HintString.Find("stretch") != -1 ) actualID.bStretch = true;
|
2004-02-03 07:41:10 +00:00
|
|
|
if( HintString.Find("nomipmaps") != -1 ) actualID.bMipMaps = false;
|
2003-03-27 06:01:43 +00:00
|
|
|
|
2003-10-08 02:52:51 +00:00
|
|
|
/* If the image is marked grayscale, then use all bits not used for alpha
|
|
|
|
|
* for the intensity. This way, if an image has no alpha, you get an 8-bit
|
|
|
|
|
* grayscale; if it only has boolean transparency, you get a 7-bit grayscale. */
|
|
|
|
|
if( HintString.Find("grayscale") != -1 ) actualID.iGrayscaleBits = 8-actualID.iAlphaBits;
|
|
|
|
|
|
2003-10-08 23:21:14 +00:00
|
|
|
/* This indicates that the only component in the texture is alpha; assume all
|
|
|
|
|
* color is white. */
|
|
|
|
|
if( HintString.Find("alphamap") != -1 ) actualID.iGrayscaleBits = 0;
|
|
|
|
|
|
2003-10-08 02:23:53 +00:00
|
|
|
/* No iGrayscaleBits for images that are already paletted. We don't support
|
|
|
|
|
* that; and that hint is intended for use on images that are already grayscale,
|
|
|
|
|
* it's not intended to change a color image into a grayscale image. */
|
|
|
|
|
if( actualID.iGrayscaleBits != -1 && img->format->BitsPerPixel == 8 )
|
|
|
|
|
actualID.iGrayscaleBits = -1;
|
|
|
|
|
|
2002-11-14 01:26:19 +00:00
|
|
|
/* Cap the max texture size to the hardware max. */
|
2003-05-22 06:32:23 +00:00
|
|
|
actualID.iMaxSize = min( actualID.iMaxSize, DISPLAY->GetMaxTextureSize() );
|
2002-11-14 01:26:19 +00:00
|
|
|
|
|
|
|
|
/* Save information about the source. */
|
|
|
|
|
m_iSourceWidth = img->w;
|
|
|
|
|
m_iSourceHeight = img->h;
|
|
|
|
|
|
|
|
|
|
/* image size cannot exceed max size */
|
2003-05-22 06:32:23 +00:00
|
|
|
m_iImageWidth = min( m_iSourceWidth, actualID.iMaxSize );
|
|
|
|
|
m_iImageHeight = min( m_iSourceHeight, actualID.iMaxSize );
|
2002-10-24 04:16:15 +00:00
|
|
|
|
2004-04-24 07:54:18 +00:00
|
|
|
if( PREFSMAN->m_bHalveTextureHeight )
|
|
|
|
|
m_iImageHeight /= 2;
|
|
|
|
|
|
2002-10-24 04:16:15 +00:00
|
|
|
/* Texture dimensions need to be a power of two; jump to the next. */
|
2002-11-14 01:26:19 +00:00
|
|
|
m_iTextureWidth = power_of_two(m_iImageWidth);
|
|
|
|
|
m_iTextureHeight = power_of_two(m_iImageHeight);
|
|
|
|
|
|
2003-06-22 01:02:22 +00:00
|
|
|
/* If we're under 8x8, increase it, to avoid filtering problems on odd hardware. */
|
|
|
|
|
if(m_iTextureWidth < 8 || m_iTextureHeight < 8)
|
|
|
|
|
{
|
|
|
|
|
actualID.bStretch = true;
|
|
|
|
|
m_iTextureWidth = max(8, m_iTextureWidth);
|
|
|
|
|
m_iTextureHeight = max(8, m_iTextureHeight);
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-22 06:32:23 +00:00
|
|
|
ASSERT( m_iTextureWidth <= actualID.iMaxSize );
|
|
|
|
|
ASSERT( m_iTextureHeight <= actualID.iMaxSize );
|
2002-11-14 01:26:19 +00:00
|
|
|
|
2003-05-22 06:32:23 +00:00
|
|
|
if(actualID.bStretch)
|
2002-11-21 22:34:37 +00:00
|
|
|
{
|
|
|
|
|
/* The hints asked for the image to be stretched to the texture size,
|
|
|
|
|
* probably for tiling. */
|
|
|
|
|
m_iImageWidth = m_iTextureWidth;
|
|
|
|
|
m_iImageHeight = m_iTextureHeight;
|
|
|
|
|
}
|
2002-11-14 01:26:19 +00:00
|
|
|
|
2003-05-22 05:28:37 +00:00
|
|
|
if( img->w != m_iImageWidth || img->h != m_iImageHeight )
|
2002-11-14 01:26:19 +00:00
|
|
|
{
|
|
|
|
|
/* resize currently only does RGBA8888 */
|
2003-05-22 05:28:37 +00:00
|
|
|
ConvertSDLSurface(img, img->w, img->h, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
|
2002-11-21 22:34:37 +00:00
|
|
|
zoomSurface(img, m_iImageWidth, m_iImageHeight );
|
2002-11-14 01:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
2003-05-22 05:28:37 +00:00
|
|
|
// Format of the image that we will pass to OpenGL and that we want OpenGL to use
|
2003-10-03 21:38:38 +00:00
|
|
|
RageDisplay::PixelFormat pixfmt;
|
2003-01-01 09:07:34 +00:00
|
|
|
|
2003-10-08 02:23:53 +00:00
|
|
|
if( actualID.iGrayscaleBits != -1 && DISPLAY->SupportsTextureFormat(RageDisplay::FMT_PAL) )
|
|
|
|
|
{
|
|
|
|
|
SDL_Surface *dst = mySDL_Palettize( img, actualID.iGrayscaleBits, actualID.iAlphaBits );
|
|
|
|
|
|
|
|
|
|
SDL_FreeSurface(img);
|
|
|
|
|
img = dst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( img->format->BitsPerPixel == 8 && actualID.iGrayscaleBits == -1 )
|
2003-10-08 01:21:36 +00:00
|
|
|
{
|
|
|
|
|
/* Unless we set up the palette ourself, assume the "unused" bit is undefined,
|
|
|
|
|
* and set it to 255. We use it for alpha. */
|
|
|
|
|
for( int index = 0; index < img->format->palette->ncolors; ++index )
|
|
|
|
|
img->format->palette->colors[index].unused = 0xFF;
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-22 05:28:37 +00:00
|
|
|
/* Figure out which texture format to use. */
|
|
|
|
|
// if the source is palleted, load palleted no matter what the prefs
|
2003-10-03 21:38:38 +00:00
|
|
|
if(img->format->BitsPerPixel == 8 && DISPLAY->SupportsTextureFormat(RageDisplay::FMT_PAL))
|
2003-05-22 05:28:37 +00:00
|
|
|
{
|
2003-10-03 21:38:38 +00:00
|
|
|
pixfmt = RageDisplay::FMT_PAL;
|
2003-05-22 05:28:37 +00:00
|
|
|
}
|
|
|
|
|
else
|
2003-01-26 02:35:55 +00:00
|
|
|
{
|
2003-05-22 05:28:37 +00:00
|
|
|
// not paletted
|
2003-05-22 06:32:23 +00:00
|
|
|
switch( actualID.iColorDepth )
|
2003-05-22 05:28:37 +00:00
|
|
|
{
|
|
|
|
|
case 16:
|
|
|
|
|
{
|
|
|
|
|
/* Bits of alpha in the source: */
|
|
|
|
|
int src_alpha_bits = 8 - img->format->Aloss;
|
|
|
|
|
|
|
|
|
|
/* No real alpha in paletted input. */
|
|
|
|
|
if( img->format->BytesPerPixel == 1 )
|
|
|
|
|
src_alpha_bits = 0;
|
|
|
|
|
|
|
|
|
|
/* Colorkeyed input effectively has at least one bit of alpha: */
|
|
|
|
|
if( img->flags & SDL_SRCCOLORKEY )
|
|
|
|
|
src_alpha_bits = max( 1, src_alpha_bits );
|
|
|
|
|
|
|
|
|
|
/* Don't use more than we were hinted to. */
|
2003-05-22 06:32:23 +00:00
|
|
|
src_alpha_bits = min( actualID.iAlphaBits, src_alpha_bits );
|
2003-05-22 05:28:37 +00:00
|
|
|
|
|
|
|
|
switch( src_alpha_bits ) {
|
|
|
|
|
case 0:
|
|
|
|
|
case 1:
|
2003-10-03 21:38:38 +00:00
|
|
|
pixfmt = RageDisplay::FMT_RGB5A1;
|
2003-05-22 05:28:37 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
2003-10-03 21:38:38 +00:00
|
|
|
pixfmt = RageDisplay::FMT_RGBA4;
|
2003-05-22 05:28:37 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 32:
|
2003-10-03 21:38:38 +00:00
|
|
|
pixfmt = RageDisplay::FMT_RGBA8;
|
2003-05-22 05:28:37 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
2003-05-22 06:32:23 +00:00
|
|
|
RageException::Throw( "Invalid color depth: %d bits", actualID.iColorDepth );
|
2003-05-22 05:28:37 +00:00
|
|
|
}
|
2003-01-26 02:35:55 +00:00
|
|
|
|
2003-05-22 05:28:37 +00:00
|
|
|
/* It's either not a paletted image, or we can't handle paletted textures.
|
|
|
|
|
* Convert to the desired RGBA format, dithering if appropriate. */
|
2003-05-22 06:32:23 +00:00
|
|
|
if( actualID.bDither &&
|
2003-10-03 21:38:38 +00:00
|
|
|
(pixfmt==RageDisplay::FMT_RGBA4 || pixfmt==RageDisplay::FMT_RGB5A1) ) /* Don't dither if format is 32bpp; there's no point. */
|
2003-01-26 02:35:55 +00:00
|
|
|
{
|
|
|
|
|
/* Dither down to the destination format. */
|
2003-10-03 21:38:38 +00:00
|
|
|
const RageDisplay::PixelFormatDesc *pfd = DISPLAY->GetPixelFormatDesc(pixfmt);
|
2003-05-26 03:12:12 +00:00
|
|
|
SDL_Surface *dst = SDL_CreateRGBSurfaceSane(SDL_SWSURFACE, img->w, img->h,
|
|
|
|
|
pfd->bpp, pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3]);
|
2003-01-26 02:35:55 +00:00
|
|
|
|
2003-04-26 10:57:40 +00:00
|
|
|
SM_SDL_ErrorDiffusionDither(img, dst);
|
2003-01-26 02:35:55 +00:00
|
|
|
SDL_FreeSurface(img);
|
|
|
|
|
img = dst;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This needs to be done *after* the final resize, since that resize
|
|
|
|
|
* may introduce new alpha bits that need to be set. It needs to be
|
|
|
|
|
* done *before* we set up the palette, since it might change it. */
|
2003-01-23 05:35:21 +00:00
|
|
|
FixHiddenAlpha(img);
|
2003-01-23 04:45:45 +00:00
|
|
|
|
2003-05-28 00:50:10 +00:00
|
|
|
/* Make we're using a supported format.
|
|
|
|
|
* Every card supports either RGBA8 or RGBA4. */
|
|
|
|
|
if( !DISPLAY->SupportsTextureFormat(pixfmt) )
|
|
|
|
|
{
|
2003-10-03 21:38:38 +00:00
|
|
|
pixfmt = RageDisplay::FMT_RGBA8;
|
2003-05-28 00:50:10 +00:00
|
|
|
if( !DISPLAY->SupportsTextureFormat(pixfmt) )
|
2003-10-03 21:38:38 +00:00
|
|
|
pixfmt = RageDisplay::FMT_RGBA4;
|
2003-05-28 00:50:10 +00:00
|
|
|
}
|
2003-07-22 07:47:27 +00:00
|
|
|
|
2003-05-28 00:50:10 +00:00
|
|
|
|
2003-05-22 05:28:37 +00:00
|
|
|
/* Convert the data to the destination format and dimensions
|
|
|
|
|
* required by OpenGL if it's not in it already. */
|
2003-10-03 21:38:38 +00:00
|
|
|
const RageDisplay::PixelFormatDesc *pfd = DISPLAY->GetPixelFormatDesc(pixfmt);
|
2003-05-26 03:12:12 +00:00
|
|
|
ConvertSDLSurface(img, m_iTextureWidth, m_iTextureHeight,
|
|
|
|
|
pfd->bpp, pfd->masks[0], pfd->masks[1], pfd->masks[2], pfd->masks[3]);
|
2003-05-22 05:28:37 +00:00
|
|
|
|
2004-01-23 06:20:28 +00:00
|
|
|
m_uTexHandle = DISPLAY->CreateTexture( pixfmt, img, actualID.bMipMaps );
|
2002-11-11 04:53:31 +00:00
|
|
|
|
|
|
|
|
CreateFrameRects();
|
2003-05-22 05:28:37 +00:00
|
|
|
|
2003-07-05 05:34:16 +00:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Enforce frames in the image have even dimensions. Otherwise,
|
|
|
|
|
// pixel/texel alignment will be off.
|
|
|
|
|
//
|
|
|
|
|
bool bRunCheck = true;
|
|
|
|
|
|
|
|
|
|
// Don't check if the artist intentionally blanked the image by making it very tiny.
|
|
|
|
|
if( this->GetSourceWidth()<=2 || this->GetSourceHeight()<=2 )
|
|
|
|
|
bRunCheck = false;
|
|
|
|
|
|
|
|
|
|
// HACK: Don't check song graphics. Many of them are weird dimensions.
|
2003-07-09 20:27:02 +00:00
|
|
|
if( !TEXTUREMAN->GetOddDimensionWarning() )
|
2003-07-07 01:29:18 +00:00
|
|
|
bRunCheck = false;
|
2003-07-05 05:34:16 +00:00
|
|
|
|
2003-07-09 20:27:02 +00:00
|
|
|
if( bRunCheck )
|
2003-07-04 22:47:20 +00:00
|
|
|
{
|
2003-07-04 23:17:42 +00:00
|
|
|
float fFrameWidth = this->GetSourceWidth() / (float)this->GetFramesWide();
|
|
|
|
|
float fFrameHeight = this->GetSourceHeight() / (float)this->GetFramesHigh();
|
|
|
|
|
float fBetterFrameWidth = roundf((fFrameWidth+0.99f)/2)*2;
|
|
|
|
|
float fBetterFrameHeight = roundf((fFrameHeight+0.99f)/2)*2;
|
|
|
|
|
float fBetterSourceWidth = this->GetFramesWide() * fBetterFrameWidth;
|
|
|
|
|
float fBetterSourceHeight = this->GetFramesHigh() * fBetterFrameHeight;
|
|
|
|
|
if( fFrameWidth!=fBetterFrameWidth || fFrameHeight!=fBetterFrameHeight )
|
|
|
|
|
{
|
|
|
|
|
CString sWarning = ssprintf(
|
|
|
|
|
"The graphic '%s' has frame dimensions that aren't even numbers.\n\n"
|
|
|
|
|
"The entire image is %dx%d and frame size is %.1fx%.1f.\n\n"
|
|
|
|
|
"Image quality will be much improved if you resize the graphic to %.0fx%.0f, which is a frame size of %.0fx%.0f.",
|
|
|
|
|
actualID.filename.c_str(),
|
|
|
|
|
this->GetSourceWidth(), this->GetSourceHeight(),
|
|
|
|
|
fFrameWidth, fFrameHeight,
|
|
|
|
|
fBetterSourceWidth, fBetterSourceHeight,
|
|
|
|
|
fBetterFrameWidth, fBetterFrameHeight );
|
|
|
|
|
LOG->Warn( sWarning );
|
2003-11-15 06:08:13 +00:00
|
|
|
HOOKS->MessageBoxOK( sWarning, "FRAME_DIMENSIONS_WARNING" );
|
2003-07-04 23:17:42 +00:00
|
|
|
}
|
2003-07-04 22:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
2003-07-05 05:34:16 +00:00
|
|
|
|
|
|
|
|
|
2003-07-04 22:47:20 +00:00
|
|
|
SDL_FreeSurface( img );
|
|
|
|
|
|
2003-05-22 06:32:23 +00:00
|
|
|
/* See if the apparent "size" is being overridden. */
|
|
|
|
|
GetResolutionFromFileName(actualID.filename, m_iSourceWidth, m_iSourceHeight);
|
|
|
|
|
|
|
|
|
|
|
2003-05-26 01:06:01 +00:00
|
|
|
CString props;
|
2003-10-03 21:38:38 +00:00
|
|
|
props += RageDisplay::PixelFormatToString( pixfmt ) + " ";
|
2003-05-22 06:32:23 +00:00
|
|
|
if(actualID.iAlphaBits == 0) props += "opaque ";
|
|
|
|
|
if(actualID.iAlphaBits == 1) props += "matte ";
|
|
|
|
|
if(actualID.bStretch) props += "stretch ";
|
|
|
|
|
if(actualID.bDither) props += "dither ";
|
2003-03-27 06:01:43 +00:00
|
|
|
props.erase(props.size()-1);
|
|
|
|
|
LOG->Trace( "RageBitmapTexture: Loaded '%s' (%ux%u); %s, source %d,%d; image %d,%d.",
|
2003-05-22 06:32:23 +00:00
|
|
|
actualID.filename.c_str(), GetTextureWidth(), GetTextureHeight(),
|
2003-04-25 00:01:35 +00:00
|
|
|
props.c_str(), m_iSourceWidth, m_iSourceHeight,
|
2003-03-27 06:01:43 +00:00
|
|
|
m_iImageWidth, m_iImageHeight);
|
2003-05-22 05:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RageBitmapTexture::Destroy()
|
|
|
|
|
{
|
|
|
|
|
DISPLAY->DeleteTexture( m_uTexHandle );
|
2001-11-03 10:52:42 +00:00
|
|
|
}
|
2002-11-14 01:26:19 +00:00
|
|
|
|