X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/be69f971c404a0260ab5e7c195182d267b893245..adb799d6ef8e1ba754ab08b26e64fa40219f95f8:/src/msw/bitmap.cpp?ds=inline diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 86bddb84ca..f0c834bb24 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -789,7 +789,7 @@ bool wxBitmap::CreateFromImage(const wxImage& image, int depth, WXHDC hdc) { hbitmap = dib.CreateDDB((HDC)hdc); - refData->m_depth = depth == -1 ? wxDisplayDepth() : depth; + refData->m_depth = depth == -1 ? dib.GetDepth() : depth; } #endif // !ALWAYS_USE_DIB @@ -811,15 +811,127 @@ wxImage wxBitmap::ConvertToImage() const { wxDIB dib(*this); - wxImage image; - if ( dib.IsOk() ) + if ( !dib.IsOk() ) { - image = dib.ConvertToImage(); - if ( image.Ok() ) + return wxNullImage; + } + + wxImage image = dib.ConvertToImage(); + if ( !image.Ok() ) + { + return wxNullImage; + } + + // set mask + + // TODO: WinCE mask-copying support and use wxDIB +#ifndef __WXWINCE__ + + if( GetMask() && GetMask()->GetMaskBitmap() ) + { + 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; + + HBITMAP hbitmap = (HBITMAP) GetMask()->GetMaskBitmap(); + int width = GetWidth(); + int height = GetHeight(); + + int bytesPerLine = width*3; + int sizeDWORD = sizeof( DWORD ); + int lineBoundary = bytesPerLine % sizeDWORD; + int padding = 0; + if( lineBoundary > 0 ) + { + padding = sizeDWORD - lineBoundary; + bytesPerLine += padding; + } + + // create a DIB header + int headersize = sizeof(BITMAPINFOHEADER); + BITMAPINFO *lpDIBh = (BITMAPINFO *) malloc( headersize ); + if( !lpDIBh ) { - // TODO: set mask + 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 = bytesPerLine * 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 DC created, color set, data copied, and memory DC deleted + + // memory for DIB data + unsigned char *lpBits + = (unsigned char *) malloc( lpDIBh->bmiHeader.biSizeImage ); + if( !lpBits ) + { + wxFAIL_MSG( wxT("could not allocate data for DIB") ); + free( lpDIBh ); + return wxNullImage; + } + + + HDC hdc = ::GetDC(NULL); + + HDC memdc = ::CreateCompatibleDC( hdc ); + ::SetTextColor( memdc, RGB( 0, 0, 0 ) ); + ::SetBkColor( memdc, RGB( 255, 255, 255 ) ); + ::GetDIBits( memdc, hbitmap, 0, height, lpBits, lpDIBh, DIB_RGB_COLORS ); + ::DeleteDC( memdc ); + unsigned char *ptdata = image.GetData();//data; + unsigned char *ptbits = lpBits; + int i, j; + for( i=0; i