From f113e64515682f1bfca40cbf92914bbc48d32e86 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 9 Jun 2020 02:27:46 +0100 Subject: [PATCH] update for latest spng 1/2/4 bit handling --- libvips/foreign/spngload.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libvips/foreign/spngload.c b/libvips/foreign/spngload.c index 319eafb2..05e33070 100644 --- a/libvips/foreign/spngload.c +++ b/libvips/foreign/spngload.c @@ -275,6 +275,7 @@ vips_foreign_load_png_header( VipsForeignLoad *load ) int flags; int error; + struct spng_trns trns; /* In non-fail mode, ignore CRC errors. */ @@ -354,6 +355,23 @@ vips_foreign_load_png_header( VipsForeignLoad *load ) return( -1 ); } + if( !spng_get_trns( png->ctx, &trns ) ) { + if( png->ihdr.color_type == SPNG_COLOR_TYPE_TRUECOLOR ) { + if( png->ihdr.bit_depth == 16 ) + png->fmt = SPNG_FMT_RGBA16; + else + png->fmt = SPNG_FMT_RGBA8; + } + else if( png->ihdr.color_type == SPNG_COLOR_TYPE_INDEXED ) + png->fmt = SPNG_FMT_RGBA8; + else if( png->ihdr.color_type == SPNG_COLOR_TYPE_GRAYSCALE ) { + if( png->ihdr.bit_depth == 16 ) + png->fmt = SPNG_FMT_GA16; + else + png->fmt = SPNG_FMT_GA8; + } + } + if( png->ihdr.bit_depth == 16 ) { png->format = VIPS_FORMAT_USHORT; if( png->interpretation == VIPS_INTERPRETATION_B_W )