SDL: Be explicit that we support the MSB variants of the 1bpp and 4bpp surface formats

From 62f4fc6f356a9cc10df82578b96a02867589d750 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 28 Nov 2022 09:06:44 -0800
Subject: [PATCH] Be explicit that we support the MSB variants of the 1bpp and
 4bpp surface formats

Fixes https://github.com/libsdl-org/SDL/issues/6242
---
 src/video/SDL_blit_0.c | 41 ++++++++++++++++++++---------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/src/video/SDL_blit_0.c b/src/video/SDL_blit_0.c
index 4dcfb6817d89..080ada71c3dc 100644
--- a/src/video/SDL_blit_0.c
+++ b/src/video/SDL_blit_0.c
@@ -525,7 +525,7 @@ SDL_CalculateBlit0(SDL_Surface * surface)
     int which;
 
     /* 4bits to 32bits */
-    if (surface->format->BitsPerPixel == 4) {
+    if (surface->format->format == SDL_PIXELFORMAT_INDEX4MSB) {
         if (surface->map->dst->format->BytesPerPixel == 4) {
             switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
                 case 0:
@@ -535,33 +535,32 @@ SDL_CalculateBlit0(SDL_Surface * surface)
                     return Blit4bto4Key;
             }
         }
-        /* We don't fully support 4-bit packed pixel modes */
         return NULL;
     }
 
-    if (surface->format->BitsPerPixel != 1) {
-        /* We don't support sub 8-bit packed pixel modes */
-        return (SDL_BlitFunc) NULL;
-    }
-    if (surface->map->dst->format->BitsPerPixel < 8) {
-        which = 0;
-    } else {
-        which = surface->map->dst->format->BytesPerPixel;
-    }
-    switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
-    case 0:
-        return bitmap_blit[which];
+    if (surface->format->format == SDL_PIXELFORMAT_INDEX1MSB) {
+        if (surface->map->dst->format->BitsPerPixel < 8) {
+            which = 0;
+        } else {
+            which = surface->map->dst->format->BytesPerPixel;
+        }
+        switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
+        case 0:
+            return bitmap_blit[which];
 
-    case SDL_COPY_COLORKEY:
-        return colorkey_blit[which];
+        case SDL_COPY_COLORKEY:
+            return colorkey_blit[which];
 
-    case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
-        return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc) NULL;
+        case SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
+            return which >= 2 ? BlitBtoNAlpha : (SDL_BlitFunc) NULL;
 
-    case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
-        return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc) NULL;
+        case SDL_COPY_COLORKEY | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND:
+            return which >= 2 ? BlitBtoNAlphaKey : (SDL_BlitFunc) NULL;
+        }
+        return NULL;
     }
-    return (SDL_BlitFunc) NULL;
+
+    return NULL;
 }
 
 #endif /* SDL_HAVE_BLIT_0 */