begin work on arbitrary alpha values in paletted textures

This commit is contained in:
Glenn Maynard
2004-05-16 05:51:25 +00:00
parent 3e91007367
commit 04a74a4455
3 changed files with 29 additions and 11 deletions
+1 -1
View File
@@ -211,7 +211,7 @@ apply_color_key:
img = dst; 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, /* Unless we set up the palette ourself, assume the "unused" bit is undefined,
* and set it to 255. We use it for alpha. */ * and set it to 255. We use it for alpha. */
+24 -10
View File
@@ -430,6 +430,18 @@ int FindSurfaceTraits( const SDL_Surface *img )
const int NEEDS_NO_ALPHA=0, NEEDS_BOOL_ALPHA=1, NEEDS_FULL_ALPHA=2; const int NEEDS_NO_ALPHA=0, NEEDS_BOOL_ALPHA=1, NEEDS_FULL_ALPHA=2;
int alpha_type = NEEDS_NO_ALPHA; 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) for(int y = 0; y < img->h; ++y)
{ {
Uint8 *row = (Uint8 *)img->pixels + img->pitch*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); Uint32 val = decodepixel(row, img->format->BytesPerPixel);
if( img->format->BitsPerPixel == 8 ) { Uint32 alpha;
if(img->flags & SDL_SRCCOLORKEY && val == img->format->colorkey ) if( img->flags & SDL_SRCCOLORKEY )
alpha_type = max( alpha_type, NEEDS_BOOL_ALPHA ); alpha = (val == img->format->colorkey)? 0x00:0xFF;
} else if(img->format->Amask) { if( img->unused1 & ALPHA_PALETTE )
Uint32 masked_alpha = val & img->format->Amask; alpha = img->format->palette->colors[val].unused;
if(masked_alpha == 0) else
alpha_type = max( alpha_type, NEEDS_BOOL_ALPHA ); alpha = (val & img->format->Amask);
else if(masked_alpha != img->format->Amask)
alpha_type = max( alpha_type, NEEDS_FULL_ALPHA ); 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; row += img->format->BytesPerPixel;
} }
+4
View File
@@ -76,6 +76,10 @@ void mySDL_BlitTransform( const SDL_Surface *src, SDL_Surface *dst,
void mySDL_BlitSurface( void mySDL_BlitSurface(
SDL_Surface *src, SDL_Surface *dst, int width, int height, bool ckey); 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 *mySDL_Palettize( SDL_Surface *src_surf, int GrayBits, int AlphaBits );
SDL_Surface *SDL_LoadImage( const CString &sPath ); SDL_Surface *SDL_LoadImage( const CString &sPath );