From 2b482fc2cf610a3f28b736788e601f2f869bd7f7 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 27 Jan 2017 16:43:37 +0000 Subject: [PATCH] seems to work! --- ChangeLog | 1 + libvips/foreign/foreign.c | 2 +- libvips/foreign/tiff2vips.c | 19 +++++++++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6ff81639..7f26e8e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -30,6 +30,7 @@ - add @max_slope to vips_hist_local() to implement CLAHE, thanks hunter-87 - vips_gaussnoise() pixels are reproducible on recalc, thanks MvGulik - max/min sort values by y and x coordinate +- tiff read uses libtiff scanline API is rows-per-strip is large 8/12/16 started 8.4.5 - allow libgsf-1.14.26 to help centos, thanks tdiprima diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index ec5ffa21..6dd59d8d 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -44,8 +44,8 @@ */ /* - */ #define DEBUG + */ #ifdef HAVE_CONFIG_H #include diff --git a/libvips/foreign/tiff2vips.c b/libvips/foreign/tiff2vips.c index 6eae316d..6d5a0341 100644 --- a/libvips/foreign/tiff2vips.c +++ b/libvips/foreign/tiff2vips.c @@ -171,6 +171,8 @@ * - add multi-page read * 17/1/17 * - invalidate operation on read error + * 27/1/17 + * - if rows_per_strip is large, read with scanline API instead */ /* @@ -246,10 +248,14 @@ typedef struct _RtiffHeader { uint32 tile_height; /* Fields for strip images. + * + * If read_scanlinewise is TRUE, the strips are too large to read in a + * single lump and we need to use the scanline API. */ uint32 rows_per_strip; tsize_t strip_size; int number_of_strips; + gboolean read_scanlinewise; } RtiffHeader; /* Scanline-type process function. @@ -447,7 +453,13 @@ rtiff_strip_read( Rtiff *rtiff, int strip, tdata_t buf ) printf( "rtiff_strip_read: reading strip %d\n", strip ); #endif /*DEBUG*/ - length = TIFFReadEncodedStrip( rtiff->tiff, strip, buf, (tsize_t) -1 ); + if( rtiff->header.read_scanlinewise ) + length = TIFFReadScanline( rtiff->tiff, + buf, strip, (tsize_t) -1 ); + else + length = TIFFReadEncodedStrip( rtiff->tiff, + strip, buf, (tsize_t) -1 ); + if( length == -1 ) { vips_foreign_load_invalidate( rtiff->out ); vips_error( "tiff2vips", "%s", _( "read error" ) ); @@ -2042,6 +2054,7 @@ rtiff_header_read( Rtiff *rtiff, RtiffHeader *header ) return( -1 ); header->strip_size = TIFFStripSize( rtiff->tiff ); header->number_of_strips = TIFFNumberOfStrips( rtiff->tiff ); + header->read_scanlinewise = FALSE; /* rows_per_strip can be 2 ** 32 - 1, meaning the whole image. * Clip this down to height to avoid confusing vips. @@ -2062,7 +2075,9 @@ rtiff_header_read( Rtiff *rtiff, RtiffHeader *header ) */ if( header->rows_per_strip > 128 ) { header->rows_per_strip = 1; - + header->strip_size = TIFFScanlineSize( rtiff->tiff ); + header->number_of_strips = header->height; + header->read_scanlinewise = TRUE; } }