Return-Path: <tiff-bounces@lists.maptools.org>
X-Original-To: info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-l.b-one.net (mx-l.one.com [91.198.169.59])
	by mail9.b-one.net (Postfix) with ESMTP id 8691540011B
	for <info@awaresystems.be>; Wed, 17 Dec 2008 22:02:01 +0100 (CET)
X-Virus-Scanned: by one.com
X-Spam-Score: 0
X-Spam-Level: 
X-Spam-Status: No, score=0 tagged_above=0 required=6 tests=[none]
X-Greylist: from auto-whitelisted by SQLgrey-1.7.4
Received: from lists.maptools.org (lists.maptools.org [65.39.174.144])
	by mx-l.b-one.net (Postfix) with ESMTP id 6E9201D1AE0B
	for <info@awaresystems.be>; Wed, 17 Dec 2008 22:02:00 +0100 (CET)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id 50C9D1CEE786A;
	Wed, 17 Dec 2008 20:54:26 +0000 (UTC)
Received: from sasl.smtp.pobox.com (a-sasl-quonix.sasl.smtp.pobox.com
	[208.72.237.25])
	by lists.maptools.org (Postfix) with ESMTP id 4E7871CEE7844
	for <tiff@lists.maptools.org>; Wed, 17 Dec 2008 20:54:25 +0000 (UTC)
Received: from localhost.localdomain (unknown [127.0.0.1])
	by b-sasl-quonix.sasl.smtp.pobox.com (Postfix) with ESMTP id 17E9D1A7A4
	for <tiff@lists.maptools.org>; Wed, 17 Dec 2008 15:54:17 -0500 (EST)
Received: from [192.168.2.4] (unknown [67.47.28.121]) (using TLSv1 with
	cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate
	requested)
	by b-sasl-quonix.sasl.smtp.pobox.com (Postfix) with ESMTPSA id
	B3E451A77D for
	<tiff@lists.maptools.org>; Wed, 17 Dec 2008 15:54:11 -0500 (EST)
Message-ID: <494966EE.6070006@pobox.com>
Date: Wed, 17 Dec 2008 15:54:06 -0500
From: Frank Warmerdam <warmerdam@pobox.com>
User-Agent: Thunderbird 2.0.0.6 (X11/20071022)
MIME-Version: 1.0
To: TIFF mailing list <tiff@lists.maptools.org>
X-Pobox-Relay-ID: DE6F9C7E-CC7C-11DD-A180-F83E113D384A-06493634!a-sasl-quonix.pobox.com
Subject: [Tiff] Deleting tags from a directory
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>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

Folks,

I have a client who needs to be able to remove a colormap from an existing
TIFF file.  This reveals a problem that has vexed me a number of times before
when trying to update TIFF files "in place".  There does not appear to be
any mechanism to delete a tag from an existing directory.

I propose, in libtiff4 to add a TIFFUnsetField() function which will remove
a tag from the current directory if present.  It would be implemented like
this:

/*
  * Clear the contents of the field in the internal structure.
  */
int
TIFFUnsetField(TIFF* tif, uint32 tag)
{
     const TIFFField *fip =  TIFFFieldWithTag(tif, tag);
     TIFFDirectory* td = &tif->tif_dir;

     if( !fip )
         return 0;

     if( fip->field_bit != FIELD_CUSTOM )
         TIFFClrFieldBit(tif, fip->field_bit);
     else
     {
         TIFFTagValue *tv;
         int i;

         for (i = 0; i < td->td_customValueCount; i++) {

             tv = td->td_customValues + i;
             if( tv->info->field_tag == tag )
                 break;
         }

         if( i < td->td_customValueCount )
         {
             _TIFFfree(tv->value);
             for( ; i < td->td_customValueCount-1; i++) {
                 td->td_customValues[i] = td->td_customValues[i+1];
             }
             td->td_customValueCount--;
         }
     }

     tif->tif_flags |= TIFF_DIRTYDIRECT;

     return (1);
}

Does anyone know of any problems with this change?  Is there already a
way for applications to remove tags I'm not aware of?  So far, I have
only tested the above a wee bit.  The following sample program demonstrates
turning a paletted file into unpaletted form:
#include "tiffio.h"

int main()

{
     TIFF *hTIFF;

     hTIFF = TIFFOpen( "cm.tif", "r+" );

     if( TIFFSetField( hTIFF, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK ) )
         printf( "Set photometric successful.\n" );
     else
         printf( "Set photometric failed.\n" );


     if( TIFFUnsetField( hTIFF, TIFFTAG_COLORMAP ) )
         printf( "clear colormap successful.\n" );
     else
         printf( "clear colormap failed.\n" );

     TIFFClose( hTIFF );
}



Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam@pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
