From 95bf1367ba340125d0e3d9111fa97ddbcd880b8d Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 28 Jun 2021 20:24:00 +0100 Subject: [PATCH] fix jpeg tiff pyramid save we were not copying the quant tables on lower pyr levels correctly add a test too --- ChangeLog | 1 + libvips/foreign/vips2tiff.c | 15 ++++++++++----- test/test-suite/test_foreign.py | 6 ++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index ce32e994..eb54d284 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ - command-line programs set glib prgname (no longer set for you by VIPS_INIT) - enable strip chopping for TIFF read [DavidStorm] - disable modules by default for static builds [kleisauke] +- fix jpeg tiff pyramid save 14/8/20 started 8.11 - add vips_jpegload_source() and vips_svgload_source() to public C API diff --git a/libvips/foreign/vips2tiff.c b/libvips/foreign/vips2tiff.c index ca2e0c2b..e158e49c 100644 --- a/libvips/foreign/vips2tiff.c +++ b/libvips/foreign/vips2tiff.c @@ -2029,12 +2029,17 @@ wtiff_copy_tiff( Wtiff *wtiff, TIFF *out, TIFF *in ) for( tile_no = 0; tile_no < n; tile_no++ ) { tsize_t len; - len = TIFFReadRawTile( in, tile_no, - wtiff->compressed_buf, wtiff->compressed_buf_length ); - if( len <= 0 || - TIFFWriteRawTile( out, tile_no, - wtiff->compressed_buf, len ) < 0 ) + /* TIFFReadRawTile()/TIFFWriteRawTile() would save us + * decompress/recompress, but they won't work for + * JPEG-compressed tiles since they won't copy the + * JPEG quant tables we need. + */ + len = TIFFReadEncodedTile( in, tile_no, buf, -1 ); + if( len < 0 || + TIFFWriteEncodedTile( out, tile_no, buf, len ) < 0 ) { + g_free( buf ); return( -1 ); + } } g_free( buf ); diff --git a/test/test-suite/test_foreign.py b/test/test-suite/test_foreign.py index e515d765..52bd7485 100644 --- a/test/test-suite/test_foreign.py +++ b/test/test-suite/test_foreign.py @@ -415,6 +415,12 @@ class TestForeign: im = pyvips.Image.new_from_file(TIF4_FILE) self.save_load_file(".tif", "[bitdepth=4]", im) + filename = temp_filename(self.tempdir, '.tif') + self.colour.write_to_file(filename, pyramid=True, compression="jpeg") + x = pyvips.Image.new_from_file(filename, page=2) + assert x.width == 72 + assert abs(x.avg() - 117.3) < 1 + filename = temp_filename(self.tempdir, '.tif') x = pyvips.Image.new_from_file(TIF_FILE) x = x.copy()