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
// 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;
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
}
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 );
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();
}
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() )
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);
}
#endif // WXWIN_COMPATIBILITY_2
+#if wxUSE_PALETTE
+
void wxBitmap::SetPalette(const wxPalette& palette)
{
EnsureHasData();
GetBitmapData()->m_bitmapPalette = palette;
}
+#endif // wxUSE_PALETTE
+
void wxBitmap::SetMask(wxMask *mask)
{
EnsureHasData();
LPBITMAPINFO lpDib;
void *lpBits = (void*) NULL;
+#if wxUSE_PALETTE
if( GetPalette() && GetPalette()->Ok() )
{
tmpBitmap.SetPalette(*GetPalette());
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
::DeleteObject((HBITMAP) m_maskBitmap);
m_maskBitmap = 0;
}
+
+#if wxUSE_PALETTE
if (bitmap.Ok() && bitmap.GetPalette()->Ok())
{
unsigned char red, green, blue;
return Create(bitmap, transparentColour);
}
}
+#endif // wxUSE_PALETTE
+
return FALSE;
}
// 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);