Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/sdl2_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -4232,6 +4232,7 @@ SDL_DECLSPEC SDL2_Surface * SDLCALL
SDL_ConvertSurface(SDL2_Surface *surface, const SDL2_PixelFormat *format, Uint32 flags)
{
SDL_Palette *palette = NULL;
SDL_PixelFormat pixel_format;
SDL2_Surface *result;

(void) flags; /* SDL3 removed the (unused) `flags` argument */
Expand All @@ -4245,6 +4246,12 @@ SDL_ConvertSurface(SDL2_Surface *surface, const SDL2_PixelFormat *format, Uint32
return NULL;
}

pixel_format = SDL3_GetPixelFormatForMasks(format->BitsPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask);
if (pixel_format == SDL_PIXELFORMAT_UNKNOWN) {
SDL3_InvalidParamError("format");
return NULL;
}

if (format->palette) {
// This conversion is going to assign the new surface this palette,
// but it might be on the stack, so always allocate a new one to be
Expand All @@ -4257,7 +4264,7 @@ SDL_ConvertSurface(SDL2_Surface *surface, const SDL2_PixelFormat *format, Uint32
SDL3_SetPaletteColors(palette, format->palette->colors, 0, ncolors);
}

result = Surface3to2(SDL3_ConvertSurfaceAndColorspace(Surface2to3(surface), (SDL_PixelFormat)format->format, palette, SDL_COLORSPACE_SRGB, 0));
result = Surface3to2(SDL3_ConvertSurfaceAndColorspace(Surface2to3(surface), pixel_format, palette, SDL_COLORSPACE_SRGB, 0));

if (palette) {
SDL3_DestroyPalette(palette);
Expand Down