Return-Path: <tiff-bounces@lists.maptools.org>
X-Original-To: info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-q.b-one.net (mx-q.one.com [91.198.169.248])
	by mail9.b-one.net (Postfix) with ESMTP id E1ACE400B7B
	for <info@awaresystems.be>; Tue, 11 May 2010 19:03:24 +0200 (CEST)
Received: by mx-q.b-one.net (Postfix, from userid 106)
	id D6BC645C2BC9; Tue, 11 May 2010 19:03:24 +0200 (CEST)
X-Virus-Scanned: by one.com
X-Spam-Score: 0
X-Spam-Level: 
X-Spam-Status: No, score=0 tagged_above=0 required=4 tests=[none]
X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4
Received: from lists.maptools.org (lists.maptools.org [65.39.174.144]) by
 mx-q.b-one.net (Postfix) with ESMTP id 1C5FA45C2BC8 for
 <info@awaresystems.be>; Tue, 11 May 2010 19:03:24 +0200 (CEST)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by
 lists.maptools.org (Postfix) with ESMTP id 58AE21D53626B; Tue, 11 May 2010
 12:02:37 -0500 (EST)
Received: from isadora.cybox.com (isadora.cybox.com [206.168.112.10]) by
 lists.maptools.org (Postfix) with ESMTP id C4E001D533CBF for
 <tiff@lists.maptools.org>; Tue, 11 May 2010 11:59:16 -0500 (EST)
Received: from aeolus.wriverody.net (vc7-1-52.dsl.indra.com [199.45.160.84])
 (authenticated) by isadora.cybox.com (msa 8.13.8/8.13.6) with ESMTP id
 o4BGxBYk005986 for <tiff@lists.maptools.org>; Tue, 11 May 2010 10:59:11 -0600
Message-ID: <4BE98CD9.5080305@cybox.com>
Date: Tue, 11 May 2010 10:59:05 -0600
From: Richard Nolde <richard.nolde@cybox.com>
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9)
 Gecko/20100330 Fedora/3.0.4-1.fc12 Thunderbird/3.0.4
MIME-Version: 1.0
To: Tiff Listserve <tiff@lists.maptools.org>
Subject: [Tiff] Combining multiple G4 images into a single output image
X-BeenThere: tiff@lists.maptools.org
X-Mailman-Version: 2.1.9
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>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

Oliver wrote:
Thank you Richard.
Yes, i want to combine several images of different size onto a bigger one, so pointing me to tiffcrop was a good idea. After getting a bit deeper into libtiff i guess it would be ok to read (or create) the background image (i call it "the pasteboard") into memory, so it does not matter if the TIFF organization was tiled or striped. Then read one image after the other an paste the lines at the location given. Therefore i need to access the image raster pixel in memory, calc the offset and overwrite the background image data with the read data from each image. The order i read the images is equal to their layer in the
pasteboard. After that i can write out the pasteboard image as a new file.

Now, is it ok (in question of speed) to use TIFFReadScanline or should I use some lower level functions?

Oliver

If you are going to make a special purpose utility and you are sure that you will never need to access data that is compressed in ways that require access to multiple scanlines at once, the TIFFReadScanline interface should work fine.  My first version of tiffcrop used that interface but I changed to a strip oriented reading approach so that I could handle YCbCr compressed data.  From what I remember, libtiff is going to read a whole strip anyway and then hand off a scanline at a time as your read from the strip even if you call TIFFReadScanline.

Depending on the size of your final image, you may have to allocate a working buffer that is only as large as a few scanlines, ideally the size of a full strip in the output image rather than creating the full output image in memory before writing any of it out. This assumes all your input images will be pasted into the output buffer from left to right and the final image will be N * the width of the input images but only 1 * the height of the input image. If you have multiple rows and columns of subimages in the output image, you have to calculate the width of the widest subset and pad every scanline to match.

My approach in tiffcrop handles tiled or strip oriented images and always loads them into a single memory block as interleaved RGB/Grayscale/Bilevel samples at depths from 1 to 32 bits per sample without expanding them to a larger sample size for the intermediate processing. After manipulating the data, the image can be written out as tiles or strips regardless of the input formats.

The difference between what you want to do and what tiffcrop does involves your use of multiple input files that are opened concurrently rather than sequentially. It might be possible to add a command line option and an alternative path through the code for opening all the files at once with additional data structures to handle access to all of the TIFF* handles. Most of the code that you need has a counterpart in tiffcrop that you could adapt to deal with multiple input files by keeping track of the read offsets into each input file and updating the write offset after each read. Reading non-byte-aligned samples is required to crop or combine images that are not a multiple of 8 bits per scanline but you will have to track the byte AND bit offsets across multiple input images when you paste the input scanlines into your output buffer. I only have to deal with that within a single source image. If you are reading a scanline at a time, it should not be too hard for Bilevel data.
  I am thinking about some code to speed up the masking operation but haven't written anything yet.

Richard

Regarding memory mapped files. There may be greater benefit for memory mapping in cases where an image is being rotated since access to the source data will require multiple passes through a given scanline.


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