Jump to content
  • Advertisement
Sign in to follow this  
Sangha Im

where is the first pixel of bitmap located?

This topic is 3891 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm dealing strictly with 256 color bitmap. I'm trying to pick the exact color of the first pixel to set as a colorkey, but this is driving me crazy. So here is the bitmap table. This site has the information about bitmap headers and stuffs. -> http://home.comcast.net/~greg_slabaugh/personal/c/bmpwrite.html So my algorithm is... (assume that BMP is loaded into memory first.) 1) Pointer is pointing to Bitmap Identifier. (BM) 2) Pointer = Pointer + bfOffbits ( It's in the table from the site above.) -> So, pointer points to the actual pixel data. 3) Pointer = Pointer + biWidth * biHeight - biWidth -> Bitmap is stored upside down. In my theory, Pointer should be pointing to the first pixel. But actually it is not. 4) Grab the byte from the pointer, and add it to Palette offset. -> This should give me 32bit XRGB Color value. Somehow this is not working. What am I doing wrong?

Share this post

Link to post
Share on other sites
Don't rely on bfOffbits. It's not necessarily set to a valid value (eg. 0).

Watch for the line padding. The lines of the image data are offset to be at a full 32bit address. This means there can be up to 3 bytes with no useful value between lines. Use this to calculate the line offset instead of width.

If the height is given negative the image is not upside down.

There's a BITMAPFILEHEADER at the start.
After it follows a BITMAPINFOHEADER.
If the image is 8bit there is a palette of RGBX values. The number of the palette entries depend on bmih.biClrUsed. If biClrUsed equals zero the palette has the full 256 entries.

A palette entry is made up of 4 bytes, R, G, B and an unused byte.

Following that is the image data.

Watch for the compression parameter, the interpretation of the data depends on which value is set for biCompression.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!