From 5637971a36bf9cc138ab3ebac159d7e7c8ec5992 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sun, 31 Jul 2016 10:34:12 +0100 Subject: [PATCH] support --strip for pngsave --- ChangeLog | 1 + libvips/foreign/pngsave.c | 8 +++++--- libvips/foreign/vipspng.c | 24 ++++++++++++++++-------- libvips/foreign/vipspng.h | 4 ++-- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 82beb035..b5debe04 100644 --- a/ChangeLog +++ b/ChangeLog @@ -30,6 +30,7 @@ - added vips_worley(), generate Worley noise - added vips_perlin(), generate Perlin noise - gif loader can write 1, 2, 3, or 4 bands depending on file contents +- support --strip for pngsave 30/7/16 started 8.3.3 - fix performance regression in 8.3.2, thanks Lovell diff --git a/libvips/foreign/pngsave.c b/libvips/foreign/pngsave.c index 5b9e533b..959c270a 100644 --- a/libvips/foreign/pngsave.c +++ b/libvips/foreign/pngsave.c @@ -164,8 +164,9 @@ vips_foreign_save_png_file_build( VipsObject *object ) build( object ) ) return( -1 ); - if( vips__png_write( save->ready, png_file->filename, - png->compression, png->interlace, png->profile, png->filter ) ) + if( vips__png_write( save->ready, + png_file->filename, png->compression, png->interlace, + png->profile, png->filter, save->strip ) ) return( -1 ); return( 0 ); @@ -223,7 +224,8 @@ vips_foreign_save_png_buffer_build( VipsObject *object ) return( -1 ); if( vips__png_write_buf( save->ready, &obuf, &olen, - png->compression, png->interlace, png->profile, png->filter ) ) + png->compression, png->interlace, png->profile, png->filter, + save->strip ) ) return( -1 ); /* vips__png_write_buf() makes a buffer that needs g_free(), not diff --git a/libvips/foreign/vipspng.c b/libvips/foreign/vipspng.c index 619ce725..0d35ba31 100644 --- a/libvips/foreign/vipspng.c +++ b/libvips/foreign/vipspng.c @@ -55,6 +55,9 @@ * 26/2/15 * - close the read down early for a header read ... this saves an * fd during file read, handy for large numbers of input images + * 31/7/16 + * - support --strip option + * */ /* @@ -808,8 +811,9 @@ write_png_block( VipsRegion *region, VipsRect *area, void *a ) /* Write a VIPS image to PNG. */ static int -write_vips( Write *write, int compress, int interlace, const char *profile, - VipsForeignPngFilter filter ) +write_vips( Write *write, + int compress, int interlace, const char *profile, + VipsForeignPngFilter filter, gboolean strip ) { VipsImage *in = write->in; @@ -883,7 +887,8 @@ write_vips( Write *write, int compress, int interlace, const char *profile, /* Set ICC Profile. */ - if( profile ) { + if( profile && + !strip ) { if( strcmp( profile, "none" ) != 0 ) { void *data; size_t length; @@ -902,7 +907,8 @@ write_vips( Write *write, int compress, int interlace, const char *profile, PNG_COMPRESSION_TYPE_BASE, data, length ); } } - else if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) { + else if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) && + !strip ) { void *data; size_t length; @@ -951,7 +957,7 @@ write_vips( Write *write, int compress, int interlace, const char *profile, int vips__png_write( VipsImage *in, const char *filename, int compress, int interlace, const char *profile, - VipsForeignPngFilter filter ) + VipsForeignPngFilter filter, gboolean strip ) { Write *write; @@ -970,7 +976,8 @@ vips__png_write( VipsImage *in, const char *filename, /* Convert it! */ - if( write_vips( write, compress, interlace, profile, filter ) ) { + if( write_vips( write, + compress, interlace, profile, filter, strip ) ) { vips_error( "vips2png", _( "unable to write \"%s\"" ), filename ); @@ -1026,7 +1033,7 @@ user_write_data( png_structp png_ptr, png_bytep data, png_size_t length ) int vips__png_write_buf( VipsImage *in, void **obuf, size_t *olen, int compression, int interlace, - const char *profile, VipsForeignPngFilter filter ) + const char *profile, VipsForeignPngFilter filter, gboolean strip ) { Write *write; @@ -1037,7 +1044,8 @@ vips__png_write_buf( VipsImage *in, /* Convert it! */ - if( write_vips( write, compression, interlace, profile, filter ) ) { + if( write_vips( write, + compression, interlace, profile, filter, strip ) ) { vips_error( "vips2png", "%s", _( "unable to write to buffer" ) ); diff --git a/libvips/foreign/vipspng.h b/libvips/foreign/vipspng.h index 053aad6b..62fe38ba 100644 --- a/libvips/foreign/vipspng.h +++ b/libvips/foreign/vipspng.h @@ -48,10 +48,10 @@ int vips__png_header_buffer( const void *buffer, size_t length, int vips__png_write( VipsImage *in, const char *filename, int compress, int interlace, const char *profile, - VipsForeignPngFilter filter ); + VipsForeignPngFilter filter, gboolean strip ); int vips__png_write_buf( VipsImage *in, void **obuf, size_t *olen, int compression, int interlace, - const char *profile, VipsForeignPngFilter filter ); + const char *profile, VipsForeignPngFilter filter, gboolean strip ); #ifdef __cplusplus }