2014.06.05 11:31 "[Tiff] What's wrong with my code for adding custom tags to a file", by Stephen Morris

2014.06.09 09:59 "Re: [Tiff] What's wrong with my code for adding custom tags to a file", by Stephen Morris

Thank you Paul.

This is working now; your suggestion of changing the format of the TIFFFieldInfo declarations was the key to it. Thank you very much.

Besides that I did, however, need to revert to my original version of the code and call TIFFMergeFieldInfo directly rather than via TIFFSetTagExtender. If I did the latter, then the TIFFMergeFieldInfo line was never called. This is when writing files, remember: the behaviour may be different when reading files, which is the next thing I’ll be moving on to…

Also, regarding viewing the generated TIFF file to verify the presence of tags, I used AsTiffTagViewer (http://www.awaresystems.be/imaging/tiff/astifftagviewer.html) which works quite nicely, though it would only output the hex values for my floating-point fields so I had to use the useful IEEE 754 converter at http://www.h-schmidt.net/FloatConverter/IEEE754.html to verify them.

I now need to move on to reading my custom tags back in again; once I’ve done that then I will post my complete code to this list for other people’s reference.

Cc: Paul Heckbert <ph@cs.cmu.edu>, "tiff@lists.maptools.org" <tiff@lists.maptools.org>

Subject: Re: [Tiff] What's wrong with my code for adding custom tags to a file

Since the lilbtiff documentation is weak, I found it necessary to read the source code to figure a lot of this out. See the comment in my code about pass_count. And in my code, the difference in how GetField is called between the tag with pass_count=1 and the one where pass_count=0.

I think I see your problem. You have

static const TIFFFieldInfo xtiffFieldInfo[] = {

{ TIFFTAG_INCIDENTPOWER, -1, -1, TIFF_LONG, FIELD_CUSTOM, 0, 1,

and looking at libtiff’s libtiff/tiffio.h, we see that these structure elements are

  ttag_t  field_tag;    /* field's tag */

short field_readcount; /* read count/TIFF_VARIABLE/TIFF_SPP */
short field_writecount; /* write count/TIFF_VARIABLE */
TIFFDataType field_type; /* type of associated data */
      unsignedshort field_bit; /* bit in fieldsset bit vector */
unsignedchar field_oktochange; /* if true, can change while writing */
unsignedchar field_passcount; /* if true, pass dir count on set */

  char  *field_name;    /* ASCII name */

A readcount or writecount of -1 means TIFF_VARIABLE (a variable number of values) but it appears that you have a constant number (1) of values for LaserIncidentPower, not a variable number. And since there is a constant number of them, it will be unnecessary to pass a count, so passcount should be 0, not 1.

So try

static const TIFFFieldInfo xtiffFieldInfo[] = {

{ TIFFTAG_INCIDENTPOWER,  1, 1, TIFF_LONG,  FIELD_CUSTOM, 0, 0,

On 2014/6/7, at 2:15 AM, Paul Heckbert <ph@cs.cmu.edu> wrote:

You might want to put asserts (or tests of