// 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
}
bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
{
+#ifdef __WXMICROWIN__
+ // TODO
+ return FALSE;
+#else
wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") )
m_refData = new wxBitmapRefData();
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() )
if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
return TRUE;
+#endif
}
wxImage wxBitmap::ConvertToImage() const
{
+#ifdef __WXMICROWIN__
+ // TODO
+ return wxImage();
+#else
wxImage image;
wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") );
free(lpBits);
return image;
+#endif
}
#endif // wxUSE_IMAGE
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;
}