From f3835ef0bfacd4b45428f12129acef79e3ee6dc8 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 31 Mar 2016 21:48:40 +0100 Subject: [PATCH] webpsave_buffer no longer ignores @lossless the @lossless arg to webpsave buffer was never wired up to anything, thanks aaron42net. see https://github.com/jcupitt/libvips/issues/410 --- ChangeLog | 1 + libvips/foreign/vips2webp.c | 49 ++++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 34c1de18..cd7a12ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21,6 +21,7 @@ - switches to disable PPM, Rad and Analyze support - added VIPS_COUNT_PIXELS(), overcomputation tracking - @out_format in vips_system() can contain [options] +- webpsave_buffer no longer ignores @lossless, thanks aaron42net 24/3/16 started 8.2.4 - fix nohalo and vsqbs interpolators, thanks Rafael diff --git a/libvips/foreign/vips2webp.c b/libvips/foreign/vips2webp.c index 4a519493..52108cc8 100644 --- a/libvips/foreign/vips2webp.c +++ b/libvips/foreign/vips2webp.c @@ -2,6 +2,8 @@ * * 6/8/13 * - from vips2jpeg.c + * 31/5/16 + * - buffer write ignored lossless, thanks aaron42net */ /* @@ -131,24 +133,47 @@ vips__webp_write_buffer( VipsImage *in, void **obuf, size_t *olen, int Q, gboolean lossless ) { VipsImage *memory; - webp_encoder encoder; if( !(memory = vips_image_copy_memory( in )) ) return( -1 ); - if( in->Bands == 4 ) - encoder = WebPEncodeRGBA; - else - encoder = WebPEncodeRGB; + if( lossless ) { + webp_encoder_lossless encoder; - if( !(*olen = encoder( VIPS_IMAGE_ADDR( memory, 0, 0 ), - memory->Xsize, memory->Ysize, - VIPS_IMAGE_SIZEOF_LINE( memory ), - Q, (uint8_t **) obuf )) ) { - VIPS_UNREF( memory ); - vips_error( "vips2webp", "%s", _( "unable to encode" ) ); - return( -1 ); + if( in->Bands == 4 ) + encoder = WebPEncodeLosslessRGBA; + else + encoder = WebPEncodeLosslessRGB; + + if( !(*olen = encoder( VIPS_IMAGE_ADDR( memory, 0, 0 ), + memory->Xsize, memory->Ysize, + VIPS_IMAGE_SIZEOF_LINE( memory ), + (uint8_t **) obuf )) ) { + VIPS_UNREF( memory ); + vips_error( "vips2webp", + "%s", _( "unable to encode" ) ); + return( -1 ); + } } + else { + webp_encoder encoder; + + if( in->Bands == 4 ) + encoder = WebPEncodeRGBA; + else + encoder = WebPEncodeRGB; + + if( !(*olen = encoder( VIPS_IMAGE_ADDR( memory, 0, 0 ), + memory->Xsize, memory->Ysize, + VIPS_IMAGE_SIZEOF_LINE( memory ), + Q, (uint8_t **) obuf )) ) { + VIPS_UNREF( memory ); + vips_error( "vips2webp", + "%s", _( "unable to encode" ) ); + return( -1 ); + } + } + VIPS_UNREF( memory ); return( 0 );