Archived

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

jaymz

Interpreting a Grayscale Bitmap

Recommended Posts

I seem to be having a bit of trouble finding information about grayscale bitmaps. I know how to read 8bpp and up color bitmaps but have no idea when it comes to grayscale. Can anyone point me in the correct direction?

Share this post


Link to post
Share on other sites
Actually, a grayscale bitmap is just an 8bpp bitmap with an all gray palett. Black and white (1bpp) is a bit different, though. That might be a bit tough to read since you have to worry about the bits being aligned to byte boundaries (i.e. some bits would just be padding).

--TheGoop

-------------------------
If cities were built like software is built, the first woodpecker to come along would level civilization

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
So how would one determine how dark a palett entry is? Does is go something like 0 is black and 255 is white?

Share this post


Link to post
Share on other sites
You read the palette data. I don't know where it is in the bitmap file, check out www.wotsit.org you'll find what you need there.

You usually store the palette in a struct like this:

struct PALETTE
{
int r, g, b;
}PALETTE [ 256 ] ;

And when you read the palette from a bitmap:

for(i = 0; i < 256; i++)
{

/* Read the red component from the bitmap and store it in PALETTE [ i ].r */

/* Read the green component from the bitmap and store it in PALETTE [ i ].g */

/* Read the blue component from the bitmap and store it in PALETTE [ i ].b */
}

I had to insert some spaces in the code in lines that had [ ] in them, but you get the idea on how to read the palette.

/. Muzzafarath

Edited by - Muzzafarath on 3/31/00 12:40:16 AM

Share this post


Link to post
Share on other sites

If you mean a 1-bit bitmap (Black & White), then the bitmap data is simply an array of DWORD values for each scanline. Each scanline is stored in an integral number of DWORDs. Each bit is a B/W pixel.

Palette (if present) would have only two entries.

// CHRIS

Share this post


Link to post
Share on other sites