Added support for alpha blending using palette alpha

Fixes https://github.com/libsdl-org/SDL_image/issues/409
This commit is contained in:
Sam Lantinga 2023-12-28 09:33:02 -08:00
parent 9c3e831e33
commit ce329d60e4

View File

@ -435,7 +435,7 @@ static void Blit1toNAlpha(SDL_BlitInfo *info)
const SDL_Color *srcpal = info->src_fmt->palette->colors;
int dstbpp;
Uint32 pixel;
unsigned sR, sG, sB;
unsigned sR, sG, sB, sA;
unsigned dR, dG, dB, dA;
const unsigned A = info->a;
@ -449,8 +449,9 @@ static void Blit1toNAlpha(SDL_BlitInfo *info)
sR = srcpal[*src].r;
sG = srcpal[*src].g;
sB = srcpal[*src].b;
sA = (srcpal[*src].a * A) / 255;
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
src++;
dst += dstbpp;
@ -475,7 +476,7 @@ static void Blit1toNAlphaKey(SDL_BlitInfo *info)
Uint32 ckey = info->colorkey;
int dstbpp;
Uint32 pixel;
unsigned sR, sG, sB;
unsigned sR, sG, sB, sA;
unsigned dR, dG, dB, dA;
const unsigned A = info->a;
@ -490,8 +491,9 @@ static void Blit1toNAlphaKey(SDL_BlitInfo *info)
sR = srcpal[*src].r;
sG = srcpal[*src].g;
sB = srcpal[*src].b;
sA = (srcpal[*src].a * A) / 255;
DISEMBLE_RGBA(dst, dstbpp, dstfmt, pixel, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, A, dR, dG, dB, dA);
ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA);
ASSEMBLE_RGBA(dst, dstbpp, dstfmt, dR, dG, dB, dA);
}
src++;
@ -531,8 +533,10 @@ SDL_BlitFunc SDL_CalculateBlit1(SDL_Surface *surface)
return one_blitkey[which];
case SDL_COPY_COLORKEY | SDL_COPY_BLEND: /* this is not super-robust but handles a specific case we found sdl12-compat. */
return (surface->map->info.a == 255) ? one_blitkey[which] : (SDL_BlitFunc)NULL;
return (surface->map->info.a == 255) ? one_blitkey[which] :
which >= 2 ? Blit1toNAlphaKey : (SDL_BlitFunc)NULL;
case SDL_COPY_BLEND:
case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
/* Supporting 8bpp->8bpp alpha is doable but requires lots of
tables which consume space and takes time to precompute,