2006.01.09 08:28 "[Tiff] Multipage 16bit TIFF in Delphi", by Andreas Christ

2006.01.09 11:10 "Re: [Tiff] Multipage 16bit TIFF in Delphi", by Joris Van Damme


I have multipage Tiffs with 16 Bit per sample, which I want to read, to manipulate and to save again.I tried it with the example LibTiffDelphiHigherLevel from Joris (February 2005), but the result is only a black image.

I've received your code and testfile.

What you have here, is a problem. You're seeing a black image, because, strictly speaking, it is a black image. Double-check with Photoshop, Irfanview, or any mainstream viewer if you like.

Of course, I suspected that merely showing how dark exactly black is and wasting 37 meg to do so, was not the file writer's intention. So I took a look at the tags. Here's a tag dump for the first IFD:

ImageWidth (1 Short): 1024
ImageLength (1 Short): 500
BitsPerSample (1 Short): 16
Compression (1 Short): Uncompressed
Photometric (1 Short): MinIsBlack

StripOffsets (500 Long): 8, 2056, 4104, 6152, 8200, 10248, 12296,... Orientation (1 Short): TopLeft

SamplesPerPixel (1 Short): 1
RowsPerStrip (1 Short): 1

StripByteCounts (500 Long): 2048, 2048, 2048, 2048, 2048, 2048, 2048,... MinSampleValue (1 Short): 0

MaxSampleValue (1 Short): 1555
PlanarConfig (1 Short): Contig
PageNumber (2 Short): 0, 36
SampleFormat (1 Short): 1

Note the MaxSampleValue tag. The writer obviously (more or less incorrectly) assumed that these SampleValue tags serve in defining the value range.

(This is more or less incorrect, in that these tags are not meant to influence interchangeable rendering. A better option, at least as far as interchange is concerned, would have been for the writer to rescale the value range it obviously uses internally to the full 16bit range of 0 to 65535 before writing. It may however make perfect sense in a less interchangeable, more private use of TIFF though, in some applications, for instance if most meaningfull content is in the range 0-1555 but rare exceptions of higher range are possible and must not be lost in storage. So it's not strictly speaking a bug or incorrect use of TIFF... but then the sensible consequence is of course that the image is mostly black, interpreted in the interchangeable sense.)

All this means that, your black rendering is correct in the interchangeable sense. But if you want to render more like is probably the intention, you'll have to rescale values. Rescaling after a first scaling from 16bit to 8bit will mean that most shading information is lost in your case, so making use of the RGBA interface is no good option. Therefore, you'll have to read original 16bit values with the TIFFReadEncodedStrip interface. For more information on that, see http://www.remotesensing.org/libtiff/libtiff.html#strips, and of course

http://www.remotesensing.org/libtiff/man/index.html. If you've any specific problems along this road, pop the questions.

Joris Van Damme
Download your free TIFF tag viewer for windows here: