2006.04.06 19:40 "[Tiff] LibTiffDelphi problem with WriteEncodedStrip Newbee", by Thorsten Hagelstein

2006.04.11 22:07 "Re: [Tiff] LibTiffDelphi problem with WriteEncodedStrip Newbee", by Joris Van Damme

Thorsten,

Please keep all mail that can be of public interest inside the mailing list. This can be a good thread, useful to many.

> thank you very much for the code you posted. It really worked fine.

> Now I tried to understand the code to alter it, because I want to use > more kinds of compression. As I understood, to use TIFF-Compression

> CCITT3 or 4 I need for example Bitmaps with PixelFormat=pf1bit. I > tried to alter the code you posted like this:

>
> TIFFSetField(OpenTiff,TIFFTAG_SAMPLESPERPIXEL,1);
> TIFFSetField(OpenTiff,TIFFTAG_BITSPERSAMPLE,1);
> TIFFSetField(OpenTiff,TIFFTAG_COMPRESSION,COMPRESSION_CCITTFAX3);
>
> And disabled the code for making sure that it is pf24bit or pf32bit.
>
> But it doesn't work so far. I think I forgot something. Or is it just

> because I understood your code false? Can you please explain me? I'm > really new at this TIFF-things... *confused*

The altered parts you show, seem fine.

My guess is you didn't change the next few parts, and the strip memory building parts still assume pf24bit or pf32bit bitmap. Is that correct?

A complete adoption to save a pf1bit Bitmap to a G4 compressed TIFF, may look somewhat 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_COMPRESSION,COMPRESSION_CCITTFAX4);

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

        StripMemory,StripRowCount*RowSize)=0 then

This is untested, edited directly in mail client. If it seems to works, but black and white seem to be swapped in the TIFF file, try PHOTOMETRIC_MINISBLACK instead of PHOTOMETRIC_MINISWHITE.

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