Return-Path: <tiff-bounces@lists.maptools.org>
Received: from mailgate003.isp.belgacom.be (mailgate003.isp.belgacom.be [195.238.6.88])
        by inmx009.isp.belgacom.be (8.12.11.20060308/8.12.11/Skynet-IN-2.32) with ESMTP id l62IqnCp014800
        for <joris.at.lebbeke@skynet.be>; Mon, 2 Jul 2007 20:52:51 +0200
        (envelope-from <tiff-bounces@lists.maptools.org>)
Received: from r153.dmsolutions.ca (HELO duke.maptools.org) ([209.217.116.153])
  by in.mx.skynet.be with ESMTP; 02 Jul 2007 20:52:50 +0200
Received: from duke.maptools.org (duke.maptools.org [127.0.0.1])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id l62IXfD7003775;
	Mon, 2 Jul 2007 14:33:55 -0400
Received: from mail816.megamailservers.com
	(mail816.carrierinternetsolutions.com [69.49.106.26])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id l62IXcuV003772
	for <tiff@lists.maptools.org>; Mon, 2 Jul 2007 14:33:38 -0400
X-Authenticated-User: kmyers1.clearwire.net
Received: from gateway (mobile-166-217-107-122.mycingular.net
	[166.217.107.122]) (authenticated bits=0)
	by mail816.megamailservers.com (8.13.6.20060614/8.13.1) with ESMTP id
	l62IXV7u012447
	for <tiff@lists.maptools.org>; Mon, 2 Jul 2007 14:33:34 -0400
Message-ID: <07bd01c7bcd7$7c907160$7a6bd9a6@gateway>
From: "Kevin Myers" <kmyers1@clearwire.net>
To: <tiff@lists.maptools.org>
Date: Mon, 2 Jul 2007 13:33:25 -0500
MIME-Version: 1.0
Content-Type: multipart/mixed;
	boundary="----=_NextPart_000_07B9_01C7BCAD.91107F10"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.3138
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
Subject: [Tiff] Tag Extensions Refuse to Work
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.4
Precedence: list
List-Id: TIFF and libtiff discussion <tiff.lists.maptools.org>
List-Unsubscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=unsubscribe>
List-Archive: <http://lists.maptools.org/mailman/private/tiff>
List-Post: <mailto:tiff@lists.maptools.org>
List-Help: <mailto:tiff-request@lists.maptools.org?subject=help>
List-Subscribe: <http://lists.maptools.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@lists.maptools.org?subject=subscribe>
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org
X-UIDL: 000000000023ceae.000024e4
X-MSP-STORE: Mon, 02 Jul 2007 20:52:55 +0200
Status:   

This is a multi-part message in MIME format.

------=_NextPart_000_07B9_01C7BCAD.91107F10
Content-Type: multipart/alternative;
	boundary="----=_NextPart_001_07BA_01C7BCAD.91107F10"


------=_NextPart_001_07BA_01C7BCAD.91107F10
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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.


------=_NextPart_001_07BA_01C7BCAD.91107F10
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.3132" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi folks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I've been trying for about 24 hours =
straight to get=20
the dynamic tiff tag extension mechanism to work properly, and it is =
driving me=20
nuts.&nbsp; I hope that&nbsp; maybe some of you who are more proficient =
C=20
programmers than myself can take a quick look at my code and jump =
straight to=20
the solution.&nbsp; Here is the basic situation:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I'm working with tiffset.c from the =
tools directory=20
in libtiff as a starting point.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I am attempting to extend tiffset so =
that it can=20
store new tags specified by the user on the command line.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>To accomplish this, I =
studied&nbsp;Defining=20
Application Tags&nbsp;in addingtags.html, and followed that =
documentation very=20
closely.&nbsp; I added&nbsp;the extended tag initialization and callback =
methods=20
to tiffset, and after a little bit of experimentation that part mostly =
seems to=20
work ok,&nbsp; I added some printf statements to the code so that I =
could see=20
when these methods were being called, and they seem to be called at =
appropriate=20
times and with appropriate values for both calling and return =
parameters.&nbsp;=20
The required additions and modifications to tiffset.c for this purpose =
really=20
weren't&nbsp;very extensive.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>But what is now happening is this: If I =
try to set=20
the value of built-in tags, everything works as expected.&nbsp; But if I =
try to=20
set the value of an extended tag, the TiffSetField method&nbsp;appears =
to=20
execute ok.&nbsp; But when you look at the resulting file, the new tag =
has been=20
added to the file, but the data contained within the tag is =
garbage.&nbsp; It=20
looks like a pointer somewhere is getting screwed up, but I am not a =
very=20
experienced C programmer, and I have limited tools at my disposal.&nbsp; =
It is=20
taking me forever&nbsp;to track down this problem.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>I have attached my modified tiffset.c =
source code,=20
along with the console output from some tests that I ran.&nbsp; If =
somebody can=20
help me figure out what is going wrong, I would sure appreciate =
it.&nbsp; BTW, I=20
am working with libtiff v3.8.2 under Windows XP, in case it=20
matters.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>One last thing:&nbsp; For my purposes, =
it is not=20
acceptable to add new built-in tags.&nbsp; I really need to get the =
dynamic tag=20
support working.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Kevin M.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_001_07BA_01C7BCAD.91107F10--

------=_NextPart_000_07B9_01C7BCAD.91107F10
Content-Type: text/plain;
	name="make.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="make.txt"


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=3DTIFF_STRIPCHOP -DSTRIP_SIZE_DEFAULT=3D8192 =
-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

------=_NextPart_000_07B9_01C7BCAD.91107F10
Content-Type: text/plain;
	name="out.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="out.txt"


C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>del out.txt=20
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=20

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

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

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?)=20

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

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif=20
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=20
_XTIFFInitialize
tifffile=3Dtest.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=3Done
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=3Done

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif=20
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).=20

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

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif=20
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=20
_XTIFFInitialize
tifffile=3Dtest.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=3Dtwo
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=3Dtwo

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif=20
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=3D%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).=20

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

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

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif=20
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=20
_XTIFFInitialize
tifffile=3Dtest.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=3Dthree

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=3Dthree


C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif=20
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).=20

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

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

C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif=20
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=20
_XTIFFInitialize
tifffile=3Dtest.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=3Dfour

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=3Dfour


C:\GnuWin32\src\tiff\3.8.2\tiff-3.8.2-src\tools>tiffdump test.tif=20
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=3D%s\n\0>

------=_NextPart_000_07B9_01C7BCAD.91107F10
Content-Type: application/octet-stream;
	name="test.bat"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="test.bat"

del out.txt

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

rem c:\autoexec.bat
rem nmake /f Makefile.vc tiffset.exe

rem Should produce "one" in tag 305, and does - BACKWARDS (is this =
normal?)
copy test0.tif test.tif
tiffdump test.tif
tiffset -s 305 one test.tif
tiffdump test.tif

rem Should produce "two" in tag 65000, and does NOT (tag created with =
garbage).
copy test0.tif test.tif
tiffdump test.tif
tiffset -s 65000 two test.tif
tiffdump test.tif

rem Should produce "three" in tag 305, and does (ok).
copy test0.tif test.tif
echo three>test.txt
tiffdump test.tif
tiffset -sf 305 test.txt test.tif
tiffdump test.tif

rem Should produce "four" in tag 65000, and does NOT (tag created with =
garbage).
copy test0.tif test.tif
echo four>test.txt
tiffdump test.tif
tiffset -sf 65000 test.txt test.tif
tiffdump test.tif




------=_NextPart_000_07B9_01C7BCAD.91107F10
Content-Type: text/plain;
	name="tiffset.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="tiffset.c"

/************************************************************************=
******=0A=
 * $Id: tiffset.c,v 1.11 2005/09/13 14:13:42 dron Exp $=0A=
 *=0A=
 * Project:  libtiff tools=0A=
 * Purpose:  Mainline for setting metadata in existing TIFF files.=0A=
 * Author:   Frank Warmerdam, warmerdam@pobox.com=0A=
 *=0A=
 =
*************************************************************************=
*****=0A=
 * Copyright (c) 2000, Frank Warmerdam=0A=
 *=0A=
 * Permission to use, copy, modify, distribute, and sell this software =
and =0A=
 * its documentation for any purpose is hereby granted without fee, =
provided=0A=
 * that (i) the above copyright notices and this permission notice =
appear in=0A=
 * all copies of the software and related documentation, and (ii) the =
names of=0A=
 * Sam Leffler and Silicon Graphics may not be used in any advertising or=0A=
 * publicity relating to the software without the specific, prior written=0A=
 * permission of Sam Leffler and Silicon Graphics.=0A=
 * =0A=
 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, =0A=
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY =0A=
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  =0A=
 * =0A=
 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR=0A=
 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY =
KIND,=0A=
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,=0A=
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY =
THEORY OF =0A=
 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR =
PERFORMANCE =0A=
 * OF THIS SOFTWARE.=0A=
 =
*************************************************************************=
*****=0A=
 *=0A=
 * $Log: tiffset.c,v $=0A=
 * Revision 1.11  2005/09/13 14:13:42  dron=0A=
 * Avoid warnings.=0A=
 *=0A=
 * Revision 1.10  2005/02/24 14:47:11  fwarmerdam=0A=
 * Updated header.=0A=
 *=0A=
 */=0A=
=0A=
=0A=
#include "tif_config.h"=0A=
=0A=
#include <stdio.h>=0A=
#include <string.h>=0A=
#include <stdlib.h>=0A=
=0A=
#include "tiffio.h"=0A=
=0A=
#define	TRUE	1=0A=
#define	FALSE	0=0A=
=0A=
#define TIFFTAG_CUSTOM 65535=0A=
=0A=
static char* usageMsg[] =3D {=0A=
"usage: tiffset [options] tiff-filename",=0A=
"where options are:",=0A=
" -s <tagname> [count] <value>...   set the tag value",=0A=
" -sf <tagname> <tag data filename>  read the tag value from file (for =
ASCII tags only)",=0A=
NULL=0A=
};=0A=
=0A=
TIFFDataType			user_field_type =3D 0;		/* user specified TIFF tag data =
type */=0A=
ttag_t					user_tag =3D 0;				/* user specified TIFF tag Id */=0A=
static TIFFExtendProc	_ParentExtender =3D NULL;		/* parent tag extender =
proc */=0A=
=0A=
static TIFFFieldInfo	xtiffFieldInfo[] =3D {=0A=
    { TIFFTAG_CUSTOM,	TIFF_VARIABLE,	TIFF_VARIABLE,	TIFF_ASCII,	=
FIELD_CUSTOM,	TRUE,	TRUE,	"Custom 65535" }=0A=
};=0A=
=0A=
=0A=
=0A=
static void=0A=
usage(void)=0A=
{=0A=
	int i;=0A=
	for (i =3D 0; usageMsg[i]; i++)=0A=
		fprintf(stderr, "%s\n", usageMsg[i]);=0A=
	exit(-1);=0A=
}=0A=
=0A=
=0A=
/* KAM - tag type extender callback */=0A=
static void=0A=
_XTIFFDefaultDirectory(TIFF *tif)=0A=
{=0A=
=0A=
	/* update our extended tag field info */=0A=
	xtiffFieldInfo[0].field_tag =3D user_tag;=0A=
//	xtiffFieldInfo[0].field_type =3D user_field_type;=0A=
	sprintf(xtiffFieldInfo[0].field_name, "Tag %d", (int) user_tag);=0A=
=0A=
	/* Install the extended Tag field info */=0A=
	/* Normally xtiffFieldInfo is a list of TIFFFieldInfo structures */=0A=
	/* but since we only have one, the memory location is identical  */=0A=
    TIFFMergeFieldInfo(tif, xtiffFieldInfo, 1);=0A=
=0A=
    /* Since an XTIFF client module may have overridden=0A=
     * the default directory method, we call it now to=0A=
     * allow it to set up the rest of its own methods.=0A=
     */=0A=
=0A=
    if (_ParentExtender) =0A=
        (*_ParentExtender)(tif);=0A=
}=0A=
=0A=
=0A=
/* KAM - initialize tag type extender */=0A=
static=0A=
void _XTIFFInitialize(void)=0A=
{=0A=
    static int first_time=3D1;=0A=
	printf("_XTIFFInitialize\n");=0A=
	=0A=
    if (! first_time) return; /* Been there. Done that. */=0A=
    first_time =3D 0;=0A=
	=0A=
    /* Grab the inherited method and install */=0A=
    _ParentExtender =3D TIFFSetTagExtender(_XTIFFDefaultDirectory);=0A=
}=0A=
=0A=
=0A=
static const TIFFFieldInfo *=0A=
GetField(TIFF *tiff, const char *tagname)=0A=
{=0A=
    const TIFFFieldInfo *fip;=0A=
=0A=
	if( user_tag > 0 )=0A=
		fip =3D TIFFFieldWithTag(tiff, user_tag);=0A=
	else=0A=
		fip =3D TIFFFieldWithName(tiff, tagname);=0A=
=0A=
	if (!fip) {=0A=
		fprintf( stderr, "Field name %s not recognized.\n", tagname );=0A=
        return (TIFFFieldInfo *)NULL;=0A=
    }=0A=
=0A=
    return fip;=0A=
}=0A=
=0A=
=0A=
int=0A=
main(int argc, char* argv[])=0A=
{=0A=
    TIFF *tiff;=0A=
    int  arg_index;=0A=
	char* tifffile;=0A=
	const char *tagname;=0A=
	char* tag_value;=0A=
=0A=
	/* initialize tag extender */=0A=
	_XTIFFInitialize();=0A=
=0A=
	/* at least 2 arguments are always required (really more) */=0A=
	if (argc < 2)=0A=
        usage();=0A=
=0A=
	/* target file is always last argument */=0A=
//	tiff =3D TIFFOpen(argv[argc-1], "r+");=0A=
	tifffile =3D argv[argc-1];=0A=
	printf("tifffile=3D%s\n",tifffile);=0A=
=0A=
    for( arg_index =3D 1; arg_index < argc-1; arg_index++ ) {=0A=
        if (strcmp(argv[arg_index],"-s") =3D=3D 0 && arg_index < argc-3) =
{=0A=
            const TIFFFieldInfo *fip;=0A=
=0A=
            arg_index++;=0A=
            tagname =3D argv[arg_index];=0A=
			user_tag =3D (ttag_t)atoi(tagname);=0A=
			tiff =3D TIFFOpen(tifffile, "r+");=0A=
            fip =3D GetField(tiff, tagname);=0A=
=0A=
			if (!fip)=0A=
                return 3;=0A=
=0A=
            arg_index++;=0A=
			tag_value=3Dargv[arg_index];=0A=
			if (fip->field_type =3D=3D TIFF_ASCII) {=0A=
=0A=
				printf("Before Text SetField\n");=0A=
				printf("fip->field_tag:%d\n",fip->field_tag);=0A=
				printf("fip->field_readcount:%d\n",fip->field_readcount);=0A=
				printf("fip->field_writecount:%d\n",fip->field_writecount);=0A=
				printf("fip->field_type:%d\n",fip->field_type);=0A=
				printf("fip->field_bit:%d\n",fip->field_bit);=0A=
				printf("fip->field_oktochange:%d\n",fip->field_oktochange);=0A=
				printf("fip->field_passcount:%d\n",fip->field_passcount);=0A=
				printf("fip->field_name:%s\n",fip->field_name);=0A=
				printf("tag_value=3D%s\n",tag_value);=0A=
=0A=
				if (TIFFSetField(tiff, fip->field_tag, tag_value) !=3D 1)=0A=
                    fprintf( stderr, "Failed to set %s=3D%s\n",=0A=
                             fip->field_name, argv[arg_index] );=0A=
=0A=
				printf("After Text SetField\n");=0A=
				printf("fip->field_tag:%d\n",fip->field_tag);=0A=
				printf("fip->field_readcount:%d\n",fip->field_readcount);=0A=
				printf("fip->field_writecount:%d\n",fip->field_writecount);=0A=
				printf("fip->field_type:%d\n",fip->field_type);=0A=
				printf("fip->field_bit:%d\n",fip->field_bit);=0A=
				printf("fip->field_oktochange:%d\n",fip->field_oktochange);=0A=
				printf("fip->field_passcount:%d\n",fip->field_passcount);=0A=
				printf("fip->field_name:%s\n",fip->field_name);=0A=
				printf("tag_value=3D%s\n",tag_value);=0A=
=0A=
            } else if (fip->field_writecount > 0) {=0A=
                int     ret =3D 1;=0A=
                short   wc;=0A=
=0A=
                if (fip->field_writecount =3D=3D TIFF_VARIABLE)=0A=
                        wc =3D atoi(argv[arg_index++]);=0A=
                else=0A=
                        wc =3D fip->field_writecount;=0A=
=0A=
                if (argc - arg_index < wc) {=0A=
                    fprintf( stderr,=0A=
                             "Number of tag values is not enough. "=0A=
                             "Expected %d values for %s tag, got %d\n",=0A=
                             wc, fip->field_name, argc - arg_index);=0A=
                    return 4;=0A=
                }=0A=
                    =0A=
                if (wc > 1) {=0A=
                        int     i, size;=0A=
                        void    *array;=0A=
=0A=
                        switch (fip->field_type) {=0A=
                                /*=0A=
                                 * XXX: We can't use TIFFDataWidth()=0A=
                                 * to determine the space needed to store=0A=
                                 * the value. For TIFF_RATIONAL values=0A=
                                 * TIFFDataWidth() returns 8, but we use =
4-byte=0A=
                                 * float to represent rationals.=0A=
                                 */=0A=
                                case TIFF_BYTE:=0A=
                                case TIFF_ASCII:=0A=
                                case TIFF_SBYTE:=0A=
                                case TIFF_UNDEFINED:=0A=
				default:=0A=
                                    size =3D 1;=0A=
                                    break;=0A=
=0A=
                                case TIFF_SHORT:=0A=
                                case TIFF_SSHORT:=0A=
                                    size =3D 2;=0A=
                                    break;=0A=
=0A=
                                case TIFF_LONG:=0A=
                                case TIFF_SLONG:=0A=
                                case TIFF_FLOAT:=0A=
                                case TIFF_IFD:=0A=
                                case TIFF_RATIONAL:=0A=
                                case TIFF_SRATIONAL:=0A=
                                    size =3D 4;=0A=
                                    break;=0A=
=0A=
                                case TIFF_DOUBLE:=0A=
                                    size =3D 8;=0A=
                                    break;=0A=
                        }=0A=
=0A=
                        array =3D _TIFFmalloc(wc * size);=0A=
                        if (!array) {=0A=
                                fprintf(stderr, "No space for %s tag\n",=0A=
                                        tagname);=0A=
                                return 4;=0A=
                        }=0A=
=0A=
                        switch (fip->field_type) {=0A=
                            case TIFF_BYTE:=0A=
                                for (i =3D 0; i < wc; i++)=0A=
                                    ((uint8 *)array)[i] =3D =
atoi(argv[arg_index+i]);=0A=
                                break;=0A=
                            case TIFF_SHORT:=0A=
                                for (i =3D 0; i < wc; i++)=0A=
                                    ((uint16 *)array)[i] =3D =
atoi(argv[arg_index+i]);=0A=
                                break;=0A=
                            case TIFF_SBYTE:=0A=
                                for (i =3D 0; i < wc; i++)=0A=
                                    ((int8 *)array)[i] =3D =
atoi(argv[arg_index+i]);=0A=
                                break;=0A=
                            case TIFF_SSHORT:=0A=
                                for (i =3D 0; i < wc; i++)=0A=
                                    ((int16 *)array)[i] =3D =
atoi(argv[arg_index+i]);=0A=
                                break;=0A=
                            case TIFF_LONG:=0A=
                                for (i =3D 0; i < wc; i++)=0A=
                                    ((uint32 *)array)[i] =3D =
atol(argv[arg_index+i]);=0A=
                                break;=0A=
                            case TIFF_SLONG:=0A=
                            case TIFF_IFD:=0A=
                                for (i =3D 0; i < wc; i++)=0A=
                                    ((uint32 *)array)[i] =3D =
atol(argv[arg_index+i]);=0A=
                                break;=0A=
                            case TIFF_DOUBLE:=0A=
                                for (i =3D 0; i < wc; i++)=0A=
                                    ((double *)array)[i] =3D =
atof(argv[arg_index+i]);=0A=
                                break;=0A=
                            case TIFF_RATIONAL:=0A=
                            case TIFF_SRATIONAL:=0A=
                            case TIFF_FLOAT:=0A=
                                for (i =3D 0; i < wc; i++)=0A=
                                    ((float *)array)[i] =3D =
(float)atof(argv[arg_index+i]);=0A=
                                break;=0A=
                            default:=0A=
                                break;=0A=
                        }=0A=
                =0A=
                        if (fip->field_passcount) {=0A=
                                ret =3D TIFFSetField(tiff, =
fip->field_tag,=0A=
                                                   wc, array);=0A=
                        } else {=0A=
                                ret =3D TIFFSetField(tiff, =
fip->field_tag,=0A=
                                                   array);=0A=
                        }=0A=
=0A=
                        _TIFFfree(array);=0A=
                } else {=0A=
                        switch (fip->field_type) {=0A=
                            case TIFF_BYTE:=0A=
                            case TIFF_SHORT:=0A=
                            case TIFF_SBYTE:=0A=
                            case TIFF_SSHORT:=0A=
                                ret =3D TIFFSetField(tiff, =
fip->field_tag,=0A=
                                                   =
atoi(argv[arg_index++]));=0A=
                                break;=0A=
                            case TIFF_LONG:=0A=
                            case TIFF_SLONG:=0A=
                            case TIFF_IFD:=0A=
                                ret =3D TIFFSetField(tiff, =
fip->field_tag,=0A=
                                                   =
atol(argv[arg_index++]));=0A=
                                break;=0A=
                            case TIFF_DOUBLE:=0A=
                                ret =3D TIFFSetField(tiff, =
fip->field_tag,=0A=
                                                   =
atof(argv[arg_index++]));=0A=
                                break;=0A=
                            case TIFF_RATIONAL:=0A=
                            case TIFF_SRATIONAL:=0A=
                            case TIFF_FLOAT:=0A=
                                ret =3D TIFFSetField(tiff, =
fip->field_tag,=0A=
                                                   =
(float)atof(argv[arg_index++]));=0A=
                                break;=0A=
                            default:=0A=
                                break;=0A=
                        }=0A=
                }=0A=
=0A=
                if (ret !=3D 1)=0A=
                    fprintf(stderr, "Failed to set %s\n", =
fip->field_name);=0A=
                arg_index +=3D wc;=0A=
            }=0A=
        } else if (strcmp(argv[arg_index],"-sf") =3D=3D 0 && arg_index < =
argc-3) {=0A=
            FILE    *fp;=0A=
            const TIFFFieldInfo *fip;=0A=
            char    *text;=0A=
            int     len;=0A=
=0A=
            arg_index++;=0A=
            tagname =3D argv[arg_index];=0A=
			user_tag =3D (ttag_t)atoi(tagname);=0A=
			tiff =3D TIFFOpen(tifffile, "r+");=0A=
            fip =3D GetField(tiff, tagname);=0A=
=0A=
            if (!fip)=0A=
                return 3;=0A=
=0A=
			/* TODO: add support for all user-specific field types */=0A=
			if (fip->field_type !=3D TIFF_ASCII) {=0A=
                fprintf( stderr,=0A=
                         "Only ASCII tags can be set from file. "=0A=
                         "%s is not ASCII tag.\n", fip->field_name );=0A=
                return 5;=0A=
            }=0A=
=0A=
            arg_index++;=0A=
            fp =3D fopen( argv[arg_index], "rt" );=0A=
            if(fp =3D=3D NULL) {=0A=
                perror( argv[arg_index] );=0A=
                continue;=0A=
            }=0A=
=0A=
			/* KAM - Should consider fixing this old kludge                  */=0A=
			/* Following code limits max data size to approximately 1 MB.    */=0A=
			/* Should allow up to 4 GB for classic TIFF (in extreme case).   */=0A=
			/* Since file name is specified on the command line (not a pipe) */=0A=
			/* should know file size in advance and be able to attempt       */=0A=
			/* allocation accordingly.  However, there really ought to be    */=0A=
			/* a version of TIFFSetField that would let us set the tag value */=0A=
			/* incrementally rather than needing to allocate all of this     */=0A=
			/* memory at one time.                                           */=0A=
=0A=
			/* TODO: get file size here, how? */=0A=
=0A=
			/* check that file size is integer multiple of data type size    */=0A=
			/* for non-ASCII data types.                                     */=0A=
			/* Use TIFFDataWidth() to get the individual field width.        */=0A=
=0A=
			/* For testing purposes, an apparently unused tag Id is 65000.   */=0A=
			/* Until add support for other types, can use TIFF_ASCII=3D2.      */=0A=
=0A=
			/* TODO: change memory allocation to match file size */=0A=
			text =3D (char *) malloc(1000000);=0A=
            len =3D fread( text, 1, 999999, fp );=0A=
            text[len] =3D '\0';=0A=
=0A=
            fclose( fp );=0A=
=0A=
				printf("Before File SetField\n");=0A=
				printf("fip->field_tag:%d\n",fip->field_tag);=0A=
				printf("fip->field_readcount:%d\n",fip->field_readcount);=0A=
				printf("fip->field_writecount:%d\n",fip->field_writecount);=0A=
				printf("fip->field_type:%d\n",fip->field_type);=0A=
				printf("fip->field_bit:%d\n",fip->field_bit);=0A=
				printf("fip->field_oktochange:%d\n",fip->field_oktochange);=0A=
				printf("fip->field_passcount:%d\n",fip->field_passcount);=0A=
				printf("fip->field_name:%s\n",fip->field_name);=0A=
				printf("text=3D%s\n",text);=0A=
=0A=
            if(TIFFSetField( tiff, fip->field_tag, text ) !=3D 1) {=0A=
                fprintf(stderr, "Failed to set %s from file %s\n", =0A=
                        fip->field_name, argv[arg_index]);=0A=
            }=0A=
=0A=
				printf("After File SetField\n");=0A=
				printf("fip->field_tag:%d\n",fip->field_tag);=0A=
				printf("fip->field_readcount:%d\n",fip->field_readcount);=0A=
				printf("fip->field_writecount:%d\n",fip->field_writecount);=0A=
				printf("fip->field_type:%d\n",fip->field_type);=0A=
				printf("fip->field_bit:%d\n",fip->field_bit);=0A=
				printf("fip->field_oktochange:%d\n",fip->field_oktochange);=0A=
				printf("fip->field_passcount:%d\n",fip->field_passcount);=0A=
				printf("fip->field_name:%s\n",fip->field_name);=0A=
				printf("text=3D%s\n",text);=0A=
=0A=
            _TIFFfree( text );=0A=
            arg_index++;=0A=
        } else if (strcmp(argv[arg_index],"-f") =3D=3D 0 && arg_index < =
argc-5) {=0A=
			/* KAM - add option to force data type and handling of unrecognized =
tags */=0A=
			arg_index++;=0A=
			user_field_type =3D atoi(argv[arg_index]);=0A=
        } else {=0A=
            fprintf(stderr, "Unrecognized option: %s\n",=0A=
                    argv[arg_index]);=0A=
            usage();=0A=
        }=0A=
    }=0A=
=0A=
    TIFFRewriteDirectory(tiff);=0A=
    TIFFClose(tiff);=0A=
    return 0;=0A=
}=0A=
=0A=
/* vim: set ts=3D8 sts=3D8 sw=3D8 noet: */=0A=

------=_NextPart_000_07B9_01C7BCAD.91107F10
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
------=_NextPart_000_07B9_01C7BCAD.91107F10--
