Archived

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

A. Buza

Quick BMP question

Recommended Posts

A. Buza    122
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
Dragonskin    122
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
Cyberdrek    100
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
Eric    138
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
Serge K    154
// 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   
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