Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inline void create_bitmap_pal(CDCHandle& dc
- , CBitmap& bmp
- , LONG width
- , LONG height
- , std::vector<RGBQUAD> const& pal
- , uint8_t const* data)
- {
- int32_t const bmi_size(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
- BITMAPINFO* bmi(static_cast<BITMAPINFO*>(alloca(bmi_size)));
- bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bmi->bmiHeader.biWidth = static_cast<LONG>(width);
- bmi->bmiHeader.biHeight = static_cast<LONG>(-height);
- bmi->bmiHeader.biPlanes = 1;
- bmi->bmiHeader.biBitCount = 8;
- bmi->bmiHeader.biCompression = BI_RGB;
- for (uint32_t i(0); i < 256; ++i) {
- if (pal.size() > i) {
- bmi->bmiColors[i] = pal[i];
- } else {
- bmi->bmiColors[i].rgbRed
- = bmi->bmiColors[i].rgbGreen
- = bmi->bmiColors[i].rgbBlue
- = bmi->bmiColors[i].rgbReserved = 0;
- }
- }
- bmp.CreateDIBitmap(dc
- , &bmi->bmiHeader
- , CBM_INIT
- , data
- , bmi
- , DIB_RGB_COLORS);
- }
- // ----------------------------------------------------------------------------
- inline void create_bitmap_gray(CDCHandle& dc
- , CBitmap& bmp
- , LONG width
- , LONG height
- , uint8_t const* data)
- {
- std::vector<RGBQUAD> pal(256);
- for (int32_t i(0); i < 256; ++i) {
- pal[i].rgbRed = pal[i].rgbGreen = pal[i].rgbBlue = i;
- pal[i].rgbReserved = 0;
- }
- create_bitmap_pal(dc, bmp, width, height, pal, data);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement