X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1cee3f6006e1838fa3d59055233c435e3124d59e..08a15c0d899daad0ff8cc2ed4c06ff78b8ec3cc3:/src/os2/bitmap.cpp diff --git a/src/os2/bitmap.cpp b/src/os2/bitmap.cpp index 6ea8aa4752..486cfed0af 100644 --- a/src/os2/bitmap.cpp +++ b/src/os2/bitmap.cpp @@ -227,6 +227,8 @@ wxBitmap::wxBitmap( pzData = (char *)zBits; // const_cast is harmless } + if (nDepth > 24) + nDepth = 24; // MAX supported in PM memset(&vHeader, '\0', 16); vHeader.cbFix = 16; vHeader.cx = (USHORT)nWidth; @@ -346,6 +348,9 @@ bool wxBitmap::Create( hDCScreen = ::GpiQueryDevice(hPSScreen); ::DevQueryCaps(hDCScreen, CAPS_COLOR_BITCOUNT, 1L, &lBitCount); + if (lBitCount > 24) + lBitCount = 24; + memset(&vHeader, '\0', 16); vHeader.cbFix = 16; vHeader.cx = nW; @@ -563,6 +568,8 @@ bool wxBitmap::CreateFromImage ( // BITMAPINFOHEADER2 vHeader; BITMAPINFO2 vInfo; + LONG alFormats[24]; // Max formats OS/2 PM supports + ULONG ulBitcount; // // Fill in the DIB header @@ -574,12 +581,6 @@ bool wxBitmap::CreateFromImage ( 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 // @@ -600,11 +601,22 @@ bool wxBitmap::CreateFromImage ( HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE); HPS hPS = ::GpiCreatePS(vHabmain, hDC, &vSize, PU_PELS | GPIA_ASSOC); LONG lScans; - HDC hDCScreen = ::WinOpenWindowDC(HWND_DESKTOP); + HDC hDCScreen = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE); HPS hPSScreen; HBITMAP hBmp; HBITMAP hBmpOld; + ::GpiQueryDeviceBitmapFormats(hPS, 24, alFormats); + ulBitcount = alFormats[1]; // the best one for the device + if (ulBitcount > 24) + ulBitcount = 24; // MAX bits supported by PM + memset(&vInfo, '\0', 16); + vInfo.cbFix = 16; + vInfo.cx = (ULONG)nWidth; + vInfo.cy = (ULONG)nHeight; + vInfo.cPlanes = 1; + vInfo.cBitCount = ulBitcount; + hBmp = ::GpiCreateBitmap( hPS ,&vHeader ,0L @@ -708,11 +720,11 @@ bool wxBitmap::CreateFromImage ( // if (rImage.HasMask()) { - vHeader.cbFix = sizeof(BITMAPINFOHEADER2); + vHeader.cbFix = 16; vHeader.cx = nWidth; vHeader.cy = nHeight; vHeader.cPlanes = 1; - vHeader.cBitCount = 1; + vHeader.cBitCount = 24; hBmp = ::GpiCreateBitmap( hPS ,&vHeader ,0L @@ -725,7 +737,6 @@ bool wxBitmap::CreateFromImage ( else nHeight = nSizeLimit / nBytePerLine; vHeader.cy = (DWORD)(nHeight); - vHeader.cbImage = nBytePerLine * nHeight; nOrigin = 0; unsigned char cRed = rImage.GetMaskRed(); @@ -745,7 +756,6 @@ bool wxBitmap::CreateFromImage ( // nHeight = nHRemain; vHeader.cy = (DWORD)(nHeight); - vHeader.cbImage = nBytePerLine * nHeight; } ptbits = pucBits; for (int j = 0; j < nHeight; j++) @@ -801,7 +811,7 @@ bool wxBitmap::CreateFromImage ( pMask->SetMaskBitmap((WXHBITMAP)hBmp); SetMask(pMask); - hBmpOld = ::GpiSetBitmap(hPS, hBmp); + hBmpOld = ::GpiSetBitmap(hPS, hBmpOld); } // @@ -809,6 +819,7 @@ bool wxBitmap::CreateFromImage ( // ::GpiSetBitmap(hPS, NULLHANDLE); ::GpiDestroyPS(hPS); + ::DevCloseDC(hDCScreen); ::DevCloseDC(hDC); free(pucBits); return TRUE; @@ -844,7 +855,13 @@ wxImage wxBitmap::ConvertToImage() const DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L}; SIZEL vSizlPage = {0,0}; HDC hDCMem; + LONG alFormats[24]; // 24 is MAX formats supported + ULONG ulBitcount; + ::GpiQueryDeviceBitmapFormats(hPS, 24, alFormats); + ulBitcount = alFormats[1]; // the best one + if (ulBitcount > 24) // PM supports a max of 24 + ulBitcount = 24; vImage.Create( nWidth ,nHeight ); @@ -877,7 +894,7 @@ wxImage wxBitmap::ConvertToImage() const vDIBInfo.cx = nWidth; vDIBInfo.cy = nHeight; vDIBInfo.cPlanes = 1; - vDIBInfo.cBitCount = 24; + vDIBInfo.cBitCount = ulBitcount; lpBits = (unsigned char *)malloc(nBytePerLine * nHeight); if (!lpBits) @@ -982,7 +999,7 @@ wxImage wxBitmap::ConvertToImage() const HPS hMemPS = ::GpiCreatePS( vHabmain ,hMemDC ,&vSizlPage - ,PU_PELS | GPIA_ASSOC | GPIT_MICRO + ,PU_PELS | GPIA_ASSOC ); ::GpiSetColor(hMemPS, OS2RGB(0, 0, 0)); ::GpiSetBackColor(hMemPS, OS2RGB(255, 255, 255) );