Interpreting a Grayscale Bitmap

Started by
3 comments, last by jaymz 24 years ago
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?
Advertisement
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
So how would one determine how dark a palett entry is? Does is go something like 0 is black and 255 is white?
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 .r */<br><br>/* Read the green component from the bitmap and store it in PALETTE .g */<br><br>/* Read the blue component from the bitmap and store it in PALETTE .b */<br>}<br><br>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.<br><br>/. Muzzafarath<br><br>Edited by - Muzzafarath on 3/31/00 12:40:16 AM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall

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
// CHRIS [win32mfc]

This topic is closed to new replies.

Advertisement