Additional orthogonalization and defensive coding around colorkeys and alpha mods
This commit is contained in:
@@ -400,6 +400,16 @@ TFB_SetGamma (float gamma)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
TFB_HasSurfaceAlphaMod (SDL_Surface *surface)
|
||||||
|
{
|
||||||
|
if (!surface)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (surface->flags & SDL_SRCALPHA) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
TFB_GetSurfaceAlphaMod (SDL_Surface *surface, Uint8 *alpha)
|
TFB_GetSurfaceAlphaMod (SDL_Surface *surface, Uint8 *alpha)
|
||||||
{
|
{
|
||||||
@@ -421,12 +431,20 @@ TFB_GetSurfaceAlphaMod (SDL_Surface *surface, Uint8 *alpha)
|
|||||||
int
|
int
|
||||||
TFB_SetSurfaceAlphaMod (SDL_Surface *surface, Uint8 alpha)
|
TFB_SetSurfaceAlphaMod (SDL_Surface *surface, Uint8 alpha)
|
||||||
{
|
{
|
||||||
|
if (!surface)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return SDL_SetAlpha (surface, SDL_SRCALPHA, alpha);
|
return SDL_SetAlpha (surface, SDL_SRCALPHA, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
TFB_DisableSurfaceAlphaMod (SDL_Surface *surface)
|
TFB_DisableSurfaceAlphaMod (SDL_Surface *surface)
|
||||||
{
|
{
|
||||||
|
if (!surface)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return SDL_SetAlpha (surface, 0, 255);
|
return SDL_SetAlpha (surface, 0, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,12 +463,20 @@ TFB_GetColorKey (SDL_Surface *surface, Uint32 *key)
|
|||||||
int
|
int
|
||||||
TFB_SetColorKey (SDL_Surface *surface, Uint32 key)
|
TFB_SetColorKey (SDL_Surface *surface, Uint32 key)
|
||||||
{
|
{
|
||||||
|
if (!surface)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return SDL_SetColorKey (surface, SDL_SRCCOLORKEY, key);
|
return SDL_SetColorKey (surface, SDL_SRCCOLORKEY, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
TFB_DisableColorKey (SDL_Surface *surface)
|
TFB_DisableColorKey (SDL_Surface *surface)
|
||||||
{
|
{
|
||||||
|
if (!surface)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return SDL_SetColorKey (surface, 0, 0);
|
return SDL_SetColorKey (surface, 0, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -366,6 +366,21 @@ TFB_SetGamma (float gamma)
|
|||||||
log_add (log_Warning, "Custom gamma correction is not available in the SDL2 engine.");
|
log_add (log_Warning, "Custom gamma correction is not available in the SDL2 engine.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
TFB_HasSurfaceAlphaMod (SDL_Surface *surface)
|
||||||
|
{
|
||||||
|
SDL_BlendMode blend_mode;
|
||||||
|
if (!surface)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (SDL_GetSurfaceBlendMode (surface, &blend_mode) != 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return blend_mode == SDL_BLENDMODE_BLEND;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
TFB_GetSurfaceAlphaMod (SDL_Surface *surface, Uint8 *alpha)
|
TFB_GetSurfaceAlphaMod (SDL_Surface *surface, Uint8 *alpha)
|
||||||
{
|
{
|
||||||
@@ -376,7 +391,10 @@ TFB_GetSurfaceAlphaMod (SDL_Surface *surface, Uint8 *alpha)
|
|||||||
}
|
}
|
||||||
if (SDL_GetSurfaceBlendMode (surface, &blend_mode) == 0)
|
if (SDL_GetSurfaceBlendMode (surface, &blend_mode) == 0)
|
||||||
{
|
{
|
||||||
return SDL_GetSurfaceAlphaMod (surface, alpha);
|
if (blend_mode == SDL_BLENDMODE_BLEND)
|
||||||
|
{
|
||||||
|
return SDL_GetSurfaceAlphaMod (surface, alpha);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*alpha = 255;
|
*alpha = 255;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -385,7 +403,12 @@ TFB_GetSurfaceAlphaMod (SDL_Surface *surface, Uint8 *alpha)
|
|||||||
int
|
int
|
||||||
TFB_SetSurfaceAlphaMod (SDL_Surface *surface, Uint8 alpha)
|
TFB_SetSurfaceAlphaMod (SDL_Surface *surface, Uint8 alpha)
|
||||||
{
|
{
|
||||||
int result = SDL_SetSurfaceBlendMode (surface, SDL_BLENDMODE_BLEND);
|
int result;
|
||||||
|
if (!surface)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
result = SDL_SetSurfaceBlendMode (surface, SDL_BLENDMODE_BLEND);
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
{
|
{
|
||||||
result = SDL_SetSurfaceAlphaMod (surface, alpha);
|
result = SDL_SetSurfaceAlphaMod (surface, alpha);
|
||||||
@@ -396,6 +419,10 @@ TFB_SetSurfaceAlphaMod (SDL_Surface *surface, Uint8 alpha)
|
|||||||
int
|
int
|
||||||
TFB_DisableSurfaceAlphaMod (SDL_Surface *surface)
|
TFB_DisableSurfaceAlphaMod (SDL_Surface *surface)
|
||||||
{
|
{
|
||||||
|
if (!surface)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
SDL_SetSurfaceAlphaMod (surface, 255);
|
SDL_SetSurfaceAlphaMod (surface, 255);
|
||||||
return SDL_SetSurfaceBlendMode (surface, SDL_BLENDMODE_NONE);
|
return SDL_SetSurfaceBlendMode (surface, SDL_BLENDMODE_NONE);
|
||||||
}
|
}
|
||||||
@@ -403,18 +430,30 @@ TFB_DisableSurfaceAlphaMod (SDL_Surface *surface)
|
|||||||
int
|
int
|
||||||
TFB_GetColorKey (SDL_Surface *surface, Uint32 *key)
|
TFB_GetColorKey (SDL_Surface *surface, Uint32 *key)
|
||||||
{
|
{
|
||||||
|
if (!surface || !key)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return SDL_GetColorKey (surface, key);
|
return SDL_GetColorKey (surface, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
TFB_SetColorKey (SDL_Surface *surface, Uint32 key)
|
TFB_SetColorKey (SDL_Surface *surface, Uint32 key)
|
||||||
{
|
{
|
||||||
|
if (!surface)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return SDL_SetColorKey (surface, SDL_TRUE, key);
|
return SDL_SetColorKey (surface, SDL_TRUE, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
TFB_DisableColorKey (SDL_Surface *surface)
|
TFB_DisableColorKey (SDL_Surface *surface)
|
||||||
{
|
{
|
||||||
|
if (!surface)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return SDL_SetColorKey (surface, SDL_FALSE, 0);
|
return SDL_SetColorKey (surface, SDL_FALSE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -243,3 +243,10 @@ TFB_UploadTransitionScreen (void)
|
|||||||
{
|
{
|
||||||
graphics_backend->uploadTransitionScreen ();
|
graphics_backend->uploadTransitionScreen ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
TFB_HasColorKey (SDL_Surface *surface)
|
||||||
|
{
|
||||||
|
Uint32 key;
|
||||||
|
return TFB_GetColorKey (surface, &key) != 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,9 +45,11 @@ extern SDL_Surface *SDL_Screens[TFB_GFX_NUMSCREENS];
|
|||||||
extern SDL_Surface *format_conv_surf;
|
extern SDL_Surface *format_conv_surf;
|
||||||
|
|
||||||
SDL_Surface* TFB_DisplayFormatAlpha (SDL_Surface *surface);
|
SDL_Surface* TFB_DisplayFormatAlpha (SDL_Surface *surface);
|
||||||
|
int TFB_HasSurfaceAlphaMod (SDL_Surface *surface);
|
||||||
int TFB_GetSurfaceAlphaMod (SDL_Surface *surface, Uint8 *alpha);
|
int TFB_GetSurfaceAlphaMod (SDL_Surface *surface, Uint8 *alpha);
|
||||||
int TFB_SetSurfaceAlphaMod (SDL_Surface *surface, Uint8 alpha);
|
int TFB_SetSurfaceAlphaMod (SDL_Surface *surface, Uint8 alpha);
|
||||||
int TFB_DisableSurfaceAlphaMod (SDL_Surface *surface);
|
int TFB_DisableSurfaceAlphaMod (SDL_Surface *surface);
|
||||||
|
int TFB_HasColorKey (SDL_Surface *surface);
|
||||||
int TFB_GetColorKey (SDL_Surface *surface, Uint32 *key);
|
int TFB_GetColorKey (SDL_Surface *surface, Uint32 *key);
|
||||||
int TFB_SetColorKey (SDL_Surface *surface, Uint32 key);
|
int TFB_SetColorKey (SDL_Surface *surface, Uint32 key);
|
||||||
int TFB_DisableColorKey (SDL_Surface *surface);
|
int TFB_DisableColorKey (SDL_Surface *surface);
|
||||||
|
|||||||
Reference in New Issue
Block a user