From 70a1dc09262be4dbe4ef4e6df45b0c2ed1dafce8 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 9 Jun 2020 02:04:55 +0100 Subject: [PATCH] Revert "improve transparency support" This reverts commit 20c9a7f7cc24965df486331738d181f641c075af. --- libvips/foreign/spngload.c | 39 ++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/libvips/foreign/spngload.c b/libvips/foreign/spngload.c index 8b43aac9..319eafb2 100644 --- a/libvips/foreign/spngload.c +++ b/libvips/foreign/spngload.c @@ -41,11 +41,12 @@ * set a chunk size limit with spng_set_chunks_limits() when that API is done * * load only, there's no save support for now + * */ /* - */ #define DEBUG + */ #ifdef HAVE_CONFIG_H #include @@ -315,28 +316,37 @@ vips_foreign_load_png_header( VipsForeignLoad *load ) switch( png->ihdr.color_type ) { - case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA: case SPNG_COLOR_TYPE_GRAYSCALE: png->bands = 1; - if( !spng_get_trns( png->ctx ) ) - png->bands += 1; + png->interpretation = VIPS_INTERPRETATION_B_W; + png->fmt = SPNG_FMT_PNG; + break; + + case SPNG_COLOR_TYPE_GRAYSCALE_ALPHA: + png->bands = 2; png->interpretation = VIPS_INTERPRETATION_B_W; png->fmt = SPNG_FMT_PNG; break; case SPNG_COLOR_TYPE_TRUECOLOR: - case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA: png->bands = 3; - if( !spng_get_trns( png->ctx ) ) - png->bands += 1; png->interpretation = VIPS_INTERPRETATION_sRGB; png->fmt = SPNG_FMT_PNG; break; case SPNG_COLOR_TYPE_INDEXED: + png->bands = 3; + png->interpretation = VIPS_INTERPRETATION_sRGB; + + /* Expand indexed images to RGB8. + */ + png->fmt = SPNG_FMT_RGB8; + break; + + case SPNG_COLOR_TYPE_TRUECOLOR_ALPHA: png->bands = 4; png->interpretation = VIPS_INTERPRETATION_sRGB; - png->fmt = SPNG_FMT_RGBA8; + png->fmt = SPNG_FMT_PNG; break; default: @@ -447,15 +457,10 @@ vips_foreign_load_png_load( VipsForeignLoad *load ) vips_object_local_array( VIPS_OBJECT( load ), 3 ); int error; - enum spng_decode_flags; if( vips_source_decode( png->source ) ) return( -1 ); - /* We want the alpha, if present. - */ - flags = SPNG_DECODE_TRNS; - if( png->ihdr.interlace_method != SPNG_INTERLACE_NONE ) { /* Arg awful interlaced image. We have to load to a huge mem * buffer, then copy to out. @@ -468,7 +473,7 @@ vips_foreign_load_png_load( VipsForeignLoad *load ) if( (error = spng_decode_image( png->ctx, VIPS_IMAGE_ADDR( t[0], 0, 0 ), VIPS_IMAGE_SIZEOF_IMAGE( t[0] ), - png->fmt, flags )) ) { + png->fmt, 0 )) ) { vips_error( class->nickname, "%s", spng_strerror( error ) ); return( -1 ); @@ -481,12 +486,10 @@ vips_foreign_load_png_load( VipsForeignLoad *load ) t[0] = vips_image_new(); vips_foreign_load_png_set_header( png, t[0] ); - /* We can decode regular PNGs progressively. + /* Initialize for progressive decoding. */ - flags |= SPNG_DECODE_PROGRESSIVE; - if( (error = spng_decode_image( png->ctx, NULL, 0, - png->fmt, flags )) ) { + png->fmt, SPNG_DECODE_PROGRESSIVE )) ) { vips_error( class->nickname, "%s", spng_strerror( error ) ); return( -1 );