AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2005.12.12 14:24 "[Tiff] how about the pixel order if I use TIFFReadScanline?", by Zuyuan Wang
2005.12.12 22:58 "Re: [Tiff] how about the pixel order if I use TIFFReadScanline?", by Bob Friesenhahn

2005.12.12 22:58 "Re: [Tiff] how about the pixel order if I use TIFFReadScanline?", by Bob Friesenhahn

     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/