AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2005.04.28 13:40 "[Tiff] Delphi 7, TIFF G3/4, Multipage", by Matthias Lach
2005.04.29 16:09 "Re: [Tiff] Delphi 7, TIFF G3/4, Multipage", by Joris
2005.05.02 16:12 "RE: [Tiff] Color TIFF/JPEG compression questions", by Frank, Jason
2005.05.02 13:44 "RE: [Tiff] Color TIFF/JPEG compression questions", by Grissom, Ed
2005.05.02 14:16 "Re: [Tiff] Color TIFF/JPEG compression questions", by Joris
2005.05.02 16:29 "RE: [Tiff] Color TIFF/JPEG compression questions", by Frank, Jason
2005.05.02 17:55 "Re: [Tiff] Color TIFF/JPEG compression questions", by Joris
2005.05.02 18:17 "RE: [Tiff] Color TIFF/JPEG compression questions", by Frank, Jason

2005.04.29 16:09 "Re: [Tiff] Delphi 7, TIFF G3/4, Multipage", by Joris

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;

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

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.

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.

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