Skip to content

Commit b799076

Browse files
yodelslouken
authored andcommitted
Revert "Cache the SDL_PixelFormatDetails in SDL2_PixelFormat::next"
This reverts commit 7f7b1e6. Specifically, it reverts the handling of the pixel format passed to SDL3_ConvertSurfaceAndColorspace inside of SDL_ConvertSurface so that the pixel format is derived by calling SDL3_GetPixelFormatForMasks instead of using the value from format->format. Note, the other hunks from 7f7b1e6 were reverted in e47c7c7. Resolves: #542 Signed-off-by: Yodel Eldar <[email protected]>
1 parent da86b66 commit b799076

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/sdl2_compat.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4232,6 +4232,7 @@ SDL_DECLSPEC SDL2_Surface * SDLCALL
42324232
SDL_ConvertSurface(SDL2_Surface *surface, const SDL2_PixelFormat *format, Uint32 flags)
42334233
{
42344234
SDL_Palette *palette = NULL;
4235+
SDL_PixelFormat pixel_format;
42354236
SDL2_Surface *result;
42364237

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

4249+
pixel_format = SDL3_GetPixelFormatForMasks(format->BitsPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask);
4250+
if (pixel_format == SDL_PIXELFORMAT_UNKNOWN) {
4251+
SDL3_InvalidParamError("format");
4252+
return NULL;
4253+
}
4254+
42484255
if (format->palette) {
42494256
// This conversion is going to assign the new surface this palette,
42504257
// but it might be on the stack, so always allocate a new one to be
@@ -4257,7 +4264,7 @@ SDL_ConvertSurface(SDL2_Surface *surface, const SDL2_PixelFormat *format, Uint32
42574264
SDL3_SetPaletteColors(palette, format->palette->colors, 0, ncolors);
42584265
}
42594266

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

42624269
if (palette) {
42634270
SDL3_DestroyPalette(palette);

0 commit comments

Comments
 (0)