diff options
author | Even Rouault <even.rouault@spatialys.com> | 2021-06-10 14:12:18 +0200 |
---|---|---|
committer | Even Rouault <even.rouault@spatialys.com> | 2021-06-10 14:12:18 +0200 |
commit | 6438425ae911ec97a08b47b87cfac9e5a9b9b047 (patch) | |
tree | 0a19b526ab96eda3dd32bf55fc221063ff77f537 | |
parent | 4ecf751f887fc28ebd50718260b9d4e515a2f43e (diff) | |
download | libtiff-git-6438425ae911ec97a08b47b87cfac9e5a9b9b047.tar.gz |
tif_jpeg.c: do not emit progressive scans with mozjpeg
Relates to #266
- On writing, explicitly disable progressive scans, which is normally
not enabled, except with mozjpeg.
- On reading, emit a warning when encountering progressive scans.
-rw-r--r-- | libtiff/tif_jpeg.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libtiff/tif_jpeg.c b/libtiff/tif_jpeg.c index 6076c117..a3bf448c 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,12 @@ 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. */ + sp->cinfo.c.num_scans = 0; + sp->cinfo.c.scan_info = NULL; + /* Set per-file parameters */ switch (sp->photometric) { case PHOTOMETRIC_YCBCR: |