diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 1c7d7ec04..563ccc3eb 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -970,13 +970,32 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format, } if (set_colorkey_by_color) { - /* Set the colorkey by color, which needs to be unique */ - Uint8 keyR, keyG, keyB, keyA; + SDL_Surface *tmp; + SDL_Surface *tmp2; + int converted_colorkey = 0; + + /* Create a dummy surface to get the colorkey converted */ + tmp = SDL_CreateRGBSurface(0, 1, 1, + surface->format->BitsPerPixel, surface->format->Rmask, + surface->format->Gmask, surface->format->Bmask, + surface->format->Amask); + + SDL_FillRect(tmp, NULL, surface->map->info.colorkey); + + tmp->map->info.flags &= ~SDL_COPY_COLORKEY; + + /* Convertion of the colorkey */ + tmp2 = SDL_ConvertSurface(tmp, format, 0); + + /* Get the converted colorkey */ + memcpy(&converted_colorkey, tmp2->pixels, tmp2->format->BytesPerPixel); + + SDL_FreeSurface(tmp); + SDL_FreeSurface(tmp2); + + /* Set the converted colorkey on the new surface */ + SDL_SetColorKey(convert, 1, converted_colorkey); - SDL_GetRGBA(surface->map->info.colorkey, surface->format, &keyR, - &keyG, &keyB, &keyA); - SDL_SetColorKey(convert, 1, - SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA)); /* This is needed when converting for 3D texture upload */ SDL_ConvertColorkeyToAlpha(convert); }