2002.09.18 17:53 "Reading 16bits from a gray scale image", by Steven Luke
I looked through the archives for the answer to this, and although the question came up a couple of times, I didn't find an answer that seemed to work (at least not for my images).
First let me start by asking the simplest question. How do I read 16bits of data from the image? If I use TIFFReadRGBAImage the raster has to be 32 bits per pixel. You can get the 8 bit color channels using the getr32 macros. How can I turn the 8bit or 32bit data into 16bits? I tried doing this:
 c = raster[i];
 r = getr32(c);
 g = getg32(c);
 b = getb32(c);
 a = geta32(c);
 uint16 value = r;
 value <<= 8;
 value += g;
 unsigned char final = value >> 8;
What happens is only the brightest spots get shown. I tried the different color components in lines  and , and the only thing that made a difference was if r was inserted into  I saw the spots as above, anything else I got an empty image. Tried only shifting the pixels by 4 in line  since the data was actually acquired in 12 bits then stored as 16, but I got the same results.
Should I be using another method to read the data from the file? Like one that accepts a buffer such as TIFFReadScanline or TIFFReadEncodedStrip? Or should I just seek to the correct offset, fread in the data and work from there?
Steven J. Luke
Kimmel Cancer Center
Thomas Jefferson University