SDL: Convert bitmap surface to RGBA for scaling

From 15a19bd69f0a40d9ee5d139c552960f159e9af87 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 10 Aug 2024 16:42:45 -0700
Subject: [PATCH] Convert bitmap surface to RGBA for scaling

Scaling bitmaps isn't currently supported, so we convert to RGBA for now.
---
 src/video/SDL_surface.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c
index 5aeead4627ca8..457cd55ce61a7 100644
--- a/src/video/SDL_surface.c
+++ b/src/video/SDL_surface.c
@@ -1240,6 +1240,15 @@ int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect,
             src->format == dst->format &&
             !SDL_ISPIXELFORMAT_INDEXED(src->format)) {
             return SDL_SoftStretch(src, srcrect, dst, dstrect, SDL_SCALEMODE_NEAREST);
+        } else if (SDL_BITSPERPIXEL(src->format) < 8) {
+            // Scaling bitmap not yet supported, convert to RGBA for blit
+            int retval = -1;
+            SDL_Surface *tmp = SDL_ConvertSurface(src, SDL_PIXELFORMAT_ARGB8888);
+            if (tmp) {
+                retval = SDL_BlitSurfaceUncheckedScaled(tmp, srcrect, dst, dstrect, SDL_SCALEMODE_NEAREST);
+                SDL_DestroySurface(tmp);
+            }
+            return retval;
         } else {
             return SDL_BlitSurfaceUnchecked(src, srcrect, dst, dstrect);
         }
@@ -1251,6 +1260,15 @@ int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect,
             src->format != SDL_PIXELFORMAT_ARGB2101010) {
             /* fast path */
             return SDL_SoftStretch(src, srcrect, dst, dstrect, SDL_SCALEMODE_LINEAR);
+        } else if (SDL_BITSPERPIXEL(src->format) < 8) {
+            // Scaling bitmap not yet supported, convert to RGBA for blit
+            int retval = -1;
+            SDL_Surface *tmp = SDL_ConvertSurface(src, SDL_PIXELFORMAT_ARGB8888);
+            if (tmp) {
+                retval = SDL_BlitSurfaceUncheckedScaled(tmp, srcrect, dst, dstrect, scaleMode);
+                SDL_DestroySurface(tmp);
+            }
+            return retval;
         } else {
             /* Use intermediate surface(s) */
             SDL_Surface *tmp1 = NULL;