From 0aba05e63294c254b5ff585a47b632fbe63b3ede Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 8 May 2023 17:33:54 +0100 Subject: gpdl: Support Multipage TIFFs. This supports the common form of Multipage TIFFs, whereby a single TIFF has multiple IFDs. We do not yet support the (much rarer) form of multipage TIFFs whereby we have a single IFD with sub-ifd's in it. Those are supposedly used for strange things like multiple subsamplings of the same image, so are probably not actually what we want anyway. --- gpdl/tifftop.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/gpdl/tifftop.c b/gpdl/tifftop.c index 5e25d8dff..4321eb45e 100644 --- a/gpdl/tifftop.c +++ b/gpdl/tifftop.c @@ -888,12 +888,6 @@ do_tiff_decode(tiff_interp_instance_t *tiff) if (scale * tiff->height * tiff->dev->HWResolution[1] > tiff->dev->height * tiff->yresolution) scale = ((float)tiff->dev->height * tiff->yresolution) / (tiff->height * tiff->dev->HWResolution[1]); - tiff->nulldev = gs_currentdevice(tiff->pgs); - rc_increment(tiff->nulldev); - code = gs_setdevice_no_erase(tiff->pgs, tiff->dev); - if (code < 0) - return code; - code = gs_erasepage(tiff->pgs); if (code < 0) return code; @@ -1107,6 +1101,29 @@ fail_decode: return code; } +static int +decode_all_tiffs(tiff_interp_instance_t *tiff) +{ + int code; + + tiff->nulldev = gs_currentdevice(tiff->pgs); + rc_increment(tiff->nulldev); + code = gs_setdevice_no_erase(tiff->pgs, tiff->dev); + if (code < 0) + return code; + + do + { + code = do_tiff_decode(tiff); + if (code < 0) + return code; + } + while (TIFFReadDirectory(tiff->handle)); + + return 0; +} + + static int do_impl_process(pl_interp_implementation_t * impl, stream_cursor_read * pr, int eof) { @@ -1209,7 +1226,7 @@ do_impl_process(pl_interp_implementation_t * impl, stream_cursor_read * pr, int &tiff_jpeg_mem_callback); #endif - code = do_tiff_decode(tiff); + code = decode_all_tiffs(tiff); if (code < 0) { tiff->state = ii_state_flush; -- cgit v1.2.1