From 39c8ebb0e912d072005771dc4f2317930c51c081 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 5 Aug 2024 07:03:18 -0700
Subject: [PATCH] Fixed handling of grayscale images with alpha
Fixes https://github.com/libsdl-org/SDL_image/issues/460
---
src/IMG_png.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/IMG_png.c b/src/IMG_png.c
index 3d211d4c..d5bfebff 100644
--- a/src/IMG_png.c
+++ b/src/IMG_png.c
@@ -336,14 +336,14 @@ static void LIBPNG_LoadPNG_IO(SDL_IOStream *src, struct loadpng_vars *vars)
/* more than one transparent index, or translucency */
lib.png_set_expand(vars->png_ptr);
}
+ } else if (color_type == PNG_COLOR_TYPE_GRAY) {
+ /* This will be turned into PNG_COLOR_TYPE_GRAY_ALPHA, so expand to RGBA */
+ lib.png_set_gray_to_rgb(vars->png_ptr);
} else {
ckey = 0; /* actual value will be set later */
}
}
- if ( color_type == PNG_COLOR_TYPE_GRAY_ALPHA )
- lib.png_set_gray_to_rgb(vars->png_ptr);
-
lib.png_read_update_info(vars->png_ptr, vars->info_ptr);
lib.png_get_IHDR(vars->png_ptr, vars->info_ptr, &width, &height, &bit_depth,