Archived

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

Krakken

Loading Monochrome Bitmaps For Manipulation

Recommended Posts

Hi, I''m trying to make a monochrome bitmap loader for an lcd game i''m making. I''ve searched around and have built a struct from what documents have told me about the bitmap structure. Now i''m stuck... I need to be able to check each pixel to see if it''s black or white (hi bit or lo bit) but am still a bit stumped by this whole bitmap structure. Here is my code thus far: struct cBMP { WORD wIdentifier; DWORD dwFileSize; DWORD dwReserved; DWORD dwOffset; DWORD dwHeader; DWORD dwWidth; DWORD dwHeight; WORD wPlane; WORD wBitPerPixel; DWORD dwCompression; DWORD dwDataSize; DWORD dwHoriRes; DWORD dwVertRes; DWORD dwColour; DWORD dwMainColour; WORD dwPallette; }; cBMP hBMP; fstream fBMP; fBit.open("lcdtest.bmp", fstream::in); fBit.read((char*)&hBMP, 54); // Read first 54 bytes (header) Any help to get me further would be great. Thanks!

Share this post


Link to post
Share on other sites
The structure looks good, as far as I can tell when comparing it to the documentation. The palette will have two entries, per the following description in BITMAPINFO Structure:

The biBitCount member of the BITMAPINFOHEADER structure determines the number of bits that define each pixel and the maximum number of colors in the bitmap. This member can be one of the following values:

The bitmap is monochrome, and the bmiColors member contains two entries. Each bit in the bitmap array represents a pixel. If the bit is clear, the pixel is displayed with the color of the first entry in the bmiColors table; if the bit is set, the pixel has the color of the second entry in the table.


However, I''m not sure if the data in the file is actually bits or not. If so, of course, each byte contains 8 pixels of data. Examine the biBitCount value when you read the file; if it is 8, then you know the data is a true bitstream.

Share this post


Link to post
Share on other sites
Okay seems i'm having a problem with the header struct. Everything "seems" to go in properly but I don't think i'm getting the right values...

Here is the report from loading the header:


Here is the test image:


I would have thought that the header would have contained "6677" for "BM" which is in the file but instead I get "19778".

Any further help would be great.


[edited by - Krakken on November 17, 2003 10:10:19 AM]

Share this post


Link to post
Share on other sites
BM is does equate 6677(424D hex) as individual charaters. But first they are stored in little endian format, so if you look at the file they are stored as "MB" or 4D42 hex. Then you have to look at the storage type used to load it WORD wIdentifier. That takes up 2 bytes and is treated as a short int. So then it becomes:

(4 * 16^3) + (13 * 16^2) + (4 * 16^1) + (2 * 16^0) = 19778

This article might help:
http://www.gamedev.net/reference/articles/article1966.asp



First make it work,
then make it fast.

--Brian Kernighan

The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)

Do not interrupt your enemy when he is making a mistake. - Napolean Bonaparte

Share this post


Link to post
Share on other sites