Jump to content
  • Advertisement

Archived

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

biskit

Reading .bmp files by hand

This topic is 6413 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 having problems reading .bmp files by hand. I can successfully read the BITMPAPFILEHEADER, and the BITMAPINFOHEADER into my program, but im not sure how to read the bitmaps actual bits. I tried reading directly after the headers, and by offsetting into the file by the value in BITMAPFILEHEADER::bOffBits. Neither seemed to work. What am I doing wrong? Any help would be appreciated. ------------------------------------------- Implementation is everything. Period. Particle Toast

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Assuming the simplest case where you''re reading 24bit uncompressed bmps,(lower bit counts have colour maps between the info header and pixel data, and if you want compression then use PNG the image is stored as 8bit per channel BGR triplets from the bottom up (i.e. last triplet of file == top left pixel of image). You''re right to use the bOffBits value, as there are sometimes padding bytes after the colourmap.

Oh, and all the rows are 4byte aligned, so the size of a row in bytes will be (pixels_per_row + 0x3) & ~0x3. For more information, take a look at the bmp specification in MSDN, or from wotsit.org.

Hope that helps!
Jim

Share this post


Link to post
Share on other sites
I suggest you get hold of a copy of FileWalk.EXE, it''s an old tool from Micro$oft''s Video for Windows days. It displays a BMP, WAVes, etc, as the list of structures (and their names) which you can double click on to expand and see all the members and their offsets into the file.

Also, from the same tool set, BitEdit.EXE/PalEDIT whic are brillant for editing palettes of BMPs.

I found a copy resently on the net (but can''t remember the URL), try using an ftp searcher looking for the compressed file bitedit.ex_ which can be uncompressed using the standard expand utility.

Share this post


Link to post
Share on other sites
> the image is stored as 8bit per channel BGR triplets from the bottom up.

This is true if Height is +ve, but a few editors store BMP top-down (left to right), you check for this by checking Height<0, where abs(Height) is the height of the bitmap.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!