Return-Path: <tiff-bounces@lists.maptools.org>
X-Original-To: info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-i.b-one.net (mx-i.one.com [91.198.169.56])
	by mail9.b-one.net (Postfix) with ESMTP id B957440080A
	for <info@awaresystems.be>; Mon, 22 Mar 2010 04:47:47 +0100 (CET)
Received: by mx-i.b-one.net (Postfix, from userid 106)
	id AEDB03D0D543; Mon, 22 Mar 2010 04:47:47 +0100 (CET)
X-Virus-Scanned: by one.com
X-Spam-Score: 2.198
X-Spam-Level: **
X-Spam-Status: No, score=2.198 tagged_above=0 required=4
 tests=[FAKE_REPLY_C=2.197, HTML_MESSAGE=0.001]
X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4
Received: from lists.maptools.org (lists.maptools.org [65.39.174.144]) by
 mx-i.b-one.net (Postfix) with ESMTP id DAB82833E6 for <info@awaresystems.be>;
 Mon, 22 Mar 2010 04:47:45 +0100 (CET)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by
 lists.maptools.org (Postfix) with ESMTP id B653B1D0E5298; Sun, 21 Mar 2010
 22:45:54 -0500 (EST)
Received: from mail-gw0-f44.google.com (mail-gw0-f44.google.com
 [74.125.83.44]) by lists.maptools.org (Postfix) with ESMTP id 9294C1D18DE13
 for <tiff@lists.maptools.org>; Sun, 21 Mar 2010 21:57:03 -0500 (EST)
Received: by gwaa11 with SMTP id a11so1248437gwa.3 for
 <tiff@lists.maptools.org>; Sun, 21 Mar 2010 19:57:02 -0700 (PDT)
Received: by 10.100.56.19 with SMTP id e19mr1498818ana.202.1269226621363;
 Sun, 21 Mar 2010 19:57:01 -0700 (PDT)
Received: from KAM1720 (cpe-66-25-159-174.austin.res.rr.com [66.25.159.174])
 by mx.google.com with ESMTPS id 13sm2938232gxk.8.2010.03.21.19.56.58
 (version=SSLv3 cipher=RC4-MD5); Sun, 21 Mar 2010 19:56:59 -0700 (PDT)
Message-ID: <4C771027322842FFB23DF352DAC9739B@KAM1720>
From: "Kevin Myers" <kmyers1@clearwire.net>
To: <tiff@lists.maptools.org>
Date: Sun, 21 Mar 2010 21:56:53 -0500
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----=_NextPart_000_000B_01CAC941.6AB207F0"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2900.5843
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Subject: Re: [Tiff] Problems with Modified tiffset
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.9
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

This is a multi-part message in MIME format.

------=_NextPart_000_000B_01CAC941.6AB207F0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_001_000C_01CAC941.6AB207F0"


------=_NextPart_001_000C_01CAC941.6AB207F0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Oops, never mind, finally found the problem myself.  Had inappropriate =
value for field_passcount member of TIFFFieldInfo structure to use with =
ASCII tag content.  After changing value for field_passcount from TRUE =
to FALSE, all works as it should.  Sorry for the false alarm.  Hope =
nobody out there wasted any time trying to track this down...

My corrected code is attached, in case anyone is interested.

s/KAM

  ----- Original Message -----=20
  From: Kevin Myers=20
  To: tiff@lists.maptools.org=20
  Sent: Sunday, March 21, 2010 20:34
  Subject: Problems with Modified tiffset


  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:
  http://www.remotesensing.org/libtiff/addingtags.html

  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
  or
  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.

  Thanks,
  Kevin M.


------=_NextPart_001_000C_01CAC941.6AB207F0
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 content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META name=3DGENERATOR content=3D"MSHTML 8.00.6001.18876">
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2 face=3DArial>Oops, never mind, finally found the =
problem=20
myself.&nbsp; Had inappropriate value for field_passcount member of=20
TIFFFieldInfo structure to use with ASCII tag content.&nbsp; After =
changing=20
value for field_passcount from TRUE to FALSE, all works as it =
should.&nbsp;=20
Sorry for the false alarm.&nbsp; Hope nobody out there wasted any time =
trying to=20
track this down...</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>My corrected code is attached, in case =
anyone is=20
interested.</FONT></DIV>
<DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2 face=3DArial>s/KAM</FONT></DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; =
PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"=20
dir=3Dltr>
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"FONT: 10pt arial; BACKGROUND: #e4e4e4; font-color: =
black"><B>From:</B>=20
  <A title=3Dkmyers1@clearwire.net =
href=3D"mailto:kmyers1@clearwire.net">Kevin=20
  Myers</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Dtiff@lists.maptools.org=20
  href=3D"mailto:tiff@lists.maptools.org">tiff@lists.maptools.org</A> =
</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Sunday, March 21, 2010 =
20:34</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Problems with Modified =

  tiffset</DIV>
  <DIV><BR></DIV>
  <DIV><FONT size=3D2 face=3DArial>I've already sent this to a couple of =
my=20
  acquaintances on this list, but thought I might as well run it past=20
  everyone&nbsp;in case someone else can spot the problem right=20
  away...</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
  <DIV>
  <DIV><FONT size=3D2 face=3DArial>I have attempted to modify the =
tiffset program to=20
  allow it to set the value of user defined (custom) tags.&nbsp; I could =
have=20
  sworn that I had this working some time ago, but now it definitely =
isn't=20
  working, and I'm not sure if it is due to a bug in libtiff, or (more =
likely)=20
  some kind of problem in my own code.&nbsp; The modifications that I =
made are=20
  relatively simple, and make use of the so-called "tag extender" =
feature of=20
  libtiff, which is documented under the "Defining Application Tags" =
section on=20
  this web page:</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial><A=20
  =
href=3D"">http://www.remotesensing.org/libtiff/addingtags.html</A></FONT>=
</DIV>
  <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2 face=3DArial>I have attached my modified version =
of tiffset.c=20
  for tiff 3.9.2.&nbsp; Since I'm sure that many of you are much =
stronger C=20
  programmers than I am, I doubt that you will&nbsp;have any problems =
compiling=20
  this.&nbsp; My own approach was to temporarily replace the standard =
version of=20
  tiffset.c in the tools directory, delete or rename any previously =
generated=20
  tiffset.exe in the tools output folder if you have one, and go from=20
  there.&nbsp; From the tools folder, I simply used nmake /f makefile.vc =
under=20
  Windows XP using VC from Visual Studio 2008 Express.</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2 face=3DArial>After successfully compiling the =
program, here is=20
  what happens:</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial>If I use my modified tiffset to set =
the value of=20
  a standard tiff tag, say ImageDescription (tag number 270, ASCII =
text),=20
  everything works fine.&nbsp; Here is how I would do that (assume =
test.tif is=20
  an existing tiff file):</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2 face=3DArial>tiffset -s 270 MyValue =
test.tif</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial>or</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial>tiffset -s ImageDescription NewValue=20
  test.tif</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2 face=3DArial>You can use tiffinfo to verify that =
the=20
  ImageDescription tag value&nbsp;is set&nbsp;correctly.</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2 face=3DArial>On the other hand, when I use the =
following=20
  command:</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2 face=3DArial>tiffset -s 65000 MyValue =
test.tif</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2 face=3DArial>Everything *appears* to proceed =
normally.&nbsp;=20
  But when I run tiffinfo, I find that tag 65000 did get set to =
*something*, but=20
  not what it was supposed to be.&nbsp; It seems to be getting set to =
some bytes=20
  from elsewhere in memory.&nbsp; Looks like some kind of pointer =
related=20
  problem...</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2 face=3DArial>Internally, tiffset is using the =
TIFFSetField=20
  function from libtiff to set the tag value.&nbsp; My modified tiffset=20
  currently includes a printf statement to print the values of the =
arguments to=20
  TIFFSetField immediately prior to the call, and everything *seems* to =
be ok at=20
  that point.&nbsp; The correct, anticipated values are printed at this =
point=20
  for both standard and user-defined tag cases.&nbsp; But somewhere =
within the=20
  execution of TIFFSetField, things are getting screwed up for the =
user-defined=20
  tag case, and I can't figure out why/where.&nbsp; The code used in=20
  TIFFSetField is somewhat beyond my level of C expertise, and it would =
take me=20
  forever to track down where the correct value is getting lost.&nbsp; =
Hopefully=20
  someone else out there may&nbsp;be able to track down this problem a =
lot more=20
  quickly.&nbsp; Any takers?</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2 face=3DArial>I'm trying to finish up a critical =
project with=20
  immediately pending deadlines.&nbsp; A small but critical portion of =
that=20
  project requires programmatically&nbsp;adding&nbsp;metadata to tiff =
images via=20
  custom tag values, and this problem currently has&nbsp;my =
progress&nbsp;ground=20
  to a complete standstill.</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2 face=3DArial>Thanks,</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial>Kevin M.</FONT></DIV>
  <DIV><FONT size=3D2 face=3DArial></FONT>&nbsp;</DIV>
  <DIV><FONT size=3D2=20
face=3DArial></FONT>&nbsp;</DIV></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_001_000C_01CAC941.6AB207F0--

------=_NextPart_000_000B_01CAC941.6AB207F0
Content-Type: text/plain;
	name="tiffset.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="tiffset.c"

/************************************************************************=
******
 * $Id: tiffset.c,v 1.13 2009/03/21 21:52:00 kam1 Exp $
 *
 * Project:  libtiff tools
 * Purpose:  Mainline for setting metadata in existing TIFF files.
 * Author:   Frank Warmerdam, warmerdam@pobox.com
 *
 =
*************************************************************************=
*****
 * Copyright (c) 2000, Frank Warmerdam
 *
 * Permission to use, copy, modify, distribute, and sell this software =
and=20
 * its documentation for any purpose is hereby granted without fee, =
provided
 * that (i) the above copyright notices and this permission notice =
appear in
 * all copies of the software and related documentation, and (ii) the =
names of
 * Sam Leffler and Silicon Graphics may not be used in any advertising =
or
 * publicity relating to the software without the specific, prior =
written
 * permission of Sam Leffler and Silicon Graphics.
 *=20
 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,=20
 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY=20
 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. =20
 *=20
 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY =
KIND,
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR =
PROFITS,
 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY =
THEORY OF=20
 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR =
PERFORMANCE=20
 * OF THIS SOFTWARE.
 =
*************************************************************************=
*****
 *
 * $Log: tiffset.c,v $
 * Revision 1.13  2009/03/21 21:52:00  kam1
 * Add support for setting undocumented ASCII tag values.
 *
 * Revision 1.12  2007/02/24 17:14:14  dron
 * Properly handle tags with TIFF_VARIABLE writecount. As per bug
 * http://bugzilla.remotesensing.org/show_bug.cgi?id=3D1350
 *
 * Revision 1.11  2005/09/13 14:13:42  dron
 * Avoid warnings.
 *
 * Revision 1.10  2005/02/24 14:47:11  fwarmerdam
 * Updated header.
 *
 */


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "tiffio.h"

#define	TRUE	1
#define	FALSE	0

#define TIFFTAG_CUSTOM 65535

static char* usageMsg[] =3D {
"usage: tiffset [options] tiff-filename",
"where options are:",
" -s <tagname> [count] <value>...   set the tag value",
" -sf <tagname> <tag data filename>  set the tag value from file (ASCII =
tags only)",
NULL
};

static TIFFDataType	user_field_type =3D 0;		/* user specified TIFF tag =
data type */
static ttag_t		user_tag =3D 0;			/* user specified TIFF tag Id */
static TIFFExtendProc	_ParentExtender =3D NULL;		/* parent tag extender =
proc */

static TIFFFieldInfo	xtiffFieldInfo[] =3D {
    { TIFFTAG_CUSTOM,	TIFF_VARIABLE,	TIFF_VARIABLE,	TIFF_ASCII,	=
FIELD_CUSTOM,	TRUE,	FALSE,	"Tag 65535" }
};



static void
usage(void)
{
	int i;
	for (i =3D 0; usageMsg[i]; i++)
		fprintf(stderr, "%s\n", usageMsg[i]);
	exit(-1);
}


/* KAM - tag type extender callback */
static void
_XTIFFDefaultDirectory(TIFF *tif)
{
	/* update our extended tag field info */
	xtiffFieldInfo[0].field_tag =3D user_tag;
//	xtiffFieldInfo[0].field_type =3D user_field_type;
	sprintf(xtiffFieldInfo[0].field_name, "Tag %d", (int) user_tag);

	/* Install the extended Tag field info */
	TIFFMergeFieldInfo(tif, xtiffFieldInfo, 1);

	/* Since an XTIFF client module may have overridden
	 * the default directory method, we call it now to
	 * allow it to set up the rest of its own methods.
	 */

    if (_ParentExtender) (*_ParentExtender)(tif);
}


/* KAM - initialize tag type extender */
static
void _XTIFFInitialize(void)
{
	static int first_time=3D1;
=09
	if (! first_time) return; /* Been there. Done that. */
	first_time =3D 0;
=09
	/* Grab the inherited method and install */
	_ParentExtender =3D TIFFSetTagExtender(_XTIFFDefaultDirectory);
}


static const TIFFFieldInfo *
GetField(TIFF *tiff, const char *tagname)
{
    const TIFFFieldInfo *fip;

	if( user_tag > 0 )
		fip =3D TIFFFieldWithTag(tiff, user_tag);
	else
		fip =3D TIFFFieldWithName(tiff, tagname);

	if (!fip) {
		fprintf( stderr, "Field name %s not recognized.\n", tagname );
        return (TIFFFieldInfo *)NULL;
    }

    return fip;
}


int
main(int argc, char* argv[])
{
    TIFF *tiff;
    int  arg_index;
	char* tifffile;
	const char *tagname;
	char* tag_value;

	/* KAM - initialize tag extender */
	_XTIFFInitialize();

	/* at least 2 arguments are always required (really more) */
	if (argc < 2)
        usage();

	/* target file is always last argument */
	tifffile =3D argv[argc-1];

    for( arg_index =3D 1; arg_index < argc-1; arg_index++ ) {
        if (strcmp(argv[arg_index],"-s") =3D=3D 0 && arg_index < argc-3) =
{
            const TIFFFieldInfo *fip;

            arg_index++;
            tagname =3D argv[arg_index];

            user_tag =3D (ttag_t)atoi(tagname);

            tiff =3D TIFFOpen(tifffile, "r+");
            if (tiff =3D=3D NULL)
                return 2;

            fip =3D GetField(tiff, tagname);

            if (!fip)
                return 3;

            arg_index++;
            tag_value=3Dargv[arg_index];
            if (fip->field_type =3D=3D TIFF_ASCII) {

                if (TIFFSetField(tiff, fip->field_tag, argv[arg_index]) =
!=3D 1)
                    fprintf( stderr, "Failed to set %s=3D%s\n",
                             fip->field_name, argv[arg_index] );

            } else if (fip->field_writecount > 0
		           || fip->field_writecount =3D=3D TIFF_VARIABLE) {
                int     ret =3D 1;
                short   wc;

                if (fip->field_writecount =3D=3D TIFF_VARIABLE)
                        wc =3D atoi(argv[arg_index++]);
                else
                        wc =3D fip->field_writecount;

                if (argc - arg_index < wc) {
                    fprintf( stderr,
                             "Number of tag values is not enough. "
                             "Expected %d values for %s tag, got %d\n",
                             wc, fip->field_name, argc - arg_index);
                    return 4;
                }
                   =20
                if (wc > 1) {
                        int     i, size;
                        void    *array;

                        switch (fip->field_type) {
                                /*
                                 * XXX: We can't use TIFFDataWidth()
                                 * to determine the space needed to =
store
                                 * the value. For TIFF_RATIONAL values
                                 * TIFFDataWidth() returns 8, but we use =
4-byte
                                 * float to represent rationals.
                                 */
                                case TIFF_BYTE:
                                case TIFF_ASCII:
                                case TIFF_SBYTE:
                                case TIFF_UNDEFINED:
				default:
                                    size =3D 1;
                                    break;

                                case TIFF_SHORT:
                                case TIFF_SSHORT:
                                    size =3D 2;
                                    break;

                                case TIFF_LONG:
                                case TIFF_SLONG:
                                case TIFF_FLOAT:
                                case TIFF_IFD:
                                case TIFF_RATIONAL:
                                case TIFF_SRATIONAL:
                                    size =3D 4;
                                    break;

                                case TIFF_DOUBLE:
                                    size =3D 8;
                                    break;
                        }

                        array =3D _TIFFmalloc(wc * size);
                        if (!array) {
                                fprintf(stderr, "No space for %s tag\n",
                                        tagname);
                                return 4;
                        }

                        switch (fip->field_type) {
                            case TIFF_BYTE:
                                for (i =3D 0; i < wc; i++)
                                    ((uint8 *)array)[i] =3D =
atoi(argv[arg_index+i]);
                                break;
                            case TIFF_SHORT:
                                for (i =3D 0; i < wc; i++)
                                    ((uint16 *)array)[i] =3D =
atoi(argv[arg_index+i]);
                                break;
                            case TIFF_SBYTE:
                                for (i =3D 0; i < wc; i++)
                                    ((int8 *)array)[i] =3D =
atoi(argv[arg_index+i]);
                                break;
                            case TIFF_SSHORT:
                                for (i =3D 0; i < wc; i++)
                                    ((int16 *)array)[i] =3D =
atoi(argv[arg_index+i]);
                                break;
                            case TIFF_LONG:
                                for (i =3D 0; i < wc; i++)
                                    ((uint32 *)array)[i] =3D =
atol(argv[arg_index+i]);
                                break;
                            case TIFF_SLONG:
                            case TIFF_IFD:
                                for (i =3D 0; i < wc; i++)
                                    ((uint32 *)array)[i] =3D =
atol(argv[arg_index+i]);
                                break;
                            case TIFF_DOUBLE:
                                for (i =3D 0; i < wc; i++)
                                    ((double *)array)[i] =3D =
atof(argv[arg_index+i]);
                                break;
                            case TIFF_RATIONAL:
                            case TIFF_SRATIONAL:
                            case TIFF_FLOAT:
                                for (i =3D 0; i < wc; i++)
                                    ((float *)array)[i] =3D =
(float)atof(argv[arg_index+i]);
                                break;
                            default:
                                break;
                        }
               =20
                        if (fip->field_passcount) {
                                ret =3D TIFFSetField(tiff, =
fip->field_tag,
                                                   wc, array);
                        } else {
                                ret =3D TIFFSetField(tiff, =
fip->field_tag,
                                                   array);
                        }

                        _TIFFfree(array);
                } else {
                        switch (fip->field_type) {
                            case TIFF_BYTE:
                            case TIFF_SHORT:
                            case TIFF_SBYTE:
                            case TIFF_SSHORT:
                                ret =3D TIFFSetField(tiff, =
fip->field_tag,
                                                   =
atoi(argv[arg_index++]));
                                break;
                            case TIFF_LONG:
                            case TIFF_SLONG:
                            case TIFF_IFD:
                                ret =3D TIFFSetField(tiff, =
fip->field_tag,
                                                   =
atol(argv[arg_index++]));
                                break;
                            case TIFF_DOUBLE:
                                ret =3D TIFFSetField(tiff, =
fip->field_tag,
                                                   =
atof(argv[arg_index++]));
                                break;
                            case TIFF_RATIONAL:
                            case TIFF_SRATIONAL:
                            case TIFF_FLOAT:
                                ret =3D TIFFSetField(tiff, =
fip->field_tag,
                                                   =
(float)atof(argv[arg_index++]));
                                break;
                            default:
                                break;
                        }
                }

                if (ret !=3D 1)
                    fprintf(stderr, "Failed to set %s\n", =
fip->field_name);
                arg_index +=3D wc;
            }
        } else if (strcmp(argv[arg_index],"-sf") =3D=3D 0 && arg_index < =
argc-3) {
            FILE    *fp;
            const TIFFFieldInfo *fip;
            char    *text;
            int     len;

            arg_index++;
            tagname =3D argv[arg_index];
			user_tag =3D (ttag_t)atoi(tagname);
			tiff =3D TIFFOpen(tifffile, "r+");
            fip =3D GetField(tiff, tagname);

            if (!fip)
                return 3;

			/* TODO: add support for all user-specific field types */
			if (fip->field_type !=3D TIFF_ASCII) {
                fprintf( stderr,
                         "Only ASCII tags can be set from file. "
                         "%s is not ASCII tag.\n", fip->field_name );
                return 5;
            }

            arg_index++;
            fp =3D fopen( argv[arg_index], "rt" );
            if(fp =3D=3D NULL) {
                perror( argv[arg_index] );
                continue;
            }

			/* KAM - Should consider fixing this old kludge                  */
			/* Following code limits max data size to approximately 1 MB.    */
			/* Should allow up to 4 GB for classic TIFF (in extreme case).   */
			/* Since file name is specified on the command line (not a pipe) */
			/* should know file size in advance and be able to attempt       */
			/* allocation accordingly.  However, there really ought to be    */
			/* a version of TIFFSetField that would let us set the tag value */
			/* incrementally rather than needing to allocate all of this     */
			/* memory at one time.                                           */

			/* TODO: get file size here, how? */

			/* check that file size is integer multiple of data type size    */
			/* for non-ASCII data types.                                     */
			/* Use TIFFDataWidth() to get the individual field width.        */

			/* For testing purposes, an apparently unused tag Id is 65000.   */
			/* Until add support for other types, can use TIFF_ASCII=3D2.      */

			/* TODO: change memory allocation to match file size */
			text =3D (char *) malloc(1000000);
            len =3D fread( text, 1, 999999, fp );
            text[len] =3D '\0';

            fclose( fp );

            if(TIFFSetField( tiff, fip->field_tag, text ) !=3D 1) {
                fprintf(stderr, "Failed to set %s from file %s\n",=20
                        fip->field_name, argv[arg_index]);
            }

            _TIFFfree( text );
            arg_index++;

        } else if (strcmp(argv[arg_index],"-f") =3D=3D 0 && arg_index < =
argc-5) {
			/* KAM - add option to force data type and handling of unrecognized =
tags */
			arg_index++;
			user_field_type =3D atoi(argv[arg_index]);
        } else {
            fprintf(stderr, "Unrecognized option: %s\n",
                    argv[arg_index]);
            usage();
        }
    }

    TIFFRewriteDirectory(tiff);
    TIFFClose(tiff);
    return 0;
}

/* vim: set ts=3D8 sts=3D8 sw=3D8 noet: */

------=_NextPart_000_000B_01CAC941.6AB207F0
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_000B_01CAC941.6AB207F0--
