https://github.com/libsdl-org/libtiff/commit/cb4759cd44d33226b42484e9a402d1380215df27
From cb4759cd44d33226b42484e9a402d1380215df27 Mon Sep 17 00:00:00 2001
From: Frank Warmerdam <[EMAIL REDACTED]>
Date: Fri, 7 May 2010 18:38:24 +0000
Subject: [PATCH] ensure quality always set in JPEGPreEncode (gdal #3539)
---
ChangeLog | 9 +++++++++
libtiff/tif_jpeg.c | 6 +++---
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e86270fc..be9c63c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2010-05-07 Frank Warmerdam <warmerdam@pobox.com>
+
+ * libtiff/tif_jpeg.c: Ensure that quality is always set in
+ JPEGPreEncode(), not just when we want to output local tables.
+ Otherwise the quality used during compression may not be right and
+ might not match the tables in the tables tag. This bug only occurs
+ when seeking between directories in the midst of writing blocks.
+ http://trac.osgeo.org/gdal/ticket/3539
+
2010-05-05 Olivier Paquet <olivier.paquet@gmail.com>
* libtiff/tif_print.c: Have TIFFTAG_REFERENCEBLACKWHITE always print 6
diff --git a/libtiff/tif_jpeg.c b/libtiff/tif_jpeg.c
index b17ff386..4e25340a 100644
--- a/libtiff/tif_jpeg.c
+++ b/libtiff/tif_jpeg.c
@@ -1,4 +1,4 @@
-/* $Id: tif_jpeg.c,v 1.50.2.6 2010-02-22 19:07:23 faxguy Exp $ */
+/* $Id: tif_jpeg.c,v 1.50.2.7 2010-05-07 18:38:24 fwarmerdam Exp $ */
/*
* Copyright (c) 1994-1997 Sam Leffler
@@ -1370,9 +1370,9 @@ JPEGPreEncode(TIFF* tif, tsample_t 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))
+ return (0);
if (! (sp->jpegtablesmode & JPEGTABLESMODE_QUANT)) {
- if (!TIFFjpeg_set_quality(sp, sp->jpegquality, FALSE))
- return (0);
unsuppress_quant_table(sp, 0);
unsuppress_quant_table(sp, 1);
}