1998.06.10 15:00 "TIFFGetField syntax and use", by Steve Garcia

1998.06.10 17:04 "RE: TIFFGetField syntax and use", by Bill Davis

try this:

#include <tiffio.h>
int photo, bitspersample;

Change the line above to:

  short photo, bitspersample;

 main ()
{
        TIFF *tif = TIFFOpen("myfile.tif", "r");
        TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photo);

Note the change to add the & on the variable. You are passing an address and it is important to pass the address of something that is the proper size. An int and short will not be the same size on every compiler. A 16 bit compiler usually has int=16 and short=16 but a 32 bit compiler usually has int=32 and short=16. Pointing at an int will work if:

  1. the int has been initialized to zero
  2. the value being read is not negative
  3. the byte order on the machine is the right one to have a pointer to an int point at the low order two bytes of the int so it is also a pointer to a short

So, don't use an int where a short is called for by the spec. The spec I referenced said short. Someone correct me if that has changed.

Bill Davis