From: sduggire@csee.usf.edu (sridhar duggireddy)
Date: Thu, 20 Nov 2003 22:17:45 -0500 (EST)
Subject: [Tiff] Reading Tiff Image files
Message-ID: <Pine.GSO.4.33.0311202210240.9825-100000@grad>

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!!


