Return-Path: <tiff-bounces@remotesensing.org>
Received: from xserve.flids.com (adsl-065-083-169-202.sip.mco.bellsouth.net [65.83.169.202])
        by inmx015.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-2.32) with ESMTP id j3TGAEIY030115
        for <joris.at.lebbeke@skynet.be>; Fri, 29 Apr 2005 18:10:32 +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 AA28E228EFC9; Fri, 29 Apr 2005 12:09:53 -0400 (EDT)
X-Original-To: Tiff@remotesensing.org
Delivered-To: Tiff@remotesensing.org
Received: from outmx015.isp.belgacom.be (outmx015.isp.belgacom.be
	[195.238.2.87])
	by xserve.flids.com (Postfix) with ESMTP id BA58E228EFA5
	for <Tiff@remotesensing.org>; Fri, 29 Apr 2005 12:09:50 -0400 (EDT)
Received: from outmx015.isp.belgacom.be (localhost [127.0.0.1])
	by outmx015.isp.belgacom.be (8.12.11/8.12.11/Skynet-OUT-2.22) with
	ESMTP id j3TG9iNA020159
	for <Tiff@remotesensing.org>; Fri, 29 Apr 2005 18:09:44 +0200
	(envelope-from <joris.at.lebbeke@skynet.be>)
Received: from dfgrrxsknr4e (230-140.246.81.adsl.skynet.be [81.246.140.230])
	by outmx015.isp.belgacom.be (8.12.11/8.12.11/Skynet-OUT-2.22) with SMTP
	id j3TG9bgQ020097; Fri, 29 Apr 2005 18:09:37 +0200
	(envelope-from <joris.at.lebbeke@skynet.be>)
Message-ID: <000501c54cd5$dbcb5c90$e68cf651@dfgrrxsknr4e>
From: "Joris" <joris.at.lebbeke@skynet.be>
To: "Matthias Lach" <matthias.lach@telefax400.de>, <Tiff@remotesensing.org>
References: <200504281347.j3SDluK24767@dtagbrg1.telefax400.de>
Subject: Re: [Tiff] Delphi 7, TIFF G3/4, Multipage
Date: Fri, 29 Apr 2005 18:09:32 +0200
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.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Cc: 
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: 000000000023ceae.0000016c
X-MSP-STORE: Fri, 29 Apr 2005 18:10:39 +0200
Status:   

Matthias,

> I can open and see my file with
> "image1.Picture.Bitmap:= ReadTiffIntoBitmap(filename);"
> and can see the TIFF in my Image-Obj on the Form.

ReadTiffIntoBitmap is not part of LibTiffDelphi. It is thus helpful to mention
where it came from...

http://www.asmail.be/msg0055571626.html

ReadTiffIntoBitmap returns a TBitmap. Your calling code now 'owns' the TBitmap.
The statement 'Picture.Bitmap:=x' is the same as 'Picture.Assign(x)'. It does
not transfer ownership of the TBitmap to the TImage, but makes a 'deep copy'
instead (which boils down to incrementation of some usage counters and only a
copy of some small upper-level objects, so is still fast). As a result, your
calling code still owns the original TBitmap... and it fails to Destroy it.
Potentially huge memory leak.

Instead, do something like...
var
  m: TBitmap;
begin
  {add error handling too!!!!!!}
  m:=ReadTiffIntoBitmap(filename);
  image1.Picture.Assign(m);
  m.Free;

> - how can i make a the opened file fit into my Image-Obj ?

TImage has properties like Stretched and stuff... see your Delphi docs.

> - show width, hight, resolution, and pages! (multi-/single-page)

Ask the value of individual tags in a TIFF IFD with TIFFGetField.

For instance, to open a TIFF file, retrieve first page image width, and next
close it again, use this:

var
  OpenTiff: PTIFF;
  FirstPageWidth,FirstPageHeight: Cardinal;
begin
  OpenTiff:=TIFFOpen(Filename,'r');
  if OpenTiff=nil then raise Exception.Create(
           'Unable to open file '''+Filename+'''');
  TIFFGetField(OpenTiff,TIFFTAG_IMAGEWIDTH,@FirstPageWidth);
  TIFFGetField(OpenTiff,TIFFTAG_IMAGELENGTH,@FirstPageHeight);
  TIFFClose(OpenTiff);
  {FirstPageWidth and FirstPageHeigth are now what you are after}

The thing to remember here, is that a TIFF 'image header' is not a fixed set of
fields, like is the case with most image file formats. Instead, it's a set of
tags, and it can contain any tags the writer choose to write. For an overview of
most known tags, see http://www.awaresystems.be/imaging/tiff/tifftags.html.

> - how to cut off lines ?
> - how to raotate?

These are not things that are the responsability of LibTiff. Remember, LibTiff
is a TIFF codec, which means it is able to decode and encode a TIFF file, not
actually do image editing.

The proper way, is to delegate such stuff to things like TBitmap and such. In
Delphi, you would probably do this to open a TIFF, read the first page into a
TBitmap, and next make a second TBitmap that does not include upper two lines
(but this is from the top of my head, and I don't usually use this stuff, so
beware)

var
  m: TBitmap;
  n: TBitmap;
begin
  m:=ReadTiffIntoBitmap(filename);
  n:=TBitmap.Create;
  n.PixelFormat:=m.PixelFormat;
  n.Width:=m.Width;
  n.Height:=m.Height-2;
  n.Canvas.Draw(0,-2,m);
  m.Destroy;
  {n is now your image decoded from filename TIFF file, minus upper two lines}
  {you now own n here, and need to destroy or something in the end}

Same principle goes for rotating and stuff, you don't want to depend on
LibTiffDelphi for that, you'll need to read the Delphi docs and play around with
TBitmap and stuff.

> - what would be the way to handle mulit-part-tiffs?

See http://www.remotesensing.org/libtiff/man/index.html, and more specifically
http://www.remotesensing.org/libtiff/man/TIFFReadDirectory.3tiff.html and
related.



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@remotesensing.org
http://xserve.flids.com/mailman/listinfo/tiff
