Sign in to follow this  

where is the first pixel of bitmap located?

This topic is 3669 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
1)
Don't rely on bfOffbits. It's not necessarily set to a valid value (eg. 0).

2)
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.

3)
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

This topic is 3669 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this