2004.08.19 12:15 "[Tiff] Tiff conversion using libTiff", by Ionita Alexandru

2004.08.20 16:37 "Re: [Tiff] Tiff conversion using libTiff", by Ross A. Finlayson

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.