32 and 16-bit BITMAPS

Started by
2 comments, last by FERNANDO-BRASIL 21 years, 9 months ago
Hi guys, I''m making a function to read BITMAPS. Until now, everything is OK. The function is working, but only reading 8 and 24-bit bitmaps. Now, I want to code 32-bit BMPs, but I face to a problem. I''m using as reference, a MS WORD tutorial that I got at WotSit webpage. The rules to read a bitmap, as they say, are: "The bitmap has a maximum of 2^32 colors. If the Compression field of the bitmap is set to BI_RGB, the Palette field does not contain any entries. Each dword in the bitmap array represents the relative intensities of blue, green, and red, respectively, for a pixel. The high byte in each dword is not used. If the Compression field of the bitmap is set to BI_BITFIELDS, the Palette field contains three dword color masks that specify the red, green, and blue components, respectively, of each pixel. Each dword in the bitmap array represents a single pixel." What I didn''t figured out, is the BI_BITFIELDS flag. This indicates that we have a pallete with 3 colors. Why do I have these 3 colors? I can''t understand it, because we already have the pixels represented by a DWORD (4 bytes = R, G, B, A) at the BITMAP ARRAY. So, the pallete isn''t necessary! Thank you a lot. Fernando
Advertisement
After scanning thru MSDN, I belive that three DWORDs are used to mask out tha R, G and B color values stored in the bitmap array:

"The bmiColors member contains three DWORD color masks which specify the red, green, and blue components, respectively, of each pixel. Bits set in the DWORD mask must be contiguous and should not overlap the bits of another mask. All the bits in the pixel do not have to be used. Each DWORD in the array represents a single pixel."

Another place in MSDN:

"If the biCompression member of the BITMAPINFOHEADER structure is the BI_BITFIELDS value, the bmiColors member of the BITMAPINFO structure contains three doubleword color masks that specify the red, green, and blue components, respectively, of each pixel. Windows 95/98/Me only supports the following color masks for 16 and 32 bits per pixel (bpp).

Value Meaning
16bpp The blue mask is 0x001F, the green mask is 0x03E0, and the red mask is 0x7C00.
16bpp The blue mask is 0x001F, the green mask is 0x07E0, and the red mask is 0xF800.
32bpp The blue mask is 0x000000FF, the green mask is 0x0000FF00, and the red mask is 0x00FF0000. "

I never used such bitmaps, so I cannot help further.

Forever trusting who we are
And nothing else matters
- Metallica
Forever trusting who we areAnd nothing else matters - Metallica
Why not let Windows handle it all for you?

HBITMAP hbmImage = (HBITMAP)LoadImage(GetModuleHandle(NULL), bmpfilename, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);

Brianmiserere nostri Domine miserere nostri
quote:Original post by BriTeg
Why not let Windows handle it all for you?

HBITMAP hbmImage = (HBITMAP)LoadImage(GetModuleHandle(NULL), bmpfilename, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);



Try this with a bitmap saved by Imaging You''ll have a surprise.



Forever trusting who we are
And nothing else matters
- Metallica
Forever trusting who we areAnd nothing else matters - Metallica

This topic is closed to new replies.

Advertisement