View Full Version : BMP File Format Help!
06-13-2001, 11:01 PM
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!
06-14-2001, 12:10 AM
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.
06-14-2001, 02:02 AM
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).]
06-14-2001, 04:03 AM
Its a 24bit Bitmap, I will try your method, thanks.
06-15-2001, 10:12 PM
Perhaps this link might help:
The page is a list of links pertaining to info on most of the popular graphics formats.
06-17-2001, 05:19 PM
Who uses BMP's? They are way too large, which equals way too slow.
06-17-2001, 09:35 PM
BMPs have the best image quality of any image file (i think)... far better than TGAs at least.
06-18-2001, 06:00 AM
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.
06-18-2001, 10:23 AM
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:
where data is an unsigned byte array.
[This message has been edited by kistompika (edited 06-18-2001).]
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.