sdl12-compat: video: SDL_SetVideoMode(x,x,0,x) now gets ONLY 16 or 32-bit formats.

From e58a6589028b94c0e28b9466b090a8ea826f1fed Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Mon, 19 Sep 2022 09:03:23 -0400
Subject: [PATCH] video: SDL_SetVideoMode(x,x,0,x) now gets ONLY 16 or 32-bit
 formats.

SDL 1.2 returns a 32-bit surface with a zero alpha mask for
`SDL_SetVideoMode(w, h, 0, 0)` on this laptop, fwiw, so returning 24 was
probably always wrong here. Also there's a million other ways this can
go wrong, so just make sure it's either 16 or 32 bits.

This makes Tucnak work again after we changed the 24-bit format, since its
24-bit rendering code in libzia has a bug, and was probably never actually
used before.

Fixes #213.
---
 src/SDL12_compat.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 854bfd1e..b8f53824 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -5743,6 +5743,11 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags12)
     if (bpp == 0) {
         flags12 |= SDL12_ANYFORMAT;
         bpp = SDL_BITSPERPIXEL(dmode.format);
+        /* keep this simple: we aren't handling palettes here, so for < 16-bit
+           formats, give them 16-bit and we'll convert later. Nothing in SDL 1.2 will
+           handle > 32 bits, so clamp there, too. AND ALSO, most apps will handle 32-bits
+           but not 24, so force around that...so basically, you can have 16 or 32 bit. */
+        bpp = (bpp <= 16) ? 16 : 32;
     }
 
     if ((bpp != 8) && (bpp != 16) && (bpp != 24) && (bpp != 32)) {