From ce24917d4a48b5b9b77d69181421be0a15ffb03b Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 16 Apr 2019 17:52:09 +0100 Subject: [PATCH] only read webp bg in anim non-anim webp does not use the background property see https://github.com/libvips/libvips/issues/1261 --- libvips/foreign/webp2vips.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libvips/foreign/webp2vips.c b/libvips/foreign/webp2vips.c index 21a8cfe3..f7f61da1 100644 --- a/libvips/foreign/webp2vips.c +++ b/libvips/foreign/webp2vips.c @@ -44,8 +44,8 @@ /* #define DEBUG_VERBOSE -#define DEBUG */ +#define DEBUG #ifdef HAVE_CONFIG_H #include @@ -421,12 +421,6 @@ read_header( Read *read, VipsImage *out ) flags = WebPDemuxGetI( read->demux, WEBP_FF_FORMAT_FLAGS ); - /* background is in B, G, R, A byte order, but we need R, G, B, A for - * libvips. - */ - read->background = bgra2rgba( - WebPDemuxGetI( read->demux, WEBP_FF_BACKGROUND_COLOR ) ); - read->alpha = flags & ALPHA_FLAG; if( read->alpha ) read->config.output.colorspace = MODE_RGBA; @@ -441,6 +435,16 @@ read_header( Read *read, VipsImage *out ) read->frame_count = WebPDemuxGetI( read->demux, WEBP_FF_FRAME_COUNT ); + /* background is in B, G, R, A byte order, but we need + * R, G, B, A for libvips. + * + * background is only relevant for animations. For + * single-frame webp, we want to just return the RGBA in the + * file. We just leave bg as 0 and blend with that. + */ + read->background = bgra2rgba( WebPDemuxGetI( read->demux, + WEBP_FF_BACKGROUND_COLOR ) ); + #ifdef DEBUG printf( "webp2vips: animation\n" ); printf( "webp2vips: loop_count = %d\n", loop_count );