sdl12-compat: video: Add a fallback case for creating 16-bit surfaces with bogus masks.

From eaeaf932ba7439ee9a75c1729ff8bd4b446e1b1e Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Wed, 19 Oct 2022 18:54:05 -0400
Subject: [PATCH] video: Add a fallback case for creating 16-bit surfaces with
 bogus masks.

Fixes #257.
---
 src/SDL12_compat.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 1c1b0e150..fb134a10d 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -5003,12 +5003,19 @@ SDL_CreateRGBSurface(Uint32 flags12, int width, int height, int depth, Uint32 Rm
        a generic blitter that just copied data blindly. SDL2 wants more strict
        pixel formats, so try to detect this case and try again with a standard
        format. */
-    if ((surface20 == NULL) && (depth >= 24) && (SDL20_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask) == SDL_PIXELFORMAT_UNKNOWN)) {
+    if ((surface20 == NULL) && (depth >= 16) && (SDL20_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask) == SDL_PIXELFORMAT_UNKNOWN)) {
         /* I have no illusions this is correct, it just works for the known problem cases so far. */
-        Rmask = SDL_SwapLE32(0x000000FF);
-        Gmask = SDL_SwapLE32(0x0000FF00);
-        Bmask = SDL_SwapLE32(0x00FF0000);
-        Amask = SDL_SwapLE32(Amask ? 0xFF000000 : 0x00000000);
+        if (depth == 16) {
+            Rmask = SDL_SwapLE32(0x0000F800);
+            Gmask = SDL_SwapLE32(0x000007E0);
+            Bmask = SDL_SwapLE32(0x0000001F);
+            Amask = 0;
+        } else {
+            Rmask = SDL_SwapLE32(0x000000FF);
+            Gmask = SDL_SwapLE32(0x0000FF00);
+            Bmask = SDL_SwapLE32(0x00FF0000);
+            Amask = SDL_SwapLE32(Amask ? 0xFF000000 : 0x00000000);
+        }
         surface20 = SDL20_CreateRGBSurface(0, width, height, depth, Rmask, Gmask, Bmask, Amask);
     }