From the documentation on CreateDIBSection
I observe that CreateDIBSection
takes a pointer to a BITMAPINFO
as the second parameter.
However, I came across various places indicating that it might be allowed to pass pointers to other structures (in particular BITMAPV5HEADER
), including
I have a feeling that this makes perfect sense (BITMAPV5HEADER
can be seen as an "extended version" of BITMAPINFO
wrt struct layout), but I could not find a single piece of official documentation on this topic.
Can anybody confirm that passing a BITMAPV5HEADER*
instead of a BITMAPINFO
is actually valid and possibly offer some documentation?
The short answer has to be no.
BITMAPV5HEADER*
is not a substitute forBITMAPINFO*
and may not be passed wheneverBITMAPINFO*
is expected (simply becauseBITMAPINFO
contains palette colors after the header, andBITMAPV5HEADER
is just a header).It is certainly fine to pass
BITMAPV5HEADER*
instead ofBITMAPINFO*
provided that theBITMAPV5HEADER
is a part ofBITMAPINFO
and has required kind of palette color data after it. That is documented, although kind of indirectly, through use instructions and common sense:BITMAPV5HEADER
is documented to be an "extended version of thBITMAPINFOHEADER
structure", so that part is clear.BITMAPINFO
is documented to combine a header and color data. The header is included by value as opposed to by pointer, so at this point it's clear the header may not just grow in size as it pleases, otherwise it would be impossible to accessBITMAPINFO.bmiColors
and the whole idea of having an extended version of the header would be pointless.And that problem is then resolved in another place in the documentation ("Remarks" section):
Although I believe this part was not confusing for you to begin with.
Now for the long answer.
There appear to be two cases when
BITMAPV5HEADER*
can be passed forBITMAPINFO*
. Neither of the two is documented in a concrete way, and if for the first one we can apply same common sense we applied above, the second one appears to be a bug in the documentation:BITMAPINFO.bmiColors
is documented to beNULL
. You can find the complete list of such cases in the documentation forBITMAPINFOHEADER
.When the header is
BITMAPV4HEADER
orBITMAPV5HEADER
, the bitmap has 16 or 32 bit colors, and compression is set toBI_BITFIELDS
. In that case the color masks that are documented to follow the header are instead taken from the respective dedicated fields of the headers, and the threeDWORD
s that follow the header are ignored.This is easy to prove by slightly modifying the original code:
Result:
It would appear the documentation was absentmindedly copied between
BITMAPINFOHEADER
,BITMAPV4HEADER
andBITMAPV5HEADER
when it should have been amended for the last two. The closest explanation I was able to find is Bitmap Header Types that at least recognizes the existence of the dedicated mask fields, but still implies the values must be provided both in these fields and after the header inbmiColors
:(emphasis mine).
We can only conclude from evidence that it is not true.
It is less of documentation than I hoped.