- 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 = wxDibColors(pdib);
+
+ GetObject(hpal,sizeof(int),(LPSTR)&nPalColors);
+ nDibColors = wxDibNumColors(pdib);
+
+ if ((SizeImage = lpbi->biSizeImage) == 0)
+ SizeImage = wxDibSizeImage(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)wxDibPtr(lpbi);
+ lpbi->biClrUsed = nPalColors;
+
+ //
+ // re-size the DIB
+ //
+ if (nPalColors > nDibColors)
+ {
+ GlobalReAllocPtr(lpbi, lpbi->biSize + nPalColors*sizeof(RGBQUAD) + SizeImage, 0);
+ hmemmove((BYTE _huge *)wxDibPtr(lpbi), (BYTE _huge *)lpBits, SizeImage);
+ lpBits = (LPBYTE)wxDibPtr(lpbi);
+ }
+ else if (nPalColors < nDibColors)
+ {
+ hmemcpy(wxDibPtr(lpbi), lpBits, SizeImage);
+ GlobalReAllocPtr(lpbi, lpbi->biSize + nPalColors*sizeof(RGBQUAD) + SizeImage, 0);
+ lpBits = (LPBYTE)wxDibPtr(lpbi);
+ }
+
+ //
+ // translate the DIB bits
+ //
+ switch (lpbi->biCompression)
+ {
+ case BI_RLE8:
+ xlatRle8(lpBits, SizeImage, xlat);
+ break;
+
+ case BI_RLE4:
+ xlatRle4(lpBits, SizeImage, xlat);
+ break;