2010.12.24 16:28 "[Tiff] TIFFTAG_SMINSAMPLEVALUE and TIFFTAG_SMAXSAMPLEVALUE", by Olivier Paquet

2010.12.24 16:28 "[Tiff] TIFFTAG_SMINSAMPLEVALUE and TIFFTAG_SMAXSAMPLEVALUE", by Olivier Paquet


I brought up the issue back in September that these two tags could not be read/written with different per sample values by libtiff because the interface expects only a single value. I suggest you go read the discussion in the archive but the short of it is that a new interface would be needed if this is to be supported.

I've since had to come up with something for my own use which I'd like to submit for some review and comments. I'm attaching two patches. The first is against the 3.9 branch and is a fairly small change to allow libtiff to read files with different values for each sample. Internally, libtiff still stores only one value which is the min/max of what was read. There are no user visible changes and this only lets libtiff read files that it couldn't before. There is no access to the per sample values.

The second patch is against 4.0 and adds read/write support for multiple values. The internal representation has been changed to multiple values. Again, the API is maintained for the TIFFGetField by returning the min/max of all sample values. Access to the per sample values is possible through a pseudo tag which changes the behavior of TIFFSetField/TIFFGetField to handle the smin/smax tag as arrays. For example, with 3 floating point samples, one used to have:

float min_value = 0;

But it is now also possible to do:

float min_values[3] = { 0f, 0.2f, 0.3f };
TIFFSetField( m_TIFF, TIFFTAG_SMINSAMPLEVALUE, &min_values[0] );
/* Reset to default behavior, if needed. */

I decided against adding TIFFSetFieldSample/etc functions as in the
original discussion for a few reasons: