Fixed bug 4798 - PNG w/transparency breaks in SDL 2.0.10 but works in SDL 2.0.9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c
index 75dc2bb..814e536 100644
--- a/src/video/SDL_surface.c
+++ b/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 {