- if (pMask)
- {
- BITMAPINFOHEADER2 vHeader;
- BITMAPINFO2 vInfo;
- int nBytesPerLine = rBmp.GetWidth() * 3;
- unsigned char* pucData;
- LONG lScans = 0L;
- LONG alFormats[24]; // Max formats OS/2 PM supports
- ULONG ulBitcount;
- HBITMAP hMask = (HBITMAP)pMask->GetMaskBitmap();
- POINTL vPointMask[4] = { 0, 0, rBmp.GetWidth(), rBmp.GetHeight()
- ,0, 0, rBmp.GetWidth(), rBmp.GetHeight()
- };
-
- ::GpiSetBitmap(hPS, hMask);
-
- ::GpiQueryDeviceBitmapFormats(hPS, 24, alFormats);
- ulBitcount = alFormats[1]; // the best one
- if (ulBitcount > 24) // PM supports a max of 24
- ulBitcount = 24;
-
- vInfo.cbFix = 16;
- vInfo.cx = rBmp.GetWidth();
- vInfo.cy = rBmp.GetHeight();
- vInfo.cPlanes = 1;
- vInfo.cBitCount = ulBitcount;
- pucData = (unsigned char*)malloc(nBytesPerLine * rBmp.GetHeight());
+ //
+ // Create the buffers for data....all wxBitmaps are 24 bit internally
+ //
+ int nBytesPerLine = rBmp.GetWidth() * 3;
+ int nSizeDWORD = sizeof(DWORD);
+ int nLineBoundary = nBytesPerLine % nSizeDWORD;
+ int nPadding = 0;
+ int i;
+ int j;
+ LONG lScans = 0L;
+ LONG lColor = 0L;
+
+ //
+ // Need to get a background color for mask blitting
+ //
+ if (IsKindOf(CLASSINFO(wxPaintDC)))
+ {
+ wxPaintDC* pPaintDC = wxDynamicCast(this, wxPaintDC);
+
+ lColor = pPaintDC->m_pCanvas->GetBackgroundColour().GetPixel();
+ }
+ else if (GetBrush() != wxNullBrush)
+ lColor = GetBrush().GetColour().GetPixel();
+ else
+ lColor = m_textBackgroundColour.GetPixel();
+
+ //
+ // Bitmap must be ina double-word alligned address so we may
+ // have some padding to worry about
+ //
+ if (nLineBoundary > 0)
+ {
+ nPadding = nSizeDWORD - nLineBoundary;
+ nBytesPerLine += nPadding;
+ }
+ pucBits = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
+ pucBitsMask = (unsigned char *)malloc(nBytesPerLine * rBmp.GetHeight());
+ memset(pucBits, '\0', (nBytesPerLine * rBmp.GetHeight()));
+ memset(pucBitsMask, '\0', (nBytesPerLine * rBmp.GetHeight()));
+
+ //
+ // Extract the bitmap and mask data
+ //
+ if ((hOldBitmap = ::GpiSetBitmap(hPS, hBitmap)) == HBM_ERROR)
+ {
+ vError = ::WinGetLastError(vHabmain);
+ sError = wxPMErrorToStr(vError);
+ }