2003.11.21 03:17 "[Tiff] Reading Tiff Image files", by Sridhar Duggireddy

2003.11.21 03:17 "[Tiff] Reading Tiff Image files", by Sridhar Duggireddy

Hi,

I have a doubt. What does StripOffsets mean? Where is it used? When I searched in the net I found that it is the only field to find the image data.? In my program I'm doing like this to get the image data...Can you please tell me whether I'm doing correct or not?

.................. Sample output from tiffdump()......

sample.tif:
Magic: 0x4949 <little-endian> Version: 0x2a
Directory 0: offset 8 (0x8) next 0 (0)
OldSubFileType (255) SHORT (3) 1 <1>
ImageWidth (256) SHORT (3) 1 <4733>
ImageLength (257) SHORT (3) 1 <4733>
BitsPerSample (258) SHORT (3) 1 <8>
Photometric (262) SHORT (3) 1 <1>
StripOffsets (273) LONG (4) 1 <265>
ImageDescription (270) ASCII (2) 155 <[30..46140] PGA-HCL-ast ...>
GrayResponseUnit (290) SHORT (3) 1 <2>

............. Sample Code...............

#include "tiffio.h"
#include <stdio.h>
int main()
{
        TIFF* tif = TIFFOpen("sample.tif","r");
        if(tif)
        {
                uint32 imagelength;
                uint32 w,h;
                int t;
                tstrip_t strips;
                unsigned char *buf;
                FILE *fp;
                fp = fopen("out.txt","w");
                TIFFGetField(tif,TIFFTAG_IMAGELENGTH,&imagelength);
                TIFFGetField(tif,TIFFTAG_IMAGEWIDTH,&w);
                printf("WIDTH = %ld,HEIGHT = %ld\n",w,imagelength);
                strips = TIFFNumberOfStrips(tif);
                printf("Number of strips = %ld\n",strips);
               printf("Strip Size = %ld\n",TIFFStripSize(tif));
                buf = (unsigned char *)(_TIFFmalloc(TIFFStripSize(tif)));
                // Get the image data...
              for(strips=0;strips < TIFFNumberOfStrips(tif);strips++)
                {
                        TIFFReadEncodedStrip(tif,strips,buf,(tsize_t)-1);
                        for(int x = 0; x < TIFFStripSize(tif); x++)
                                fprintf(fp,"%d ",buf[x]);
                        fprintf(fp,"\n");
                }
                _TIFFfree(buf);
                TIFFClose(tif);
        }
}

Thanks,
Sridhar!!