Fixed bug 3657 - Color-key doesn't work when an alpha channel is present
authorSylvain Becker <sylvain.becker@gmail.com>
Sat, 19 Jan 2019 16:47:43 +0100
changeset 12561d4d5e1272239
parent 12560 a7d52e2db27a
child 12562 d21956a01eed
child 12566 884f99b039f0
Fixed bug 3657 - Color-key doesn't work when an alpha channel is present

When surface format is the same as renderer format, it still needs an
intermediate conversion to transform colorkey to alpha.
src/render/SDL_render.c
     1.1 --- a/src/render/SDL_render.c	Thu Jan 17 16:30:19 2019 +0100
     1.2 +++ b/src/render/SDL_render.c	Sat Jan 19 16:47:43 2019 +0100
     1.3 @@ -1187,6 +1187,7 @@
     1.4  {
     1.5      const SDL_PixelFormat *fmt;
     1.6      SDL_bool needAlpha;
     1.7 +    SDL_bool direct_update;
     1.8      Uint32 i;
     1.9      Uint32 format;
    1.10      SDL_Texture *texture;
    1.11 @@ -1233,6 +1234,20 @@
    1.12      }
    1.13  
    1.14      if (format == surface->format->format) {
    1.15 +        if (surface->format->Amask && SDL_HasColorKey(surface)) {
    1.16 +            /* Surface and Renderer formats are identicals. 
    1.17 +             * Intermediate conversion is needed to convert color key to alpha (SDL_ConvertColorkeyToAlpha()). */
    1.18 +            direct_update = SDL_FALSE;
    1.19 +        } else {
    1.20 +            /* Update Texture directly */
    1.21 +            direct_update = SDL_TRUE;
    1.22 +        }
    1.23 +    } else {
    1.24 +        /* Surface and Renderer formats are differents, it needs an intermediate conversion. */
    1.25 +        direct_update = SDL_FALSE;
    1.26 +    }
    1.27 +
    1.28 +    if (direct_update) {
    1.29          if (SDL_MUSTLOCK(surface)) {
    1.30              SDL_LockSurface(surface);
    1.31              SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);