- SetMask(new wxMask(*this, wxColour(image.GetMaskRed(),
- image.GetMaskGreen(),
- image.GetMaskBlue())));
- }
-
- return TRUE;
-#else
- // FIXME: wxWinCE doesn't support wxDIB yet
- return FALSE;
-#endif
-}
-
-wxImage wxBitmap::ConvertToImage() const
-{
- // FIXME: this is untested code for WinCE, and
- // the mask is not yet handled.
- // For tips, see:
- // http://www.codeproject.com/bitmap/dibsection.asp?print=true
-
-#ifdef __WXWINCE__
- // the colour used as transparent one in wxImage and the one it is replaced
- // with when it really occurs in the bitmap
- static const int MASK_RED = 1;
- static const int MASK_GREEN = 2;
- static const int MASK_BLUE = 3;
- static const int MASK_BLUE_REPLACEMENT = 2;
-
- wxImage image;
-
- wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") );
-
- // create an wxImage object
- int width = GetWidth();
- int height = GetHeight();
- image.Create( width, height );
- unsigned char *data = image.GetData();
- if( !data )
- {
- wxFAIL_MSG( wxT("could not allocate data for image") );
- return wxNullImage;
- }
-
- // calc the number of bytes per scanline and padding in the DIB
- int bytePerLine = width*3;
- int sizeDWORD = sizeof( DWORD );
- int lineBoundary = bytePerLine % sizeDWORD;
- int padding = 0;
- if( lineBoundary > 0 )
- {
- padding = sizeDWORD - lineBoundary;
- bytePerLine += padding;
- }
-
- // create a DIB header
- int headersize = sizeof(BITMAPINFOHEADER);
- BITMAPINFO *lpDIBh = (BITMAPINFO *) malloc( headersize );
- if( !lpDIBh )
- {
- wxFAIL_MSG( wxT("could not allocate data for DIB header") );
- free( data );
- return wxNullImage;
- }
- // Fill in the DIB header
- lpDIBh->bmiHeader.biSize = headersize;
- lpDIBh->bmiHeader.biWidth = width;
- lpDIBh->bmiHeader.biHeight = -height;
- lpDIBh->bmiHeader.biSizeImage = bytePerLine * height;
- lpDIBh->bmiHeader.biPlanes = 1;
- lpDIBh->bmiHeader.biBitCount = 24;
- lpDIBh->bmiHeader.biCompression = BI_RGB;
- lpDIBh->bmiHeader.biClrUsed = 0;
- // These seem not really needed for our purpose here.
- lpDIBh->bmiHeader.biClrImportant = 0;
- lpDIBh->bmiHeader.biXPelsPerMeter = 0;
- lpDIBh->bmiHeader.biYPelsPerMeter = 0;
-
- // memory for DIB data is allocated by CreateDIBSection
- void *lpBits = NULL;
-
- // copy data from the device-dependent bitmap to the DIB
- HDC hdc = ::GetDC(NULL);
- HBITMAP hBitmap = (HBITMAP) GetHBITMAP();
-
- HBITMAP hBitmapSection = ::CreateDIBSection( hdc, lpDIBh, DIB_RGB_COLORS, & lpBits, NULL, 0 );
- if (!hBitmapSection)
- {
- wxFAIL_MSG( wxT("could not create a DIB section") );
- return wxNullImage;
- }
-
- // Copy the image from the DDB to the DIBSection
- // Need to copy the supplied bitmap onto the newly created DIBsection
- HDC hMemDC = CreateCompatibleDC(hdc);
- HDC hCopyDC = CreateCompatibleDC(hdc);
-
- if (! hMemDC || ! hCopyDC)
- {
- wxFAIL_MSG( wxT("unable to create compatible DCs") );
- return wxNullImage;
- }
-
-#if 0
- if (m_hPal)
- {
- SelectPalette(hMemDC, m_hPal, FALSE); RealizePalette(hMemDC);
- SelectPalette(hCopyDC, m_hPal, FALSE); RealizePalette(hCopyDC);
- }
-#endif
-
- HBITMAP hOldMemBitmap = (HBITMAP) SelectObject(hMemDC, hBitmap);
- HBITMAP hOldCopyBitmap = (HBITMAP) SelectObject(hCopyDC, hBitmapSection);
-
- BitBlt(hCopyDC, 0, 0, GetWidth(), GetHeight(), hMemDC, 0, 0, SRCCOPY);
-
- SelectObject(hMemDC, hOldMemBitmap);
- SelectObject(hCopyDC, hOldCopyBitmap);
- DeleteDC(hMemDC);
- DeleteDC(hCopyDC);
-
-#if 0
- if (m_hPal)
- {
- HGDIOBJ hObj = ::GetStockObject(DEFAULT_PALETTE);
- SelectObject(hMemDC, hObj);
- SelectObject(hCopyDC, hObj);
- }
-#endif
-
- ReleaseDC(NULL, hdc);
-
- // copy DIB data into the wxImage object
- int i, j;
- unsigned char *ptdata = data;
- unsigned char *ptbits = (unsigned char*) lpBits;
- for( i=0; i<height; i++ )
- {
- for( j=0; j<width; j++ )