Return-Path: <awaresystems.be+caf_=filtered=awaresystems.be@gmail.com>
X-Original-To: filtered@awaresystems.be
Delivered-To: filtered@awaresystems.be
Received: from mx-i.one.com (mx-i.one.com [91.198.169.56])
	by mail9.b-one.net (Postfix) with ESMTP id 5F941401F0F
	for <filtered@awaresystems.be>; Thu,  5 Jan 2012 10:41:52 +0100 (CET)
X-Virus-Scanned: by one.com
X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "MIME-Version"
Received-SPF: pass (mx-i: domain of awaresystems.be+caf_=filtered=awaresystems.be@gmail.com designates 209.85.160.48 as permitted sender)
X-Greylist: whitelisted by SQLgrey-1.8.0-rc2
Received: from mail-pw0-f48.google.com (mail-pw0-f48.google.com [209.85.160.48])
	by mx-i.one.com (Postfix) with ESMTP id 9D9DE12A2609
	for <filtered@awaresystems.be>; Thu,  5 Jan 2012 09:41:51 +0000 (UTC)
Received: by pbaa12 with SMTP id a12so259449pba.21
        for <filtered@awaresystems.be>; Thu, 05 Jan 2012 01:41:50 -0800 (PST)
Received: by 10.68.72.69 with SMTP id b5mr3407033pbv.120.1325756510595;
        Thu, 05 Jan 2012 01:41:50 -0800 (PST)
X-Forwarded-To: filtered@awaresystems.be
X-Forwarded-For: awaresystems.be@gmail.com filtered@awaresystems.be
Delivered-To: awaresystems.be@gmail.com
Received: by 10.142.215.12 with SMTP id n12cs314594wfg;
        Thu, 5 Jan 2012 01:41:48 -0800 (PST)
Received: by 10.68.199.4 with SMTP id jg4mr3376125pbc.131.1325756507288;
        Thu, 05 Jan 2012 01:41:47 -0800 (PST)
Received-SPF: softfail (google.com: best guess record for domain of transitioning tiff-bounces@lists.maptools.org does not designate 91.198.169.249 as permitted sender) client-ip=91.198.169.249;
Received: by 10.130.152.9 with POP3 id z9mf13658783dad.5;
        Thu, 05 Jan 2012 01:41:47 -0800 (PST)
X-Gmail-Fetch-Info: info@awaresystems.be 1 pop.awaresystems.be 110 info@awaresystems.be
X-Original-To: info@awaresystems.be
Delivered-To: info@awaresystems.be
Received: from mx-r.one.com (mx-r.one.com [91.198.169.249])
	by mail9.b-one.net (Postfix) with ESMTP id 681E4401F0F
	for <info@awaresystems.be>; Thu,  5 Jan 2012 10:34:55 +0100 (CET)
X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "MIME-Version"
X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2
Received: from lists.maptools.org (lists.maptools.org [65.39.174.144])
	by mx-r.one.com (Postfix) with ESMTP id C82AC39AE891
	for <info@awaresystems.be>; Thu,  5 Jan 2012 09:34:54 +0000 (UTC)
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by lists.maptools.org (Postfix) with ESMTP id B39C91ED919;
	Thu,  5 Jan 2012 04:33:35 -0500 (EST)
Received: from mail-qy0-f172.google.com (mail-qy0-f172.google.com
	[209.85.216.172])
	by lists.maptools.org (Postfix) with ESMTPS id 183521EDA19
	for <tiff@lists.maptools.org>; Thu,  5 Jan 2012 04:12:57 -0500 (EST)
Received: by qcsf15 with SMTP id f15so194288qcs.3
	for <tiff@lists.maptools.org>; Thu, 05 Jan 2012 01:12:56 -0800 (PST)
MIME-Version: 1.0
Received: by 10.229.78.215 with SMTP id m23mr448366qck.108.1325754776743; Thu,
	05 Jan 2012 01:12:56 -0800 (PST)
Received: by 10.229.212.71 with HTTP; Thu, 5 Jan 2012 01:12:56 -0800 (PST)
In-Reply-To: <alpine.GSO.2.01.1201040908400.15666@freddy.simplesystems.org>
References: <CAPKW8o0JcCJT4LRkVNDpnnEBjFaC23tASwwR6cCv6J_4S-xMaw@mail.gmail.com>
	<alpine.GSO.2.01.1201040826280.15666@freddy.simplesystems.org>
	<CAPKW8o2KUkb1A-ObBiYBHp-tbfMoBdUw--LCU01eYpQ5HO3Cxw@mail.gmail.com>
	<alpine.GSO.2.01.1201040908400.15666@freddy.simplesystems.org>
Date: Thu, 5 Jan 2012 10:12:56 +0100
Message-ID: <CAPKW8o3nP0E=-knpuF8pn__yVfeNRd0o+nYTEBWZni_mkHGOng@mail.gmail.com>
From: Martin Alegre <tin.alegre@gmail.com>
To: Olivier Paquet <olivier.paquet@gmail.com>, 
	Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
Cc: tiff@lists.maptools.org
Subject: Re: [Tiff] reading rgb values from 16 bits tif images
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: multipart/mixed; boundary="===============1821910934=="
Mime-version: 1.0
Sender: tiff-bounces@lists.maptools.org
Errors-To: tiff-bounces@lists.maptools.org

--===============1821910934==
Content-Type: multipart/alternative; boundary=00235429dfa486f20804b5c45676

--00235429dfa486f20804b5c45676
Content-Type: text/plain; charset=ISO-8859-1

Hi Olivier & Bob,

Thanks a lot for your advices. So far, I'm dealing with very limited sort
of TIFF formats. Therefore, following the code snippet that Olivier
suggested, I'm allowed to correctly load the data into memory. However,
I'll have the suggestions of you Bob, if I need to consider more TIFF
formats. Below, I'm pasting the code, I'm using, just in case somebody in
the future might need it as well.

Best,

Tin

   TIFF* tif = TIFFOpen("example.tif", "r");
   if (tif) {

        uint32 imagelength, imagewidth;
        tdata_t buf;
        uint32 row, col;
        uint16 config, nsamples;

        TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &imagelength);
        TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &imagewidth);
        TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &config);
        TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &nsamples);

        buf = _TIFFmalloc(TIFFScanlineSize(tif));
        if (config == PLANARCONFIG_CONTIG) {
            for (row = 0; row < imagelength; row++){
                TIFFReadScanline(tif, buf, row);

                for(col=0; col < imagewidth; col++){

                    if (nsamples == 1){
                        uint16 gray        =
static_cast<uint16*>(buf)[col*nsamples+0];
                        std::cout << gray << " ";
                    }
                    else if(nsamples == 3 ){
                        uint16 red        =
static_cast<uint16*>(buf)[col*nsamples+0];
                        uint16 green    =
static_cast<uint16*>(buf)[col*nsamples+1];
                        uint16 blue        =
static_cast<uint16*>(buf)[col*nsamples+2];
                        std::cout << red << " " << green << " " << blue <<
std::endl;
                    }
                }
                std::cout << "\n";
            }
        } else if (config == PLANARCONFIG_SEPARATE) {

            std::cerr << "Not yet supported!\n";
            return (EXIT_FAILURE);

        }
        _TIFFfree(buf);
        TIFFClose(tif);
    }


On Wed, Jan 4, 2012 at 4:24 PM, Bob Friesenhahn <
bfriesen@simple.dallas.tx.us> wrote:

> On Wed, 4 Jan 2012, Martin Alegre wrote:
>
>  Hi Bob,
>>
>> Thanks for your suggestions on the high-level libraries. At the
>> beginning, I was thniking to use Magick++
>> for my application, but it seemed to me that it was going to be more
>> faster to integrate the libtiff
>> library into my code, also due to time constraints. If you have any
>> illustrations on how to use libtiff
>> for 16bits images, it will be great or if you also have some good
>> webpointers where I could get more
>> information? I found a very illustrative webpage on how to use libtiff
>> (http://bitmiracle.com/**libtiff/help/samples.aspx<http://bitmiracle.com/libtiff/help/samples.aspx>),
>> but it was mainly for C#, and I'm currently working
>> with C++.
>>
>
> It makes a huge difference if you plan to accept arbitrary TIFF files
> written by some other software or if you only plan to accept a very limited
> set of TIFF formats.  If the former, then you should expect to do quite a
> lot of development (e.g. weeks, months).
>
> You can use TIFFReadRGBAStrip() to access strip-oriented files or
> TIFFReadTile() for tile-oriented files.  These interfaces provide "raw"
> decompressed + native-endian-swapped pixel sample data.  The swapping to
> native endian is only done if the sample bits are evenly divisible by 8
> (e.g. 16-bit "short" is swapped to native format).
>
>
> Bob
> --
> Bob Friesenhahn
> bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/**
> users/bfriesen/ <http://www.simplesystems.org/users/bfriesen/>
> GraphicsMagick Maintainer,    http://www.GraphicsMagick.org/
>

--00235429dfa486f20804b5c45676
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi Olivier &amp; Bob,<br><br>Thanks a lot for your advices. So far, I&#39;m=
 dealing with very limited sort of TIFF formats. Therefore, following the c=
ode snippet that Olivier suggested, I&#39;m allowed to correctly load the d=
ata into memory. However, I&#39;ll have the suggestions of you Bob, if I ne=
ed to consider more TIFF formats. Below, I&#39;m pasting the code, I&#39;m =
using, just in case somebody in the future might need it as well.<br>
<br>Best,<br><br>Tin<br><br>=A0=A0 TIFF* tif =3D TIFFOpen(&quot;example.tif=
&quot;, &quot;r&quot;);<br>=A0=A0 if (tif) {<br><br>=A0=A0=A0 =A0=A0=A0 uin=
t32 imagelength, imagewidth;<br>=A0=A0=A0 =A0=A0=A0 tdata_t buf;<br>=A0=A0=
=A0 =A0=A0=A0 uint32 row, col;<br>=A0=A0=A0 =A0=A0=A0 uint16 config, nsampl=
es;<br>
<br>=A0=A0=A0 =A0=A0=A0 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &amp;imagele=
ngth);<br>=A0=A0=A0 =A0=A0=A0 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &amp;im=
agewidth);<br>=A0=A0=A0 =A0=A0=A0 TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &=
amp;config);<br>=A0=A0=A0 =A0=A0=A0 TIFFGetField(tif, TIFFTAG_SAMPLESPERPIX=
EL, &amp;nsamples);<br>
<br>=A0=A0=A0 =A0=A0=A0 buf =3D _TIFFmalloc(TIFFScanlineSize(tif));<br>=A0=
=A0=A0 =A0=A0=A0 if (config =3D=3D PLANARCONFIG_CONTIG) {<br>=A0=A0=A0 =A0=
=A0=A0 =A0=A0=A0 for (row =3D 0; row &lt; imagelength; row++){<br>=A0=A0=A0=
 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 TIFFReadScanline(tif, buf, row);<br><br>=A0=
=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 for(col=3D0; col &lt; imagewidth; col+=
+){<br>
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 <br>=A0=A0=A0 =A0=A0=A0 =
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 if (nsamples =3D=3D 1){<br>=A0=A0=A0 =A0=A0=
=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 uint16 gray=A0=A0=A0 =A0=A0=A0 =
=3D static_cast&lt;uint16*&gt;(buf)[col*nsamples+0];<br>=A0=A0=A0 =A0=A0=A0=
 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 std::cout &lt;&lt; gray &lt;&lt; &=
quot; &quot;;<br>
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 }<br>=A0=A0=A0 =A0=A0=A0 =
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 else if(nsamples =3D=3D 3 ){<br>=A0=A0=A0 =A0=
=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 uint16 red=A0=A0=A0 =A0=A0=
=A0 =3D static_cast&lt;uint16*&gt;(buf)[col*nsamples+0];<br>=A0=A0=A0 =A0=
=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 uint16 green=A0=A0=A0 =3D st=
atic_cast&lt;uint16*&gt;(buf)[col*nsamples+1];<br>
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 uint16 blue=A0=
=A0=A0 =A0=A0=A0 =3D static_cast&lt;uint16*&gt;(buf)[col*nsamples+2];<br>=
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 std::cout &lt;&=
lt; red &lt;&lt; &quot; &quot; &lt;&lt; green &lt;&lt; &quot; &quot; &lt;&l=
t; blue &lt;&lt; std::endl;<br>
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 }<br>=A0=A0=A0 =A0=A0=A0 =
=A0=A0=A0 =A0=A0=A0 }<br>=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 std::cout =
&lt;&lt; &quot;\n&quot;;<br>=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 }<br>=A0=A0=A0 =
=A0=A0=A0 } else if (config =3D=3D PLANARCONFIG_SEPARATE) {<br><br>=A0=A0=
=A0 =A0=A0=A0 =A0=A0=A0 std::cerr &lt;&lt; &quot;Not yet supported!\n&quot;=
;<br>
=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 return (EXIT_FAILURE);<br>=A0=A0=A0 =A0=A0=A0=
 =A0=A0=A0 <br>=A0=A0=A0 =A0=A0=A0 }<br>=A0=A0=A0 =A0=A0=A0 _TIFFfree(buf);=
<br>=A0=A0=A0 =A0=A0=A0 TIFFClose(tif);<br>=A0=A0=A0 }<br><br><br><div clas=
s=3D"gmail_quote">On Wed, Jan 4, 2012 at 4:24 PM, Bob Friesenhahn <span dir=
=3D"ltr">&lt;<a href=3D"mailto:bfriesen@simple.dallas.tx.us">bfriesen@simpl=
e.dallas.tx.us</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div class=3D"im">On Wed, 4 Jan 2012, Martin=
 Alegre wrote:<br>
<br>
</div><div class=3D"im"><blockquote class=3D"gmail_quote" style=3D"margin:0=
 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Bob,<br>
<br>
Thanks for your suggestions on the high-level libraries. At the beginning, =
I was thniking to use Magick++<br>
for my application, but it seemed to me that it was going to be more faster=
 to integrate the libtiff<br>
library into my code, also due to time constraints. If you have any illustr=
ations on how to use libtiff<br>
for 16bits images, it will be great or if you also have some good webpointe=
rs where I could get more<br>
information? I found a very illustrative webpage on how to use libtiff<br>
(<a href=3D"http://bitmiracle.com/libtiff/help/samples.aspx" target=3D"_bla=
nk">http://bitmiracle.com/<u></u>libtiff/help/samples.aspx</a>), but it was=
 mainly for C#, and I&#39;m currently working<br>
with C++.<br>
</blockquote>
<br></div>
It makes a huge difference if you plan to accept arbitrary TIFF files writt=
en by some other software or if you only plan to accept a very limited set =
of TIFF formats. =A0If the former, then you should expect to do quite a lot=
 of development (e.g. weeks, months).<br>

<br>
You can use TIFFReadRGBAStrip() to access strip-oriented files or TIFFReadT=
ile() for tile-oriented files. =A0These interfaces provide &quot;raw&quot; =
decompressed + native-endian-swapped pixel sample data. =A0The swapping to =
native endian is only done if the sample bits are evenly divisible by 8 (e.=
g. 16-bit &quot;short&quot; is swapped to native format).<div class=3D"HOEn=
Zb">
<div class=3D"h5"><br>
<br>
Bob<br>
-- <br>
Bob Friesenhahn<br>
<a href=3D"mailto:bfriesen@simple.dallas.tx.us" target=3D"_blank">bfriesen@=
simple.dallas.tx.us</a>, <a href=3D"http://www.simplesystems.org/users/bfri=
esen/" target=3D"_blank">http://www.simplesystems.org/<u></u>users/bfriesen=
/</a><br>

GraphicsMagick Maintainer, =A0 =A0<a href=3D"http://www.GraphicsMagick.org/=
" target=3D"_blank">http://www.GraphicsMagick.org/</a><br>
</div></div></blockquote></div><br>

--00235429dfa486f20804b5c45676--

--===============1821910934==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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