From 86a6fd9d18440ba5955c6bf474fd3550933ba060 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 4 Mar 2021 09:39:50 +0000 Subject: [PATCH 1/3] fix tiff deflate predictor setting the enums were mixed up, thanks Adios see https://github.com/libvips/libvips/issues/2128 --- ChangeLog | 1 + libvips/foreign/vips2tiff.c | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0b6981a0..24bcfd63 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ - fix includes of glib headers in C++ [lovell] - fix build with more modern librsvg [lovell] - fix a possible segv with very wide images [f1ac] +- fix tiff deflate predictor setting [Adios] 18/12/20 started 8.10.5 - fix potential /0 in animated webp load [lovell] diff --git a/libvips/foreign/vips2tiff.c b/libvips/foreign/vips2tiff.c index 1ea73895..29f3f130 100644 --- a/libvips/foreign/vips2tiff.c +++ b/libvips/foreign/vips2tiff.c @@ -333,9 +333,9 @@ struct _Wtiff { VipsPel *tbuf; /* TIFF output buffer */ int tls; /* Tile line size */ - int compression; /* Compression type */ + int compression; /* libtiff compression type */ int Q; /* JPEG q-factor, webp level */ - int predictor; /* Predictor value */ + int predictor; /* libtiff predictor type */ int tile; /* Tile or not */ int tilew, tileh; /* Tile size */ int pyramid; /* Wtiff pyramid */ @@ -663,8 +663,8 @@ wtiff_write_header( Wtiff *wtiff, Layer *layer ) TIFFSetField( tif, TIFFTAG_ZSTD_LEVEL, wtiff->level ); #endif /*HAVE_TIFF_COMPRESSION_WEBP*/ - if( (wtiff->compression == VIPS_FOREIGN_TIFF_COMPRESSION_DEFLATE || - wtiff->compression == VIPS_FOREIGN_TIFF_COMPRESSION_LZW) && + if( (wtiff->compression == COMPRESSION_ADOBE_DEFLATE || + wtiff->compression == COMPRESSION_LZW) && wtiff->predictor != VIPS_FOREIGN_TIFF_PREDICTOR_NONE ) TIFFSetField( tif, TIFFTAG_PREDICTOR, wtiff->predictor ); @@ -1866,6 +1866,11 @@ wtiff_copy_tiff( Wtiff *wtiff, TIFF *out, TIFF *in ) TIFFSetField( out, TIFFTAG_ZSTD_LEVEL, wtiff->level ); #endif /*HAVE_TIFF_COMPRESSION_WEBP*/ + if( (wtiff->compression == COMPRESSION_ADOBE_DEFLATE || + wtiff->compression == COMPRESSION_LZW) && + wtiff->predictor != VIPS_FOREIGN_TIFF_PREDICTOR_NONE ) + TIFFSetField( out, TIFFTAG_PREDICTOR, wtiff->predictor ); + /* We can't copy profiles or xmp :( Set again from wtiff. */ if( !wtiff->strip ) From 4d0252f31c6f0792b859650549e0c1a88dbd4a82 Mon Sep 17 00:00:00 2001 From: AdiosF6F <62105+Adios@users.noreply.github.com> Date: Thu, 4 Mar 2021 22:38:47 +0800 Subject: [PATCH 2/3] add tiff zstd predictor support --- libvips/foreign/tiffsave.c | 4 ++-- libvips/foreign/vips2tiff.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libvips/foreign/tiffsave.c b/libvips/foreign/tiffsave.c index c0565c59..57eda43b 100644 --- a/libvips/foreign/tiffsave.c +++ b/libvips/foreign/tiffsave.c @@ -590,8 +590,8 @@ vips_foreign_save_tiff_buffer_init( VipsForeignSaveTiffBuffer *buffer ) * User @level to set the ZSTD compression level. Use @lossless to * set WEBP lossless mode on. Use @Q to set the WEBP compression level. * - * Use @predictor to set the predictor for lzw and deflate compression. It - * defaults to #VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL, meaning horizontal + * Use @predictor to set the predictor for lzw, deflate and zstd compression. + * It defaults to #VIPS_FOREIGN_TIFF_PREDICTOR_HORIZONTAL, meaning horizontal * differencing. Please refer to the libtiff * specifications for further discussion of various predictors. * diff --git a/libvips/foreign/vips2tiff.c b/libvips/foreign/vips2tiff.c index 29f3f130..05103a4e 100644 --- a/libvips/foreign/vips2tiff.c +++ b/libvips/foreign/vips2tiff.c @@ -659,8 +659,13 @@ wtiff_write_header( Wtiff *wtiff, Layer *layer ) TIFFSetField( tif, TIFFTAG_WEBP_LEVEL, wtiff->Q ); TIFFSetField( tif, TIFFTAG_WEBP_LOSSLESS, wtiff->lossless ); } - if( wtiff->compression == COMPRESSION_ZSTD ) + if( wtiff->compression == COMPRESSION_ZSTD ) { TIFFSetField( tif, TIFFTAG_ZSTD_LEVEL, wtiff->level ); + + if( wtiff->predictor != VIPS_FOREIGN_TIFF_PREDICTOR_NONE ) + TIFFSetField( tif, TIFFTAG_PREDICTOR, + wtiff->predictor ); + } #endif /*HAVE_TIFF_COMPRESSION_WEBP*/ if( (wtiff->compression == COMPRESSION_ADOBE_DEFLATE || @@ -1862,8 +1867,13 @@ wtiff_copy_tiff( Wtiff *wtiff, TIFF *out, TIFF *in ) TIFFSetField( out, TIFFTAG_WEBP_LEVEL, wtiff->Q ); TIFFSetField( out, TIFFTAG_WEBP_LOSSLESS, wtiff->lossless ); } - if( wtiff->compression == COMPRESSION_ZSTD ) + if( wtiff->compression == COMPRESSION_ZSTD ) { TIFFSetField( out, TIFFTAG_ZSTD_LEVEL, wtiff->level ); + + if( wtiff->predictor != VIPS_FOREIGN_TIFF_PREDICTOR_NONE ) + TIFFSetField( out, TIFFTAG_PREDICTOR, + wtiff->predictor ); + } #endif /*HAVE_TIFF_COMPRESSION_WEBP*/ if( (wtiff->compression == COMPRESSION_ADOBE_DEFLATE || From 495b54dfcfc2ce3aeead23603b691df841af0902 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 4 Mar 2021 17:31:08 +0000 Subject: [PATCH 3/3] grou predictor settings --- libvips/foreign/vips2tiff.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/libvips/foreign/vips2tiff.c b/libvips/foreign/vips2tiff.c index 05103a4e..6c8d6d71 100644 --- a/libvips/foreign/vips2tiff.c +++ b/libvips/foreign/vips2tiff.c @@ -659,16 +659,12 @@ wtiff_write_header( Wtiff *wtiff, Layer *layer ) TIFFSetField( tif, TIFFTAG_WEBP_LEVEL, wtiff->Q ); TIFFSetField( tif, TIFFTAG_WEBP_LOSSLESS, wtiff->lossless ); } - if( wtiff->compression == COMPRESSION_ZSTD ) { + if( wtiff->compression == COMPRESSION_ZSTD ) TIFFSetField( tif, TIFFTAG_ZSTD_LEVEL, wtiff->level ); - - if( wtiff->predictor != VIPS_FOREIGN_TIFF_PREDICTOR_NONE ) - TIFFSetField( tif, TIFFTAG_PREDICTOR, - wtiff->predictor ); - } #endif /*HAVE_TIFF_COMPRESSION_WEBP*/ if( (wtiff->compression == COMPRESSION_ADOBE_DEFLATE || + wtiff->compression == COMPRESSION_ZSTD || wtiff->compression == COMPRESSION_LZW) && wtiff->predictor != VIPS_FOREIGN_TIFF_PREDICTOR_NONE ) TIFFSetField( tif, TIFFTAG_PREDICTOR, wtiff->predictor ); @@ -1867,16 +1863,12 @@ wtiff_copy_tiff( Wtiff *wtiff, TIFF *out, TIFF *in ) TIFFSetField( out, TIFFTAG_WEBP_LEVEL, wtiff->Q ); TIFFSetField( out, TIFFTAG_WEBP_LOSSLESS, wtiff->lossless ); } - if( wtiff->compression == COMPRESSION_ZSTD ) { + if( wtiff->compression == COMPRESSION_ZSTD ) TIFFSetField( out, TIFFTAG_ZSTD_LEVEL, wtiff->level ); - - if( wtiff->predictor != VIPS_FOREIGN_TIFF_PREDICTOR_NONE ) - TIFFSetField( out, TIFFTAG_PREDICTOR, - wtiff->predictor ); - } #endif /*HAVE_TIFF_COMPRESSION_WEBP*/ if( (wtiff->compression == COMPRESSION_ADOBE_DEFLATE || + wtiff->compression == COMPRESSION_ZSTD || wtiff->compression == COMPRESSION_LZW) && wtiff->predictor != VIPS_FOREIGN_TIFF_PREDICTOR_NONE ) TIFFSetField( out, TIFFTAG_PREDICTOR, wtiff->predictor );