0
votes

I have a weird issue with creating an Bitmap in C++. I'm using the BITMAPFILEHEADER and BITMAPINFOHEADER Structure for creating an 8bit grayscale image. Bitmap data is coming from a camera over DMA as unsigned char an has exactly the same lenghts as expected. Saving the image an opening it, it contains colors?!

The way it should be: http://www.freeimagehosting.net/qd1ku
The way it is: http://www.freeimagehosting.net/83r1s

Do you have any Idea where this is comping from?

The Header of the bitmap is:

42 4D 36 00 04 00 00 00 00 00 36 00 00 00 28 00 00 00 00 02 00 00 00 02 00 00 01 00 08 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

    Info-Header:
    42 4D           Its a Bitmap
    36 00 04 00     Size of Bitmap = 0x04 00 36 - Header-Size = 512x512
    00 00 00 00     Reserved
    36 00 00 00     Offset = Sizeof(Bitmapinfoheader);
    28 00 00 00     Sizeof(Bitmapinfoheader);
    00 02 00 00     =0x200 = 512 px.
    00 02 00 00     same
    01 00           = 1 - Standard. Not used anymore.
    08 00           Color dept = 8 bit.
    00 00 00 00     Compression: 0 = none.
    00 00 00 00     Filesize or zero
    00 00 00 00     X-Dot-Per-Meter, may be left 0
    00 00 00 00     y-Dot-Per-Meter, may be left 0
    00 00 00 00     If zero, all 255 colors are used
    00 00 00 00     If zero, no color table values are used

Do you have any Idea where this comes from?

1
An 8bpp image should always contain a color table. - Hans Passant
Oh I'm sorry. Yes, you're right. Bitmap under Windows is ... well... Next time I'll use png. - AllDayPiano

1 Answers

2
votes

Under windows, if you do not supply a palette for your 8 bit image a system default one is provided for you. I do not recall offhand the win32 way to add a palette, but it should be as simple as creating a 256 element char array where the value of each entry is the same as its index, and writing it out to your file at the appropriate point and updating the offset parameter, etc.