From 2c3db4446485d0867b602738e7f24a34e5e5e784 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 14 Jun 2004 01:13:31 +0000 Subject: [PATCH] error handling fixes; SDL color key fix --- stepmania/src/SDL_utils.cpp | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/stepmania/src/SDL_utils.cpp b/stepmania/src/SDL_utils.cpp index f63dc74215..4b61d5cf57 100644 --- a/stepmania/src/SDL_utils.cpp +++ b/stepmania/src/SDL_utils.cpp @@ -211,7 +211,8 @@ void mySDL_WM_SetIcon( CString sIconFile ) return; } - RageSurface *srf = RageSurfaceUtils::LoadFile(sIconFile); + CString error; + RageSurface *srf = RageSurfaceUtils::LoadFile( sIconFile, error ); if( srf == NULL ) return; @@ -247,11 +248,39 @@ SDL_Surface *SDLSurfaceFromRageSurface( RageSurface *surf ) if( surf->format->BytesPerPixel == 1 ) { ASSERT( sizeof(RageSurfaceColor) == sizeof(SDL_Color) ); - memcpy( ret->format->palette->colors, surf->fmt.palette->colors, - 256 * sizeof(RageSurfaceColor) ); + SDL_SetPalette( ret, SDL_LOGPAL, (SDL_Color *) surf->fmt.palette->colors, 0, 256 ); + + /* If we have one alpha value, transfer it to the color key. */ + int iKey = -1; + bool bUsesColorKey = true; + + for( int i = 0; i < surf->format->palette->ncolors; ++i ) + { + if( surf->format->palette->colors[i].a == 0xFF ) + continue; + if( surf->format->palette->colors[i].a != 0 ) + { + bUsesColorKey = false; + break; + } + + /* a == 0 */ + if( iKey != -1 ) + { + bUsesColorKey = false; + break; + } + iKey = i; + } + + if( bUsesColorKey && iKey != -1 ) + SDL_SetColorKey( ret, SDL_SRCCOLORKEY, iKey ); + + /* XXX: If we have more than one alpha value, or any alpha values between 1 and + * 254, it needs to be converted to RGBA. I'm not sure that we ever do that + * with surfaces passed to SDL, though. */ } - /* XXX: if we have one alpha value, transfer to colorkey */ return ret; }