X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8cb172b4f12fae80b06d5936108a1bc7f2521674..b403ab005c463ecd3246d864b345a3814f7be4f2:/src/msw/bitmap.cpp diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index c7dc1834fd..c4b2b8bed5 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -144,6 +144,10 @@ bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon) refData->m_bitmapMask = new wxMask((WXHBITMAP) wxInvertMask(iconInfo.hbmMask, w, h)); + + // delete the old one now as we don't need it any more + ::DeleteObject(iconInfo.hbmMask); + #if WXWIN_COMPATIBILITY_2 refData->m_ok = TRUE; #endif // WXWIN_COMPATIBILITY_2 @@ -242,9 +246,9 @@ wxBitmap::wxBitmap(const char bits[], int width, int height, int depth) // we assume that it is in XBM format which is not quite the same as // the format CreateBitmap() wants because the order of bytes in the // line is inversed! - static const size_t bytesPerLine = (width + 7) / 8; - static const size_t padding = bytesPerLine % 2; - static const size_t len = height * ( padding + bytesPerLine ); + const size_t bytesPerLine = (width + 7) / 8; + const size_t padding = bytesPerLine % 2; + const size_t len = height * ( padding + bytesPerLine ); data = (char *)malloc(len); const char *src = bits; char *dst = data; @@ -297,15 +301,15 @@ bool wxBitmap::CreateFromXpm(const char **data) Init(); wxCHECK_MSG( data != NULL, FALSE, wxT("invalid bitmap data") ) - + wxXPMDecoder decoder; wxImage img = decoder.ReadData(data); wxCHECK_MSG( img.Ok(), FALSE, wxT("invalid bitmap data") ) - + *this = wxBitmap(img); return TRUE; #else - return FALSE; + return FALSE; #endif } @@ -431,6 +435,9 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) if (depth == -1) depth = wxDisplayDepth(); SetDepth( depth ); + // Copy the palette from the source image + SetPalette(image.GetPalette()); + // create a DIB header int headersize = sizeof(BITMAPINFOHEADER); BITMAPINFO *lpDIBh = (BITMAPINFO *) malloc( headersize ); @@ -467,12 +474,14 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) hbitmap = ::CreateCompatibleBitmap( hdc, width, bmpHeight ); ::SelectObject( memdc, hbitmap); +#if wxUSE_PALETTE HPALETTE hOldPalette = 0; if (image.GetPalette().Ok()) { hOldPalette = ::SelectPalette(memdc, (HPALETTE) image.GetPalette().GetHPALETTE(), FALSE); ::RealizePalette(memdc); } +#endif // wxUSE_PALETTE // copy image data into DIB data and then into DDB (in a loop) unsigned char *data = image.GetData(); @@ -523,8 +532,10 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) } SetHBITMAP( (WXHBITMAP) hbitmap ); +#if wxUSE_PALETTE if (hOldPalette) SelectPalette(memdc, hOldPalette, FALSE); +#endif // wxUSE_PALETTE // similarly, created an mono-bitmap for the possible mask if( image.HasMask() ) @@ -792,7 +803,9 @@ bool wxBitmap::Create(void *data, long type, int width, int height, int depth) return handler->Create(this, data, type, width, height, depth); } -bool wxBitmap::SaveFile(const wxString& filename, int type, const wxPalette *palette) +bool wxBitmap::SaveFile(const wxString& filename, + int type, + const wxPalette *palette) { wxBitmapHandler *handler = wxDynamicCast(FindHandler(type), wxBitmapHandler); @@ -882,6 +895,8 @@ void wxBitmap::SetOk(bool isOk) } #endif // WXWIN_COMPATIBILITY_2 +#if wxUSE_PALETTE + void wxBitmap::SetPalette(const wxPalette& palette) { EnsureHasData(); @@ -889,6 +904,8 @@ void wxBitmap::SetPalette(const wxPalette& palette) GetBitmapData()->m_bitmapPalette = palette; } +#endif // wxUSE_PALETTE + void wxBitmap::SetMask(wxMask *mask) { EnsureHasData(); @@ -911,6 +928,7 @@ wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const LPBITMAPINFO lpDib; void *lpBits = (void*) NULL; +#if wxUSE_PALETTE if( GetPalette() && GetPalette()->Ok() ) { tmpBitmap.SetPalette(*GetPalette()); @@ -927,6 +945,9 @@ wxBitmap wxBitmap::GetBitmapForDC(wxDC& dc) const memDC.SelectObject(tmpBitmap); memDC.SetPalette( palette ); } +#else // !wxUSE_PALETTE + hPal = (HPALETTE) ::GetStockObject(DEFAULT_PALETTE); +#endif // wxUSE_PALETTE/!wxUSE_PALETTE // set the height negative because in a DIB the order of the lines is // reversed @@ -1032,6 +1053,8 @@ bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex) ::DeleteObject((HBITMAP) m_maskBitmap); m_maskBitmap = 0; } + +#if wxUSE_PALETTE if (bitmap.Ok() && bitmap.GetPalette()->Ok()) { unsigned char red, green, blue; @@ -1041,6 +1064,8 @@ bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex) return Create(bitmap, transparentColour); } } +#endif // wxUSE_PALETTE + return FALSE; } @@ -1062,7 +1087,7 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) // scan the bitmap for the transparent colour and set the corresponding // pixels in the mask to BLACK and the rest to WHITE - COLORREF maskColour = wxColourToRGB(colour); + COLORREF maskColour = RGB(colour.Red(), colour.Green(), colour.Blue()); m_maskBitmap = (WXHBITMAP)::CreateBitmap(width, height, 1, 1, 0); HDC srcDC = ::CreateCompatibleDC(NULL);