Skip to content
Permalink
Browse files

Fixed bug 4798 - PNG w/transparency breaks in SDL 2.0.10 but works in…

… SDL 2.0.9
  • Loading branch information
1bsyl committed Sep 10, 2019
1 parent 32bb8b4 commit 79e388bfd8b3e568bd9ff039a4fa3bb8235d2f22
Showing with 20 additions and 1 deletion.
  1. +20 −1 src/video/SDL_surface.c
@@ -959,6 +959,8 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
SDL_Color copy_color;
SDL_Rect bounds;
int ret;
int palette_ck_transform = 0;
int palette_ck_value = 0;

if (!surface) {
SDL_InvalidParamError("surface");
@@ -1019,8 +1021,23 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
bounds.y = 0;
bounds.w = surface->w;
bounds.h = surface->h;

/* Transform colorkey to alpha. for cases where source palette has duplicate values, and colorkey is one of them */
if (copy_flags & SDL_COPY_COLORKEY) {
if (surface->format->palette && !format->palette) {
palette_ck_transform = 1;
palette_ck_value = surface->format->palette->colors[surface->map->info.colorkey].a;
surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_TRANSPARENT;
}
}

ret = SDL_LowerBlit(surface, &bounds, convert, &bounds);

/* Restore value */
if (palette_ck_transform) {
surface->format->palette->colors[surface->map->info.colorkey].a = palette_ck_value;
}

/* Clean up the original surface, and update converted surface */
convert->map->info.r = copy_color.r;
convert->map->info.g = copy_color.g;
@@ -1055,7 +1072,9 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format,
surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) {
/* The palette is identical, just set the same colorkey */
SDL_SetColorKey(convert, 1, surface->map->info.colorkey);
} else if (format->Amask) {
} else if (!format->palette) {
/* Was done by 'palette_ck_transform' */
}else if (format->Amask) {
set_colorkey_by_color = SDL_TRUE;
ignore_alpha = SDL_FALSE;
} else {

0 comments on commit 79e388b

Please sign in to comment.