I am working on an API to cache GDI objects, written in C++, in which I am implementing different Create methods that imitate the win32 API. One such method is CreateDIBPatternBrushPt()
, which takes in a VOID*
to a packed DIB. The VOID*
contains a BITMAPINFO
structure followed immediately by an array of bytes defining the pixels of the bitmap. I did some research on packed DIBs. According to the book, Programming Windows, as well as Wikipedia the length is equal to the product of the row length and biHeight
(a member of BITMAPINFOHEADER
), where:
RowLength = 4 * ((bmi.bcWidth * bmi.bcBitCount + 31) / 32) ;
So, currently my thought is to do something like this:
//copy BIMAPINFO to access width and height
//lpPackedDIB is the VOID* parameter of CreateDIBPatternBrushPt()
BITMAPINFO tmpBitmapInfo;
std::memcpy(&tmpBitmapInfo, lpPackedDIB, sizeof(BITMAPINFO));
//copy entire packed DIB
int rowLength = 4 * ((tmpBitmapInfo.bmiHeader.biWidth * tmpBitmapInfo.bmiHeader.biBitCount + 31) / 32);
std::memcpy(m_pPackedDIB, lpPackedDIB, sizeof(BITMAPINFO) + rowLength * std::abs(bitmapInfo.bmiHeader.biHeight));
Does this seem like a valid way to do this? I would also like to know where lpPackedDIB
would come from for people who use CreateDIBPatternBrushPt()
, so that I can properly test this logic.
EDIT:
References: https://msdn.microsoft.com/en-us/library/windows/desktop/dd183493(v=vs.85).aspx https://en.wikipedia.org/wiki/BMP_file_format#File_structure https://www-user.tu-chemnitz.de/~heha/petzold/ch15b.htm (particularly "The DIB Pixel Bits" section)