BMP File Format Help!

I am trying to create a heightmap program that loads BMP greyscale images. But the values seem all screwed up. a white pixel is -1.0, a black one is 0.0, some grey ones are < -1.0 some are > 0.0, please help!

Remember, colors are usually stored as unsigned bytes. That’s pretty much the only way you’d be getting -1 out of a bitmap file.

Sorry, i dont understand… I have something like
float height = image->data[whatever]
whatever is the pixel i want to access. You are saying i should be using
unsigned byte height = image->data[whatever]

1st is this a 24bit image, or 256color, then do you read the image by yourself or did you use some funtions from glut etc ???

if you use 24bit color images, then the greyscale colors would have same rgb values all stored in unsigned byte format !, so you would read: float height= (image->data[nelement * 3] / 128) -1.0f;

then you get from the blue component( bmp= BGR) a value betwen -1 an 1 …
the f of “-1.0f” is to cast the type into float …

if you use 256color bmps then you have to readin the colortable and then do like:
float height= colortable[image->data[nelement]] …

[This message has been edited by T2k (edited 06-14-2001).]

Its a 24bit Bitmap, I will try your method, thanks.

Perhaps this link might help:

The page is a list of links pertaining to info on most of the popular graphics formats.

Who uses BMP’s? They are way too large, which equals way too slow.

BMPs have the best image quality of any image file (i think)… far better than TGAs at least.

I don’t see how a BMP files image quality can be any better than TGA. Neither of them use a lossy compression like JPG so they are perfectly capable of storing the same RGB data and a TGA has the additional option of storing an Alpha channel.

So far as “way too large” == “way too slow”, that’s not necessarily true. BMP files are big because they aren’t compressed. JPG files are smaller because they are compressed, but it takes time to uncompress them. It doesn’t take any time at all to uncompress a BMP since there is no compression.

Bitmaps are uncompressed. That’s why they’re so big.

But you have to use uncompressed images as textures in OpenGL(compressed textures are only compressed when they are already specified), or to draw onto the screen.

By the way, BMP file format is to be found on MSDN Library CDs. If you don’t have one e-mail me.

By the way if you want to convert 8-bit grayscale to [0.0;1.0] float you should clamp it this way:

float f=(double)(data[offset])/256.0;

where data is an unsigned byte array.

[This message has been edited by kistompika (edited 06-18-2001).]