Skip to content

Commit

Permalink
surface: Make sure SDL_ConvertSurface() deals with palettes (thanks, …
Browse files Browse the repository at this point in the history
…Sylvain!).

Fixes Bugzilla #3826.
Fixes Bugzilla #2979.
  • Loading branch information
icculus committed Sep 14, 2017
1 parent ac782d7 commit 7617648
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/video/SDL_pixels.c
Expand Up @@ -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");
}

Expand Down
5 changes: 5 additions & 0 deletions src/video/SDL_surface.c
Expand Up @@ -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;
Expand Down

0 comments on commit 7617648

Please sign in to comment.