diff --git a/stepmania/src/RageBitmapTexture.cpp b/stepmania/src/RageBitmapTexture.cpp index d47313ecac..35c55128bb 100644 --- a/stepmania/src/RageBitmapTexture.cpp +++ b/stepmania/src/RageBitmapTexture.cpp @@ -211,7 +211,7 @@ apply_color_key: img = dst; } - if( img->format->BitsPerPixel == 8 && actualID.iGrayscaleBits == -1 ) + if( img->format->BitsPerPixel == 8 && actualID.iGrayscaleBits == -1 && !(img->unused1 & ALPHA_PALETTE) ) { /* Unless we set up the palette ourself, assume the "unused" bit is undefined, * and set it to 255. We use it for alpha. */ diff --git a/stepmania/src/SDL_utils.cpp b/stepmania/src/SDL_utils.cpp index 6b8e6b1b6b..33e935b3cd 100644 --- a/stepmania/src/SDL_utils.cpp +++ b/stepmania/src/SDL_utils.cpp @@ -430,6 +430,18 @@ int FindSurfaceTraits( const SDL_Surface *img ) const int NEEDS_NO_ALPHA=0, NEEDS_BOOL_ALPHA=1, NEEDS_FULL_ALPHA=2; int alpha_type = NEEDS_NO_ALPHA; + /* If 8bpp and neither SDL_SRCCOLORKEY nor ALPHA_PALETTE, there is no transparency + * to search for. */ + if( img->format->BitsPerPixel == 8 && + !(img->flags & SDL_SRCCOLORKEY) && !(img->unused1 & ALPHA_PALETTE) ) + return TRAIT_NO_TRANSPARENCY; + + Uint32 max_alpha; + if( img->format->BitsPerPixel == 8 ) + max_alpha = 0xFF; + else + max_alpha = img->format->Amask; + for(int y = 0; y < img->h; ++y) { Uint8 *row = (Uint8 *)img->pixels + img->pitch*y; @@ -438,16 +450,18 @@ int FindSurfaceTraits( const SDL_Surface *img ) { Uint32 val = decodepixel(row, img->format->BytesPerPixel); - if( img->format->BitsPerPixel == 8 ) { - if(img->flags & SDL_SRCCOLORKEY && val == img->format->colorkey ) - alpha_type = max( alpha_type, NEEDS_BOOL_ALPHA ); - } else if(img->format->Amask) { - Uint32 masked_alpha = val & img->format->Amask; - if(masked_alpha == 0) - alpha_type = max( alpha_type, NEEDS_BOOL_ALPHA ); - else if(masked_alpha != img->format->Amask) - alpha_type = max( alpha_type, NEEDS_FULL_ALPHA ); - } + Uint32 alpha; + if( img->flags & SDL_SRCCOLORKEY ) + alpha = (val == img->format->colorkey)? 0x00:0xFF; + if( img->unused1 & ALPHA_PALETTE ) + alpha = img->format->palette->colors[val].unused; + else + alpha = (val & img->format->Amask); + + if( alpha == 0 ) + alpha_type = max( alpha_type, NEEDS_BOOL_ALPHA ); + else if( alpha != max_alpha ) + alpha_type = max( alpha_type, NEEDS_FULL_ALPHA ); row += img->format->BytesPerPixel; } diff --git a/stepmania/src/SDL_utils.h b/stepmania/src/SDL_utils.h index 03a657b9d8..a5f133988f 100644 --- a/stepmania/src/SDL_utils.h +++ b/stepmania/src/SDL_utils.h @@ -76,6 +76,10 @@ void mySDL_BlitTransform( const SDL_Surface *src, SDL_Surface *dst, void mySDL_BlitSurface( SDL_Surface *src, SDL_Surface *dst, int width, int height, bool ckey); +/* Use the "unused1" field in surfaces to mark surfaces that store alpha values + * in the palette. (SDL proper does not support this.) */ +enum { ALPHA_PALETTE = 0x1 }; + SDL_Surface *mySDL_Palettize( SDL_Surface *src_surf, int GrayBits, int AlphaBits ); SDL_Surface *SDL_LoadImage( const CString &sPath );