Advertisement
dan-masek

Untitled

Apr 12th, 2018
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. inline void create_bitmap_pal(CDCHandle& dc
  2.     , CBitmap& bmp
  3.     , LONG width
  4.     , LONG height
  5.     , std::vector<RGBQUAD> const& pal
  6.     , uint8_t const* data)
  7. {
  8.     int32_t const bmi_size(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256);
  9.     BITMAPINFO* bmi(static_cast<BITMAPINFO*>(alloca(bmi_size)));
  10.     bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  11.     bmi->bmiHeader.biWidth = static_cast<LONG>(width);
  12.     bmi->bmiHeader.biHeight = static_cast<LONG>(-height);
  13.     bmi->bmiHeader.biPlanes = 1;
  14.     bmi->bmiHeader.biBitCount = 8;
  15.     bmi->bmiHeader.biCompression = BI_RGB;
  16.  
  17.     for (uint32_t i(0); i < 256; ++i) {
  18.         if (pal.size() > i) {
  19.             bmi->bmiColors[i] = pal[i];
  20.         } else {
  21.             bmi->bmiColors[i].rgbRed
  22.                 = bmi->bmiColors[i].rgbGreen
  23.                 = bmi->bmiColors[i].rgbBlue
  24.                 = bmi->bmiColors[i].rgbReserved = 0;
  25.         }
  26.     }
  27.  
  28.     bmp.CreateDIBitmap(dc
  29.         , &bmi->bmiHeader
  30.         , CBM_INIT
  31.         , data
  32.         , bmi
  33.         , DIB_RGB_COLORS);
  34. }
  35. // ----------------------------------------------------------------------------
  36. inline void create_bitmap_gray(CDCHandle& dc
  37.     , CBitmap& bmp
  38.     , LONG width
  39.     , LONG height
  40.     , uint8_t const* data)
  41. {
  42.     std::vector<RGBQUAD> pal(256);
  43.     for (int32_t i(0); i < 256; ++i) {
  44.         pal[i].rgbRed = pal[i].rgbGreen = pal[i].rgbBlue = i;
  45.         pal[i].rgbReserved = 0;
  46.     }
  47.  
  48.     create_bitmap_pal(dc, bmp, width, height, pal, data);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement