Return-Path: <tiff-bounces@lists.maptools.org>
Received: from inas008.isp.belgacom.be (localhost [127.0.0.1])
        by inav019.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-AV-3.00) with ESMTP id k09BF0C0006372
        for <joris.at.lebbeke@skynet.be>; Mon, 9 Jan 2006 12:15:00 +0100
        (envelope-from <tiff-bounces@lists.maptools.org>)
Received: from inmx014.isp.belgacom.be (inmx014.isp.belgacom.be [195.238.4.217])
        by inas008.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-AS-2.03) with ESMTP id k09BEtYt004905
        for <joris.at.lebbeke@skynet.be>; Mon, 9 Jan 2006 12:14:56 +0100
        (envelope-from <tiff-bounces@lists.maptools.org>)
Received: from duke.maptools.org (r153.dmsolutions.ca [209.217.116.153] (may be forged))
        by inmx014.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-2.32) with ESMTP id k09BEoUE013847
        for <joris.at.lebbeke@skynet.be>; Mon, 9 Jan 2006 12:14:51 +0100
        (envelope-from <tiff-bounces@lists.maptools.org>)
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 k09BAaLn029969;
	Mon, 9 Jan 2006 06:10:56 -0500
Received: from outmx028.isp.belgacom.be (outmx028.isp.belgacom.be
	[195.238.3.49])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id k09BAZmD029966
	for <tiff@lists.maptools.org>; Mon, 9 Jan 2006 06:10:35 -0500
Received: from outmx028.isp.belgacom.be (localhost [127.0.0.1])
	by outmx028.isp.belgacom.be (8.12.11/8.12.11/Skynet-OUT-2.22) with
	ESMTP id k09BASkN013526
	for <tiff@lists.maptools.org>; Mon, 9 Jan 2006 12:10:29 +0100
	(envelope-from <joris.at.lebbeke@skynet.be>)
Received: from dfgrrxsknr4e (190-181.246.81.adsl.skynet.be [81.246.181.190])
	by outmx028.isp.belgacom.be (8.12.11/8.12.11/Skynet-OUT-2.22) with SMTP
	id k09BAL7f013408; Mon, 9 Jan 2006 12:10:21 +0100
	(envelope-from <joris.at.lebbeke@skynet.be>)
Message-ID: <001201c6150d$4f12d430$beb5f651@dfgrrxsknr4e>
From: "Joris" <joris.at.lebbeke@skynet.be>
To: "Andreas Christ" <andreas.chr@gmx.de>, <tiff@lists.maptools.org>
References: <43C21EB1.6060109@gmx.de>
Subject: Re: [Tiff] Multipage 16bit TIFF in Delphi
Date: Mon, 9 Jan 2006 12:10:27 +0100
MIME-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2800.1506
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
Cc: 
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.00001106
X-MSP-STORE: Mon, 09 Jan 2006 12:15:07 +0100
Status:   

Andreas,

Andreas Christ wrote:
> I have multipage Tiffs with 16 Bit per sample, which I want to read,
> to manipulate and to save again.I tried it with the example
> LibTiffDelphiHigherLevel from Joris (February 2005), but the result is
> only a black image.

I've received your code and testfile.

What you have here, is a problem. You're seeing a black image, because,
strictly speaking, it is a black image. Double-check with Photoshop,
Irfanview, or any mainstream viewer if you like.

Of course, I suspected that merely showing how dark exactly black is and
wasting 37 meg to do so, was not the file writer's intention. So I took
a look at the tags. Here's a tag dump for the first IFD:

ImageWidth (1 Short): 1024
ImageLength (1 Short): 500
BitsPerSample (1 Short): 16
Compression (1 Short): Uncompressed
Photometric (1 Short): MinIsBlack
StripOffsets (500 Long): 8, 2056, 4104, 6152, 8200, 10248, 12296,...
Orientation (1 Short): TopLeft
SamplesPerPixel (1 Short): 1
RowsPerStrip (1 Short): 1
StripByteCounts (500 Long): 2048, 2048, 2048, 2048, 2048, 2048, 2048,...
MinSampleValue (1 Short): 0
MaxSampleValue (1 Short): 1555
PlanarConfig (1 Short): Contig
PageNumber (2 Short): 0, 36
SampleFormat (1 Short): 1

Note the MaxSampleValue tag. The writer obviously (more or less
incorrectly) assumed that these SampleValue tags serve in defining the
value range.

(This is more or less incorrect, in that these tags are not meant to
influence interchangeable rendering. A better option, at least as far as
interchange is concerned, would have been for the writer to rescale the
value range it obviously uses internally to the full 16bit range of 0 to
65535 before writing. It may however make perfect sense in a less
interchangeable, more private use of TIFF though, in some applications,
for instance if most meaningfull content is in the range 0-1555 but rare
exceptions of higher range are possible and must not be lost in storage.
So it's not strictly speaking a bug or incorrect use of TIFF... but then
the sensible consequence is of course that the image is mostly black,
interpreted in the interchangeable sense.)

All this means that, your black rendering is correct in the
interchangeable sense. But if you want to render more like is probably
the intention, you'll have to rescale values. Rescaling after a first
scaling from 16bit to 8bit will mean that most shading information is
lost in your case, so making use of the RGBA interface is no good
option. Therefore, you'll have to read original 16bit values with the
TIFFReadEncodedStrip interface. For more information on that, see
http://www.remotesensing.org/libtiff/libtiff.html#strips, and of course
http://www.remotesensing.org/libtiff/man/index.html. If you've any
specific problems along this road, pop the questions.


Joris Van Damme
info@awaresystems.be
http://www.awaresystems.be/
Download your free TIFF tag viewer for windows here:
http://www.awaresystems.be/imaging/tiff/astifftagviewer.html

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