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] 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 ||