+ GdkGC *data_gc = gdk_gc_new( M_BMPDATA->m_pixmap );
+
+ gdk_draw_image( M_BMPDATA->m_pixmap, data_gc, data_image, 0, 0, 0, 0, width, height );
+
+ gdk_image_destroy( data_image );
+ gdk_gc_unref( data_gc );
+
+ // Blit mask
+
+ if (image.HasMask())
+ {
+ GdkGC *mask_gc = gdk_gc_new( M_BMPDATA->m_mask->m_bitmap );
+
+ gdk_draw_image( M_BMPDATA->m_mask->m_bitmap, mask_gc, mask_image, 0, 0, 0, 0, width, height );
+
+ gdk_image_destroy( mask_image );
+ gdk_gc_unref( mask_gc );
+ }
+
+}
+
+wxImage wxBitmap::ConvertToImage() const
+{
+ wxImage image;
+
+ if (!Ok())
+ {
+ wxFAIL_MSG( "invalid bitmap" );
+ return image;
+ }
+
+ GdkImage *gdk_image = gdk_image_get( M_BMPDATA->m_pixmap, 0, 0, M_BMPDATA->m_width, M_BMPDATA->m_height );
+
+ if (!gdk_image) return image;
+
+ image.Create( M_BMPDATA->m_width, M_BMPDATA->m_height );
+ char unsigned *data = image.GetData();
+
+ int bpp = gdk_image->bpp;
+ GdkColormap *cmap = gtk_widget_get_default_colormap();
+
+ long pos = 0;
+ for (int j = 0; j < M_BMPDATA->m_height; j++)
+ {
+ for (int i = 0; i < M_BMPDATA->m_width; i++)
+ {
+ int pixel = gdk_image_get_pixel( gdk_image, i, j );
+ if (bpp <= 8)
+ {
+ data[pos] = cmap->colors[pixel].red >> 8;
+ data[pos+1] = cmap->colors[pixel].green >> 8;
+ data[pos+2] = cmap->colors[pixel].blue >> 8;
+ } else if (bpp == 15)
+ {
+ data[pos] = (pixel >> 7) & 0xf8;
+ data[pos+1] = (pixel >> 3) & 0xf8;
+ data[pos+2] = (pixel << 3) & 0xf8;
+ } else if (bpp == 16)
+ {
+ data[pos] = (pixel >> 8) & 0xf8;
+ data[pos+1] = (pixel >> 3) & 0xfc;
+ data[pos+2] = (pixel << 3) & 0xf8;
+ } else
+ {
+ data[pos] = (pixel >> 16) & 0xff;
+ data[pos+1] = (pixel >> 8) & 0xff;
+ data[pos+2] = pixel & 0xff;
+ }
+
+ pos += 3;
+ }
+ }
+
+ gdk_image_destroy( gdk_image );
+
+ return image;
+}
+