Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

A. Buza

Quick BMP question

This topic is 6568 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 read over a doc on the .bmp format, and it said that bitmap data was aligned on the dword boundary (padded w/ 0''s). Now, does BMPINFOHEADER.biWidth include the padding? Also, how can I find the length of the padding given the width? I had a macro that did this, but I''m not sure if its working right. Thanks for any help you can give.

Share this post


Link to post
Share on other sites
Advertisement
From looking at what I''ve written for a BMP loader, I''d say that the field means the actual width of the the image. Then you decide whether it''s aligned or not.

Share this post


Link to post
Share on other sites
Serge K:

you wrote this:
BITMAPINFOHEADER bih;

alignedRowLength = ((bih.biWidth * bih.biBitCount + 31) & ~31) >> 3;

where did your 31, ~31 and 3 come from? and what does this do exactly... ( I''m not talking about the bitshift, that I know )...






Cyberdrek
Headhunter Soft
DLC Multimedia

Share this post


Link to post
Share on other sites
Just for comparison, here is what I do (this is VC++):

HBITMAP hbm;

if( !( hbm = (HBITMAP)LoadImage( NULL, filePath, IMAGE_BITMAP,0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION ) ) ){
return E_FAIL;
}

BITMAP bm;
GetObject( hbm, sizeof(BITMAP), &bm );

someVar = bm.bmWidthBytes; // width in bytes, including dword padding
someOtherVar = bm.bmWidth; // width in pixels

Share this post


Link to post
Share on other sites
// biBitCount = 1,4,8,16,24,32 (or can be =2 - on WinCE)
RowLength_inBits = bih.biWidth * bih.biBitCount;

// bitmap rows must be aligned on the dword boundary
// so we need to adjust RowLength_inBits to be multiple of 32 (>= RowLength_inBits).
// if it's aligned already, we don't need to change it:
(32n + 31) & ~31 == 32n
// otherwise it should be incremented:
((32n+1..31) + 31) & ~31 == 32n + 32

alignedRowLength_inBits = (RowLength_inBits + 31) & ~31;

// then we have to convert the number of bits to the number of bytes:
alignedRowLength = alignedRowLength_inBits >> 3;


quote:
Original post by Eric

someVar = bm.bmWidthBytes; // width in bytes, including dword padding


yes, in case if you have DIBSECTION or BITMAP structure.


Edited by - Serge K on July 21, 2000 6:13:01 AM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
how do you free the BITMAP?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
ah nevermind, it''s freed once the module it was declared in is done

Share this post


Link to post
Share on other sites

  • 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!