From cdcf63f8e5ba38ee2e0b743bd5abd67ca8baf2ca Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 17 Aug 2020 10:10:23 +0100 Subject: [PATCH] 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,