WHat do i do when a struct requires a "RGBQUAD [1]" type?
-
The BITMAPINFO struct is defined as follows:
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO, *PBITMAPINFO;It's the bmiColors[1] property i'm confused about. This requires an array to RGBQUAD structs and all i have is a pointer to an array of them, how do i use the pointer when it wants an array? Thanks
-
The BITMAPINFO struct is defined as follows:
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO, *PBITMAPINFO;It's the bmiColors[1] property i'm confused about. This requires an array to RGBQUAD structs and all i have is a pointer to an array of them, how do i use the pointer when it wants an array? Thanks
MSDN : The RGBQUAD structure describes a color consisting of relative intensities of red, green, and blue. typedef struct tagRGBQUAD { // rgbq BYTE rgbBlue; BYTE rgbGreen; BYTE rgbRed; BYTE rgbReserved; } RGBQUAD; Members rgbBlue Specifies the intensity of blue in the color. rgbGreen Specifies the intensity of green in the color. rgbRed Specifies the intensity of red in the color. rgbReserved Reserved; must be zero. Remarks The bmiColors member of the BITMAPINFO structure consists of an array of RGBQUAD structures. And keep in mind that an array is a pointer! u can always write: int a[5]; a[1] = 2; *(a+1) = 3; // Means a[1] = 3; Papa Murex Co.
-
The BITMAPINFO struct is defined as follows:
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO, *PBITMAPINFO;It's the bmiColors[1] property i'm confused about. This requires an array to RGBQUAD structs and all i have is a pointer to an array of them, how do i use the pointer when it wants an array? Thanks
This
bmiColors
is the tip of a variably-sized array ofRGBQUAD
s. Suppose for instance your palette hasnBmiColors
entries, you'd allocate and stuff the thing like this:unsigned nBmiColors=256;
BIMAPINFO* lpbmi=(BITMAPINFO *)malloc(
sizeof(BITMAPINFO)+
nBmiColors==0?0:(nBmiColors-1)*sizeof(RGBQUAD));
for(unsigned n=0;n<nBmiColors;++n)
{
lpbmi->bmiColors[n]=...;
}Joaquín M López Muñoz Telefónica, Investigación y Desarrollo