AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2002.08.22 22:17 "Problem Reading MultiPage TIFFs", by Steven Luke
2002.08.22 22:39 "RE: Problem Reading MultiPage TIFFs", by Rypysc, George
2002.08.30 19:04 "Re: Problem Reading MultiPage TIFFs", by Steven Luke
2002.08.30 20:05 "RE: Problem Reading MultiPage TIFFs", by Bostrup, Tore
2002.08.31 13:12 "Re: Problem Reading MultiPage TIFFs", by Steven Luke
2002.09.02 13:20 "Re: Problem Reading MultiPage TIFFs", by Antonio E. Scuri
2002.09.03 17:58 "RE: Problem Reading MultiPage TIFFs", by Frank Palmieri
2002.09.03 18:32 "Re: Problem Reading MultiPage TIFFs", by Frank Warmerdam
2002.09.05 04:50 "Re: Problem Reading MultiPage TIFFs", by Steven Luke

2002.08.22 22:17 "Problem Reading MultiPage TIFFs", by Steven Luke

Hi,

I have a program in which I need to display multipage TIFFs on the screen, in a linked fashion so they can be scrolled through and processed as a group. The program was pre-written by someone else to read other file formats, and I have to edit it to work. My problem is, I don't seem to be able to read the differenent pages in the TIFF. I have all the code that matters at the bottom of the email, I would appreciate it if someone could help me with this, all I have been able to do is open the first page of the image over and over again.

One last thing (related probably). I have also had trouble counting the pages in the TIFF. I was using this code:

do
{ TIFFReadDirectory (tif);
   count++;
} while (!TIFFLastDirectory (tif));

but it would only give me a count of 1 (saying my first directory is my last one). But I know that the image had 20 pages to it. So I think I just don't have any idea how to use these functions. I would really like any help I could get.

Thanks,
Steve

--------------------Code for Opening Multipage TIFFs------------------------------------------

void LoadFile(char filename[])
{
   int i, ht;
   FILE *fptr;
   BITMAP *bmp;
   TIFF *tif;

   CODE TO OPEN FILE FOR INPUT, ETC...

   ht=LoadHeader(fptr);;

   if (ht==-1)
   {
      alert("Error!","Not a known image file","","OK",NULL,13,0);
      return;
   }
   else if (i == MM_TIFF) tif = TIFFOpen (filename, "r");

   sprintf(info.ts.startframe,"%d",0);
   sprintf(info.ts.endframe,"%d",info.f.tframes-1);

  MORE SETTING UP CODE

   for (i=0;i<info.f.tframes;i++)
   {
      if (i>info.ti.endframe) break;

      if (info.f.type == MM_TIFF)
     {
           info.f.currDir = i;
          TIFFSetDirectory (tif, TIFFCurrentDirectory (tif));
           bmp = read_tif (tif);
           TIFFReadDirectory (tif);
      }// end if MM_TIFF
     else
     { CODE FOR OTHER FILE TYPES }

     CODE FOR MANIPULATING POINTERS and DISPLAY

    } //End For Loop

   fclose(fptr);

} // End LoadFile

BITMAP *read_tif(TIFF *tif)
{
   unsigned int c,r,g,b;
   uint32 w, h;
   size_t npixels;
   uint32* raster;
   BITMAP* bmp;
   int x,y,n;

   bmp = (BITMAP*)NULL;
   if (tif)
  {
      TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
      TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
      npixels = w * h;
      raster = (uint32*) _TIFFmalloc(npixels * sizeof (uint32));
      if (raster != NULL)
     {
         if (TIFFReadRGBAImage (tif, w, h, raster, 0))
         {
            bmp = create_bitmap(w,h);

            n=0;
            for (y=h-1;y>=0;y--)
               for (x=0;x<w;x++)
               { c = *(raster+(n++));
                  r = getr32(c);
                  g = getg32(c);
                  b = getb32(c);
                  c = makecol(b,g,r);
                  putpixel(bmp,x,y,c);
               } //End x For
         }//End TIFFRead good
         _TIFFfree(raster);
      }//End tif exists
   }//End if Raster good

  info.p.min = 65535;
  info.p.max = 0;
  return(bmp);
}//End read_tif

--

Steven J. Luke
Kimmel Cancer Center Bioimaging Facility
Thomas Jefferson University
Philadelphia, Pennsylvania