Return-Path: <awaresystems.be+caf_=filtered=awaresystems.be@gmail.com>
Delivered-To: filtered@awaresystems.be
Received: from mx03.one.com (mx03.one.com [195.47.247.74])
	by mail6.local.one.com (Postfix) with ESMTP id 3D1163000E7452
	for <filtered@awaresystems.be>; Sat, 27 Dec 2014 23:25:30 +0000 (UTC)
X-Virus-Scanned: by one.com
Received-SPF: pass (mx03: domain of awaresystems.be+caf_=filtered=awaresystems.be@gmail.com designates 209.85.217.169 as permitted sender)
X-Greylist: whitelisted by SQLgrey-1.8.0-rc2
Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com [209.85.217.169])
	by mx03.one.com (Postfix) with ESMTP id EDACA2262A
	for <filtered@awaresystems.be>; Sat, 27 Dec 2014 23:25:29 +0000 (UTC)
Received: by mail-lb0-f169.google.com with SMTP id p9so9726686lbv.0
        for <filtered@awaresystems.be>; Sat, 27 Dec 2014 15:25:29 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-original-authentication-results:delivered-to:delivered-to
         :message-id:date:from:user-agent:mime-version:to:content-type
         :subject:precedence:list-id:list-unsubscribe:list-archive:list-post
         :list-help:list-subscribe:sender:errors-to;
        bh=nQX07iOG7q+2JIREyyaVUyZOI/b+j5B8fkCMBMp9F/s=;
        b=fYmVT4Mm/DM44CeLn5jB+rgPv4CrOmRp8aUySJPAD8T8MuRmzLSR4jwYGtBRDt4X5N
         1jK1W6aXzHHH9VaGqm+Rj+BXO8LBi+MR6wulOuS7V0Z32eCvUDZAhsPpCaq96QzAois6
         RGyN2qQx2vropflPSIJf1qXxXf6CTNqJAKwA9PYk1onnAAwgV3wQxuJLM32p5Ms9cELt
         Mb2hclDO1y3W0jzu0CKNPLupgYVvGeUoBO03V8Rknjk35clB1e0XErKR27gWRYpvwjqw
         /IjIF8U6n92/pIt5xfClcQ6oSarVWKv1rB4k8AQBmKEtiO6wng5BZuXiFkF53EZqrWxl
         26lg==
X-Original-Authentication-Results: mx.google.com;       spf=none (google.com: tiff-bounces@lists.maptools.org does not designate permitted sender hosts) smtp.mail=tiff-bounces@lists.maptools.org
X-Received: by 10.112.55.101 with SMTP id r5mr31993512lbp.98.1419722729725;
        Sat, 27 Dec 2014 15:25:29 -0800 (PST)
X-Forwarded-To: filtered@awaresystems.be
X-Forwarded-For: awaresystems.be@gmail.com filtered@awaresystems.be
Delivered-To: awaresystems.be@gmail.com
Received: by 10.114.181.147 with SMTP id dw19csp1610018ldc;
        Sat, 27 Dec 2014 15:25:28 -0800 (PST)
X-Received: by 10.112.147.10 with SMTP id tg10mr49660638lbb.92.1419722725384;
        Sat, 27 Dec 2014 15:25:25 -0800 (PST)
Authentication-Results: mx.google.com;
       spf=none (google.com: tiff-bounces@lists.maptools.org does not designate permitted sender hosts) smtp.mail=tiff-bounces@lists.maptools.org
Received-SPF: none (google.com: tiff-bounces@lists.maptools.org does not designate permitted sender hosts) client-ip=195.47.247.147;
Received: by 10.152.105.137 with POP3 id gm9mf11567123lab.12;
        Sat, 27 Dec 2014 15:25:25 -0800 (PST)
X-Gmail-Fetch-Info: info@awaresystems.be 1 pop.awaresystems.be 110 info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-v.one.com (mx-v.one.com [195.47.247.147])
	by mail6.local.one.com (Postfix) with ESMTP id 4272A300A51AC9
	for <info@awaresystems.be>; Sat, 27 Dec 2014 22:31:14 +0000 (UTC)
X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2
Received: from lists.maptools.org (ks365428.kimsufi.com [94.23.4.142])
	by mx-v.one.com (Postfix) with ESMTP id 06ABC12A8579
	for <info@awaresystems.be>; Sat, 27 Dec 2014 22:31:13 +0000 (UTC)
Received: from [10.1.0.241] (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id D542135C02B;
	Sat, 27 Dec 2014 17:30:24 -0500 (EST)
Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com
	[209.85.217.172])
	by lists.maptools.org (Postfix) with ESMTPS id D92A435C023
	for <tiff@lists.maptools.org>; Sat, 27 Dec 2014 17:30:09 -0500 (EST)
Received: by mail-lb0-f172.google.com with SMTP id z12so1766621lbi.3
	for <tiff@lists.maptools.org>; Sat, 27 Dec 2014 14:30:17 -0800 (PST)
X-Received: by 10.152.6.8 with SMTP id w8mr50102399law.41.1419719416652;
	Sat, 27 Dec 2014 14:30:16 -0800 (PST)
Received: from ?IPv6:2a00:1370:8000:eff::3c6b? ([2a00:1370:8000:eff::3c6b])
	by mx.google.com with ESMTPSA id b4sm8815133lbp.17.2014.12.27.14.30.14
	for <tiff@lists.maptools.org>
	(version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
	Sat, 27 Dec 2014 14:30:15 -0800 (PST)
Message-ID: <549F32F6.9050106@gmail.com>
Date: Sun, 28 Dec 2014 01:30:14 +0300
From: "Yuriy M. Kaminskiy" <yumkam@gmail.com>
User-Agent: Mozilla/5.0 (X11; Linux x86_64;
	rv:24.0) Gecko/20100101 Thunderbird/24.6.0
MIME-Version: 1.0
To: tiff@lists.maptools.org
Content-Type: multipart/mixed; boundary="------------090400040408030002070709"
Subject: [Tiff] [PATCH] tiff2pdf fixes for grayscale (min-is-white/black)
	and alpha
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=subscribe>
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

This is a multi-part message in MIME format.
--------------090400040408030002070709
Content-Type: text/plain; charset=KOI8-R
Content-Transfer-Encoding: 7bit

Samples to test:
https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=21;filename=test1s3.tiff;att=1;bug=611141
(from https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=611141)
and
https://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=doc673.tif.126;att=5;bug=552382
(from https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=552382)

(both bugs are about tiff2ps [patch will be posted separately], but also exposes
bug in tiff2pdf).


--------------090400040408030002070709
Content-Type: text/x-diff;
 name="01-tiff2pdf-disable-passthrough-when-conversion.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="01-tiff2pdf-disable-passthrough-when-conversion.patch"

From: Yuriy M. Kaminskiy <yumkam@gmail.com>
Subject: Disable compression passthrough when sample conversion requested

It is not possible to use passthrough compression when
conversion from separate to contig or drop alpha is requested.

Index: tiff-3.9.4/tools/tiff2pdf.c
===================================================================
--- tiff-3.9.4.orig/tools/tiff2pdf.c	2014-12-27 19:36:10.552594211 +0300
+++ tiff-3.9.4/tools/tiff2pdf.c	2014-12-27 23:40:32.708095195 +0300
@@ -1700,7 +1700,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* 
 	t2p_compose_pdf_page(t2p);
 
 	t2p->pdf_transcode = T2P_TRANSCODE_ENCODE;
-	if(t2p->pdf_nopassthrough==0){
+	if(t2p->pdf_nopassthrough==0 && t2p->pdf_sample == T2P_SAMPLE_NOTHING){
 #ifdef CCITT_SUPPORT
 		if(t2p->tiff_compression==COMPRESSION_CCITTFAX4  
 			){

--------------090400040408030002070709
Content-Type: text/x-diff;
 name="02-tiff2pdf-fix-separate-and-other-conversion.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="02-tiff2pdf-fix-separate-and-other-conversion.patch"

From: Yuriy M. Kaminskiy <yumkam@gmail.com>
Subject: tiff2pdf: fix combination of SEPARATE to CONTIG conversion with other sample format conversions (dropping alpha/etc)

Index: tiff-3.9.4/tools/tiff2pdf.c
===================================================================
--- tiff-3.9.4.orig/tools/tiff2pdf.c	2014-12-27 19:36:10.552594211 +0300
+++ tiff-3.9.4/tools/tiff2pdf.c	2014-12-27 23:40:32.708095195 +0300
@@ -1649,7 +1649,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* 
 			case PLANARCONFIG_CONTIG:
 				break;
 			case PLANARCONFIG_SEPARATE:
-				t2p->pdf_sample=T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG;
+				t2p->pdf_sample |= T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG;
 				if(t2p->tiff_bitspersample!=8){
 					TIFFError(
 						TIFF2PDF_MODULE, 
@@ -2898,7 +2962,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P
 
 	} else {
 
-		if(t2p->pdf_sample == T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG){
+		if(t2p->pdf_sample & T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG){
 			septilesize=TIFFTileSize(input);
 			septilecount=TIFFNumberOfTiles(input);
 			tilesize=septilesize*t2p->tiff_samplesperpixel;

--------------090400040408030002070709
Content-Type: text/x-diff;
 name="03-tiff2pdf-grayscale-alpha.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="03-tiff2pdf-grayscale-alpha.patch"

From: Yuriy M. Kaminskiy <yumkam@gmail.com>
Subject: tiff2pdf: fix/add support for grayscale-alpha formats

Index: tiff-3.9.4/tools/tiff2pdf.c
===================================================================
--- tiff-3.9.4.orig/tools/tiff2pdf.c	2014-12-27 19:36:10.552594211 +0300
+++ tiff-3.9.4/tools/tiff2pdf.c	2014-12-27 23:40:32.708095195 +0300
@@ -94,6 +94,8 @@ typedef enum{
 	T2P_SAMPLE_ABGR_TO_RGB=0x0001, /* The unencoded samples are the result of ReadRGBAImage */
 	T2P_SAMPLE_RGBA_TO_RGB=0x0002, /* The unencoded samples are contiguous RGBA */
 	T2P_SAMPLE_RGBAA_TO_RGB=0x0004, /* The unencoded samples are RGBA with premultiplied alpha */
+	T2P_SAMPLE_GRAYA_TO_GRAY=0x0200, /* The unencoded samples are contiguous Min-is-* */
+	T2P_SAMPLE_GRAYAA_TO_GRAY=0x0400, /* The unencoded samples are Min-is-* with premultiplied alpha */
 	T2P_SAMPLE_YCBCR_TO_RGB=0x0008, 
 	T2P_SAMPLE_YCBCR_TO_LAB=0x0010, 
 	T2P_SAMPLE_REALIZE_PALETTE=0x0020, /* The unencoded samples are indexes into the color map */
@@ -274,6 +277,8 @@ tsize_t t2p_sample_realize_palette(T2P*,
 tsize_t t2p_sample_abgr_to_rgb(tdata_t, uint32);
 tsize_t t2p_sample_rgba_to_rgb(tdata_t, uint32);
 tsize_t t2p_sample_rgbaa_to_rgb(tdata_t, uint32);
+tsize_t t2p_sample_graya_to_gray(tdata_t, uint32);
+tsize_t t2p_sample_grayaa_to_gray(tdata_t, uint32);
 tsize_t t2p_sample_lab_signed_to_unsigned(tdata_t, uint32);
 tsize_t t2p_write_pdf_header(T2P*, TIFF*);
 tsize_t t2p_write_pdf_obj_start(uint32, TIFF*);
@@ -1415,6 +1425,32 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* 
 					t2p->pdf_switchdecode ^= 1;
 				} 
 			}
+			if(t2p->tiff_samplesperpixel == 1){
+				break;
+			}
+			if(t2p->tiff_samplesperpixel > 1) {
+				if(t2p->tiff_samplesperpixel == 2) {
+					if(TIFFGetField(input,
+							TIFFTAG_EXTRASAMPLES,
+							&xuint16, &xuint16p)
+					   && xuint16 == 1) {
+						if(xuint16p[0] == EXTRASAMPLE_ASSOCALPHA){
+							t2p->pdf_sample=T2P_SAMPLE_GRAYAA_TO_GRAY;
+							break;
+						}
+						if(xuint16p[0] == EXTRASAMPLE_UNASSALPHA){
+							t2p->pdf_sample=T2P_SAMPLE_GRAYA_TO_GRAY;
+							break;
+						}
+					}
+				}
+			}
+			TIFFError(
+				TIFF2PDF_MODULE,
+				"No support for grayscale image %s with %u samples per pixel",
+				TIFFFileName(input),
+				t2p->tiff_samplesperpixel);
+			t2p->t2p_error = T2P_ERR_ERROR;
 			break;
 		case PHOTOMETRIC_RGB: 
 			t2p->pdf_colorspace=T2P_CS_RGB;
@@ -2536,6 +2588,18 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p
 				t2p->tiff_width*t2p->tiff_length);
 		}
 
+		if(t2p->pdf_sample & T2P_SAMPLE_GRAYA_TO_GRAY){
+			t2p->tiff_datasize=t2p_sample_graya_to_gray(
+				(tdata_t)buffer,
+				t2p->tiff_width*t2p->tiff_length);
+		}
+
+		if(t2p->pdf_sample & T2P_SAMPLE_GRAYAA_TO_GRAY){
+			t2p->tiff_datasize=t2p_sample_grayaa_to_gray(
+				(tdata_t)buffer,
+				t2p->tiff_width*t2p->tiff_length);
+		}
+
 		if(t2p->pdf_sample & T2P_SAMPLE_YCBCR_TO_RGB){
 			samplebuffer=(unsigned char*)_TIFFrealloc(
 				(tdata_t)buffer, 
@@ -2992,6 +3056,20 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P
 				*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);
 		}
 
+		if(t2p->pdf_sample & T2P_SAMPLE_GRAYA_TO_GRAY){
+			t2p->tiff_datasize=t2p_sample_graya_to_gray(
+				(tdata_t)buffer,
+				t2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth
+				*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);
+		}
+
+		if(t2p->pdf_sample & T2P_SAMPLE_GRAYAA_TO_GRAY){
+			t2p->tiff_datasize=t2p_sample_grayaa_to_gray(
+				(tdata_t)buffer,
+				t2p->tiff_tiles[t2p->pdf_page].tiles_tilewidth
+				*t2p->tiff_tiles[t2p->pdf_page].tiles_tilelength);
+		}
+
 		if(t2p->pdf_sample & T2P_SAMPLE_YCBCR_TO_RGB){
 			TIFFError(TIFF2PDF_MODULE, 
 				"No support for YCbCr to RGB in tile for %s", 
@@ -3649,6 +3727,41 @@ t2p_sample_rgba_to_rgb(tdata_t data, uin
 }
 
 /*
+ * This functions converts in place a buffer of GRAYA interleaved data
+ * into GRAY interleaved data, discarding A.
+ */
+
+tsize_t
+t2p_sample_grayaa_to_gray(tdata_t data, uint32 samplecount)
+{
+	uint32 i;
+
+	for(i = 0; i < samplecount; i++)
+		((uint8 *)data)[i] = ((uint8*)data)[i*2];
+
+	return i;
+}
+
+/*
+ * This functions converts in place a buffer of GRAYA interleaved data
+ * into GRAY interleaved data, adding 255-A to each component sample.
+ */
+
+tsize_t
+t2p_sample_graya_to_gray(tdata_t data, uint32 samplecount)
+{
+	uint32 i = 0;
+	uint8 alpha = 0;
+
+	for (i = 0; i < samplecount; i++) {
+		alpha= 255 - (((uint8 *)data)[i*2+1] & 0xff);
+		((uint8 *)data)[i] = (((uint8 *)data)[i*2] & 0xff) + alpha;
+	}
+
+	return i;
+}
+
+/*
 	This function converts the a and b samples of Lab data from signed
 	to unsigned.
 */

--------------090400040408030002070709
Content-Type: text/x-diff;
 name="04-tiff2pdf-fix-decode-components.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="04-tiff2pdf-fix-decode-components.patch"

From: Yuriy M. Kaminskiy <yumkam@gmail.com>
Subject: tiff2pdf: fix number of decoded components

/Decode array was incorrect for case when alpha was cropped.

Index: tiff-3.9.4/tools/tiff2pdf.c
===================================================================
--- tiff-3.9.4.orig/tools/tiff2pdf.c	2014-12-27 19:36:10.552594211 +0300
+++ tiff-3.9.4/tools/tiff2pdf.c	2014-12-27 23:40:32.708095195 +0300
@@ -5078,10 +5191,15 @@ tsize_t t2p_write_pdf_xobject_palettecs_
 tsize_t t2p_write_pdf_xobject_decode(T2P* t2p, TIFF* output){
 
 	tsize_t written=0;
-	int i=0;
+	int i=t2p->tiff_samplesperpixel;
 
+	if ((t2p->pdf_sample & (T2P_SAMPLE_GRAYA_TO_GRAY |
+				T2P_SAMPLE_GRAYAA_TO_GRAY |
+				T2P_SAMPLE_RGBA_TO_RGB |
+				T2P_SAMPLE_RGBAA_TO_RGB)))
+		i--;
 	written += t2pWriteFile(output, (tdata_t) "/Decode [ ", 10);
-	for (i=0;i<t2p->tiff_samplesperpixel;i++){
+	while(i-- > 0){
 		written += t2pWriteFile(output, (tdata_t) "1 0 ", 4);
 	}
 	written += t2pWriteFile(output, (tdata_t) "]\n", 2);

--------------090400040408030002070709
Content-Type: text/x-diff;
 name="05-tiff2pdf-optimize-separate-unassoc-alpha-crop.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="05-tiff2pdf-optimize-separate-unassoc-alpha-crop.patch"

From: Yuriy M. Kaminskiy <yumkam@gmail.com>
Subject: tiff2pdf: short-circuit unassociated alpha cropping and PLANARCONFIG_SEPARATE decoding

In grayscale case, it is possible to completely avoid decoding and enables use of passthrough compression.
In RGB case, just integrate alpha dropping into separate->contig step

Index: tiff-3.9.4/tools/tiff2pdf.c
===================================================================
--- tiff-4.0.x-20141215.orig/tools/tiff2pdf.c	2014-12-27 19:36:10.552594211 +0300
+++ tiff-4.0.x-20141215/tools/tiff2pdf.c	2014-12-27 23:40:32.708095195 +0300
@@ -153,6 +155,7 @@ typedef struct {
 	uint16 tiff_fillorder;
 	uint16 tiff_bitspersample;
 	uint16 tiff_samplesperpixel;
+	uint16 tiff_strips;
 	uint16 tiff_planar;
 	uint32 tiff_width;
 	uint32 tiff_length;
@@ -1179,7 +1184,7 @@ void t2p_read_tiff_init(T2P* t2p, TIFF* 
                         if( (xuint16== COMPRESSION_DEFLATE ||
                              xuint16== COMPRESSION_ADOBE_DEFLATE) && 
                             ((t2p->tiff_pages[i].page_tilecount != 0) 
-                             || TIFFNumberOfStrips(input)==1) &&
+                             || t2p->tiff_strips==1) &&
                             (t2p->pdf_nopassthrough==0)	){
                                 if(t2p->pdf_minorversion<2){t2p->pdf_minorversion=2;}
                         }
@@ -1400,7 +1405,12 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* 
                 return;
 
         }
         
+	if (TIFFIsTiled(input))
+	    t2p->tiff_strips = 1;
+	else
+	    t2p->tiff_strips = TIFFNumberOfStrips(input);
+
 	switch(t2p->tiff_photometric){
 		case PHOTOMETRIC_MINISWHITE:
 		case PHOTOMETRIC_MINISBLACK: 
@@ -1649,7 +1685,23 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* 
 			case PLANARCONFIG_CONTIG:
 				break;
 			case PLANARCONFIG_SEPARATE:
+				if (t2p->tiff_planar == PLANARCONFIG_SEPARATE
+				    && (t2p->pdf_sample & (T2P_SAMPLE_RGBA_TO_RGB | T2P_SAMPLE_GRAYA_TO_GRAY))) {
+					/* just crop alpha strip/tile */
+					if (TIFFIsTiled(input))
+						t2p->tiff_pages[t2p->pdf_page].page_tilecount = (t2p->tiff_pages[t2p->pdf_page].page_tilecount/t2p->tiff_samplesperpixel) * (t2p->tiff_samplesperpixel - 1);
+					else
+						t2p->tiff_strips = (t2p->tiff_strips / t2p->tiff_samplesperpixel) * (t2p->tiff_samplesperpixel - 1);
+					t2p->tiff_samplesperpixel--;
+					if ((t2p->pdf_sample & T2P_SAMPLE_GRAYA_TO_GRAY)) {
+						/* skip conversion to GRAY */
+						t2p->tiff_planar = PLANARCONFIG_CONTIG;
+						t2p->pdf_sample &= ~T2P_SAMPLE_GRAYA_TO_GRAY;
+						break;
+					}
+					t2p->pdf_sample &= ~T2P_SAMPLE_RGBA_TO_RGB;
+				}
 				t2p->pdf_sample |= T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG;
 				if(t2p->tiff_bitspersample!=8){
 					TIFFError(
 						TIFF2PDF_MODULE, 
@@ -1705,6 +1757,6 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* 
 		if(t2p->tiff_compression==COMPRESSION_CCITTFAX4  
 			){
-			if(TIFFIsTiled(input) || (TIFFNumberOfStrips(input)==1) ){
+			if(/*TIFFIsTiled(input) || */(t2p->tiff_strips==1) ){
 				t2p->pdf_transcode = T2P_TRANSCODE_RAW;
 				t2p->pdf_compression=T2P_COMPRESS_G4;
 			}
@@ -1713,7 +1765,7 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* 
 #ifdef ZIP_SUPPORT
 		if(t2p->tiff_compression== COMPRESSION_ADOBE_DEFLATE 
 			|| t2p->tiff_compression==COMPRESSION_DEFLATE){
-			if(TIFFIsTiled(input) || (TIFFNumberOfStrips(input)==1) ){
+			if(/*TIFFIsTiled(input) || */(t2p->tiff_strips==1) ){
 				t2p->pdf_transcode = T2P_TRANSCODE_RAW;
 				t2p->pdf_compression=T2P_COMPRESS_ZIP;
 			}
@@ -1884,7 +1936,7 @@ void t2p_read_tiff_size(T2P* t2p, TIFF* 
 				t2p->t2p_error = T2P_ERR_ERROR;
 				return;
 			}
-			stripcount=TIFFNumberOfStrips(input);
+			stripcount=t2p->tiff_strips;
 			for(i=0;i<stripcount;i++){
 				k = checkAdd64(k, sbc[i], t2p);
 			}
@@ -1939,7 +1991,7 @@ void t2p_read_tiff_size(T2P* t2p, TIFF* 
 			} else {
 				k = 2; /* SOI for first strip */
 			}
-			stripcount=TIFFNumberOfStrips(input);
+			stripcount=t2p->tiff_strips;
 			if(!TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc)){
 				TIFFError(TIFF2PDF_MODULE, 
 					"Input file %s missing field: TIFFTAG_STRIPBYTECOUNTS",
@@ -2258,7 +2310,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p
 					ri*=(rows+v_samp-1)/v_samp;
 					buffer[bufferoffset++]= (ri>>8) & 0xff;
 					buffer[bufferoffset++]= ri & 0xff;
-					stripcount=TIFFNumberOfStrips(input);
+					stripcount=t2p->tiff_strips;
 					for(i=0;i<stripcount;i++){
 						if(i != 0 ){ 
 							buffer[bufferoffset++]=0xff;
@@ -2294,7 +2346,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p
                                 memset(buffer, 0, t2p->tiff_datasize);
 				_TIFFmemcpy(buffer, t2p->pdf_ojpegdata, t2p->pdf_ojpegdatalength);
 				bufferoffset=t2p->pdf_ojpegdatalength;
-				stripcount=TIFFNumberOfStrips(input);
+				stripcount=t2p->tiff_strips;
 				for(i=0;i<stripcount;i++){
 					if(i != 0){
 						buffer[bufferoffset++]=0xff;
@@ -2341,7 +2393,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p
 					bufferoffset += count - 2;
 				}
 			}
-			stripcount=TIFFNumberOfStrips(input);
+			stripcount=t2p->tiff_strips;
 			TIFFGetField(input, TIFFTAG_STRIPBYTECOUNTS, &sbc);
 			for(i=0;i<stripcount;i++){
 				if(sbc[i]>max_striplength) max_striplength=sbc[i];
@@ -2398,7 +2450,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p
 		}
                 memset(buffer, 0, t2p->tiff_datasize);
 		stripsize=TIFFStripSize(input);
-		stripcount=TIFFNumberOfStrips(input);
+		stripcount=t2p->tiff_strips;
 		for(i=0;i<stripcount;i++){
 			read = 
 				TIFFReadEncodedStrip(input, 
@@ -2420,7 +2472,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p
 		if(t2p->pdf_sample & T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG){
 		
 			sepstripsize=TIFFStripSize(input);
-			sepstripcount=TIFFNumberOfStrips(input);
+			sepstripcount=t2p->tiff_strips;
 		
 			stripsize=sepstripsize*t2p->tiff_samplesperpixel;
 			stripcount=sepstripcount/t2p->tiff_samplesperpixel;
@@ -2485,7 +2537,7 @@ tsize_t t2p_readwrite_pdf_image(T2P* t2p
 		}
                 memset(buffer, 0, t2p->tiff_datasize);
 		stripsize=TIFFStripSize(input);
-		stripcount=TIFFNumberOfStrips(input);
+		stripcount=t2p->tiff_strips;
 		for(i=0;i<stripcount;i++){
 			read = 
 				TIFFReadEncodedStrip(input, 
@@ -2898,7 +2962,7 @@ tsize_t t2p_readwrite_pdf_image_tile(T2P
 
 		if(t2p->pdf_sample & T2P_SAMPLE_PLANAR_SEPARATE_TO_CONTIG){
 			septilesize=TIFFTileSize(input);
-			septilecount=TIFFNumberOfTiles(input);
+			septilecount=t2p->tiff_pages[t2p->pdf_page].page_tilecount;
 			/* tilesize=septilesize*t2p->tiff_samplesperpixel; */
 			tilecount=septilecount/t2p->tiff_samplesperpixel;
 			buffer = (unsigned char*) _TIFFmalloc(t2p->tiff_datasize);
@@ -3342,7 +3420,7 @@ int t2p_process_ojpeg_tables(T2P* t2p, T
 			t2p->pdf_ojpegdatalength+=code_count;
 		}
 	}
-	if(TIFFNumberOfStrips(input)>1){
+	if(t2p->tiff_strips>1){
 		ojpegdata[t2p->pdf_ojpegdatalength++]=0xff;
 		ojpegdata[t2p->pdf_ojpegdatalength++]=0xdd;
 		ojpegdata[t2p->pdf_ojpegdatalength++]=0x00;

--------------090400040408030002070709
Content-Type: text/x-diff;
 name="06-tiff2pdf-invert-simplification.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="06-tiff2pdf-invert-simplification.patch"

From: Yuriy M. Kaminskiy <yumkam@gmail.com>
Subject: tiff2pdf: move/simplify pdf_switchdecode toggle

Index: tiff-3.9.4/tools/tiff2pdf.c
===================================================================
--- tiff-3.9.4.orig/tools/tiff2pdf.c	2014-12-28 00:58:45.560598630 +0300
+++ tiff-3.9.4/tools/tiff2pdf.c	2014-12-28 01:01:33.744598722 +0300
@@ -1413,17 +1413,13 @@ void t2p_read_tiff_data(T2P* t2p, TIFF* 
 
 	switch(t2p->tiff_photometric){
 		case PHOTOMETRIC_MINISWHITE:
+			t2p->pdf_switchdecode ^= 1;
+			/* fallthrough */
 		case PHOTOMETRIC_MINISBLACK: 
 			if (t2p->tiff_bitspersample==1){
 				t2p->pdf_colorspace=T2P_CS_BILEVEL;
-				if(t2p->tiff_photometric==PHOTOMETRIC_MINISWHITE){
-					t2p->pdf_switchdecode ^= 1;
-				}
 			} else {
 				t2p->pdf_colorspace=T2P_CS_GRAY;
-				if(t2p->tiff_photometric==PHOTOMETRIC_MINISWHITE){
-					t2p->pdf_switchdecode ^= 1;
-				} 
 			}
 			if(t2p->tiff_samplesperpixel == 1){
 				break;

--------------090400040408030002070709
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
--------------090400040408030002070709--
