AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2006.04.06 19:40 "[Tiff] LibTiffDelphi problem with WriteEncodedStrip Newbee", by Thorsten Hagelstein
2006.04.07 09:56 "Re: [Tiff] LibTiffDelphi problem with WriteEncodedStrip Newbee", by Joris
2006.04.11 16:43 "AW: [Tiff] LibTiffDelphi problem with WriteEncodedStrip Newbee", by Thorsten Hagelstein
2006.04.11 22:07 "Re: [Tiff] LibTiffDelphi problem with WriteEncodedStrip Newbee", by Joris
2006.04.13 15:02 "AW: [Tiff] LibTiffDelphi problem with WriteEncodedStrip Newbee", by Thorsten Hagelstein
2006.04.13 19:53 "RE: [Tiff] LibTiffDelphi problem with WriteEncodedStrip Newbee", by
2006.04.14 17:02 "Re: [Tiff] LibTiffDelphi problem with WriteEncodedStrip Newbee", by Joris
2006.04.15 10:46 "Re: [Tiff] LibTiffDelphi problem with WriteEncodedStrip Newbee", by Joris
2006.04.18 09:22 "Re: [Tiff] LibTiffDelphi problem with WriteEncodedStrip Newbee", by Thorsten Hagelstein

2006.04.15 10:46 "Re: [Tiff] LibTiffDelphi problem with WriteEncodedStrip Newbee", by Joris

Thorsten,

Joris wrote:

> Try again. If it still doesn't work, mail me your zipped bitmap and > relevant code, and I'll take a look.

I've received your code and testfile, made sure I used the distributed version of LibTiffDelphi, and... Sure enough, I can reproduce your problem.

Apparently, you need to set the planar config tag, even though SamplesPerPixel equals 1. I can only assume this is no longer a requirement in my own LibTiffDelphi, and I thus didn't see the problem. It is a bit silly requirement anyway, probably it got removed at some later time.

As after inserting the line...

  TIFFSetField(OpenTiff,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);

...before the setting of TIFFTAG_COMPRESSION, all is fine.

Since you had a problem, I was intriged by the fact that the proposed procedure didn't raise an exception. It was designed to do that, as is usual in Delphi code. The reason is, I got confused about error return value of TIFFWriteEncodedStrip (again!), and tested against 0 instead of -1.

One more thing I noticed in your own code, is that you write with G3 compression, instead of G4. There should be no advantage to G3 over G4, except for better error recovery in some situations that only possibly arise after corruption. But it's not as efficient. So I'd recommend you use G4 instead.

With these corrections in place, the code for writing a pf1bit Delphi TBitmap to a G4 compressed TIFF should be looking like this:

  RowSize: Longword;

  mb: PByte;
  ny: Longword;
begin
  if (Bitmap.PixelFormat<>pf1bit) then
    raise Exception.Create('WriteBitmapToTiff is designed for singlebit
                    bitmaps only');
  RowSize:=((Bitmap.Width+7) div 8);
  RowsPerStrip:=((256*1024) div RowSize);

  StripMemory:=GetMemory(RowsPerStrip*RowSize);

  TIFFSetField(OpenTiff,TIFFTAG_PHOTOMETRIC,PHOTOMETRIC_MINISWHITE);

TIFFSetField(OpenTiff,TIFFTAG_SAMPLESPERPIXEL,1);

TIFFSetField(OpenTiff,TIFFTAG_BITSPERSAMPLE,1);

  TIFFSetField(OpenTiff,TIFFTAG_PLANARCONFIG,PLANARCONFIG_CONTIG);

  TIFFSetField(OpenTiff,TIFFTAG_COMPRESSION,COMPRESSION_CCITTFAX4);

      CopyMemory(mb,Bitmap.ScanLine[ny],RowSize);
      Inc(mb,RowSize);

        StripMemory,StripRowCount*RowSize)=-1 then

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