From 0000fb07f267eb53023b9e648f6d126025708ada Mon Sep 17 00:00:00 2001 From: Sam Lantinga 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 (cherry picked from commit 39c8ebb0e912d072005771dc4f2317930c51c081) --- 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 83b1ec56..bf1f0987 100644 --- a/src/IMG_png.c +++ b/src/IMG_png.c @@ -336,14 +336,14 @@ static void LIBPNG_LoadPNG_RW(SDL_RWops *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,