Skip to content

Commit 7f7b1e6

Browse files
committed
Cache the SDL_PixelFormatDetails in SDL2_PixelFormat::next
Fixes https://github.com/libsdl-org/sdl12-compat
1 parent b7213dc commit 7f7b1e6

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/sdl2_compat.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4186,7 +4186,6 @@ SDL_DECLSPEC SDL2_Surface * SDLCALL
41864186
SDL_ConvertSurface(SDL2_Surface *surface, const SDL2_PixelFormat *format, Uint32 flags)
41874187
{
41884188
SDL_Palette *palette = NULL;
4189-
SDL_PixelFormat pixel_format;
41904189
SDL2_Surface *result;
41914190

41924191
(void) flags; /* SDL3 removed the (unused) `flags` argument */
@@ -4200,12 +4199,6 @@ SDL_ConvertSurface(SDL2_Surface *surface, const SDL2_PixelFormat *format, Uint32
42004199
return NULL;
42014200
}
42024201

4203-
pixel_format = SDL3_GetPixelFormatForMasks(format->BitsPerPixel, format->Rmask, format->Gmask, format->Bmask, format->Amask);
4204-
if (pixel_format == SDL_PIXELFORMAT_UNKNOWN) {
4205-
SDL3_InvalidParamError("format");
4206-
return NULL;
4207-
}
4208-
42094202
if (format->palette) {
42104203
// This conversion is going to assign the new surface this palette,
42114204
// but it might be on the stack, so always allocate a new one to be
@@ -4218,7 +4211,7 @@ SDL_ConvertSurface(SDL2_Surface *surface, const SDL2_PixelFormat *format, Uint32
42184211
SDL3_SetPaletteColors(palette, format->palette->colors, 0, ncolors);
42194212
}
42204213

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

42234216
if (palette) {
42244217
SDL3_DestroyPalette(palette);
@@ -9542,6 +9535,7 @@ SDL_AllocFormat(Uint32 pixel_format)
95429535
format->Bshift = details->Bshift;
95439536
format->Ashift = details->Ashift;
95449537
format->refcount = 1;
9538+
format->next = (SDL2_PixelFormat *)details;
95459539

95469540
return format;
95479541
}
@@ -9999,11 +9993,7 @@ SDL_SetPixelFormatPalette(SDL2_PixelFormat *format, SDL_Palette *palette)
99999993

100009994
static const SDL_PixelFormatDetails *GetPixelFormatDetails(const SDL2_PixelFormat *format2)
100019995
{
10002-
SDL_PixelFormat format = (SDL_PixelFormat)format2->format;
10003-
if (format == SDL_PIXELFORMAT_UNKNOWN) {
10004-
format = SDL3_GetPixelFormatForMasks(format2->BitsPerPixel, format2->Rmask, format2->Gmask, format2->Bmask, format2->Amask);
10005-
}
10006-
return SDL3_GetPixelFormatDetails(format);
9996+
return (SDL_PixelFormatDetails *)format2->next;
100079997
}
100089998

100099999
SDL_DECLSPEC Uint32 SDLCALL

0 commit comments

Comments
 (0)