-// ----------------------------------------------------------------------------
-// private functions
-// ----------------------------------------------------------------------------
-
-WXHBITMAP wxToolBar::MapBitmap(WXHBITMAP bitmap, int width, int height)
-{
- MemoryHDC hdcMem;
-
- if ( !hdcMem )
- {
- wxLogLastError(_T("CreateCompatibleDC"));
-
- return bitmap;
- }
-
- SelectInHDC bmpInHDC(hdcMem, (HBITMAP)bitmap);
-
- if ( !bmpInHDC )
- {
- wxLogLastError(_T("SelectObject"));
-
- return bitmap;
- }
-
- wxCOLORMAP *cmap = wxGetStdColourMap();
-
- for ( int i = 0; i < width; i++ )
- {
- for ( int j = 0; j < height; j++ )
- {
- COLORREF pixel = ::GetPixel(hdcMem, i, j);
-
- for ( size_t k = 0; k < wxSTD_COL_MAX; k++ )
- {
- COLORREF col = cmap[k].from;
- if ( abs(GetRValue(pixel) - GetRValue(col)) < 10 &&
- abs(GetGValue(pixel) - GetGValue(col)) < 10 &&
- abs(GetBValue(pixel) - GetBValue(col)) < 10 )
- {
- ::SetPixel(hdcMem, i, j, cmap[k].to);
- break;
- }
- }
- }
- }
-
- return bitmap;
-
- // VZ: I leave here my attempts to map the bitmap to the system colours
- // faster by using BitBlt() even though it's broken currently - but
- // maybe someone else can finish it? It should be faster than iterating
- // over all pixels...
-#if 0
- MemoryHDC hdcMask, hdcDst;
- if ( !hdcMask || !hdcDst )
- {
- wxLogLastError(_T("CreateCompatibleDC"));
-
- return bitmap;
- }
-
- // create the target bitmap
- HBITMAP hbmpDst = ::CreateCompatibleBitmap(hdcDst, width, height);
- if ( !hbmpDst )
- {
- wxLogLastError(_T("CreateCompatibleBitmap"));
-
- return bitmap;
- }
-
- // create the monochrome mask bitmap
- HBITMAP hbmpMask = ::CreateBitmap(width, height, 1, 1, 0);
- if ( !hbmpMask )
- {
- wxLogLastError(_T("CreateBitmap(mono)"));
-
- ::DeleteObject(hbmpDst);
-
- return bitmap;
- }
-
- SelectInHDC bmpInDst(hdcDst, hbmpDst),
- bmpInMask(hdcMask, hbmpMask);
-
- // for each colour:
- for ( n = 0; n < NUM_OF_MAPPED_COLOURS; n++ )
- {
- // create the mask for this colour
- ::SetBkColor(hdcMem, ColorMap[n].from);
- ::BitBlt(hdcMask, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY);
-
- // replace this colour with the target one in the dst bitmap
- HBRUSH hbr = ::CreateSolidBrush(ColorMap[n].to);
- HGDIOBJ hbrOld = ::SelectObject(hdcDst, hbr);
-
- ::MaskBlt(hdcDst, 0, 0, width, height,
- hdcMem, 0, 0,
- hbmpMask, 0, 0,
- MAKEROP4(PATCOPY, SRCCOPY));
-
- (void)::SelectObject(hdcDst, hbrOld);
- ::DeleteObject(hbr);
- }
-
- ::DeleteObject((HBITMAP)bitmap);
-
- return (WXHBITMAP)hbmpDst;
-#endif // 0
-}
-