+ if (nHeight >= nBmpHeight)
+ nHeight = nBmpHeight;
+ else
+ {
+ nNumDIB = nBmpHeight / nHeight;
+ nHRemain = nBmpHeight % nHeight;
+ if (nHRemain > 0)
+ nNumDIB++;
+ }
+
+ //
+ // Set bitmap parameters
+ //
+ wxCHECK_MSG(rImage.Ok(), FALSE, wxT("invalid image"));
+ SetWidth(nWidth);
+ SetHeight(nBmpHeight);
+ if (nDepth == -1)
+ nDepth = wxDisplayDepth();
+ SetDepth(nDepth);
+
+#if wxUSE_PALETTE
+ //
+ // Copy the palette from the source image
+ //
+ SetPalette(rImage.GetPalette());
+#endif // wxUSE_PALETTE
+
+ //
+ // Create a DIB header
+ //
+ BITMAPINFOHEADER2 vHeader;
+ BITMAPINFO2 vInfo;
+
+ //
+ // Fill in the DIB header
+ //
+ memset(&vHeader, '\0', 16);
+ vHeader.cbFix = 16;
+ vHeader.cx = (ULONG)nWidth;
+ vHeader.cy = (ULONG)nHeight;
+ vHeader.cPlanes = 1L;
+ vHeader.cBitCount = 24;
+
+ memset(&vInfo, '\0', 16);
+ vInfo.cbFix = 16;
+ vInfo.cx = (ULONG)nWidth;
+ vInfo.cy = (ULONG)nHeight;
+ vInfo.cPlanes = 1L;
+ vInfo.cBitCount = 24;
+ //
+ // Memory for DIB data
+ //
+ unsigned char* pucBits;
+
+ pucBits = (unsigned char *)malloc(nBytePerLine * nHeight);
+ if(!pucBits)
+ {
+ wxFAIL_MSG(wxT("could not allocate memory for DIB"));
+ return FALSE;
+ }
+
+ //
+ // 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);
+ LONG lScans;
+ HDC hDCScreen = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
+ HPS hPSScreen;
+ 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;
+ }