2010.03.22 01:34 "[Tiff] Problems with Modified tiffset", by Kevin Myers

2010.03.22 01:34 "[Tiff] Problems with Modified tiffset", by Kevin Myers

I've already sent this to a couple of my acquaintances on this list, but thought I might as well run it past everyone in case someone else can spot the problem right away...

I have attempted to modify the tiffset program to allow it to set the value of user defined (custom) tags. I could have sworn that I had this working some time ago, but now it definitely isn't working, and I'm not sure if it is due to a bug in libtiff, or (more likely) some kind of problem in my own code. The modifications that I made are relatively simple, and make use of the so-called "tag extender" feature of libtiff, which is documented under the "Defining Application Tags" section on this web page:


I have attached my modified version of tiffset.c for tiff 3.9.2. Since I'm sure that many of you are much stronger C programmers than I am, I doubt that you will have any problems compiling this. My own approach was to temporarily replace the standard version of tiffset.c in the tools directory, delete or rename any previously generated tiffset.exe in the tools output folder if you have one, and go from there. From the tools folder, I simply used nmake /f makefile.vc under Windows XP using VC from Visual Studio 2008 Express.

After successfully compiling the program, here is what happens:

If I use my modified tiffset to set the value of a standard tiff tag, say ImageDescription (tag number 270, ASCII text), everything works fine. Here is how I would do that (assume test.tif is an existing tiff file):

tiffset -s 270 MyValue test.tif
tiffset -s ImageDescription NewValue test.tif

You can use tiffinfo to verify that the ImageDescription tag value is set correctly.

On the other hand, when I use the following command:

tiffset -s 65000 MyValue test.tif

Everything *appears* to proceed normally. But when I run tiffinfo, I find that tag 65000 did get set to *something*, but not what it was supposed to be. It seems to be getting set to some bytes from elsewhere in memory. Looks like some kind of pointer related problem...

Internally, tiffset is using the TIFFSetField function from libtiff to set the tag value. My modified tiffset currently includes a printf statement to print the values of the arguments to TIFFSetField immediately prior to the call, and everything *seems* to be ok at that point. The correct, anticipated values are printed at this point for both standard and user-defined tag cases. But somewhere within the execution of TIFFSetField, things are getting screwed up for the user-defined tag case, and I can't figure out why/where. The code used in TIFFSetField is somewhat beyond my level of C expertise, and it would take me forever to track down where the correct value is getting lost. Hopefully someone else out there may be able to track down this problem a lot more quickly. Any takers?

I'm trying to finish up a critical project with immediately pending deadlines. A small but critical portion of that project requires programmatically adding metadata to tiff images via custom tag values, and this problem currently has my progress ground to a complete standstill.

Kevin M.