From fe0f147d6b50ed5084648aba82c4ce595f8c6111 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Wed, 1 Apr 2026 14:19:29 -0400
Subject: [PATCH] bmp: SDL_LoadBMP_RW() converts 4-bpp BMPs to 8-bit in SDL2,
but SDL3 doesn't.
Do the conversion explicitly if we get a surface back that is < 8bpp.
Fixes #585.
---
src/sdl2_compat.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index aaae356a..c351f0e6 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -4068,6 +4068,13 @@ SDL_LoadBMP_RW(SDL2_RWops *rwops2, int freesrc)
if (rwops2 && freesrc) {
SDL_RWclose(rwops2);
}
+
+ if (SDL_BITSPERPIXEL(retval->format) < 8) { /* SDL3 can provide BMPs that are < 8bpp. In SDL2, these would get converted to 8bpp. */
+ SDL_Surface *cvt = SDL3_ConvertSurface(retval, SDL_PIXELFORMAT_INDEX8);
+ SDL3_DestroySurface(retval);
+ retval = cvt; /* if conversion failed, Surface3to2(), below, will notice. */
+ }
+
return Surface3to2(retval);
}