2011.12.22 00:50 "[Tiff] Announcing Libtiff 4.0.0", by Bob Friesenhahn

2012.01.05 09:12 "Re: [Tiff] reading rgb values from 16 bits tif images", by Martin Alegre

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/