-/****************************************************************************
- * *
- * FUNCTION : wxMakeDIBPalette(lpInfo) *
- * *
- * PURPOSE : Given a BITMAPINFOHEADER, create a palette based on
- * the color table.
- *
- * *
- * RETURNS : non-zero - handle of a corresponding palette
- * zero - unable to create palette
- * *
- ****************************************************************************/
-HPALETTE wxMakeDIBPalette(LPBITMAPINFOHEADER lpInfo)
-{
- LPLOGPALETTE npPal;
- RGBQUAD far *lpRGB;
- HPALETTE hLogPal;
- WORD i;
-
- /* since biClrUsed field was filled during the loading of the DIB,
- ** we know it contains the number of colors in the color table.
- */
- if (lpInfo->biClrUsed)
- {
-/*
- npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) +
- (WORD)lpInfo->biClrUsed * sizeof(PALETTEENTRY));
-*/
- npPal = (LPLOGPALETTE)malloc(sizeof(LOGPALETTE) +
- (WORD)lpInfo->biClrUsed * sizeof(PALETTEENTRY));
- if (!npPal)
- return NULL;
-
- npPal->palVersion = 0x300;
- npPal->palNumEntries = (WORD)lpInfo->biClrUsed;
-
- /* get pointer to the color table */
- lpRGB = (RGBQUAD FAR *)((LPSTR)lpInfo + lpInfo->biSize);
-
- /* copy colors from the color table to the LogPalette structure */
- for (i = 0; (DWORD)i < lpInfo->biClrUsed; i++, lpRGB++)
- {
- npPal->palPalEntry[i].peRed = lpRGB->rgbRed;
- npPal->palPalEntry[i].peGreen = lpRGB->rgbGreen;
- npPal->palPalEntry[i].peBlue = lpRGB->rgbBlue;
- npPal->palPalEntry[i].peFlags = 0;
- }
-
- hLogPal = CreatePalette((LPLOGPALETTE)npPal);
-// LocalFree((HANDLE)npPal);
- free(npPal);