Return-Path: <tiff-bounces@lists.maptools.org>
Received: from inas025.isp.belgacom.be (localhost [127.0.0.1])
        by inav015.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-AV-3.00) with ESMTP id jBCN4DAX022635
        for <joris.at.lebbeke@skynet.be>; Tue, 13 Dec 2005 00:04:13 +0100
        (envelope-from <tiff-bounces@lists.maptools.org>)
Received: from inmx009.isp.belgacom.be (inmx009.isp.belgacom.be [195.238.5.146])
        by inas025.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-AS-2.03) with ESMTP id jBCN44GG024533
        for <joris.at.lebbeke@skynet.be>; Tue, 13 Dec 2005 00:04:04 +0100
        (envelope-from <tiff-bounces@lists.maptools.org>)
Received: from duke.maptools.org (r153.dmsolutions.ca [209.217.116.153] (may be forged))
        by inmx009.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-2.32) with ESMTP id jBCN3req024995
        for <joris.at.lebbeke@skynet.be>; Tue, 13 Dec 2005 00:03:53 +0100
        (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 jBCMwkAC006401;
	Mon, 12 Dec 2005 17:58:51 -0500
Received: from scooby.simplesystems.org (scooby.simplesystems.org
	[65.66.246.67])
	by duke.maptools.org (8.12.11/8.12.10) with ESMTP id jBCMwiLY006398
	for <tiff@lists.maptools.org>; Mon, 12 Dec 2005 17:58:45 -0500
Received: from blade.simplesystems.org (blade.simplesystems.org [65.66.246.74])
	by scooby.simplesystems.org (8.12.10+Sun/8.12.10) with ESMTP id
	jBCMwius011493; Mon, 12 Dec 2005 16:58:44 -0600 (CST)
Date: Mon, 12 Dec 2005 16:58:44 -0600 (CST)
From: Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
X-X-Sender: bfriesen@blade.simplesystems.org
To: Zuyuan Wang <zuyuan.wang@wsl.ch>
Subject: Re: [Tiff] how about the pixel order if I use TIFFReadScanline?
In-Reply-To: <5.2.1.1.1.20051212151607.01dc6878@mail.wsl.ch>
Message-ID: <Pine.SOC.4.60.0512121650230.4804@blade.simplesystems.org>
References: <5.2.1.1.1.20051212151607.01dc6878@mail.wsl.ch>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
Cc: tiff@lists.maptools.org
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.00000f57
X-MSP-STORE: Tue, 13 Dec 2005 00:04:16 --22-99
Status:   

On Mon, 12 Dec 2005, Zuyuan Wang wrote:

>   I try to use the TIFFReadScanline to read the TIFF image.  What I did is:
>
> 1) use the TIFFScanline for read the image row by row
>          for (row = 0; row < height; row++){
>    	result = TIFFReadScanline(tif, scanline, row,0); }

And this does???  Does it just overwrite the existing scanline buffer 
content with the content of the next scanline?

> 2)  later on, put each line to a whole buffer RGB:
>         for (i=0;i<width;i++){
>
> 	*(RGB+row*width*3+i*3)=*(scanline+i*3);
> 	*(RGB+row*width*3+i*3+1)=*(scanline+i*3+1);
> 	*(RGB+row*width*3+i*3+2)=*(scanline+i*3+2);}}

This seems very complicated.  TIFF scanlines are packed and (for an 
RGB image) are in RGB order.  If the data is 8 or 16-bit, then it is 
reasonably easy to access as a char array or array of short, but 
otherwise you need to do whatever bit-unstuffing is necessary to 
obtain the samples.  16, 24, and 32-bit samples will be converted (by 
libtiff) to the native endian order.  The unpacking can be challenging 
to implement, it usually makes sense to immediately convert the 
samples into your preferred internal representation rather than buffer 
them up and do the conversion later.

Also, rather than doing all the math, you might find it easier (and 
faster) to use pointers and increment the pointer positions.

> But when I open the RGB buffer pixel by pixel, it seems that it is not the 
> original image( I mean top to bottom, left to right). I think that I must 
> misunderstand the pixel order of the TIFFScanline, but I have no idea about

Pixel order is indeed top to bottom, left to right, although the final 
page orientation (indicated by a tag) may differ from that.

Bob
======================================
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/
_______________________________________________
Tiff mailing list: Tiff@lists.maptools.org
http://lists.maptools.org/mailman/listinfo/tiff
http://www.remotesensing.org/libtiff/
