mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-02-28 13:57:37 +00:00
MORTAR: wrap palette from loaded SDL3 surfaces
When loading BMP files via MORTAR_LoadBMP, SDL3 attaches a palette to the surface internally. Previously, create_mortar_surface_from_sdl3 did not extract this palette, causing MORTAR_GetSurfacePalette to return NULL for 8-bit palettized images. Create an independent MORTAR palette and copy the colors from the SDL3 surface's palette to make it accessible via MORTAR_GetSurfacePalette.
This commit is contained in:
parent
bbd8f2e489
commit
aeda30bef6
@ -268,6 +268,7 @@
|
|||||||
X(SDL_Surface*, SDL_CreateSurfaceFrom, (int width, int height, SDL_PixelFormat format, void* pixels, int pitch)) \
|
X(SDL_Surface*, SDL_CreateSurfaceFrom, (int width, int height, SDL_PixelFormat format, void* pixels, int pitch)) \
|
||||||
X(void, SDL_DestroySurface, (SDL_Surface * surface)) \
|
X(void, SDL_DestroySurface, (SDL_Surface * surface)) \
|
||||||
X(bool, SDL_SetSurfacePalette, (SDL_Surface * surface, SDL_Palette * palette)) \
|
X(bool, SDL_SetSurfacePalette, (SDL_Surface * surface, SDL_Palette * palette)) \
|
||||||
|
X(SDL_Palette*, SDL_GetSurfacePalette, (SDL_Surface * surface)) \
|
||||||
X(bool, SDL_LockSurface, (SDL_Surface * surface)) \
|
X(bool, SDL_LockSurface, (SDL_Surface * surface)) \
|
||||||
X(void, SDL_UnlockSurface, (SDL_Surface * surface)) \
|
X(void, SDL_UnlockSurface, (SDL_Surface * surface)) \
|
||||||
X(SDL_Surface*, SDL_LoadBMP_IO, (SDL_IOStream * src, bool closeio)) \
|
X(SDL_Surface*, SDL_LoadBMP_IO, (SDL_IOStream * src, bool closeio)) \
|
||||||
@ -4465,7 +4466,7 @@ static void unload_sdl3_api()
|
|||||||
#ifdef SDL_GetSurfacePalette
|
#ifdef SDL_GetSurfacePalette
|
||||||
#undef SDL_GetSurfacePalette
|
#undef SDL_GetSurfacePalette
|
||||||
#endif // SDL_GetSurfacePalette
|
#endif // SDL_GetSurfacePalette
|
||||||
#define SDL_GetSurfacePalette SDL3_symbol_SDL_GetSurfacePalette_is_marked_unused
|
#define SDL_GetSurfacePalette SDL3.SDL_GetSurfacePalette_symbol
|
||||||
#ifdef SDL_AddSurfaceAlternateImage
|
#ifdef SDL_AddSurfaceAlternateImage
|
||||||
#undef SDL_AddSurfaceAlternateImage
|
#undef SDL_AddSurfaceAlternateImage
|
||||||
#endif // SDL_AddSurfaceAlternateImage
|
#endif // SDL_AddSurfaceAlternateImage
|
||||||
|
|||||||
@ -66,6 +66,26 @@ static MORTAR_Surface* create_mortar_surface_from_sdl3(SDL_Surface* sdl3_surface
|
|||||||
mortar_surface->mortar.pixels = sdl3_surface->pixels;
|
mortar_surface->mortar.pixels = sdl3_surface->pixels;
|
||||||
mortar_surface->mortar.format = pixelformat_sdl3_to_mortar(sdl3_surface->format);
|
mortar_surface->mortar.format = pixelformat_sdl3_to_mortar(sdl3_surface->format);
|
||||||
mortar_surface->sdl3_surface = sdl3_surface;
|
mortar_surface->sdl3_surface = sdl3_surface;
|
||||||
|
|
||||||
|
SDL_Palette* sdl3_palette = SDL_GetSurfacePalette(sdl3_surface);
|
||||||
|
if (sdl3_palette && sdl3_palette->ncolors > 0) {
|
||||||
|
MORTAR_Palette* mortar_palette = MORTAR_CreatePalette(sdl3_palette->ncolors);
|
||||||
|
if (mortar_palette) {
|
||||||
|
MORTAR_Color* colors = (MORTAR_Color*) SDL_malloc(sizeof(MORTAR_Color) * sdl3_palette->ncolors);
|
||||||
|
if (colors) {
|
||||||
|
for (int i = 0; i < sdl3_palette->ncolors; i++) {
|
||||||
|
colors[i].r = sdl3_palette->colors[i].r;
|
||||||
|
colors[i].g = sdl3_palette->colors[i].g;
|
||||||
|
colors[i].b = sdl3_palette->colors[i].b;
|
||||||
|
colors[i].a = sdl3_palette->colors[i].a;
|
||||||
|
}
|
||||||
|
MORTAR_SetPaletteColors(mortar_palette, colors, 0, sdl3_palette->ncolors);
|
||||||
|
SDL_free(colors);
|
||||||
|
}
|
||||||
|
mortar_surface->mortar_palette = (MORTAR_SDL_Palette*) mortar_palette;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return &mortar_surface->mortar;
|
return &mortar_surface->mortar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -92,6 +92,7 @@
|
|||||||
"SDL_GetPrimaryDisplay",
|
"SDL_GetPrimaryDisplay",
|
||||||
"SDL_GetRGBA",
|
"SDL_GetRGBA",
|
||||||
"SDL_GetRevision",
|
"SDL_GetRevision",
|
||||||
|
"SDL_GetSurfacePalette",
|
||||||
"SDL_GetSystemRAM",
|
"SDL_GetSystemRAM",
|
||||||
"SDL_GetTicks",
|
"SDL_GetTicks",
|
||||||
"SDL_GetTicksNS",
|
"SDL_GetTicksNS",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user