AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2014.04.21 14:54 "[Tiff] Correct use of TIFFGetField with FieldInfo", by Roger Leigh
2014.05.14 14:44 "Re: [Tiff] Correct use of TIFFGetField with FieldInfo", by Roger Leigh

2014.05.14 14:44 "Re: [Tiff] Correct use of TIFFGetField with FieldInfo", by Roger Leigh

On Mon, Apr 21, 2014 at 03:54:58PM +0100, Roger Leigh wrote:

Looking at the documentation, TIFFGetField appears to require calling TIFFFieldReadCount and TIFFFieldPassCount to determine which parameters need to be passed in the argument list.

However, taking TIFFTAG_BITSPERSAMPLE as an example, this has TIFFFieldReadCount == -1 (TIFF_VARIABLE) and TIFFFieldPassCount == 0. All the examples I've looked at in the source tree use a uint16 pointer directly to retrieve the value, but I'm not sure how this squares with a TIFF_VARIABLE read count. Why isn't the count 1? (I'm aware libtiff doesn't match the spec exactly for this tag, but why does it appear to be different from the implementated behaviour--is it possible to use this safely?)

Is it possible to safely call TIFF(Get|Set)Field using only the information available in FieldInfo, or are there any cases where this isn't correct and calling requires a priori knowledge of how the interface behaves?

I'm still running into additional examples of this. For example:

TIFFTAG_COMPRESSION
    readcount documented+specified to be 1
    dirinfo is: -1/TIFF_VARIABLE
    getfield is: 1
TIFFTAG_DATATYPE
    readcount documented to be 1
    dirinfo is: -2/TIFF_SPP
    getfield is: 1
TIFFTAG_(MIN|MAX)SAMPLEVALUE
    read/writecount documented to be 1
    dirinfo is TIFF_SPP/TIFF_VARIABLE resp.
    get/setfield is 1
TIFFTAG_SAMPLEFORMAT
    read/writecount documented to be 1
    dirinfo is: TIFF_VARIABLE
    get/setfield are: 1

By documented, I mean what's in the manpages, which doesn't necessarily match the TIFF spec. The default FieldInfo seems to mostly follow the spec, but when libtiff doesn't support e.g. multiple values for TIFF_SPP, it seems to leave the FieldInfo using TIFF_SPP/TIFF_VARIABLE while the actual interface for Get/SetField is using single values. Could anyone please confirm what the intended logic and usage are here? I'd like to be able to call TIFF[V]Get/SetField safely based upon the content of the FieldInfo for the tag in use, but this doesn't appear to be possible due to these discrepancies, which are leading me to hardcode behaviour. But this seems very fragile: if the libtiff internal behaviour changes to match the FieldInfo data at some point, my code will start crashing.

Regards,

Roger

--
  .''`. Roger Leigh

 : :' :  Debian GNU/Linux    http://people.debian.org/~rleigh/
 `. `'   schroot and sbuild  http://alioth.debian.org/projects/buildd-tools

`- GPG Public Key F33D 281D 470A B443 6756 147C 07B3 C8BC 4083 E800