if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
}
+wxBitmap::wxBitmap( const char **bits )
+{
+ wxCHECK_RET( bits != NULL, "invalid bitmap data" )
+
+ m_refData = new wxBitmapRefData();
+
+ GdkBitmap *mask = (GdkBitmap*) NULL;
+ GdkWindow *parent = (GdkWindow*) &gdk_root_parent;
+
+ M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( parent, &mask, NULL, (gchar **) bits );
+
+ if (mask)
+ {
+ M_BMPDATA->m_mask = new wxMask();
+ M_BMPDATA->m_mask->m_bitmap = mask;
+ }
+
+ gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
+
+ M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; // ?
+ if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
+}
+
wxBitmap::wxBitmap( char **bits )
{
wxCHECK_RET( bits != NULL, "invalid bitmap data" )
gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth; // ?
-
if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
}
int wxBitmap::GetHeight(void) const
{
- if (!Ok())
- {
- wxFAIL_MSG( "invalid bitmap" );
- return -1;
- }
+ wxCHECK_MSG( Ok(), -1, "invalid bitmap" );
return M_BMPDATA->m_height;
}
int wxBitmap::GetWidth(void) const
{
- if (!Ok())
- {
- wxFAIL_MSG( "invalid bitmap" );
- return -1;
- }
+ wxCHECK_MSG( Ok(), -1, "invalid bitmap" );
return M_BMPDATA->m_width;
}
int wxBitmap::GetDepth(void) const
{
- if (!Ok())
- {
- wxFAIL_MSG( "invalid bitmap" );
- return -1;
- }
+ wxCHECK_MSG( Ok(), -1, "invalid bitmap" );
return M_BMPDATA->m_bpp;
}
wxMask *wxBitmap::GetMask(void) const
{
- if (!Ok())
- {
- wxFAIL_MSG( "invalid bitmap" );
- return (wxMask *) NULL;
- }
+ wxCHECK_MSG( Ok(), (wxMask *) NULL, "invalid bitmap" );
return M_BMPDATA->m_mask;
}
void wxBitmap::SetMask( wxMask *mask )
{
- if (!Ok())
- {
- wxFAIL_MSG( "invalid bitmap" );
- return;
- }
+ wxCHECK_RET( Ok(), "invalid bitmap" );
if (M_BMPDATA->m_mask) delete M_BMPDATA->m_mask;
bool wxBitmap::SaveFile( const wxString &name, int type, wxPalette *WXUNUSED(palette) )
{
- if (!Ok())
- {
- wxFAIL_MSG( "invalid bitmap" );
- return FALSE;
- }
+ wxCHECK_MSG( Ok(), FALSE, "invalid bitmap" );
if (type == wxBITMAP_TYPE_PNG)
{
wxPalette *wxBitmap::GetPalette(void) const
{
if (!Ok()) return (wxPalette *) NULL;
+
return M_BMPDATA->m_palette;
}
GdkPixmap *wxBitmap::GetPixmap(void) const
{
- if (!Ok())
- {
- wxFAIL_MSG( "invalid bitmap" );
- return (GdkPixmap *) NULL;
- }
+ wxCHECK_MSG( Ok(), (GdkPixmap *) NULL, "invalid bitmap" );
return M_BMPDATA->m_pixmap;
}
GdkBitmap *wxBitmap::GetBitmap(void) const
{
- if (!Ok())
- {
- wxFAIL_MSG( "invalid bitmap" );
- return (GdkBitmap *) NULL;
- }
+ wxCHECK_MSG( Ok(), (GdkBitmap *) NULL, "invalid bitmap" );
return M_BMPDATA->m_bitmap;
}
// Retrieve depth
- M_BMPDATA->m_bpp = data_image->depth;
-
- int render_depth = 8;
- if (M_BMPDATA->m_bpp > 8) render_depth = M_BMPDATA->m_bpp;
-
+ GdkVisual *visual = gdk_window_get_visual( M_BMPDATA->m_pixmap );
+ if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent );
+ int bpp = visual->depth;
+ if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
+ if (bpp < 8) bpp = 8;
+
// Render
enum byte_order { RGB, RBG, BRG, BGR, GRB, GBR };
byte_order b_o = RGB;
- if (render_depth >= 24)
+ if (bpp >= 24)
{
GdkVisual *visual = gdk_visual_get_system();
if ((visual->red_mask > visual->green_mask) && (visual->green_mask > visual->blue_mask)) b_o = RGB;
if (image.HasMask())
{
- if ((r == r_mask) && (b = b_mask) && (g = g_mask))
- gdk_image_put_pixel( mask_image, x, y, 0 );
- else
+ if ((r == r_mask) && (b == b_mask) && (g == g_mask))
gdk_image_put_pixel( mask_image, x, y, 1 );
+ else
+ gdk_image_put_pixel( mask_image, x, y, 0 );
}
- switch (render_depth)
+ switch (bpp)
{
case 8:
{
{
wxImage image;
- if (!Ok())
- {
- wxFAIL_MSG( "invalid bitmap" );
- return image;
- }
+ wxCHECK_MSG( Ok(), image, "invalid bitmap" );
GdkImage *gdk_image = gdk_image_get( M_BMPDATA->m_pixmap, 0, 0, M_BMPDATA->m_width, M_BMPDATA->m_height );
GdkVisual *visual = gdk_window_get_visual( M_BMPDATA->m_pixmap );
if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent );
int bpp = visual->depth;
-
+ if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
+
GdkColormap *cmap = gtk_widget_get_default_colormap();
long pos = 0;