Received: from mailgate002.isp.belgacom.be (mailgate002.isp.belgacom.be [195.238.6.87])
	by maildelivery006.isp.belgacom.be (Postfix) with ESMTP id 585A434001C
	for <joris.at.lebbeke@skynet.be>; Wed, 16 Apr 2008 18:25:32 +0200 (CEST)
Authentication-Results: in.mx.skynet.be; dkim=neutral (message not signed) header.i=none
Received: from r153.dmsolutions.ca (HELO duke.maptools.org) ([209.217.116.153])
  by in.mx.skynet.be with ESMTP; 16 Apr 2008 18:25:31 +0200
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 m3GG5JSe002743;
	Wed, 16 Apr 2008 12:06:25 -0400
Received: from cerious.com (mail.cerious.com [66.193.70.90])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id m3GG5Gvv002739
	for <tiff@lists.maptools.org>; Wed, 16 Apr 2008 12:05:16 -0400
Received: from [192.168.1.113] (account pcrews HELO [192.168.1.113])
	by cerious.com (CommuniGate Pro SMTP 4.1.8)
	with ESMTP id 9406013 for tiff@lists.maptools.org;
	Wed, 16 Apr 2008 12:05:14 -0400
Message-ID: <480623CE.3040202@cerious.com>
Date: Wed, 16 Apr 2008 12:05:34 -0400
From: Phillip Crews <pcrews@cerious.com>
Organization: Cerious Software Inc.
User-Agent: Thunderbird 2.0.0.12 (Windows/20080213)
MIME-Version: 1.0
To: tiff@lists.maptools.org
Subject: Re: [Tiff] efficient thumbnailing
References: <4805FE97.8010109@avtechpulse.com>
	<A758B1C4-7792-42F7-AE2C-CFD97D714B19@pricepages.org>
In-Reply-To: <A758B1C4-7792-42F7-AE2C-CFD97D714B19@pricepages.org>
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.00002be6
X-MSP-STORE: Wed, 16 Apr 2008 18:24:23 +0200
Status: RO

Seth Price wrote:
> I would like to say that I've just been having the exact same problem, 
> except I've been using ImageMagick and GDAL. The images I'm working 
> with are 14400x14400px.
>
> Any solutions out there?
> ~Seth
You can skip most scan lines in untiled, non-YCbCr images if they are 
uncompressed, or compressed with rowsperstrip = 1, and only load enough 
scan lines to get a good thumbnail. (I use 3 * the thumbnail height, 
then reduce). This doesn't produce as nice of a thumbnail as a fully 
resampled image, but it does a good job.

Here's some pseudo-code with no error checking. Variable names should be 
obvious. All scan lines retain their full width, so your 14400 x 14400 
images would load as (for example) 14400 x 300, eliminating 14100 scan 
line reads and decompressions, requiring 2% of the memory required for a 
full image load, and much less CPU for resampling to 100x100.

- For planar-contiguous images, I only use this code if height > 
thumbnail_height * 8.
- For planar-separate images, because of the disk seeks between the 
planes, I only use this code if height > thumbnail_height * planes * 8.
- There may be some improvement with rowsperstrip > 1, especially with 
memory usage.
- For compressed images with rowsperstrip = height, the library will 
decompress the whole file into memory anyway

    loadheight = thumbnail_height * 3;
    if (planar_config == PLANARCONFIG_CONTIG) {
        PFNCTGOUT put;
        BYTE *pbuf = malloc(TIFFScanlineSize(tif));
        put = GetContigOutputRoutine();
        for (row=0; row < loadheight; row++) {
            fromrow = (row * height) / loadheight;
            TIFFReadScanline(tif, pbuf, fromrow, 0);
            (*put)(my_image, row, 0, pbuf, width, 1, 1, 0);
        }
    } else {
        PFNSEPOUT put;
        BYTE *r, *g, *b, *a;
        r = pbuf = malloc(4*TIFFScanlineSize(tif));
        g = r + TIFFScanlineSize(tif);
        b = g + TIFFScanlineSize(tif);
        a = b + TIFFScanlineSize(tif);
        put = GetSeparateOutputRoutine();
        for (row=0; row < loadheight; row++) {
            fromrow = (row * height) / loadheight;
            TIFFReadScanline(tif, r, fromrow, 0);
            TIFFReadScanline(tif, g, fromrow, 1);
            TIFFReadScanline(tif, b, fromrow, 2);
            if (sampperpix == 4)
                TIFFReadScanline(tif, a, fromrow, 3);
            (*put)(my_image, row, 0, r, g, b, a, width, 1, 1, 0);
        }
    }

This significantly speeds thumbnailing of very large images as long as 
they meet the criteria.

_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
