Fixed bug 4798 - PNG w/transparency breaks in SDL 2.0.10 but works in SDL 2.0.9
authorSylvain Becker <sylvain.becker@gmail.com>
Tue, 10 Sep 2019 17:12:34 +0200
changeset 130710c66be754e29
parent 13070 d953f28d33e3
child 13074 2ede888544ac
Fixed bug 4798 - PNG w/transparency breaks in SDL 2.0.10 but works in SDL 2.0.9
src/video/SDL_surface.c
     1.1 --- a/src/video/SDL_surface.c	Tue Sep 10 10:03:20 2019 +0300
     1.2 +++ b/src/video/SDL_surface.c	Tue Sep 10 17:12:34 2019 +0200
     1.3 @@ -959,6 +959,8 @@
     1.4      SDL_Color copy_color;
     1.5      SDL_Rect bounds;
     1.6      int ret;
     1.7 +    int palette_ck_transform = 0;
     1.8 +    int palette_ck_value = 0;
     1.9  
    1.10      if (!surface) {
    1.11          SDL_InvalidParamError("surface");
    1.12 @@ -1019,8 +1021,23 @@
    1.13      bounds.y = 0;
    1.14      bounds.w = surface->w;
    1.15      bounds.h = surface->h;
    1.16 +
    1.17 +    /* Transform colorkey to alpha. for cases where source palette has duplicate values, and colorkey is one of them */
    1.18 +    if (copy_flags & SDL_COPY_COLORKEY) {
    1.19 +        if (surface->format->palette && !format->palette) {
    1.20 +            palette_ck_transform = 1;
    1.21 +            palette_ck_value = surface->format->palette->colors[surface->map->info.colorkey].a;
    1.22 +            surface->format->palette->colors[surface->map->info.colorkey].a = SDL_ALPHA_TRANSPARENT;
    1.23 +        }
    1.24 +    }
    1.25 +
    1.26      ret = SDL_LowerBlit(surface, &bounds, convert, &bounds);
    1.27  
    1.28 +    /* Restore value */
    1.29 +    if (palette_ck_transform) {
    1.30 +        surface->format->palette->colors[surface->map->info.colorkey].a = palette_ck_value;
    1.31 +    }
    1.32 +
    1.33      /* Clean up the original surface, and update converted surface */
    1.34      convert->map->info.r = copy_color.r;
    1.35      convert->map->info.g = copy_color.g;
    1.36 @@ -1055,7 +1072,9 @@
    1.37                    surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) {
    1.38                  /* The palette is identical, just set the same colorkey */
    1.39                  SDL_SetColorKey(convert, 1, surface->map->info.colorkey);
    1.40 -            } else if (format->Amask) {
    1.41 +            } else if (!format->palette) {
    1.42 +                /* Was done by 'palette_ck_transform' */
    1.43 +            }else if (format->Amask) {
    1.44                  set_colorkey_by_color = SDL_TRUE;
    1.45                  ignore_alpha = SDL_FALSE;
    1.46              } else {