| 88 | |
| 89 | |
| 90 | PBITMAPINFO CreateBitmapInfoStruct(HWND hwnd, HBITMAP hBmp, PBITMAPINFO pbmi) |
| 91 | { |
| 92 | BITMAP bmp; |
| 93 | WORD cClrBits; |
| 94 | |
| 95 | // Retrieve the bitmap's color format, width, and height. |
| 96 | GetObject(hBmp, sizeof(BITMAP), (LPSTR)&bmp); |
| 97 | |
| 98 | // Convert the color format to a count of bits. |
| 99 | cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel); |
| 100 | if (cClrBits == 1) |
| 101 | cClrBits = 1; |
| 102 | else if (cClrBits <= 4) |
| 103 | cClrBits = 4; |
| 104 | else if (cClrBits <= 8) |
| 105 | cClrBits = 8; |
| 106 | else if (cClrBits <= 16) |
| 107 | cClrBits = 16; |
| 108 | else if (cClrBits <= 24) |
| 109 | cClrBits = 24; |
| 110 | else cClrBits = 32; |
| 111 | |
| 112 | // Allocate memory for the BITMAPINFO structure. (This structure |
| 113 | // contains a BITMAPINFOHEADER structure and an array of RGBQUAD |
| 114 | // data structures.) |
| 115 | |
| 116 | /*if (cClrBits != 24) |
| 117 | pbmi = (PBITMAPINFO) LocalAlloc(LPTR, |
| 118 | sizeof(BITMAPINFOHEADER) + |
| 119 | sizeof(RGBQUAD) * (1<< cClrBits)); |
| 120 | |
| 121 | // There is no RGBQUAD array for the 24-bit-per-pixel format. |
| 122 | |
| 123 | else |
| 124 | pbmi = (PBITMAPINFO) LocalAlloc(LPTR, |
| 125 | sizeof(BITMAPINFOHEADER)); */ |
| 126 | |
| 127 | // Initialize the fields in the BITMAPINFO structure. |
| 128 | |
| 129 | pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
| 130 | pbmi->bmiHeader.biWidth = bmp.bmWidth; |
| 131 | pbmi->bmiHeader.biHeight = bmp.bmHeight; |
| 132 | pbmi->bmiHeader.biPlanes = bmp.bmPlanes; |
| 133 | pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel; |
| 134 | if (cClrBits < 24) |
| 135 | pbmi->bmiHeader.biClrUsed = (1<<cClrBits); |
| 136 | |
| 137 | // If the bitmap is not compressed, set the BI_RGB flag. |
| 138 | pbmi->bmiHeader.biCompression = BI_RGB; |
| 139 | |
| 140 | // Compute the number of bytes in the array of color |
| 141 | // indices and store the result in biSizeImage. |
| 142 | // Width must be DWORD aligned unless bitmap is RLE compressed. |
| 143 | pbmi->bmiHeader.biSizeImage = (pbmi->bmiHeader.biWidth + 15) /16 |
| 144 | * pbmi->bmiHeader.biHeight |
| 145 | * cClrBits; |
| 146 | // Set biClrImportant to 0, indicating that all of the |
| 147 | // device colors are important. |