- 2014.06.06 11:11 "Re: [Tiff] What's wrong with my code for adding custom tags to a file", by Stephen Morris
2014.06.08 17:40 "Re: [Tiff] What's wrong with my code for adding custom tags to a file", by Paul Heckbert
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 */
unsigned short field_bit; /* bit in fieldsset bit vector */
unsigned char field_oktochange; /* if true, can change while writing */
unsigned char 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 some kind) on the return value of all your libtiff calls, to help you detect where things are going wrong.
For examining TIFF and EXIF tags in files, I recommend exiftool, in particular “exiftool -htmldump”. Maybe you already know about it. See http://www.sno.phy.queensu.ca/~phil/exiftool
On 2014/6/6, at 7:11 AM, Stephen Morris <s-morris@n-eos.com> wrote:
Thank you Paul. I incorporated the TiffSetTagExtender call in the way that you showed (which helped me a lot to make sense of the documentation) to produce the code shown below. Sure enough, the access violation has gone away but I still don¹t get the custom tags in the file. As the routine runs, I get error messages in my console to the effect of:
TIFFSetField: TestImage.tif: Unknown tag 65000.
TIFFSetField: TestImage.tif: Unknown tag 65001.
TIFFSetField: TestImage.tif: Unknown tag 65002.
TIFFSetField: TestImage.tif: Unknown tag 65003.
TIFFSetField: TestImage.tif: Unknown tag 65004.
TIFFSetField: TestImage.tif: Unknown tag 65005.
Šso there¹s obviously something that I¹m still missing. Here¹s my new code:
#include "stdafx.h"
#include "PGM.h"#define TIFFTAG_INCIDENTPOWER 65000
#define TIFFTAG_REFLECTEDPOWER 65001
#define TIFFTAG_T1 65002
#define TIFFTAG_T2 65003
#define TIFFTAG_HUMIDITY 65004
#define TIFFTAG_EXPOSURE 65005static const TIFFFieldInfo xtiffFieldInfo[] = {
{ TIFFTAG_INCIDENTPOWER, -1, -1, TIFF_LONG, FIELD_CUSTOM, 0, 1,
const_cast<char*>("LaserIncidentPower") },
{ TIFFTAG_REFLECTEDPOWER, -1, -1, TIFF_LONG, FIELD_CUSTOM, 0, 1,
const_cast<char*>("LaserReflectedPower") },
>> }(