Support returning <8bpp surfaces in SDL_LoadBMP_RW

This commit is contained in:
Cameron Cawley authored and Sam Lantinga committed 2023-11-17 08:45:32 -08:00
1 parent 773ec1cfcb
commit 05e7dcf8f8
3 files changed
+40 -79

No files matched your search

+6 -1
View File
@@ -72,7 +72,12 @@ init_color_cursor(const char *file)
SDL_Surface *surface = SDL_LoadBMP(file);
if (surface) {
if (surface->format->palette) {
SDL_SetSurfaceColorKey(surface, 1, *(Uint8 *)surface->pixels);
const Uint8 bpp = surface->format->BitsPerPixel;
const Uint8 mask = (1 << bpp) - 1;
if (SDL_PIXELORDER(surface->format->format) == SDL_BITMAPORDER_4321)
SDL_SetSurfaceColorKey(surface, 1, (*(Uint8 *)surface->pixels) & mask);
else
SDL_SetSurfaceColorKey(surface, 1, ((*(Uint8 *)surface->pixels) >> (8 - bpp)) & mask);
} else {
switch (surface->format->BitsPerPixel) {
case 15: