summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2021-06-15 15:27:30 +0000
committerEven Rouault <even.rouault@spatialys.com>2021-06-15 15:27:30 +0000
commitc253d546f1c6f5ed0a6354f2822bcc4f9998d809 (patch)
tree413a18fb7632eabd8211e75af6079617dad8b04b
parent1eb58f0a65f42cbdd649f3d3d79d598cb7098c46 (diff)
parente494de484685933c04cf19394ea769e9b213c249 (diff)
downloadlibtiff-git-c253d546f1c6f5ed0a6354f2822bcc4f9998d809.tar.gz
Merge branch 'jpeg_disable_progressive_with_mozjpeg' into 'master'
tif_jpeg.c: do not emit progressive scans with mozjpeg and force optimize_coding See merge request libtiff/libtiff!254
-rw-r--r--libtiff/tif_jpeg.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/libtiff/tif_jpeg.c b/libtiff/tif_jpeg.c
index 6076c117..ca386dc4 100644
--- a/libtiff/tif_jpeg.c
+++ b/libtiff/tif_jpeg.c
@@ -179,6 +179,7 @@ typedef struct {
int ycbcrsampling_fetched;
int max_allowed_scan_number;
+ int has_warned_about_progressive_mode;
} JPEGState;
#define JState(tif) ((JPEGState*)(tif)->tif_data)
@@ -1202,6 +1203,16 @@ JPEGPreDecode(TIFF* tif, uint16_t s)
}
#endif
+ if( sp->cinfo.d.progressive_mode && !sp->has_warned_about_progressive_mode )
+ {
+ TIFFWarningExt(tif->tif_clientdata, module,
+ "The JPEG strip/tile is encoded with progressive mode, "
+ "which is normally not legal for JPEG-in-TIFF.\n"
+ "libtiff should be able to decode it, but it might "
+ "cause compatibility issues with other readers");
+ sp->has_warned_about_progressive_mode = TRUE;
+ }
+
/* In some cases, libjpeg needs to allocate a lot of memory */
/* http://www.libjpeg-turbo.org/pmwiki/uploads/About/TwoIssueswiththeJPEGStandard.pdf */
if( TIFFjpeg_has_multiple_scans(sp) )
@@ -1770,6 +1781,23 @@ JPEGSetupEncode(TIFF* tif)
}
if (!TIFFjpeg_set_defaults(sp))
return (0);
+
+ /* mozjpeg by default enables progressive JPEG, which is illegal in JPEG-in-TIFF */
+ /* So explicitly disable it. */
+ if( sp->cinfo.c.num_scans != 0 &&
+ (sp->jpegtablesmode & JPEGTABLESMODE_HUFF) != 0 )
+ {
+ /* it has been found that mozjpeg could create corrupt strips/tiles */
+ /* in non optimize_coding mode. */
+ TIFFWarningExt(tif->tif_clientdata, module,
+ "mozjpeg library likely detected. Disable emission of "
+ "Huffman tables in JpegTables tag, and use optimize_coding "
+ "to avoid potential issues");
+ sp->jpegtablesmode &= ~JPEGTABLESMODE_HUFF;
+ }
+ sp->cinfo.c.num_scans = 0;
+ sp->cinfo.c.scan_info = NULL;
+
/* Set per-file parameters */
switch (sp->photometric) {
case PHOTOMETRIC_YCBCR: