From f1e4fff0c92026cec5e6a7a3e3086047fba20cf1 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
(cherry picked from commit d4153324124963b8003e4e5b1d6743661969fdf5)
---
CHANGES.txt | 3 +++
src/IMG_bmp.c | 7 ++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index 372ef043..18848a13 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,6 @@
+2.8.8:
+ * Fixed alpha in less than 32-bit ICO and CUR images
+
2.8.6:
* Fixed partial alpha in ICO and CUR images
diff --git a/src/IMG_bmp.c b/src/IMG_bmp.c
index e5f21f95..ee1f628c 100644
--- a/src/IMG_bmp.c
+++ b/src/IMG_bmp.c
@@ -307,6 +307,11 @@ LoadICOCUR_RW(SDL_RWops * src, int type, int freesrc)
}
for (i = 0; i < (int) biClrUsed; ++i) {
SDL_RWread(src, &palette[i], 4, 1);
+
+ /* Since biSize == 40, we know alpha is reserved and should be zero, meaning opaque */
+ if ((palette[i] & 0xFF000000) == 0) {
+ palette[i] |= 0xFF000000;
+ }
}
}
@@ -361,7 +366,7 @@ LoadICOCUR_RW(SDL_RWops * src, int type, int freesrc)
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_RWread(src, &channel, 1, 1)) {