PDA

View Full Version : 16 bit greyscale image.



dancvogel
09-23-2008, 01:21 PM
How can I display a 16bit greyscale image?

The image is represented as an array of unsigned shorts. For testing purposes I have been filling the array with random values.

I have been playing around with glDrawPixels but have had minimal success. If I use GL_LUMINANCE I can get something to display but I get a bunch of columns. Its seems as though only every fourth pixel in a row will display. I've tried other values for format, but with those i either get all white or all black. Please help.

Should I be even using glDrawPixels or is there a better way to be doing this?

unsigned void
09-23-2008, 10:43 PM
AFAIK, you cannot display 16 bit in a single channel. Think of mapping 16-bit values to 8-bit to display it (scale down or show some range).

songho
09-24-2008, 09:18 AM
The glDrawPixels() call should look like:
glDrawPixels(imageWidth, imageHeight, GL_LUMINANCE, GL_UNSIGNED_SHORT, imageBuffer);

Also, make sure the data endian is same as the system endian and the correct data alignment (GL_UNPACK_ALIGNMENT).

Here is an example code to draw a 16-bit raw image:
imageRaw16bit.zip (http://www.songho.ca/opengl/files/imageRaw16bit.zip)