AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
July 2007

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



2007.07.02 18:33 "Tag Extensions Refuse to Work", by Kevin Myers

Hi folks,

I've been trying for about 24 hours straight to get the dynamic tiff tag
extension mechanism to work properly, and it is driving me nuts.  I hope
that  maybe some of you who are more proficient C programmers than myself
can take a quick look at my code and jump straight to the solution.  Here is
the basic situation:

I'm working with tiffset.c from the tools directory in libtiff as a starting
point.
I am attempting to extend tiffset so that it can store new tags specified by
the user on the command line.

To accomplish this, I studied Defining Application Tags in addingtags.html,
and followed that documentation very closely.  I added the extended tag
initialization and callback methods to tiffset, and after a little bit of
experimentation that part mostly seems to work ok,  I added some printf
statements to the code so that I could see when these methods were being
called, and they seem to be called at appropriate times and with appropriate
values for both calling and return parameters.  The required additions and
modifications to tiffset.c for this purpose really weren't very extensive.

But what is now happening is this: If I try to set the value of built-in
tags, everything works as expected.  But if I try to set the value of an
extended tag, the TiffSetField method appears to execute ok.  But when you
look at the resulting file, the new tag has been added to the file, but the
data contained within the tag is garbage.  It looks like a pointer somewhere
is getting screwed up, but I am not a very experienced C programmer, and I
have limited tools at my disposal.  It is taking me forever to track down
this problem.

I have attached my modified tiffset.c source code, along with the console
output from some tests that I ran.  If somebody can help me figure out what
is going wrong, I would sure appreciate it.  BTW, I am working with libtiff
v3.8.2 under Windows XP, in case it matters.

One last thing:  For my purposes, it is not acceptable to add new built-in
tags.  I really need to get the dynamic tag support working.

Thanks,
Kevin M.


Microsoft (R) Program Maintenance Utility Version 8.00.50727.762
Copyright (C) Microsoft Corporation.  All rights reserved.

	cl /nologo /Ox /MD /EHsc /W3 -I..\libtiff -DAVOID_WIN32_FILEIO
	-DCHECK_JPEG_YCBCR_SUBSAMPLING -DDEFAULT_EXTRASAMPLE_AS_ALPHA
	-DSTRIPCHOP_DEFAULT=TIFF_STRIPCHOP -DSTRIP_SIZE_DEFAULT=8192
	-DPIXARLOG_SUPPORT -DZIP_SUPPORT -DJPEG_SUPPORT -DLOGLUV_SUPPORT
	-DNEXT_SUPPORT -DTHUNDER_SUPPORT -DLZW_SUPPORT -DPACKBITS_SUPPORT
	-DCCITT_SUPPORT -DTIF_PLATFORM_CONSOLE -DFILLODER_LSB2MSB  tiffset.c  
	C:\GnuWin32\lib/jpeg.lib C:\GnuWin32\lib/zlib.lib ..\port\libport.lib
	..\libtiff\libtiff.lib
tiffset.c


C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>del out.txt 
C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools\out.txt
The process cannot access the file because it is being used by another
process.

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>C:

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>cd
\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools 

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>rem c:\autoexec.bat 

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>rem nmake /f Makefile.vc
tiffset.exe 

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>rem Should produce "one" in
tag 305, and does - BACKWARDS (is this normal?) 

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>copy test0.tif test.tif 
        1 file(s) copied.

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif 
test.tif:
Magic: 0x4d4d <big-endian> Version: 0x2a
Directory 0: offset 8 (0x8) next 0 (0)
ImageWidth (256) LONG (4) 1<1888>
ImageLength (257) LONG (4) 1<73125>
BitsPerSample (258) SHORT (3) 1<1>
Compression (259) SHORT (3) 1<4>
Photometric (262) SHORT (3) 1<0>
FillOrder (266) SHORT (3) 1<1>
Make (271) ASCII (2) 9<XEROX   \0>
Model (272) ASCII (2) 17<7356            \0>
StripOffsets (273) LONG (4) 1<316>
SamplesPerPixel (277) SHORT (3) 1<1>
RowsPerStrip (278) LONG (4) 1<73125>
StripByteCounts (279) LONG (4) 1<1819148>
XResolution (282) RATIONAL (5) 1<200>
YResolution (283) RATIONAL (5) 1<200>
ResolutionUnit (296) SHORT (3) 1<2>
Software (305) ASCII (2) 36<AccXES Version 6.1.00C   ...>
DateTime (306) ASCII (2) 20<1999:12:07 19:32:49\0>

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffset -s 305 one test.tif 
_XTIFFInitialize
tifffile=test.tif
Before Text SetField
fip->field_tag:305
fip->field_readcount:-1
fip->field_writecount:-1
fip->field_type:2
fip->field_bit:65
fip->field_oktochange:1
fip->field_passcount:0
fip->field_name:Software
tag_value=one
After Text SetField
fip->field_tag:305
fip->field_readcount:-1
fip->field_writecount:-1
fip->field_type:2
fip->field_bit:65
fip->field_oktochange:1
fip->field_passcount:0
fip->field_name:Software
tag_value=one

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif 
test.tif:
Magic: 0x4d4d <big-endian> Version: 0x2a
Directory 0: offset 1819464 (0x1bc348) next 0 (0)
ImageWidth (256) SHORT (3) 1<1888>
ImageLength (257) LONG (4) 1<73125>
BitsPerSample (258) SHORT (3) 1<1>
Compression (259) SHORT (3) 1<4>
Photometric (262) SHORT (3) 1<0>
FillOrder (266) SHORT (3) 1<1>
Make (271) ASCII (2) 9<XEROX   \0>
Model (272) ASCII (2) 17<7356            \0>
StripOffsets (273) LONG (4) 1<316>
SamplesPerPixel (277) SHORT (3) 1<1>
RowsPerStrip (278) LONG (4) 1<73125>
StripByteCounts (279) LONG (4) 1<1819148>
XResolution (282) RATIONAL (5) 1<200>
YResolution (283) RATIONAL (5) 1<200>
PlanarConfig (284) SHORT (3) 1<1>
ResolutionUnit (296) SHORT (3) 1<2>
Software (305) ASCII (2) 4<\0eno>
DateTime (306) ASCII (2) 20<1999:12:07 19:32:49\0>

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>rem Should produce "two" in
tag 65000, and does NOT (tag created with garbage). 

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>copy test0.tif test.tif 
        1 file(s) copied.

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif 
test.tif:
Magic: 0x4d4d <big-endian> Version: 0x2a
Directory 0: offset 8 (0x8) next 0 (0)
ImageWidth (256) LONG (4) 1<1888>
ImageLength (257) LONG (4) 1<73125>
BitsPerSample (258) SHORT (3) 1<1>
Compression (259) SHORT (3) 1<4>
Photometric (262) SHORT (3) 1<0>
FillOrder (266) SHORT (3) 1<1>
Make (271) ASCII (2) 9<XEROX   \0>
Model (272) ASCII (2) 17<7356            \0>
StripOffsets (273) LONG (4) 1<316>
SamplesPerPixel (277) SHORT (3) 1<1>
RowsPerStrip (278) LONG (4) 1<73125>
StripByteCounts (279) LONG (4) 1<1819148>
XResolution (282) RATIONAL (5) 1<200>
YResolution (283) RATIONAL (5) 1<200>
ResolutionUnit (296) SHORT (3) 1<2>
Software (305) ASCII (2) 36<AccXES Version 6.1.00C   ...>
DateTime (306) ASCII (2) 20<1999:12:07 19:32:49\0>

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffset -s 65000 two
test.tif 
_XTIFFInitialize
tifffile=test.tif
Before Text SetField
fip->field_tag:65000
fip->field_readcount:-1
fip->field_writecount:-1
fip->field_type:2
fip->field_bit:65
fip->field_oktochange:1
fip->field_passcount:1
fip->field_name:Tag 65000
tag_value=two
After Text SetField
fip->field_tag:65000
fip->field_readcount:-1
fip->field_writecount:-1
fip->field_type:2
fip->field_bit:65
fip->field_oktochange:1
fip->field_passcount:1
fip->field_name:Tag 65000
tag_value=two

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif 
test.tif:
Magic: 0x4d4d <big-endian> Version: 0x2a
Directory 0: offset 1819464 (0x1bc348) next 0 (0)
ImageWidth (256) SHORT (3) 1<1888>
ImageLength (257) LONG (4) 1<73125>
BitsPerSample (258) SHORT (3) 1<1>
Compression (259) SHORT (3) 1<4>
Photometric (262) SHORT (3) 1<0>
FillOrder (266) SHORT (3) 1<1>
Make (271) ASCII (2) 9<XEROX   \0>
Model (272) ASCII (2) 17<7356            \0>
StripOffsets (273) LONG (4) 1<316>
SamplesPerPixel (277) SHORT (3) 1<1>
RowsPerStrip (278) LONG (4) 1<73125>
StripByteCounts (279) LONG (4) 1<1819148>
XResolution (282) RATIONAL (5) 1<200>
YResolution (283) RATIONAL (5) 1<200>
PlanarConfig (284) SHORT (3) 1<1>
ResolutionUnit (296) SHORT (3) 1<2>
Software (305) ASCII (2) 36<AccXES Version 6.1.00C   ...>
DateTime (306) ASCII (2) 20<1999:12:07 19:32:49\0>
65000 (0xfde8) ASCII (2) 14<tag_value=%s\n\0>

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>rem Should produce "three"
in tag 305, and does (ok). 

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>copy test0.tif test.tif 
        1 file(s) copied.

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>echo three 1>test.txt 

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif 
test.tif:
Magic: 0x4d4d <big-endian> Version: 0x2a
Directory 0: offset 8 (0x8) next 0 (0)
ImageWidth (256) LONG (4) 1<1888>
ImageLength (257) LONG (4) 1<73125>
BitsPerSample (258) SHORT (3) 1<1>
Compression (259) SHORT (3) 1<4>
Photometric (262) SHORT (3) 1<0>
FillOrder (266) SHORT (3) 1<1>
Make (271) ASCII (2) 9<XEROX   \0>
Model (272) ASCII (2) 17<7356            \0>
StripOffsets (273) LONG (4) 1<316>
SamplesPerPixel (277) SHORT (3) 1<1>
RowsPerStrip (278) LONG (4) 1<73125>
StripByteCounts (279) LONG (4) 1<1819148>
XResolution (282) RATIONAL (5) 1<200>
YResolution (283) RATIONAL (5) 1<200>
ResolutionUnit (296) SHORT (3) 1<2>
Software (305) ASCII (2) 36<AccXES Version 6.1.00C   ...>
DateTime (306) ASCII (2) 20<1999:12:07 19:32:49\0>

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffset -sf 305 test.txt
test.tif 
_XTIFFInitialize
tifffile=test.tif
Before File SetField
fip->field_tag:305
fip->field_readcount:-1
fip->field_writecount:-1
fip->field_type:2
fip->field_bit:65
fip->field_oktochange:1
fip->field_passcount:0
fip->field_name:Software
text=three

After File SetField
fip->field_tag:305
fip->field_readcount:-1
fip->field_writecount:-1
fip->field_type:2
fip->field_bit:65
fip->field_oktochange:1
fip->field_passcount:0
fip->field_name:Software
text=three


C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif 
test.tif:
Magic: 0x4d4d <big-endian> Version: 0x2a
Directory 0: offset 1819464 (0x1bc348) next 0 (0)
ImageWidth (256) SHORT (3) 1<1888>
ImageLength (257) LONG (4) 1<73125>
BitsPerSample (258) SHORT (3) 1<1>
Compression (259) SHORT (3) 1<4>
Photometric (262) SHORT (3) 1<0>
FillOrder (266) SHORT (3) 1<1>
Make (271) ASCII (2) 9<XEROX   \0>
Model (272) ASCII (2) 17<7356            \0>
StripOffsets (273) LONG (4) 1<316>
SamplesPerPixel (277) SHORT (3) 1<1>
RowsPerStrip (278) LONG (4) 1<73125>
StripByteCounts (279) LONG (4) 1<1819148>
XResolution (282) RATIONAL (5) 1<200>
YResolution (283) RATIONAL (5) 1<200>
PlanarConfig (284) SHORT (3) 1<1>
ResolutionUnit (296) SHORT (3) 1<2>
Software (305) ASCII (2) 7<three\n\0>
DateTime (306) ASCII (2) 20<1999:12:07 19:32:49\0>

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>rem Should produce "four" in
tag 65000, and does NOT (tag created with garbage). 

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>copy test0.tif test.tif 
        1 file(s) copied.

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>echo four 1>test.txt 

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif 
test.tif:
Magic: 0x4d4d <big-endian> Version: 0x2a
Directory 0: offset 8 (0x8) next 0 (0)
ImageWidth (256) LONG (4) 1<1888>
ImageLength (257) LONG (4) 1<73125>
BitsPerSample (258) SHORT (3) 1<1>
Compression (259) SHORT (3) 1<4>
Photometric (262) SHORT (3) 1<0>
FillOrder (266) SHORT (3) 1<1>
Make (271) ASCII (2) 9<XEROX   \0>
Model (272) ASCII (2) 17<7356            \0>
StripOffsets (273) LONG (4) 1<316>
SamplesPerPixel (277) SHORT (3) 1<1>
RowsPerStrip (278) LONG (4) 1<73125>
StripByteCounts (279) LONG (4) 1<1819148>
XResolution (282) RATIONAL (5) 1<200>
YResolution (283) RATIONAL (5) 1<200>
ResolutionUnit (296) SHORT (3) 1<2>
Software (305) ASCII (2) 36<AccXES Version 6.1.00C   ...>
DateTime (306) ASCII (2) 20<1999:12:07 19:32:49\0>

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffset -sf 65000 test.txt
test.tif 
_XTIFFInitialize
tifffile=test.tif
Before File SetField
fip->field_tag:65000
fip->field_readcount:-1
fip->field_writecount:-1
fip->field_type:2
fip->field_bit:65
fip->field_oktochange:1
fip->field_passcount:1
fip->field_name:Tag 65000
text=four

After File SetField
fip->field_tag:65000
fip->field_readcount:-1
fip->field_writecount:-1
fip->field_type:2
fip->field_bit:65
fip->field_oktochange:1
fip->field_passcount:1
fip->field_name:Tag 65000
text=four


C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif 
test.tif:
Magic: 0x4d4d <big-endian> Version: 0x2a
Directory 0: offset 1819464 (0x1bc348) next 0 (0)
ImageWidth (256) SHORT (3) 1<1888>
ImageLength (257) LONG (4) 1<73125>
BitsPerSample (258) SHORT (3) 1<1>
Compression (259) SHORT (3) 1<4>
Photometric (262) SHORT (3) 1<0>
FillOrder (266) SHORT (3) 1<1>
Make (271) ASCII (2) 9<XEROX   \0>
Model (272) ASCII (2) 17<7356            \0>
StripOffsets (273) LONG (4) 1<316>
SamplesPerPixel (277) SHORT (3) 1<1>
RowsPerStrip (278) LONG (4) 1<73125>
StripByteCounts (279) LONG (4) 1<1819148>
XResolution (282) RATIONAL (5) 1<200>
YResolution (283) RATIONAL (5) 1<200>
PlanarConfig (284) SHORT (3) 1<1>
ResolutionUnit (296) SHORT (3) 1<2>
Software (305) ASCII (2) 36<AccXES Version 6.1.00C   ...>
DateTime (306) ASCII (2) 20<1999:12:07 19:32:49\0>
65000 (0xfde8) ASCII (2) 9<text=%s\n\0>