Return-Path: <tiff-bounces@lists.maptools.org>
Received: from inas004.isp.belgacom.be (localhost [127.0.0.1])
        by inav011.isp.belgacom.be (8.12.11.20060308/8.12.11/Skynet-IN-AV-3.00) with ESMTP id k3BMCFeX025681
        for <joris.at.lebbeke@skynet.be>; Wed, 12 Apr 2006 00:12:15 +0200
        (envelope-from <tiff-bounces@lists.maptools.org>)
Received: from inmx008.isp.belgacom.be (inmx008.isp.belgacom.be [195.238.5.88])
        by inas004.isp.belgacom.be (8.12.11.20060308/8.12.11/Skynet-IN-AS-2.03) with ESMTP id k3BMC66L012942
        for <joris.at.lebbeke@skynet.be>; Wed, 12 Apr 2006 00:12:06 +0200
        (envelope-from <tiff-bounces@lists.maptools.org>)
Received: from duke.maptools.org (r153.dmsolutions.ca [209.217.116.153] (may be forged))
        by inmx008.isp.belgacom.be (8.12.11.20060308/8.12.11/Skynet-IN-2.32) with ESMTP id k3BMBxoo027560
        for <joris.at.lebbeke@skynet.be>; Wed, 12 Apr 2006 00:12:00 +0200
        (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 k3BM7Q7T015488;
	Tue, 11 Apr 2006 18:07:45 -0400
Received: from outmx012.isp.belgacom.be (outmx012.isp.belgacom.be
	[195.238.5.70])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id k3BM7PEu015460
	for <tiff@lists.maptools.org>; Tue, 11 Apr 2006 18:07:25 -0400
Received: from outmx012.isp.belgacom.be (localhost [127.0.0.1])
	by outmx012.isp.belgacom.be (8.12.11.20060308/8.12.11/Skynet-OUT-2.22)
	with ESMTP id k3BM7MMw024391
	for <tiff@lists.maptools.org>; Wed, 12 Apr 2006 00:07:22 +0200
	(envelope-from <joris.at.lebbeke@skynet.be>)
Received: from dfgrrxsknr4e (96.143-246-81.adsl-dyn.isp.belgacom.be
	[81.246.143.96])
	by outmx012.isp.belgacom.be (8.12.11.20060308/8.12.11/Skynet-OUT-2.22)
	with SMTP id k3BM7E8u024305; Wed, 12 Apr 2006 00:07:15 +0200
	(envelope-from <joris.at.lebbeke@skynet.be>)
Message-ID: <000c01c65db4$476cffe0$608ff651@dfgrrxsknr4e>
From: "Joris" <joris.at.lebbeke@skynet.be>
To: "TIFF mailing list" <tiff@lists.maptools.org>,
        "Thorsten Hagelstein" <T.Hagelstein@gmx.de>
References: <000101c65d87$1f1adc60$0301a8c0@thtoolznb>
Subject: Re: [Tiff] LibTiffDelphi problem with WriteEncodedStrip Newbee 
Date: Wed, 12 Apr 2006 00:07:06 +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.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.00001589
X-MSP-STORE: Wed, 12 Apr 2006 00:12:18 --21-99
Status:   

Thorsten,

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

Thorsten Hagelstein wrote:
> 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:

procedure WriteBitmapToTiff(Bitmap: TBitmap; Filename: String);
var
  OpenTiff: PTIFF;
  RowSize: Longword;
  RowsPerStrip: Longword;
  StripMemory: Pointer;
  StripIndex: Longword;
  StripRowOffset: Longword;
  StripRowCount: 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);
  if RowsPerStrip>Bitmap.Height then
    RowsPerStrip:=Bitmap.Height
  else if RowsPerStrip=0 then
    RowsPerStrip:=1;
  StripMemory:=GetMemory(RowsPerStrip*RowSize);
  OpenTiff:=TIFFOpen(PAnsiChar(Filename),'w');
  if OpenTiff=nil then
  begin
    FreeMemory(StripMemory);
    raise Exception.Create('Unable to create file '''+Filename+'''');
  end;
  TIFFSetField(OpenTiff,TIFFTAG_IMAGEWIDTH,Bitmap.Width);
  TIFFSetField(OpenTiff,TIFFTAG_IMAGELENGTH,Bitmap.Height);
  TIFFSetField(OpenTiff,TIFFTAG_PHOTOMETRIC,PHOTOMETRIC_MINISWHITE);
  TIFFSetField(OpenTiff,TIFFTAG_SAMPLESPERPIXEL,1);
  TIFFSetField(OpenTiff,TIFFTAG_BITSPERSAMPLE,1);
  TIFFSetField(OpenTiff,TIFFTAG_COMPRESSION,COMPRESSION_CCITTFAX4);
  TIFFSetField(OpenTiff,TIFFTAG_ROWSPERSTRIP,RowsPerStrip);
  StripIndex:=0;
  StripRowOffset:=0;
  while StripRowOffset<Bitmap.Height do
  begin
    StripRowCount:=RowsPerStrip;
    if StripRowCount>Bitmap.Height-StripRowOffset then
      StripRowCount:=Bitmap.Height-StripRowOffset;
    mb:=StripMemory;
    for ny:=StripRowOffset to StripRowOffset+StripRowCount-1 do
    begin
      CopyMemory(mb,Bitmap.ScanLine[ny],RowSize);
      Inc(mb,RowSize);
    end;
    if TIFFWriteEncodedStrip(OpenTiff,StripIndex,
        StripMemory,StripRowCount*RowSize)=0 then
    begin
      TIFFClose(OpenTiff);
      FreeMemory(StripMemory);
      raise Exception.Create('Failed to write '''+Filename+'''');
    end;
    Inc(StripIndex);
    Inc(StripRowOffset,StripRowCount);
  end;
  TIFFClose(OpenTiff);
  FreeMem(StripMemory);
end;

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.


Best regards,


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/
