- LPBITMAPINFOHEADER lpbi;
- PALETTEENTRY pe;
- int n;
- int nDibColors;
- int nPalColors=0;
- BYTE FAR * lpBits;
- RGBQUAD FAR * lpRgb;
- BYTE xlat[256];
- DWORD SizeImage;
-
- if (!hpal || !pdib)
- return FALSE;
-
- lpbi = (LPBITMAPINFOHEADER)pdib;
- lpRgb = DibColors(pdib);
-
- GetObject(hpal,sizeof(int),(LPSTR)&nPalColors);
- nDibColors = DibNumColors(pdib);
-
- if ((SizeImage = lpbi->biSizeImage) == 0)
- SizeImage = DibSizeImage(lpbi);
-
- //
- // build a xlat table. from the current DIB colors to the given
- // palette.
- //
- for (n=0; n<nDibColors; n++)
- xlat[n] = (BYTE)GetNearestPaletteIndex(hpal,RGB(lpRgb[n].rgbRed,lpRgb[n].rgbGreen,lpRgb[n].rgbBlue));
-
- lpBits = (LPBYTE)DibPtr(lpbi);
- lpbi->biClrUsed = nPalColors;
-
- //
- // re-size the DIB
- //
- if (nPalColors > nDibColors)
- {
- GlobalReAllocPtr(lpbi, lpbi->biSize + nPalColors*sizeof(RGBQUAD) + SizeImage, 0);
- hmemmove((BYTE _huge *)DibPtr(lpbi), (BYTE _huge *)lpBits, SizeImage);
- lpBits = (LPBYTE)DibPtr(lpbi);
- }
- else if (nPalColors < nDibColors)
- {
- hmemcpy(DibPtr(lpbi), lpBits, SizeImage);
- GlobalReAllocPtr(lpbi, lpbi->biSize + nPalColors*sizeof(RGBQUAD) + SizeImage, 0);
- lpBits = (LPBYTE)DibPtr(lpbi);
- }
-
- //
- // translate the DIB bits
- //
- switch (lpbi->biCompression)
- {
- case BI_RLE8:
- xlatRle8(lpBits, SizeImage, xlat);
- break;
-
- case BI_RLE4:
- xlatRle4(lpBits, SizeImage, xlat);
- break;
+ LPBITMAPINFOHEADER lpbi;
+ PALETTEENTRY pe;
+ int n;
+ int nDibColors;
+ int nPalColors=0;
+ BYTE FAR * lpBits;
+ RGBQUAD FAR * lpRgb;
+ BYTE xlat[256];
+ DWORD SizeImage;
+
+ if (!hpal || !pdib)
+ return FALSE;
+
+ lpbi = (LPBITMAPINFOHEADER)pdib;
+ lpRgb = DibColors(pdib);
+
+ GetObject(hpal,sizeof(int),(LPSTR)&nPalColors);
+ nDibColors = DibNumColors(pdib);
+
+ if ((SizeImage = lpbi->biSizeImage) == 0)
+ SizeImage = DibSizeImage(lpbi);
+
+ //
+ // build a xlat table. from the current DIB colors to the given
+ // palette.
+ //
+ for (n=0; n<nDibColors; n++)
+ xlat[n] = (BYTE)GetNearestPaletteIndex(hpal,RGB(lpRgb[n].rgbRed,lpRgb[n].rgbGreen,lpRgb[n].rgbBlue));
+
+ lpBits = (LPBYTE)DibPtr(lpbi);
+ lpbi->biClrUsed = nPalColors;
+
+ //
+ // re-size the DIB
+ //
+ if (nPalColors > nDibColors)
+ {
+ GlobalReAllocPtr(lpbi, lpbi->biSize + nPalColors*sizeof(RGBQUAD) + SizeImage, 0);
+ hmemmove((BYTE _huge *)DibPtr(lpbi), (BYTE _huge *)lpBits, SizeImage);
+ lpBits = (LPBYTE)DibPtr(lpbi);
+ }
+ else if (nPalColors < nDibColors)
+ {
+ hmemcpy(DibPtr(lpbi), lpBits, SizeImage);
+ GlobalReAllocPtr(lpbi, lpbi->biSize + nPalColors*sizeof(RGBQUAD) + SizeImage, 0);
+ lpBits = (LPBYTE)DibPtr(lpbi);
+ }
+
+ //
+ // translate the DIB bits
+ //
+ switch (lpbi->biCompression)
+ {
+ case BI_RLE8:
+ xlatRle8(lpBits, SizeImage, xlat);
+ break;
+
+ case BI_RLE4:
+ xlatRle4(lpBits, SizeImage, xlat);
+ break;
- LOGPALETTE* logPal = (LOGPALETTE*)
- new BYTE[sizeof(LOGPALETTE) + (nColors-1)*sizeof(PALETTEENTRY)];
-
- logPal->palVersion = 0x300; // Windows 3.0 version
- logPal->palNumEntries = nColors;
- for (short n = 0; n < nColors; n++) {
- logPal->palPalEntry[n].peRed = rgb[n].rgbRed;
- logPal->palPalEntry[n].peGreen = rgb[n].rgbGreen;
- logPal->palPalEntry[n].peBlue = rgb[n].rgbBlue;
- logPal->palPalEntry[n].peFlags = (BYTE)flags;
- }
- hPalette = ::CreatePalette(logPal);
- delete logPal;
+ LOGPALETTE* logPal = (LOGPALETTE*)
+ new BYTE[sizeof(LOGPALETTE) + (nColors-1)*sizeof(PALETTEENTRY)];
+
+ logPal->palVersion = 0x300; // Windows 3.0 version
+ logPal->palNumEntries = nColors;
+ for (short n = 0; n < nColors; n++) {
+ logPal->palPalEntry[n].peRed = rgb[n].rgbRed;
+ logPal->palPalEntry[n].peGreen = rgb[n].rgbGreen;
+ logPal->palPalEntry[n].peBlue = rgb[n].rgbBlue;
+ logPal->palPalEntry[n].peFlags = (BYTE)flags;
+ }
+ hPalette = ::CreatePalette(logPal);
+ delete logPal;