Fixed bug 4425 - promote to alpha format, palette surface with alpha values.
authorSylvain Becker <sylvain.becker@gmail.com>
Sat, 15 Dec 2018 14:50:12 +0100
changeset 124746e387413a916
parent 12473 8a05e33d1b4b
child 12475 0ae268b6ddf0
Fixed bug 4425 - promote to alpha format, palette surface with alpha values.

SDL_CreateTextureFromSurface() forgets to choose a texture format with alpha for
surfaces that have palettes with alpha values.
src/render/SDL_render.c
     1.1 --- a/src/render/SDL_render.c	Tue Dec 11 20:04:10 2018 -0800
     1.2 +++ b/src/render/SDL_render.c	Sat Dec 15 14:50:12 2018 +0100
     1.3 @@ -1205,6 +1205,18 @@
     1.4      } else {
     1.5          needAlpha = SDL_FALSE;
     1.6      }
     1.7 +
     1.8 +    /* If Palette contains alpha values, promotes to alpha format */
     1.9 +    if (fmt->palette) {
    1.10 +        for (i = 0; i < fmt->palette->ncolors; i++) {
    1.11 +            Uint8 alpha_value = fmt->palette->colors[i].a;
    1.12 +            if (alpha_value != 0 || alpha_value != SDL_ALPHA_OPAQUE) {
    1.13 +                needAlpha = SDL_TRUE;
    1.14 +                break;
    1.15 +            }
    1.16 +        }
    1.17 +    }
    1.18 +
    1.19      format = renderer->info.texture_formats[0];
    1.20      for (i = 0; i < renderer->info.num_texture_formats; ++i) {
    1.21          if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&