AWARE [SYSTEMS] Imaging expertise for the Delphi developer
AWare Systems, Imaging expertise for the Delphi developer, Home TIFF and LibTiff Mailing List Archive

LibTiff Mailing List

TIFF and LibTiff Mailing List Archive
April 2008

Previous Thread
Next Thread

Previous by Thread
Next by Thread

Previous by Date
Next by Date

Contact

The TIFF Mailing List Homepage
This list is run by Frank Warmerdam
Archive maintained by AWare Systems



Valid HTML 4.01!



Thread

2008.04.16 13:26 "efficient thumbnailing", by Dr Michael J Chudobiak
2008.04.16 14:55 "Re: efficient thumbnailing", by Seth Price
2008.04.16 16:05 "Re: efficient thumbnailing", by Phillip Crews
2008.04.16 19:01 "Re: efficient thumbnailing", by Dr Michael J Chudobiak
2008.04.16 15:19 "Re: efficient thumbnailing", by <jcupitt@gmail.com>
2008.04.16 16:52 "Re: efficient thumbnailing", by Kai-uwe Behrmann
2008.04.16 17:29 "Re: efficient thumbnailing", by Dr Michael J Chudobiak
2008.04.16 19:37 "Re: efficient thumbnailing", by Kai-uwe Behrmann
2008.04.17 12:08 "Re: efficient thumbnailing", by Dr Michael J Chudobiak
2008.04.17 06:02 "Re: efficient thumbnailing", by Joris Van Damme
2008.04.17 11:57 "Re: efficient thumbnailing", by Dr Michael J Chudobiak
2008.04.17 13:48 "Re: efficient thumbnailing", by Joris Van Damme

2008.04.16 16:05 "Re: efficient thumbnailing", by Phillip Crews

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.