+ gdk_drawable_get_size(pixmap, &M_BMPDATA->m_width, &M_BMPDATA->m_height);
+ M_BMPDATA->m_bpp = gdk_drawable_get_depth(pixmap);
+ PurgeOtherRepresentations(Pixmap);
+}
+
+GdkPixmap *wxBitmap::GetPixmap() const
+{
+ wxCHECK_MSG( Ok(), (GdkPixmap *) NULL, wxT("invalid bitmap") );
+
+ // create the pixmap on the fly if we use Pixbuf representation:
+ if (M_BMPDATA->m_pixmap == NULL)
+ {
+ delete M_BMPDATA->m_mask;
+ M_BMPDATA->m_mask = new wxMask;
+ gdk_pixbuf_render_pixmap_and_mask(M_BMPDATA->m_pixbuf,
+ &M_BMPDATA->m_pixmap,
+ &M_BMPDATA->m_mask->m_bitmap,
+ 128 /*threshold*/);
+ }
+
+ return M_BMPDATA->m_pixmap;
+}
+
+bool wxBitmap::HasPixmap() const
+{
+ wxCHECK_MSG( Ok(), false, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_pixmap != NULL;
+}
+
+GdkPixbuf *wxBitmap::GetPixbuf() const
+{
+ wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
+
+ if (M_BMPDATA->m_pixbuf == NULL)
+ {
+ int width = GetWidth();
+ int height = GetHeight();
+
+ // always create the alpha channel so raw bitmap access will work
+ // correctly
+ GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
+ true, // GetMask() != NULL,
+ 8, width, height);
+ M_BMPDATA->m_pixbuf =
+ gdk_pixbuf_get_from_drawable(pixbuf, M_BMPDATA->m_pixmap, NULL,
+ 0, 0, 0, 0, width, height);
+
+ // apply the mask to created pixbuf:
+ if (M_BMPDATA->m_pixbuf && M_BMPDATA->m_mask)
+ {
+ GdkPixbuf *pmask =
+ gdk_pixbuf_get_from_drawable(NULL,
+ M_BMPDATA->m_mask->GetBitmap(),
+ NULL,
+ 0, 0, 0, 0, width, height);
+ if (pmask)
+ {
+ guchar *bmp = gdk_pixbuf_get_pixels(pixbuf);
+ guchar *mask = gdk_pixbuf_get_pixels(pmask);
+ int bmprowinc = gdk_pixbuf_get_rowstride(pixbuf) - 4 * width;
+ int maskrowinc = gdk_pixbuf_get_rowstride(pmask) - 3 * width;
+
+ for (int y = 0; y < height;
+ y++, bmp += bmprowinc, mask += maskrowinc)
+ {
+ for (int x = 0; x < width; x++, bmp += 4, mask += 3)
+ {
+ if (mask[0] == 0 /*black pixel*/)
+ bmp[3] = 0;
+ }
+ }
+
+ g_object_unref (pmask);
+ }
+ }
+ }
+
+ return M_BMPDATA->m_pixbuf;
+}
+
+bool wxBitmap::HasPixbuf() const
+{
+ wxCHECK_MSG( Ok(), false, wxT("invalid bitmap") );
+
+ return M_BMPDATA->m_pixbuf != NULL;