2000.11.20 00:11 "Reading other formats beside RGBA", by Gerrard Jenner

2000.11.20 06:19 "Re: Reading other formats beside RGBA", by Peter Montgomery

Jed,

I'm not quite sure what you're asking. You say you want to read in a grayscale image into an 8 bit unsigned char buffer. Sure, that's no problem. If you open a grayscale image and read a scanline using "TIFFReadScanline()" you'll get a grayscale image in an unsigned 8 bit buffer. All you have to do is copy it where you want to keep it. However, you then ask about a desired "TIFFGetR/G/B/A" style read that makes me think you want to read a single channel of an RGBA image into a grayscale buffer.

As far as I know, the library doesn't have any inherent support for that. However, it's a trivial matter to use "TIFFReadScanline()" to read an RGBA scanline into an RGBA buffer and then just copy the specific channel into your own unsigned 8 bit char buffer. something along these lines...

int CurrSrcPixel;
unsigned char* SrcPixel;    // This is a pointer used to access a particular channel of an RGBA image
 unsigned char* DstPixel;    // This is a scanline that you malloc to hold a single channel from an RGBA image
 tdata_t Buf; // This is the pointer that is malloc'ed and used to read TIF scanlines

SrcPixel = Buf[2]; // Lets say we want to copy only the green channel from an RGBA scanline

     for (CurrSrcPixel = 0; CurrSrcPixel < Width; CurrSrcPixel++){
      *DstPixel= *SrcPixel ;

      SrcPixel += 4; // Advance to next SRC pixel
      DstPixel++; // Advance to next DST pixel
      }

I haven't compiled the code, but something like this should basically work fine. I do things like this in my code all the time.

Thanks,
PeterM