Confused about BITMAPINFO structure

Hello,

When I want to create an 8-bit DIB using SetDIBits(), how would I go about setting the 256-color RGBQUAD array in the BITMAPINFO structure? Its size appears to be fixed, since the member is declared as:

RGBQUAD rgbColors[1];

Or do I have to use SetDIBColorTable() after the call to SetDIBits(), or something similar?



To this day I don't know wtf the point of that member is. It makes no sense.

Anyway to set the pallet in an 8bit bmp you call SetDIBColorTable with your RGBQUAD array.
You will find some structures like this in windows - sometimes you will see them with an array declaration of
size [0] sometimes you will see them with and array declared as size[1] like in the BITMAPINFO structure.

The idea is idea is as follows:
1. The BITMAPINFO header looks like this:
1
2
3
4
typedef struct tagBITMAPINFO { 
  BITMAPINFOHEADER bmiHeader; 
  RGBQUAD          bmiColors[1]; 
} BITMAPINFO, *PBITMAPINFO; 


2. You create a buffer of the required number of RGBQUAD elements PLUS the size of the BITMAPINFOHEADER

Example:
for 256 quad elements

1
2
3
4
5
PBITMAPINFO pInfo  = (PBITMAPINFO)new char [sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD) ]
//The head of the buffer is treated as a BITMAPINFOHEADER
pInfo->bmiHeader.memberofbmiHeader = ?????
//The 256  RGBQUAD array
 pInfo->bmiColors[200] = ????

Last edited on
Thank you - I will try that, since I am having zero success whatsoever using SetDIBColorTable (as noted in another post that's floating around on this board...).

But why doesn't the structure just instead define its members in the following manner?

1
2
3
BITMAPINFOHEADER bmiHeader;
RGBQUAD*         pBmiColors;
UINT             nColors;


...because the proper way, as you describe it, seems completely convoluted and counter-intuitive. I'm looking at the MSDN documentation for it right now, and in no way does the doc even imply the need to create a separate buffer and cast it to a BITMAPINFO pointer. I shouldn't be surprised, since MSDN's documentation has for whatever reason always been next-to-useless on certain topics.
Topic archived. No new replies allowed.