From aa0504baee79e4c2de6b2ef8899934e54fdfd502 Mon Sep 17 00:00:00 2001 From: Robert Sprowson Date: Thu, 29 Jun 2023 12:03:28 +0100 Subject: [PATCH] Fix for missed optimisation with grayscale same layouts The outer 'if' clause prevented the inner test on GRAYSCALE_ALPHA being reached, so when source and destination are the same the faster copy out from the decoder isn't used. --- spng/spng.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spng/spng.c b/spng/spng.c index b22b711..f7fef83 100644 --- a/spng/spng.c +++ b/spng/spng.c @@ -3749,13 +3749,15 @@ int spng_decode_image(spng_ctx *ctx, void *out, size_t len, int fmt, int flags) f.apply_trns = 0; } - else if(fmt == SPNG_FMT_GA8 && ihdr->color_type == SPNG_COLOR_TYPE_GRAYSCALE && ihdr->bit_depth <= 8) + else if(fmt == SPNG_FMT_GA8 && (ihdr->color_type == SPNG_COLOR_TYPE_GRAYSCALE || + ihdr->color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) && ihdr->bit_depth <= 8) { if(ihdr->color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA && ihdr->bit_depth == depth_target) f.same_layout = 1; else if(ihdr->bit_depth <= 8) f.unpack = 1; } - else if(fmt == SPNG_FMT_GA16 && ihdr->color_type == SPNG_COLOR_TYPE_GRAYSCALE && ihdr->bit_depth == 16) + else if(fmt == SPNG_FMT_GA16 && (ihdr->color_type == SPNG_COLOR_TYPE_GRAYSCALE || + ihdr->color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA) && ihdr->bit_depth == 16) { if(ihdr->color_type == SPNG_COLOR_TYPE_GRAYSCALE_ALPHA && ihdr->bit_depth == depth_target) f.same_layout = 1;