Received: from mailgate008.isp.belgacom.be (mailgate008.isp.belgacom.be [195.238.6.1])
	by maildelivery007.isp.belgacom.be (Postfix) with ESMTP id EC74045C00E
	for <joris.at.lebbeke@skynet.be>; Thu, 20 Sep 2007 22:33:03 +0200 (CEST)
Received: from r153.dmsolutions.ca (HELO duke.maptools.org) ([209.217.116.153])
  by in.mx.skynet.be with ESMTP; 20 Sep 2007 22:33:02 +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 l8KK6OG4022227;
	Thu, 20 Sep 2007 16:07:27 -0400
Received: from rune.pobox.com (rune.pobox.com [208.210.124.79])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id l8KK6Lex022224
	for <tiff@lists.maptools.org>; Thu, 20 Sep 2007 16:06:21 -0400
Received: from rune (localhost [127.0.0.1])
	by rune.pobox.com (Postfix) with ESMTP id 250F2138D16
	for <tiff@lists.maptools.org>; Thu, 20 Sep 2007 16:06:42 -0400 (EDT)
Received: from [192.168.2.3] (dpc674728121.direcpc.com [67.47.28.121])
	by rune.sasl.smtp.pobox.com (Postfix) with ESMTP id 8C20613668A
	for <tiff@lists.maptools.org>; Thu, 20 Sep 2007 16:06:37 -0400 (EDT)
Message-ID: <46F2E03D.6040905@pobox.com>
Date: Thu, 20 Sep 2007 17:03:57 -0400
From: Frank Warmerdam <warmerdam@pobox.com>
User-Agent: Thunderbird 1.5.0.9 (X11/20070104)
MIME-Version: 1.0
To: TIFF mailing list <tiff@lists.maptools.org>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Subject: [Tiff] libtiff4, and the size of STRIPOFFSETs and TILEOFFSETs
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.000027d7
X-MSP-STORE: Thu, 20 Sep 2007 22:33:04 +0200
Status: RO

Joris, and others,

I discovered a problem today with GDAL's use of libtiff4.  The problem
occurs because libtiff decides as it is writing directories whether to
write fields like TILEOFFSETs as LONG (4byte) or LONG8 (8byte).  However,
my code depends on the questionable assumption that I can rewrite a
directory after altering (only) the tile/strip offset and size values.

This apparently used to be true, but now it may happen that the offsets
switch from using LONG to LONG8.

How important is this dynamic behavior?

I have taken the liberty of changing tif_dirwrite.c so that for BigTIFF
files the tile/strip sizes and offsets are always written as LONG8.  (r1.58
of tif_dirwrite.c) in order to resolve my GDAL problems.

I have done so by altering the semantics of
TIFFWriteDirectoryTagLongLong8Array().  I believe it used to write the
array of values as LONG if possible, otherwise write as LONG8 (if values are
too large).  Now it basically just writes as LONG for classic tiff, and as
LONG8 for bigtiff.  It also does some checking to confirm that larger than
LONG values aren't being written to classic tiff.

If the dynamic sizing of these tags is considered important then I
can consider other approaches.  Perhaps some sort of flag I can set
at runtime to get the "biggest size" behavior I need.  But if this is
just intended to be a small space savings in file sizes I think it would
be simplier and safer to just write strip/tile offset/size values in "big"
form for bigtiff.

PS. I see the following when building now.  At least one of these used
to be used, but I altered things.  But a bunch have never been used. I'd
also like to remove the unused code.  It would cut down on warnings as well
as code bloat.

tif_dirwrite.c:902: warning: 'TIFFWriteDirectoryTagByte' defined but not used
tif_dirwrite.c:950: warning: 'TIFFWriteDirectoryTagSbyte' defined but not used
tif_dirwrite.c:1046: warning: 'TIFFWriteDirectoryTagSshort' defined but not used
tif_dirwrite.c:1142: warning: 'TIFFWriteDirectoryTagSlong' defined but not used
tif_dirwrite.c:1190: warning: 'TIFFWriteDirectoryTagLong8' defined but not used
tif_dirwrite.c:1212: warning: 'TIFFWriteDirectoryTagSlong8' defined but not used
tif_dirwrite.c:1266: warning: 'TIFFWriteDirectoryTagFloat' defined but not used
tif_dirwrite.c:1311: warning: 'TIFFWriteDirectoryTagDouble' defined but not used
tif_dirwrite.c:1451: warning: 'TIFFWriteDirectoryTagShortLongLong8Array' 
defined but not used

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    | President OSGeo, http://osgeo.org

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