2016.11.18 14:18 "[Tiff] Generic use of TIFFSetField", by Paavo Helde

I'm now in a fresh attempt to use LibTIFF for TIFF file writing, mainly because I do not want to tweak with BigTIFF bit twiddling and create new obscure bugs. My task is to interface a scripting language layer, it sends in a table with TIFF tags and data and I need to produce a compliant TIFF file. Some tags like image width and bit depth I can set easily, based on the properties of the incoming image, but the script layer can send in also any other tags. In the previous "manual" implementation it was easy, if the script sent in e.g. a 3-element vector of int16 type for a tag, then I created a corresponding TIFF IFD entry and stored the info there. However, in LibTIFF I do not find such a function, there is TIFFSetField() which takes ellipsis arguments, but as far as I can see there is no way to tell it that I am sending a 3-element array of int16, for example.

OK, I tried to do this in a harder way. I found the functions TIFFFieldWithTag(), TIFFFieldDataType() and TIFFFieldWriteCount() which ought to tell me the expected type and count of the data to be passed into the ellipsis. But it appears it's not so simple, for example for TIFFTAG_SMAXSAMPLEVALUE it reports me TIFF_ANY and TIFF_VARIABLE. On the other hand, the TIFFSetField() man page says that for TIFFTAG_SMAXSAMPLEVALUE I have to pass a single double. How do I translate TIFF_ANY and TIFF_VARIABLE into a single double? And what if I want to follow the TIFF standard and store N=SamplesPerPixel values instead of a single value?

Should I just copy the TIFFSetField man page and make a huge switch statement from it?

TIA,

Paavo