BmiColors field of the BITMAPINFO structure

Structure

BITMAPINFO has the following announcement

typedef struct tagBITMAPINFO {
    BITMAPINFOHEADER bmiHeader;
    RGBQUAD bmiColors[1];
} BITMAPINFO;

Why a static array RGBQUAD? Why is this not a pointer?

+1
source share
2 answers

This is a standard trick for declaring a variable size structure. There is never just one entry in the color table; it has at least 2 for a monochrome bitmap, usually 256 for an 8bpp bitmap, etc. Designated by bmiHeader.biClrUUsed. Thus, the actual size of the structure depends on the format of the bitmap image.

C ​​ , . , malloc() , biClrUsed. (BITMAPINFO *) .

+5

, . , . RGBQuad, R, G, B, A .

:

for(i = 0; i < 256; i++)
{
    lpbmpinfo->bmiColors[i].rgbRed = some_r;
    lpbmpinfo->bmiColors[i].rgbGreen = some_g;
    lpbmpinfo->bmiColors[i].rgbBlue = some_b;
    lpbmpinfo->bmiColors[i].rgbReserved = 0;
}
+1

Source: https://habr.com/ru/post/1696114/


All Articles