From cdcf63f8e5ba38ee2e0b743bd5abd67ca8baf2ca Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 17 Aug 2020 10:10:23 +0100 Subject: [PATCH 1/4] fix regression in thumbnail of pyr tiff The new subifd pyramid thumbnail code broke the old page-based pyramid detector. Thanks tand826 See https://github.com/libvips/libvips/issues/1784 --- ChangeLog | 1 + libvips/resample/thumbnail.c | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index c790522a..bdb6cf34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 9/8/20 started 8.10.1 - fix markdown -> xml conversion in doc generation - remove typedef redefinitions to please old gccs +- fix regression in tiff pyramid thumbnailing [tand826] 24/1/20 started 8.10.0 - more conformat IIIF output from dzsave [regisrob] diff --git a/libvips/resample/thumbnail.c b/libvips/resample/thumbnail.c index 5f71943f..1b6a7862 100644 --- a/libvips/resample/thumbnail.c +++ b/libvips/resample/thumbnail.c @@ -135,10 +135,14 @@ typedef struct _VipsThumbnail { int heif_thumbnail_width; int heif_thumbnail_height; - /* For TIFF sources, open subifds rather than pages to get pyr layers. + /* For TIFF sources, open subifds to get pyr layers. */ gboolean subifd_pyramid; + /* For TIFF sources, open pages to get pyr layers. + */ + gboolean page_pyramid; + } VipsThumbnail; typedef struct _VipsThumbnailClass { @@ -261,13 +265,10 @@ vips_thumbnail_get_tiff_pyramid_page( VipsThumbnail *thumbnail ) /* Single-page docs can't be pyramids. */ - if( thumbnail->n_loaded_pages < 2 ) + if( thumbnail->n_pages < 2 ) return; - /* Use n_loaded_pages not n_pages since we support thumbnailing a page - * or range of pages from a many-page tiff. - */ - for( i = 0; i < thumbnail->n_loaded_pages; i++ ) { + for( i = 0; i < thumbnail->n_pages; i++ ) { VipsImage *page; int level_width; int level_height; @@ -301,9 +302,9 @@ vips_thumbnail_get_tiff_pyramid_page( VipsThumbnail *thumbnail ) #ifdef DEBUG printf( "vips_thumbnail_get_tiff_pyramid_page: " "%d layer pyramid detected\n", - thumbnail->n_loaded_pages ); + thumbnail->n_pages ); #endif /*DEBUG*/ - thumbnail->level_count = thumbnail->n_loaded_pages; + thumbnail->level_count = thumbnail->n_pages; } /* Detect a TIFF pyramid made of subifds following a roughly /2 shrink. @@ -549,7 +550,12 @@ vips_thumbnail_open( VipsThumbnail *thumbnail ) if( thumbnail->level_count == 0 ) { thumbnail->subifd_pyramid = FALSE; + thumbnail->page_pyramid = TRUE; + vips_thumbnail_get_tiff_pyramid_page( thumbnail ); + + if( thumbnail->level_count == 0 ) + thumbnail->page_pyramid = FALSE; } } @@ -1060,7 +1066,7 @@ vips_thumbnail_file_open( VipsThumbnail *thumbnail, double factor ) "access", VIPS_ACCESS_SEQUENTIAL, "subifd", (int) factor, NULL ) ); - else if( thumbnail->level_count > 0 ) + else if( thumbnail->page_pyramid ) return( vips_image_new_from_file( file->filename, "access", VIPS_ACCESS_SEQUENTIAL, "page", (int) factor, From b73bc3a85500092e0601b079ec90aca2cc896ed9 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Mon, 17 Aug 2020 12:29:16 +0100 Subject: [PATCH 2/4] Ensure magick buffer+file checks use consistent min length guard Prevents a zero-length buffer from crashing GetImageMagick It looks like the fix for magick7 in #1642 is also now required for magick6 as the assertion appears to have been backported. --- libvips/foreign/magickload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libvips/foreign/magickload.c b/libvips/foreign/magickload.c index bfb26566..e94d2226 100644 --- a/libvips/foreign/magickload.c +++ b/libvips/foreign/magickload.c @@ -256,7 +256,7 @@ G_DEFINE_TYPE( VipsForeignLoadMagickBuffer, vips_foreign_load_magick_buffer, static gboolean vips_foreign_load_magick_buffer_is_a_buffer( const void *buf, size_t len ) { - return( magick_ismagick( (const unsigned char *) buf, len ) ); + return( len > 10 && magick_ismagick( (const unsigned char *) buf, len ) ); } /* Unfortunately, libMagick does not support header-only reads very well. See From 182e88957ef292710eacc354e2628cef33d1c202 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 17 Aug 2020 14:18:59 +0100 Subject: [PATCH 3/4] prevent 0-length buffers reaching imagemagick im6 seems to have added an assert for this see https://github.com/libvips/libvips/pull/1785 --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index bdb6cf34..eea4cfff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ - fix markdown -> xml conversion in doc generation - remove typedef redefinitions to please old gccs - fix regression in tiff pyramid thumbnailing [tand826] +- stop 0-length buffer being passed to imagemagick [lovell] 24/1/20 started 8.10.0 - more conformat IIIF output from dzsave [regisrob] From 270933c281671ff725ff5e9e153c7a0ae611cc25 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 19 Aug 2020 11:09:38 +0100 Subject: [PATCH 4/4] convert no-profile CMYK to RGB on save Use the fallback cmyk profile to convert to RGB on save if the image has no embedded profile. Thanks augustocdias. See https://github.com/libvips/libvips/issues/1767 --- ChangeLog | 1 + libvips/foreign/foreign.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index eea4cfff..5bffe2bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ - remove typedef redefinitions to please old gccs - fix regression in tiff pyramid thumbnailing [tand826] - stop 0-length buffer being passed to imagemagick [lovell] +- convert no-profile CMYK to RGB on save [augustocdias] 24/1/20 started 8.10.0 - more conformat IIIF output from dzsave [regisrob] diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index 0459c47f..37e92768 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -1336,8 +1336,7 @@ vips__foreign_convert_saveable( VipsImage *in, VipsImage **ready, } /* If this image is CMYK and the saver is RGB-only, use lcms to try to - * import to XYZ. This will only work if the image has an embedded - * profile. + * import to XYZ. */ if( in->Type == VIPS_INTERPRETATION_CMYK && in->Bands >= 4 && @@ -1348,6 +1347,8 @@ vips__foreign_convert_saveable( VipsImage *in, VipsImage **ready, if( vips_icc_import( in, &out, "pcs", VIPS_PCS_XYZ, + "embedded", TRUE, + "input_profile", "cmyk", NULL ) ) { g_object_unref( in ); return( -1 );