fix traits detection for surfaces with partial alpha, but no alpha=0 pixels
This commit is contained in:
+16
-12
@@ -396,8 +396,10 @@ int FindSurfaceTraits(const SDL_Surface *img)
|
|||||||
{
|
{
|
||||||
// bool HaveAlphaValue = false; /* whether ar, ag, ab is valid */
|
// bool HaveAlphaValue = false; /* whether ar, ag, ab is valid */
|
||||||
// bool HaveConsistentAlphaValue = true;
|
// bool HaveConsistentAlphaValue = true;
|
||||||
bool HaveTransparency = false;
|
const int NEEDS_NO_ALPHA=0, NEEDS_BOOL_ALPHA=1, NEEDS_FULL_ALPHA=2;
|
||||||
bool HaveTranslucensy = false;
|
int alpha_type = NEEDS_NO_ALPHA;
|
||||||
|
// bool HaveTransparency = false;
|
||||||
|
// bool HaveTranslucensy = false;
|
||||||
// bool WhiteOnly = true;
|
// bool WhiteOnly = true;
|
||||||
|
|
||||||
for(int y = 0; y < img->h; ++y)
|
for(int y = 0; y < img->h; ++y)
|
||||||
@@ -409,20 +411,17 @@ int FindSurfaceTraits(const SDL_Surface *img)
|
|||||||
{
|
{
|
||||||
Uint32 val = decodepixel(row, img->format->BytesPerPixel);
|
Uint32 val = decodepixel(row, img->format->BytesPerPixel);
|
||||||
|
|
||||||
bool Transparent = false;
|
|
||||||
bool Translucent = false;
|
|
||||||
if( img->format->BitsPerPixel == 8 ) {
|
if( img->format->BitsPerPixel == 8 ) {
|
||||||
if(img->flags & SDL_SRCCOLORKEY && val == img->format->colorkey )
|
if(img->flags & SDL_SRCCOLORKEY && val == img->format->colorkey )
|
||||||
Transparent = true;
|
alpha_type = max( alpha_type, NEEDS_BOOL_ALPHA );
|
||||||
} else if(img->format->Amask) {
|
} else if(img->format->Amask) {
|
||||||
Uint32 masked_alpha = val & img->format->Amask;
|
Uint32 masked_alpha = val & img->format->Amask;
|
||||||
if(masked_alpha == 0) Transparent = true;
|
if(masked_alpha == 0)
|
||||||
else if(masked_alpha != img->format->Amask) Translucent = true;
|
alpha_type = max( alpha_type, NEEDS_BOOL_ALPHA );
|
||||||
|
else if(masked_alpha != img->format->Amask)
|
||||||
|
alpha_type = max( alpha_type, NEEDS_FULL_ALPHA );
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Transparent) HaveTransparency = true;
|
|
||||||
if(Translucent) HaveTranslucensy = true;
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* Hmm. This doesn't quite work. For example, the ScreenCompany
|
/* Hmm. This doesn't quite work. For example, the ScreenCompany
|
||||||
* shadow is actually black; we load it as 8alphaonly, which discards
|
* shadow is actually black; we load it as 8alphaonly, which discards
|
||||||
@@ -479,8 +478,13 @@ int FindSurfaceTraits(const SDL_Surface *img)
|
|||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
// if(HaveConsistentAlphaValue) ret |= TRAIT_CONSISTENT_TRANSPARENT_COLOR;
|
// if(HaveConsistentAlphaValue) ret |= TRAIT_CONSISTENT_TRANSPARENT_COLOR;
|
||||||
if(!HaveTransparency) ret |= TRAIT_NO_TRANSPARENCY;
|
switch( alpha_type )
|
||||||
if(!HaveTranslucensy) ret |= TRAIT_BOOL_TRANSPARENCY;
|
{
|
||||||
|
case NEEDS_NO_ALPHA: ret |= TRAIT_NO_TRANSPARENCY; break;
|
||||||
|
case NEEDS_BOOL_ALPHA: ret |= TRAIT_BOOL_TRANSPARENCY; break;
|
||||||
|
case NEEDS_FULL_ALPHA: break;
|
||||||
|
default: ASSERT(0);
|
||||||
|
}
|
||||||
// if(WhiteOnly) ret |= TRAIT_WHITE_ONLY;
|
// if(WhiteOnly) ret |= TRAIT_WHITE_ONLY;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user