SDL_image: Set the alpha channel for less than 32-bit ICO/CUR images

From d4153324124963b8003e4e5b1d6743661969fdf5 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 3 Mar 2025 13:05:29 -0800
Subject: [PATCH] Set the alpha channel for less than 32-bit ICO/CUR images

Fixes https://github.com/libsdl-org/SDL_image/issues/532
---
 CHANGES.txt   | 3 +++
 src/IMG_bmp.c | 7 ++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index a99ff447..dcdc3838 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,6 @@
+3.2.4:
+ * Fixed alpha in less than 32-bit ICO and CUR images
+
 3.2.2:
  * Fixed partial alpha in ICO and CUR images
  * Set the cursor hotspot properties when loading CUR images
diff --git a/src/IMG_bmp.c b/src/IMG_bmp.c
index 69bad1c9..49ef7657 100644
--- a/src/IMG_bmp.c
+++ b/src/IMG_bmp.c
@@ -313,6 +313,11 @@ static SDL_Surface *LoadICOCUR_IO(SDL_IOStream * src, int type, bool closeio)
             if (SDL_ReadIO(src, &palette[i], 4) != 4) {
                 goto done;
             }
+
+            /* Since biSize == 40, we know alpha is reserved and should be zero, meaning opaque */
+            if ((palette[i] & 0xFF000000) == 0) {
+                palette[i] |= 0xFF000000;
+            }
         }
     }
 
@@ -365,7 +370,7 @@ static SDL_Surface *LoadICOCUR_IO(SDL_IOStream * src, int type, bool closeio)
                 Uint32 pixel;
                 Uint8 channel;
                 for (i = 0; i < surface->w; ++i) {
-                    pixel = 0;
+                    pixel = 0xFF000000;
                     for (j = 0; j < 3; ++j) {
                         /* Load each color channel into pixel */
                         if (SDL_ReadIO(src, &channel, 1) != 1) {