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
31 changes: 14 additions & 17 deletions src/sdl2_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -4186,7 +4186,6 @@ 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 @@ -4200,12 +4199,6 @@ 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 @@ -4218,7 +4211,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), pixel_format, palette, SDL_COLORSPACE_SRGB, 0));
result = Surface3to2(SDL3_ConvertSurfaceAndColorspace(Surface2to3(surface), (SDL_PixelFormat)format->format, palette, SDL_COLORSPACE_SRGB, 0));

if (palette) {
SDL3_DestroyPalette(palette);
Expand Down Expand Up @@ -9542,6 +9535,7 @@ SDL_AllocFormat(Uint32 pixel_format)
format->Bshift = details->Bshift;
format->Ashift = details->Ashift;
format->refcount = 1;
format->next = (SDL2_PixelFormat *)details;

return format;
}
Expand Down Expand Up @@ -9999,21 +9993,24 @@ SDL_SetPixelFormatPalette(SDL2_PixelFormat *format, SDL_Palette *palette)

static const SDL_PixelFormatDetails *GetPixelFormatDetails(const SDL2_PixelFormat *format2)
{
SDL_PixelFormat format = (SDL_PixelFormat)format2->format;
if (format == SDL_PIXELFORMAT_UNKNOWN) {
format = SDL3_GetPixelFormatForMasks(format2->BitsPerPixel, format2->Rmask, format2->Gmask, format2->Bmask, format2->Amask);
}
return SDL3_GetPixelFormatDetails(format);
return (SDL_PixelFormatDetails *)format2->next;
}

SDL_DECLSPEC Uint32 SDLCALL
SDL_MapRGB(const SDL2_PixelFormat *format2, Uint8 r, Uint8 g, Uint8 b)
{
const SDL_PixelFormatDetails *format = GetPixelFormatDetails(format2);
if (!format) {
return 0;
const SDL_PixelFormatDetails *format;

switch (format2->format) {
case SDL_PIXELFORMAT_XRGB8888:
return ((Uint32)r << 24) | ((Uint32)g << 16) | b;
default:
format = GetPixelFormatDetails(format2);
if (!format) {
return 0;
}
return SDL3_MapRGB(format, format2->palette, r, g, b);
}
return SDL3_MapRGB(format, format2->palette, r, g, b);
}

SDL_DECLSPEC Uint32 SDLCALL
Expand Down
Loading