From 76176486ced3a053f8afca6d96cbbbdc2248af56 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 14 Sep 2017 08:37:27 -0400 Subject: [PATCH] surface: Make sure SDL_ConvertSurface() deals with palettes (thanks, Sylvain!). Fixes Bugzilla #3826. Fixes Bugzilla #2979. --- src/video/SDL_pixels.c | 2 +- src/video/SDL_surface.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index 13cd75abe..649303c58 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -658,7 +658,7 @@ SDL_SetPixelFormatPalette(SDL_PixelFormat * format, SDL_Palette *palette) return SDL_SetError("SDL_SetPixelFormatPalette() passed NULL format"); } - if (palette && palette->ncolors != (1 << format->BitsPerPixel)) { + if (palette && palette->ncolors > (1 << format->BitsPerPixel)) { return SDL_SetError("SDL_SetPixelFormatPalette() passed a palette that doesn't match the format"); } diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index 678fdc291..600056fe9 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -998,6 +998,11 @@ SDL_ConvertSurface(SDL_Surface * surface, const SDL_PixelFormat * format, surface->format->Gmask, surface->format->Bmask, surface->format->Amask); + /* Share the palette, if any */ + if (surface->format->palette) { + SDL_SetSurfacePalette(tmp, surface->format->palette); + } + SDL_FillRect(tmp, NULL, surface->map->info.colorkey); tmp->map->info.flags &= ~SDL_COPY_COLORKEY;