summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorerouault <erouault>2014-12-15 15:40:06 +0000
committererouault <erouault>2014-12-15 15:40:06 +0000
commit259c61e8d58a3908e2fdf7fd232565c71358fc27 (patch)
tree6e1a9b6a65c28a035fbbd8c6d1c79647b1a83c58
parent503a5c98f8376e11b72da79f32e9c355b0e4d7bb (diff)
downloadlibtiff-259c61e8d58a3908e2fdf7fd232565c71358fc27.tar.gz
libtiff/tif_jpeg.c: Fix regression introduced on 2010-05-07 that caused all tiles/strips to include quantization tables even when the jpegtablesmode had the JPEGTABLESMODE_QUANT bit set. Also add explicit removal of Huffman tables when jpegtablesmode has the JPEGTABLESMODE_HUFF bit set, which avoids Huffman tables to be emitted in the first tile/strip (only useful in update scenarios. create-only was fine)
-rw-r--r--ChangeLog10
-rw-r--r--libtiff/tif_jpeg.c42
2 files changed, 49 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 9069c35d..de2c349f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2014-12-15 Even Rouault <even.rouault@spatialys.com>
+
+ * libtiff/tif_jpeg.c: Fix regression introduced on 2010-05-07 that caused
+ all tiles/strips to include quantization tables even when the jpegtablesmode
+ had the JPEGTABLESMODE_QUANT bit set.
+ Also add explicit removal of Huffman tables when jpegtablesmode has the
+ JPEGTABLESMODE_HUFF bit set, which avoids Huffman tables to be emitted in the
+ first tile/strip (only useful in update scenarios. create-only was
+ fine)
+
2014-12-09 Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
* tools/tiff2pdf.c: Assure that memory size calculations for
diff --git a/libtiff/tif_jpeg.c b/libtiff/tif_jpeg.c
index 80aa2712..ce7f9dcb 100644
--- a/libtiff/tif_jpeg.c
+++ b/libtiff/tif_jpeg.c
@@ -1,4 +1,4 @@
-/* $Id: tif_jpeg.c,v 1.112 2014-11-20 14:34:51 erouault Exp $ */
+/* $Id: tif_jpeg.c,v 1.113 2014-12-15 15:40:07 erouault Exp $ */
/*
* Copyright (c) 1994-1997 Sam Leffler
@@ -1452,6 +1452,15 @@ unsuppress_quant_table (JPEGState* sp, int tblno)
}
static void
+suppress_quant_table (JPEGState* sp, int tblno)
+{
+ JQUANT_TBL* qtbl;
+
+ if ((qtbl = sp->cinfo.c.quant_tbl_ptrs[tblno]) != NULL)
+ qtbl->sent_table = TRUE;
+}
+
+static void
unsuppress_huff_table (JPEGState* sp, int tblno)
{
JHUFF_TBL* htbl;
@@ -1462,6 +1471,17 @@ unsuppress_huff_table (JPEGState* sp, int tblno)
htbl->sent_table = FALSE;
}
+static void
+suppress_huff_table (JPEGState* sp, int tblno)
+{
+ JHUFF_TBL* htbl;
+
+ if ((htbl = sp->cinfo.c.dc_huff_tbl_ptrs[tblno]) != NULL)
+ htbl->sent_table = TRUE;
+ if ((htbl = sp->cinfo.c.ac_huff_tbl_ptrs[tblno]) != NULL)
+ htbl->sent_table = TRUE;
+}
+
static int
prepare_JPEGTables(TIFF* tif)
{
@@ -1726,14 +1746,30 @@ JPEGPreEncode(TIFF* tif, uint16 s)
sp->cinfo.c.write_JFIF_header = FALSE;
sp->cinfo.c.write_Adobe_marker = FALSE;
/* set up table handling correctly */
- if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE))
+ /* calling TIFFjpeg_set_quality() causes quantization tables to be flagged */
+ /* as being to be emitted, which we don't want in the JPEGTABLESMODE_QUANT */
+ /* mode, so we must manually suppress them. However TIFFjpeg_set_quality() */
+ /* should really be called when dealing with files with directories with */
+ /* mixed qualities. see http://trac.osgeo.org/gdal/ticket/3539 */
+ if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE))
return (0);
- if (! (sp->jpegtablesmode & JPEGTABLESMODE_QUANT)) {
+ if (sp->jpegtablesmode & JPEGTABLESMODE_QUANT) {
+ suppress_quant_table(sp, 0);
+ suppress_quant_table(sp, 1);
+ }
+ else {
unsuppress_quant_table(sp, 0);
unsuppress_quant_table(sp, 1);
}
if (sp->jpegtablesmode & JPEGTABLESMODE_HUFF)
+ {
+ /* Explicit suppression is only needed if we did not go through the */
+ /* prepare_JPEGTables() code path, which may be the case if updating */
+ /* an existing file */
+ suppress_huff_table(sp, 0);
+ suppress_huff_table(sp, 1);
sp->cinfo.c.optimize_coding = FALSE;
+ }
else
sp->cinfo.c.optimize_coding = TRUE;
if (downsampled_input) {