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

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


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:

{ TIFFReadDirectory (tif);
} 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.


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

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



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



   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


    } //End For Loop


} // 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);

            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);
               } //End x For
         }//End TIFFRead good
      }//End tif exists
   }//End if Raster good

  info.p.min = 65535;
  info.p.max = 0;
}//End read_tif

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