libtiff: * libtiff/tif_jpeg.c: Do not generate a JPEGTables tag when creating

https://github.com/libsdl-org/libtiff/commit/df49ff17ed9ea641bd697ea44c7589c2c14baa44

From df49ff17ed9ea641bd697ea44c7589c2c14baa44 Mon Sep 17 00:00:00 2001
From: Lee Howard <[EMAIL REDACTED]>
Date: Mon, 22 Feb 2010 19:07:23 +0000
Subject: [PATCH]         * libtiff/tif_jpeg.c: Do not generate a JPEGTables
 tag when creating         the JPEG TIFF as is is not required in order to
 prevent it from         being unused and filled with invalid data.  (Leave it
 to be         generated by later activity.)         * tools/tiff2pdf.c: Write
 the JPEG SOI headers into the TIFF strip         data rather than skipping
 them.  This fixes the ability to view in         Acrobat Reader, Evince, and
 Ghostscript.

---
 ChangeLog          | 10 ++++++++++
 libtiff/tif_jpeg.c |  9 ++++++++-
 tools/tiff2pdf.c   |  5 ++++-
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 617e6f27..9d561bb8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-02-22  Lee Howard  <faxguy@howardsilvan.com>
+
+	* libtiff/tif_jpeg.c: Do not generate a JPEGTables tag when creating
+	the JPEG TIFF as is is not required in order to prevent it from 
+	being unused and filled with invalid data.  (Leave it to be 
+	generated by later activity.)
+	* tools/tiff2pdf.c: Write the JPEG SOI headers into the TIFF strip 
+	data rather than skipping them.  This fixes the ability to view in
+	Acrobat Reader, Evince, and Ghostscript.
+
 2010-01-06  Frank Warmerdam  <warmerdam@pobox.com>
 
 	* libtiff/tif_dir.c: Ensure tile and scanline sizes are reset
diff --git a/libtiff/tif_jpeg.c b/libtiff/tif_jpeg.c
index 286310f5..b17ff386 100644
--- a/libtiff/tif_jpeg.c
+++ b/libtiff/tif_jpeg.c
@@ -1,4 +1,4 @@
-/* $Id: tif_jpeg.c,v 1.50.2.5 2009-12-04 01:04:00 fwarmerdam Exp $ */
+/* $Id: tif_jpeg.c,v 1.50.2.6 2010-02-22 19:07:23 faxguy Exp $ */
 
 /*
  * Copyright (c) 1994-1997 Sam Leffler
@@ -2026,7 +2026,14 @@ TIFFInitJPEG(TIFF* tif, int scheme)
         if( tif->tif_diroff == 0 )
         {
 #define SIZE_OF_JPEGTABLES 2000
+/*
+The following line assumes incorrectly that all JPEG-in-TIFF files will have
+a JPEGTABLES tag generated and causes null-filled JPEGTABLES tags to be written
+when the JPEG data is placed with TIFFWriteRawStrip.  The field bit should be 
+set, anyway, later when actual JPEGTABLES header is generated, so removing it 
+here hopefully is harmless.
             TIFFSetFieldBit(tif, FIELD_JPEGTABLES);
+*/
             sp->jpegtables_length = SIZE_OF_JPEGTABLES;
             sp->jpegtables = (void *) _TIFFmalloc(sp->jpegtables_length);
 	    _TIFFmemset(sp->jpegtables, 0, SIZE_OF_JPEGTABLES);
diff --git a/tools/tiff2pdf.c b/tools/tiff2pdf.c
index cc36abc0..d78d14f5 100644
--- a/tools/tiff2pdf.c
+++ b/tools/tiff2pdf.c
@@ -1,4 +1,4 @@
-/* $Id: tiff2pdf.c,v 1.37.2.7 2009-01-01 00:10:43 bfriesen Exp $
+/* $Id: tiff2pdf.c,v 1.37.2.8 2010-02-22 19:07:24 faxguy Exp $
  *
  * tiff2pdf - converts a TIFF image to a PDF document
  *
@@ -3320,6 +3320,9 @@ int t2p_process_jpeg_strip(
 	while(i<(*striplength)){
 		switch( strip[i] ){
 			case 0xd8:
+				/* SOI - start of image */
+				_TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), 2);
+				*bufferoffset+=2;
 				i+=2;
 				break;
 			case 0xc0: