+ // 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
+}