Return-Path: <tiff-bounces@remotesensing.org>
Received: from inav014.isp.belgacom.be (inav014.isp.belgacom.be [195.238.2.246])
        by mailst034.isp.belgacom.be (8.12.11/8.12.11/Skynet-MAILSTORE-2.14) with ESMTP id i9LII4A2017340
        for <joris.at.lebbeke@skynet.be>; Thu, 21 Oct 2004 20:18:04 +0200
        (envelope-from <tiff-bounces@remotesensing.org>)
Received: from inas005.isp.belgacom.be (localhost [127.0.0.1])
        by inav014.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-AV-3.00) with ESMTP id i9LIHrvU026236
        for <joris.at.lebbeke@skynet.be>; Thu, 21 Oct 2004 20:17:54 +0200
        (envelope-from <tiff-bounces@remotesensing.org>)
Received: from inmx009.isp.belgacom.be (inmx009.isp.belgacom.be [195.238.3.146])
        by inas005.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-AS-2.03) with ESMTP id i9LIHjnx028470
        for <joris.at.lebbeke@skynet.be>; Thu, 21 Oct 2004 20:17:46 +0200
        (envelope-from <tiff-bounces@remotesensing.org>)
Received: from xserve.flids.com (adsl-065-083-169-202.sip.mco.bellsouth.net [65.83.169.202])
        by inmx009.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-2.32) with ESMTP id i9LIHO2L023505
        for <joris.at.lebbeke@skynet.be>; Thu, 21 Oct 2004 20:17:26 +0200
        (envelope-from <tiff-bounces@remotesensing.org>)
Received: from adsl-065-083-169-202.sip.mco.bellsouth.net (localhost [127.0.0.1])
	by xserve.flids.com (Postfix) with ESMTP
	id B67013DD5BA; Thu, 21 Oct 2004 14:17:05 -0400 (EDT)
X-Original-To: tiff@remotesensing.org
Delivered-To: tiff@remotesensing.org
Received: from ahk.pu.ru (ahk.pu.ru [193.124.85.198])
	by xserve.flids.com (Postfix) with ESMTP id 3EFC73DD5A9
	for <tiff@remotesensing.org>; Thu, 21 Oct 2004 14:17:03 -0400 (EDT)
Received: from wg.pu.ru (wg.pu.ru [193.124.85.219])
	by ahk.pu.ru (8.12.11/8.12.9) with ESMTP id i9LIH11P039055
	for <tiff@remotesensing.org>; Thu, 21 Oct 2004 22:17:01 +0400 (MSD)
	(envelope-from dron@ak4719.spb.edu)
Received: (from uucp@localhost)
	by wg.pu.ru (8.9.1a/8.9.1) with UUCP id SAA24440
	for tiff@remotesensing.org; Thu, 21 Oct 2004 18:17:01 GMT
Received: from ak4719.spb.edu (localhost [127.0.0.1])
	by ak4719.spb.edu (8.12.11/8.12.11/Debian-5) with ESMTP id
	i9LIALvd013184
	for <tiff@remotesensing.org>; Thu, 21 Oct 2004 22:10:21 +0400
Received: (from dron@localhost)
	by ak4719.spb.edu (8.12.11/8.12.11/Debian-5) id i9LIALc4013181
	for tiff@remotesensing.org; Thu, 21 Oct 2004 22:10:21 +0400
From: Andrey Kiselev <dron@ak4719.spb.edu>
Date: Thu, 21 Oct 2004 22:10:21 +0400
To: tiff@remotesensing.org
Subject: Re: [Tiff] Changing TIFF value
Message-ID: <20041021181021.GA11026@ak4719.spb.edu>
Mail-Followup-To: tiff@remotesensing.org
References: <527F3325BBD82D469D09A95B375F1EDEBA8823@exchsrv.salepoint.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <527F3325BBD82D469D09A95B375F1EDEBA8823@exchsrv.salepoint.com>
X-GnuPG-Key: http://www.srces.spb.org/dron/export.home.key
X-Face: "t+se9s~+y~[XUH]L|pmeO3Pt/Q@DNv**S, d@_1-C=}/,
	c%<3Qp]eu!ok<"2lYJm$!9qVcg F?7o*L; |$`6|Q|>Rt-cU%2_y@6tQ|`!Li}TsvZvEKx;
	>fuY=fc(=sX^`7Wmw8%SsR`AvM$a; 0U/eN\ P?B\FTyqD, 0np$U2!*'z_4D,
	VPlFf?bN0&zYf"zF0s!7Tl7?$we)xD0@lL>[h|8bhys0i.g|zLnu@C
	Ti@d]i=[!:j1CB\5/TF[m]`lfHfaqSN[0qn@T3zeosV/[LAss{@p_?],x*j8P_9t[}uHD^X-;
	j~\M! gyTly;fj`}&Y~i{<#bN.#QmkE}#T`dxP.I1\.)_MEN{@#W
User-Agent: Mutt/1.5.6+20040722i
X-Virus-Scanned: clamd / ClamAV version 0.75-1, clamav-milter version 0.75c
	on ak4719
X-Virus-Status: Clean
X-BeenThere: tiff@remotesensing.org
X-Mailman-Version: 2.1.2
Precedence: list
List-Id: TIFF and libtiff discussion  <tiff.remotesensing.org>
List-Unsubscribe: <http://xserve.flids.com/mailman/listinfo/tiff>,
	<mailto:tiff-request@remotesensing.org?subject=unsubscribe>
List-Archive: <http://xserve.flids.com/pipermail/tiff>
List-Post: <mailto:tiff@remotesensing.org>
List-Help: <mailto:tiff-request@remotesensing.org?subject=help>
List-Subscribe: <http://xserve.flids.com/mailman/listinfo/tiff>,
	<mailto:tiff-request@remotesensing.org?subject=subscribe>
Sender: tiff-bounces@remotesensing.org
Errors-To: tiff-bounces@remotesensing.org
X-UIDL: e0f65f6edce74086fed7f3eebe23800e

On Tue, Oct 19, 2004 at 12:22:50PM -0700, Edwards, Richard wrote:
> Hello.  I'm having some trouble successfully changing TIFF values.  I
> have scanned some of the archives.  I'm adding the functionality in a
> Windows DLL.
> 
> The primary problem seems to be that I cannot read my changed value
> successfully.  Note that I am attempting to change the ARTIST field.
> I'm all but certain that the field does not exist in the original TIFF
> file.
> 
> Here's my two functions:
> 
> extern "C" __declspec (dllexport) BOOL WINAPI ReadTag(char *filename,
> long tag, char *result)
> {
> 	TIFF *image;
> 	long returncode, counter;
> 
> 	// Open the TIFF file
> 	if((image = TIFFOpen(filename, "r")) == NULL)
> 	{
> 		return FALSE;
> 	}
> 	
> 	returncode = TIFFGetField(image, tag, result);
                                              ^^^^^^

The bug is here. Should be

	returncode = TIFFGetField(image, tag, &result);

> 	// Close the file
> 	TIFFClose(image);
> 
> 	return TRUE;
> }
> 
> extern "C" __declspec (dllexport) BOOL WINAPI ChangeTag(char
> *filename, long tag, char *value)
> {
> 	TIFF *image;
> 	long returncode;
> 
> 	// Open the TIFF file.
> 	if((image = TIFFOpen(filename, "a")) == NULL)
> 	{
> 		return FALSE;
> 	}
> 	
> 	returncode = TIFFSetField(image, tag, value);
> 
> 	// Write data.
> 	returncode = TIFFRewriteDirectory(image);
> 
> 	// Close the file
> 	TIFFClose(image);
> 
> 	return TRUE;
> }
> 
> Here's the body of the code:
> 
> ReadTag("C:\\tmp\\sample.tif", 315, resultbuffer);
> ChangeTag("C:\\tmp\\sample.tif", 315, "RICHARD");
> ReadTag("C:\\tmp\\sample.tif", 315, resultbuffer);
> 
> When I open the TIFF file after running the code in a binary editor, I
> see "RICHARD", which implies that ChangeTag had some success.  As a
> matter of fact, I get an additional "RICHARD" every time I run the
> code, which isn't so great.

TIFFRewriteDirectory() adds the new directory at the end of the file
every time being called and we loose the space, occuped by the old
directories. So you should minimize the amount of TIFFRewriteDirectory()
calls.

						Andrey

-- 
Andrey V. Kiselev
Home phone:  +7 812 5274898  ICQ# 26871517
_______________________________________________
Tiff mailing list
Tiff@remotesensing.org
http://xserve.flids.com/mailman/listinfo/tiff
