diff --git a/ChangeLog b/ChangeLog index eb41e6d2..49a1e20e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 6/9/20 started 8.10.2 - update magicksave/load profile handling [kelilevi] - better demand hint rules [kaas3000] +- fix tiff thumbnail from buffer and source [vansante] 9/8/20 started 8.10.1 - fix markdown -> xml conversion in doc generation diff --git a/libvips/resample/thumbnail.c b/libvips/resample/thumbnail.c index 1b6a7862..b6ffe672 100644 --- a/libvips/resample/thumbnail.c +++ b/libvips/resample/thumbnail.c @@ -1057,6 +1057,7 @@ vips_thumbnail_file_open( VipsThumbnail *thumbnail, double factor ) "scale", 1.0 / factor, NULL ) ); } + else if( vips_isprefix( "VipsForeignLoadTiff", thumbnail->loader ) ) { /* We support three modes: subifd pyramids, page-based * pyramids, and simple multi-page TIFFs (no pyramid). @@ -1075,8 +1076,8 @@ vips_thumbnail_file_open( VipsThumbnail *thumbnail, double factor ) return( vips_image_new_from_file( file->filename, "access", VIPS_ACCESS_SEQUENTIAL, NULL ) ); - } + else if( vips_isprefix( "VipsForeignLoadHeif", thumbnail->loader ) ) { return( vips_image_new_from_file( file->filename, "access", VIPS_ACCESS_SEQUENTIAL, @@ -1270,12 +1271,29 @@ vips_thumbnail_buffer_open( VipsThumbnail *thumbnail, double factor ) NULL ) ); } else if( vips_isprefix( "VipsForeignLoadTiff", thumbnail->loader ) ) { - return( vips_image_new_from_buffer( - buffer->buf->data, buffer->buf->length, - buffer->option_string, - "access", VIPS_ACCESS_SEQUENTIAL, - "page", (int) factor, - NULL ) ); + /* We support three modes: subifd pyramids, page-based + * pyramids, and simple multi-page TIFFs (no pyramid). + */ + if( thumbnail->subifd_pyramid ) + return( vips_image_new_from_buffer( + buffer->buf->data, buffer->buf->length, + buffer->option_string, + "access", VIPS_ACCESS_SEQUENTIAL, + "subifd", (int) factor, + NULL ) ); + else if( thumbnail->page_pyramid ) + return( vips_image_new_from_buffer( + buffer->buf->data, buffer->buf->length, + buffer->option_string, + "access", VIPS_ACCESS_SEQUENTIAL, + "page", (int) factor, + NULL ) ); + else + return( vips_image_new_from_buffer( + buffer->buf->data, buffer->buf->length, + buffer->option_string, + "access", VIPS_ACCESS_SEQUENTIAL, + NULL ) ); } else if( vips_isprefix( "VipsForeignLoadHeif", thumbnail->loader ) ) { return( vips_image_new_from_buffer( @@ -1449,12 +1467,29 @@ vips_thumbnail_source_open( VipsThumbnail *thumbnail, double factor ) NULL ) ); } else if( vips_isprefix( "VipsForeignLoadTiff", thumbnail->loader ) ) { - return( vips_image_new_from_source( - source->source, - source->option_string, - "access", VIPS_ACCESS_SEQUENTIAL, - "page", (int) factor, - NULL ) ); + /* We support three modes: subifd pyramids, page-based + * pyramids, and simple multi-page TIFFs (no pyramid). + */ + if( thumbnail->subifd_pyramid ) + return( vips_image_new_from_source( + source->source, + source->option_string, + "access", VIPS_ACCESS_SEQUENTIAL, + "subifd", (int) factor, + NULL ) ); + else if( thumbnail->page_pyramid ) + return( vips_image_new_from_source( + source->source, + source->option_string, + "access", VIPS_ACCESS_SEQUENTIAL, + "page", (int) factor, + NULL ) ); + else + return( vips_image_new_from_source( + source->source, + source->option_string, + "access", VIPS_ACCESS_SEQUENTIAL, + NULL ) ); } else if( vips_isprefix( "VipsForeignLoadHeif", thumbnail->loader ) ) { return( vips_image_new_from_source( diff --git a/test/test-suite/test_resample.py b/test/test-suite/test_resample.py index ceb2eecf..afd21422 100644 --- a/test/test-suite/test_resample.py +++ b/test/test-suite/test_resample.py @@ -2,7 +2,7 @@ import pytest import pyvips -from helpers import JPEG_FILE, OME_FILE, HEIC_FILE, all_formats, have +from helpers import JPEG_FILE, OME_FILE, HEIC_FILE, TIF_FILE, all_formats, have # Run a function expecting a complex image on a two-band image @@ -186,6 +186,13 @@ class TestResample: assert im.width == 100 assert im.height == 570 + # should be able to thumbnail a single-page tiff in a buffer + im1 = pyvips.Image.thumbnail(TIF_FILE, 100) + with open(TIF_FILE, 'rb') as f: + buf = f.read() + im2 = pyvips.Image.thumbnail_buffer(buf, 100) + assert abs(im1.avg() - im2.avg()) < 1 + if have("heifload"): # this image is orientation 6 ... thumbnail should flip it im = pyvips.Image.new_from_file(HEIC_FILE)