libtiff: 1) Reset tif->tif_curstrip to -1 at the end of the JPEGFixupTestSubsampling()

https://github.com/libsdl-org/libtiff/commit/833e48cd584834cee2c30edc228ac1ad01e1bcbb

From 833e48cd584834cee2c30edc228ac1ad01e1bcbb Mon Sep 17 00:00:00 2001
From: Frank Warmerdam <[EMAIL REDACTED]>
Date: Fri, 4 Dec 2009 01:04:00 +0000
Subject: [PATCH] 1) Reset tif->tif_curstrip to -1 at the end of the
 JPEGFixupTestSubsampling() so that JPEGPreDecode will be called again later
 when the first scanline or block is read.  This ensures that the appropriate
 decode method gets installed. 2) In JPEGResetUpsampling() the recomputation
 of tif_scanlinesize size is triggered (if we already had a meaningful value).
  This fix was actually provided by Even Rouault this afternoon.
 http://bugzilla.maptools.org/show_bug.cgi?id=1936

---
 ChangeLog          |  7 +++++++
 libtiff/tif_jpeg.c | 18 +++++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 20cb7538..bb251ef1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-12-03  Frank Warmerdam  <warmerdam@pobox.com>
+
+	* libtiff/tif_jpeg.c: Fix a couple of issues that trigger failures in
+	some cases when using TIFFReadScanline() with JPEG compressed 
+	subsampled ycbcr images.
+	http://bugzilla.maptools.org/show_bug.cgi?id=1936
+
 2009-11-04  Bob Friesenhahn  <bfriesen@simple.dallas.tx.us>
 
 	* libtiff 3.9.2 released.
diff --git a/libtiff/tif_jpeg.c b/libtiff/tif_jpeg.c
index 74b0d3f8..286310f5 100644
--- a/libtiff/tif_jpeg.c
+++ b/libtiff/tif_jpeg.c
@@ -1,4 +1,4 @@
-/* $Id: tif_jpeg.c,v 1.50.2.4 2009-08-30 16:21:46 bfriesen Exp $ */
+/* $Id: tif_jpeg.c,v 1.50.2.5 2009-12-04 01:04:00 fwarmerdam Exp $ */
 
 /*
  * Copyright (c) 1994-1997 Sam Leffler
@@ -1613,7 +1613,11 @@ JPEGResetUpsampled( TIFF* tif )
 	 * Must recalculate cached tile size in case sampling state changed.
 	 * Should we really be doing this now if image size isn't set? 
 	 */
-	tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tsize_t) -1;
+        if( tif->tif_tilesize > 0 )
+            tif->tif_tilesize = isTiled(tif) ? TIFFTileSize(tif) : (tsize_t) -1;
+
+        if(tif->tif_scanlinesize > 0 )
+            tif->tif_scanlinesize = TIFFScanlineSize(tif); 
 }
 
 static int
@@ -1741,13 +1745,21 @@ JPEGFixupTestSubsampling( TIFF * tif )
 			return;
     }
     else
-	{
+    {
         if( !TIFFFillStrip( tif, 0 ) )
             return;
     }
 
     TIFFSetField( tif, TIFFTAG_YCBCRSUBSAMPLING, 
                   (uint16) sp->h_sampling, (uint16) sp->v_sampling );
+
+    /*
+    ** We want to clear the loaded strip so the application has time
+    ** to set JPEGCOLORMODE or other behavior modifiers.  This essentially
+    ** undoes the JPEGPreDecode triggers by TIFFFileStrip().  (#1936)
+    */
+    tif->tif_curstrip = -1;
+
 #endif /* CHECK_JPEG_YCBCR_SUBSAMPLING */
 }