Return-Path: <tiff-bounces@remotesensing.org>
Received: from inmx016.isp.belgacom.be (inmx016.isp.belgacom.be [195.238.2.219])
        by mailst006.isp.belgacom.be (8.12.11/8.12.11/Skynet-MAILSTORE-2.14) with ESMTP id i7KGfsp8028207
        for <joris.at.lebbeke@skynet.be>; Fri, 20 Aug 2004 18:41:54 +0200
        (envelope-from <tiff-bounces@remotesensing.org>)
Received: from xserve.flids.com (adsl-065-083-169-202.sip.mco.bellsouth.net [65.83.169.202])
        by inmx016.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-2.32) with ESMTP id i7KGfkYY019883
        for <joris.at.lebbeke@skynet.be>; Fri, 20 Aug 2004 18:41:49 +0200
        (envelope-from <tiff-bounces@remotesensing.org>)
Received: from adsl-065-083-169-202.sip.mco.bellsouth.net (localhost [127.0.0.1])
	by xserve.flids.com (Postfix) with ESMTP
	id E1B811F6F5B; Fri, 20 Aug 2004 12:41:26 -0400 (EDT)
X-Original-To: tiff@remotesensing.org
Delivered-To: tiff@remotesensing.org
Received: from tiki-lounge.com (tiki-lounge.com [199.181.107.26])
	by xserve.flids.com (Postfix) with ESMTP id 3C7DB1F6F33
	for <tiff@remotesensing.org>; Fri, 20 Aug 2004 12:41:25 -0400 (EDT)
Received: from tiki-lounge.com (localhost [127.0.0.1])
	by tiki-lounge.com (8.12.1/8.12.1) with ESMTP id i7KGbETe009765;
	Fri, 20 Aug 2004 09:37:14 -0700 (PDT)
Received: from localhost (raf@localhost)
	by tiki-lounge.com (8.12.1/8.12.1/Submit) with ESMTP id i7KGbD7x009762; 
	Fri, 20 Aug 2004 09:37:13 -0700 (PDT)
Date: Fri, 20 Aug 2004 09:37:13 -0700 (PDT)
From: "Ross A. Finlayson" <raf@tiki-lounge.com>
X-X-Sender: raf@tiki-lounge.com
To: Joris <joris.at.lebbeke@skynet.be>
Subject: Re: [Tiff] Tiff conversion using libTiff
In-Reply-To: <001c01c486d2$2be33060$9c5df051@dfgrrxsknr4e>
Message-ID: <Pine.GSO.4.43.0408200933590.9719-100000@tiki-lounge.com>
X-Ross: Ross
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Cc: "Alexandru, Ionita" <galexandru@mail.cst.ro>,
        Tiff mailing list <tiff@remotesensing.org>
X-BeenThere: tiff@remotesensing.org
X-Mailman-Version: 2.1.2
Precedence: list
List-Id: TIFF and libtiff discussion  <tiff.remotesensing.org>
List-Unsubscribe: <http://xserve.flids.com/mailman/listinfo/tiff>,
	<mailto:tiff-request@remotesensing.org?subject=unsubscribe>
List-Archive: <http://xserve.flids.com/pipermail/tiff>
List-Post: <mailto:tiff@remotesensing.org>
List-Help: <mailto:tiff-request@remotesensing.org?subject=help>
List-Subscribe: <http://xserve.flids.com/mailman/listinfo/tiff>,
	<mailto:tiff-request@remotesensing.org?subject=subscribe>
Sender: tiff-bounces@remotesensing.org
Errors-To: tiff-bounces@remotesensing.org
X-UIDL: d1aaf4e176dbb59c68b96a33929c9121

TIFF Directory at offset 0xb5706
  Image Width: 1640 Image Length: 2602
  Resolution: 199.975, 199.975
  Bits/Sample: 1
  Compression Scheme: LZW
  Orientation: row 0 top, col 0 lhs
  Rows/Strip: 39
  Planar Configuration: single image plane
TIFF Directory at offset 0xbcf9a
  Subfile Type: multi-page document (2 = 0x2)
  ...

This IFD does not have the PhotometricInterpretation field set, or
SamplesPerPixel.  The default is probably 0, and 1.

So when a previous IFD had set RGB, then when the function call is made to
get the PhotometricInterpretation, it could fail bcause I don't check the
reurn value.

        TIFFGetField(input, TIFFTAG_PHOTOMETRIC,
&(t2p->tiff_photometric));


Then, it reuses the value of tiff_photometric from a previous IFD.

I considered you could change the line maching the above line in
tiff2pdf.c to:

        TIFFGetFieldDefaulted(input, TIFFTAG_PHOTOMETRIC,
&(t2p->tiff_photometric));

That won't work.

TIFFGetFieldDefaulted is defined in tif_aux.c.  It does not have a case
for PhotometricInterpretation, TIFFTAG_PHOTOMETRIC.  That probably means
that in the standard document TIFF 6.0 that PhotometricInterpretation
field presence is a requirement of Baseline TIFF.  As it is a required
field for bilevel TIFF images, there is no standard default.

Perhaps I may suggest to you to write a program using libtiff to check for
the presence of the TIFFTAG_PHOTOMETRIC tag in your input images and if
non-existent to add the correct required tag to the image.  You could
change the TIFFGetField to TIFFGetFieldDefaulted, and it would do no good
unless you added a case in TIFFVGetFieldDefaulted in tif_aux.c to set the
value to the correct value for those nonstandard image files while not
affecting the standard ones.

Your best solution to keep your software compatible with libtiff, because
libtiff should not deem a default PhotometricInterpretation as it is a
required field with no default value, is to have your own program check
the input file for all required tags and add your own default values for
those that are missing.  You can use TIFFSetField on an image you have
loaded for reading, I think, I don't recall.

It seems that neither libtiff nor tiff2pdf are in error in this case, and
solving the problem for this case would be nonstandard and encumber
maintenance.

You could change the line in tiff2pdf.c to:

if(TIFFGetField(input, TIFFTAG_PHOTOMETRIC, &(t2p->tiff_photometric))==0){

	t2p->tiff_photometric = 0;  // or maybe 1

}

About the Indexed tag, that's absolutely correct, and also I think there
are broken images that set PhotometricInterpretation to RGB,
SamplesPerPixel to 1, and have a ColorMap.

Now, what would be really great is if you wrote a profile validator that
scanned TIFFs for these missing required fields, for all known profiles,
and gave it to libtiff.  That would be a wild beastie.

Ross F.


_______________________________________________
Tiff mailing list
Tiff@remotesensing.org
http://xserve.flids.com/mailman/listinfo/tiff
