+ //
+ // Create and set the device-dependent bitmap
+ //
+ DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
+ SIZEL vSize = {0, 0};
+ HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
+ HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC);
+ HBITMAP hBmp;
+ HBITMAP hBmpOld;
+
+ hBmp = ::GpiCreateBitmap( hPS
+ ,&vHeader
+ ,0L
+ ,NULL
+ ,NULL
+ );
+ hBmpOld = ::GpiSetBitmap(hPS, hBmp);
+#if wxUSE_PALETTE
+ HPAL hOldPalette = NULLHANDLE;
+ if (rImage.GetPalette().Ok())
+ {
+ hOldPalette = ::GpiSelectPalette(hPS, (HPAL)rImage.GetPalette().GetHPALETTE());
+ }
+#endif // wxUSE_PALETTE
+
+ //
+ // Copy image data into DIB data and then into DDB (in a loop)
+ //
+ unsigned char* pData = rImage.GetData();
+ int i;
+ int j;
+ int n;
+ int nOrigin = 0;
+ unsigned char* ptdata = pData;
+ unsigned char* ptbits;
+
+ for (n = 0; n < nNumDIB; n++)
+ {
+ if (nNumDIB > 1 && n == nNumDIB - 1 && nHRemain > 0)
+ {
+ //
+ // Redefine height and size of the (possibly) last smaller DIB
+ // memory is not reallocated
+ //
+ nHeight = nHRemain;
+ vHeader.cy = (DWORD)(nHeight);
+ vHeader.cbImage = nBytePerLine * nHeight;
+ }
+ ptbits = pucBits;
+ for (j = 0; j < nHeight; j++)
+ {
+ for (i = 0; i < nWidth; i++)
+ {
+ *(ptbits++) = *(ptdata + 2);
+ *(ptbits++) = *(ptdata + 1);
+ *(ptbits++) = *(ptdata);
+ ptdata += 3;
+ }
+ for (i = 0; i < nPadding; i++)
+ *(ptbits++) = 0;
+ }
+
+ //
+ // Have to do something similar to WIN32's StretchDIBits, use GpiBitBlt
+ //
+ POINTL vPoint[4] = { 0, nOrigin,
+ nWidth, nHeight,
+ 0, 0, nWidth, nHeight
+ };
+
+ ::GpiBitBlt( hPS
+ ,hPS
+ ,4
+ ,vPoint
+ ,ROP_SRCCOPY
+ ,BBO_IGNORE
+ );
+ nOrigin += nHeight;
+ }
+ SetHBITMAP((WXHBITMAP)hBmp);
+#if wxUSE_PALETTE
+ if (hOldPalette)
+ ::GpiSelectPalette(hPS, hOldPalette);
+#endif // wxUSE_PALETTE
+
+ //
+ // Similarly, created an mono-bitmap for the possible mask
+ //
+ if (rImage.HasMask())
+ {
+ memset(&vHeader, '\0', sizeof(BITMAPINFOHEADER2));
+ vHeader.cbFix = sizeof(BITMAPINFOHEADER2);
+ vHeader.cx = nWidth;
+ vHeader.cy = nHeight;
+ vHeader.cPlanes = 1;
+ vHeader.cBitCount = 1;
+ hBmp = ::GpiCreateBitmap( hPS
+ ,&vHeader
+ ,0L
+ ,NULL
+ ,NULL
+ );
+ hBmpOld = ::GpiSetBitmap(hPS, hBmp);
+ if (nNumDIB == 1)
+ nHeight = nBmpHeight;
+ else
+ nHeight = nSizeLimit / nBytePerLine;
+ vHeader.cy = (DWORD)(nHeight);
+ vHeader.cbImage = nBytePerLine * nHeight;
+ nOrigin = 0;
+
+ unsigned char cRed = rImage.GetMaskRed();
+ unsigned char cGreen = rImage.GetMaskGreen();
+ unsigned char cBlue = rImage.GetMaskBlue();
+ unsigned char cZero = 0;
+ unsigned char cOne = 255;
+
+ ptdata = pData;
+ for (n = 0; n < nNumDIB; n++)
+ {
+ if (nNumDIB > 1 && n == nNumDIB - 1 && nHRemain > 0)
+ {
+ //
+ // Redefine height and size of the (possibly) last smaller DIB
+ // memory is not reallocated
+ //
+ nHeight = nHRemain;
+ vHeader.cy = (DWORD)(nHeight);
+ vHeader.cbImage = nBytePerLine * nHeight;
+ }
+ ptbits = pucBits;
+ for (int j = 0; j < nHeight; j++)
+ {
+ for (i = 0; i < nWidth; i++)
+ {
+ if ((*(ptdata++) != cRed) || (*(ptdata++) != cGreen) || (*(ptdata++) != cBlue))
+ {
+ *(ptbits++) = cOne;
+ *(ptbits++) = cOne;
+ *(ptbits++) = cOne;
+ }
+ else
+ {
+ *(ptbits++) = cZero;
+ *(ptbits++) = cZero;
+ *(ptbits++) = cZero;
+ }
+ }
+ for (i = 0; i < nPadding; i++)
+ *(ptbits++) = cZero;
+ }
+ POINTL vPoint[4] = { 0, nOrigin,
+ nWidth, nHeight,
+ 0, 0, nWidth, nHeight
+ };
+
+ ::GpiBitBlt( hPS
+ ,hPS
+ ,4
+ ,vPoint
+ ,ROP_SRCCOPY
+ ,BBO_IGNORE
+ );
+ nOrigin += nHeight;
+ }
+
+ //
+ // Create a wxMask object
+ //
+ wxMask* pMask = new wxMask();
+
+ pMask->SetMaskBitmap((WXHBITMAP)hBmp);
+ SetMask(pMask);
+ hBmpOld = ::GpiSetBitmap(hPS, hBmp);
+ }
+
+ //
+ // Free allocated resources
+ //
+ ::GpiSetBitmap(hPS, NULLHANDLE);
+ ::GpiDestroyPS(hPS);
+ ::DevCloseDC(hDC);
+ free(pucBits);
+ return TRUE;
+} // end of wxBitmap::CreateFromImage
+
+wxImage wxBitmap::ConvertToImage() const