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
1 changed files with 9 additions and 5 deletions

View File

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