Skip to content

Commit

Permalink
Enable alpha blending for palettized images with alpha
Browse files Browse the repository at this point in the history
Fixes #402
  • Loading branch information
slouken committed Dec 11, 2023
1 parent 52d0a6d commit 2e5662a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/IMG_stb.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ SDL_Surface *IMG_LoadSTB_RW(SDL_RWops *src)
SDL_PIXELFORMAT_INDEX8
);
if (surface) {
SDL_bool has_alpha = SDL_FALSE;
SDL_Palette *palette = surface->format->palette;
if (palette) {
int i;
Expand All @@ -155,8 +156,14 @@ SDL_Surface *IMG_LoadSTB_RW(SDL_RWops *src)
palette->colors[i].g = *palette_bytes++;
palette->colors[i].b = *palette_bytes++;
palette->colors[i].a = *palette_bytes++;
if (palette->colors[i].a != SDL_ALPHA_OPAQUE) {
has_alpha = SDL_TRUE;
}
}
}
if (has_alpha) {
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
}

/* FIXME: This sucks. It'd be better to allocate the surface first, then
* write directly to the pixel buffer:
Expand Down

0 comments on commit 2e5662a

Please sign in to comment.