From 6894159ad5f41452e3f5a8fdf8da12598b5e51dd Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 11 Nov 2020 10:02:46 +0000 Subject: [PATCH] fix icc-profiles and dzsave --no-strip We were not copying metadata down pyramid layers in dzsave, so --no-strip didn't allow icc profiles on tiles. Thanks altert See https://github.com/libvips/libvips/issues/1879 --- ChangeLog | 1 + libvips/foreign/dzsave.c | 11 +++++++++-- libvips/include/vips/internal.h | 1 + libvips/iofuncs/header.c | 10 +++++----- test/test-suite/test_foreign.py | 7 +++++++ 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5d17d315..77fd80ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ - fix tiffsave region shrink mode [imgifty] - add missing flushes on write to target [harukizaemon] - hide info messages you could get with some older glibs [kleisauke] +- fix --no-strip on dzsave with icc-profiles [altert] 6/9/20 started 8.10.2 - update magicksave/load profile handling [kelilevi] diff --git a/libvips/foreign/dzsave.c b/libvips/foreign/dzsave.c index 9b85d622..e617bb3e 100644 --- a/libvips/foreign/dzsave.c +++ b/libvips/foreign/dzsave.c @@ -613,8 +613,8 @@ write_image( VipsForeignSaveDz *dz, if( vips_copy( image, &t, NULL ) ) return( -1 ); - /* We default to stripping all metadata. Only "no_strip" turns this - * off. Very few people really want metadata on every tile. + /* We default to stripping all metadata. "no_strip" turns this + * off. Most people don't want metadata on every tile. */ vips_image_set_int( t, "hide-progress", 1 ); if( vips_image_write_to_buffer( t, format, &buf, &len, @@ -1312,6 +1312,13 @@ strip_init( Strip *strip, Layer *layer ) return; } + /* The strip needs to inherit the layer's metadata. + */ + if( vips__image_meta_copy( strip->image, layer->image ) ) { + strip_free( strip ); + return; + } + /* Type needs to be set so we know how to convert for save correctly. */ strip->image->Type = layer->image->Type; diff --git a/libvips/include/vips/internal.h b/libvips/include/vips/internal.h index d549c321..10fd818a 100644 --- a/libvips/include/vips/internal.h +++ b/libvips/include/vips/internal.h @@ -152,6 +152,7 @@ int vips__write_extension_block( VipsImage *im, void *buf, int size ); int vips__writehist( VipsImage *image ); int vips__read_header_bytes( VipsImage *im, unsigned char *from ); int vips__write_header_bytes( VipsImage *im, unsigned char *to ); +int vips__image_meta_copy( VipsImage *dst, const VipsImage *src ); extern GMutex *vips__global_lock; diff --git a/libvips/iofuncs/header.c b/libvips/iofuncs/header.c index b10235b3..3e1e8ca8 100644 --- a/libvips/iofuncs/header.c +++ b/libvips/iofuncs/header.c @@ -994,8 +994,8 @@ meta_cp_field( VipsMeta *meta, VipsImage *dst, void *b ) /* Copy meta on to dst. */ -static int -meta_cp( VipsImage *dst, const VipsImage *src ) +int +vips__image_meta_copy( VipsImage *dst, const VipsImage *src ) { if( src->meta ) { /* We lock with vips_image_set() to stop races in highly- @@ -1051,7 +1051,7 @@ vips__image_copy_fields_array( VipsImage *out, VipsImage *in[] ) * subclass loaders will sometimes write to an image. */ for( i = ni - 1; i >= 0; i-- ) - if( meta_cp( out, in[i] ) ) + if( vips__image_meta_copy( out, in[i] ) ) return( -1 ); /* Merge hists first to last. @@ -1094,7 +1094,7 @@ vips_image_set( VipsImage *image, const char *name, GValue *value ) g_assert( value ); /* We lock between modifying metadata and copying metadata between - * images, see meta_cp(). + * images, see vips__image_meta_copy(). * * This prevents modification of metadata by one thread racing with * metadata copy on another -- this can lead to crashes in @@ -1302,7 +1302,7 @@ vips_image_remove( VipsImage *image, const char *name ) if( image->meta ) { /* We lock between modifying metadata and copying metadata - * between images, see meta_cp(). + * between images, see vips__image_meta_copy(). * * This prevents modification of metadata by one thread * racing with metadata copy on another -- this can lead to diff --git a/test/test-suite/test_foreign.py b/test/test-suite/test_foreign.py index e4f847ba..fa196aae 100644 --- a/test/test-suite/test_foreign.py +++ b/test/test-suite/test_foreign.py @@ -1026,6 +1026,13 @@ class TestForeign: buf = self.colour.dzsave_buffer(region_shrink="mode") buf = self.colour.dzsave_buffer(region_shrink="median") + # test no-strip ... icc profiles should be passed down + filename = temp_filename(self.tempdir, '') + self.colour.dzsave(filename, no_strip=True) + + y = pyvips.Image.new_from_file(filename + "_files/0/0_0.jpeg") + assert y.get_typeof("icc-profile-data") != 0 + @skip_if_no("heifload") def test_heifload(self): def heif_valid(im):