Return-Path: <tiff-bounces@lists.maptools.org>
Received: from inas024.isp.belgacom.be (localhost [127.0.0.1])
        by inav004.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-AV-3.00) with ESMTP id j8DHs8Ye008415
        for <joris.at.lebbeke@skynet.be>; Tue, 13 Sep 2005 19:54:09 +0200
        (envelope-from <tiff-bounces@lists.maptools.org>)
Received: from inmx004.isp.belgacom.be (inmx004.isp.belgacom.be [195.238.3.48])
        by inas024.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-AS-2.03) with ESMTP id j8DHs6wd026218
        for <joris.at.lebbeke@skynet.be>; Tue, 13 Sep 2005 19:54: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 inmx004.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-2.32) with ESMTP id j8DHrw6Y029480
        for <joris.at.lebbeke@skynet.be>; Tue, 13 Sep 2005 19:53:58 +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 j8DHn2m2009803;
	Tue, 13 Sep 2005 13:49:21 -0400
Received: from statler.midrivers.com (smtp1.midrivers.com [216.228.34.53])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id j8DHmxeM009800
	for <tiff@lists.maptools.org>; Tue, 13 Sep 2005 13:48:59 -0400
Received: from [192.168.200.16] ([216.228.33.151])
	by statler.midrivers.com (8.11.6/8.11.6) with ESMTP id j8DHmw000746
	for <tiff@lists.maptools.org>; Tue, 13 Sep 2005 11:48:58 -0600
Message-ID: <43271109.6080506@midrivers.com>
Date: Tue, 13 Sep 2005 11:48:57 -0600
From: Mark Pilon <mpilon@midrivers.com>
User-Agent: Mozilla Thunderbird 1.0 (X11/20041206)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: tiff@lists.maptools.org
Subject: Re: [Tiff] read-by-scan-line buffers full strip, part 3
References: <4326FBAA.1090401@midrivers.com>
	<000901c5b883$d16ac870$4baef651@dfgrrxsknr4e>
In-Reply-To: <000901c5b883$d16ac870$4baef651@dfgrrxsknr4e>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
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.00000c13
X-MSP-STORE: Tue, 13 Sep 2005 19:54:15 +0200
Status:   

Joris,

Thanks for this -- exactly what I need.  and I'm not even playing w/ a really small-memory system; I have several megabytes of memory I can alloc for this -- but not 60+.

thanks again,

Mark


Joris wrote:
> Mark Pilon wrote:
> 
>>i.e. using libtiff part-way to get access to the compressed data, but
>>perform the decompression in smaller increments than the whole strip.
> 
> 
> Much of my first reply stands. And you're fortunate: the LZW compression
> codec isn't very complicated. Neither is your type of image, it's just a
> single plane, single strip, without any subsampling or prediction or
> whatever... Still, though, this will keep you occupied for at least a
> few days I guess... ;-)
> 
> Use TIFFGetField to get the offsets and bytecount of the single strip as
> detailed.
> 
> The next part of your code should be thought of as a pulling pipeline
> scheme. Whatever the destination of the scanlines is, this pulls the
> scanlines from the LZW decoder as they are needed. This decoder pulls
> data from the strip as it needs it, small buffer at a time (say 2K).
> 
> 'Pulling from the strip' may be implemented as calls to the seek and
> read proc that are given in TIFFClientOpen, and pointed to in the
> LibTiff TIFF structure. That way, it'll work whatever IO layer is used
> added to LibTiff. The LZW decoder, you'll have to build. Use tif_lzw.c
> as a source of documentation. There is also a good deal of detail on the
> LZW codec in the TIFF spec (section 13, page 57 and below), but do make
> sure to also peek at tif_lzw.c as this documents also an older pre-6.0
> LZW encoding that is not detailed in the spec and that you may or may
> not need to include.
> 
> Essentially, what you want to do is rework the decoder in tif_lzw.c,
> such that
> - it returns when it has build a single scanline
> - where it currently merely accessed the compressed data in available
> memory, it makes a call to a reading helper procedure instead. This
> helper procedure will check whether data is available still in the small
> buffer, and if it's not, refill it
> 
> A particular issue to keep in mind is that neither your input buffer nor
> your output buffer of your own LZW decoder respects scanline boundaries.
> For your input buffer, this is normal, of course, since you can't
> predict how much input you'll need to output a scanline. Thus, simply
> keep the input buffer around, without changing its state from one
> scanline-pulling call to the next.
> 
> For your output buffer, this is because the LZW compression doesn't
> 'stop and restart' at scanline boundaries. It may very well be that a
> particular LZW compressed code resolves to five uncompressed bytes,
> where your scanline has only 2 bytes left, and the next three bytes are
> the first three of the next scanline. This is a nasty issue, that is
> resolved on tif_lzw with 'restart logic' with the aid of such state
> variables as 'dec_restart' and related.
> 
> Good luck!
> 
> 
> 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
> 
> 

-- 
Mark Pilon
Konica Minolta Printing Solutions U.S.A.

P.O. Box 37
325 Dawson County Road 227
Fallon, MT.  59326-0037
1-406-853-0433
mailto: mark.pilon@bil.konicaminolta.us
_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
