- if ((r == 255) && (b == 255) && (g == 255))
- gdk_image_put_pixel( data_image, x, y, 1 );
- else
- gdk_image_put_pixel( data_image, x, y, 0 );
-
- } // for
- } // for
-
- // Blit picture
-
- GdkGC *data_gc = gdk_gc_new( GetBitmap() );
-
- gdk_draw_image( GetBitmap(), data_gc, data_image, 0, 0, 0, 0, width, height );
-
- gdk_image_destroy( data_image );
- gdk_gc_unref( data_gc );
+#if wxUSE_IMAGE
+#ifdef __WXGTK3__
+wxBitmap::wxBitmap(const wxImage& image, int depth)
+{
+ wxCHECK_RET(image.IsOk(), "invalid image");
+
+ const int w = image.GetWidth();
+ const int h = image.GetHeight();
+ const guchar* alpha = image.GetAlpha();
+ if (depth < 0)
+ depth = alpha ? 32 : 24;
+ else if (depth != 1 && depth != 32)
+ depth = 24;
+ wxBitmapRefData* bmpData = new wxBitmapRefData(w, h, depth);
+ m_refData = bmpData;
+ GdkPixbuf* pixbuf_dst = gdk_pixbuf_new(GDK_COLORSPACE_RGB, depth == 32, 8, w, h);
+ bmpData->m_pixbufNoMask = pixbuf_dst;
+ wxASSERT(bmpData->m_bpp == 32 || !gdk_pixbuf_get_has_alpha(bmpData->m_pixbufNoMask));
+ const guchar* src = image.GetData();
+
+ guchar* dst = gdk_pixbuf_get_pixels(pixbuf_dst);
+ const int dstStride = gdk_pixbuf_get_rowstride(pixbuf_dst);
+ CopyImageData(dst, gdk_pixbuf_get_n_channels(pixbuf_dst), dstStride, src, 3, 3 * w, w, h);
+
+ if (depth == 32 && alpha)
+ {
+ for (int j = 0; j < h; j++, dst += dstStride)
+ for (int i = 0; i < w; i++)
+ dst[i * 4 + 3] = *alpha++;
+ }
+ if (image.HasMask())
+ {
+ const guchar r = image.GetMaskRed();
+ const guchar g = image.GetMaskGreen();
+ const guchar b = image.GetMaskBlue();
+ cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_A8, w, h);
+ const int stride = cairo_image_surface_get_stride(surface);
+ dst = cairo_image_surface_get_data(surface);
+ memset(dst, 0xff, stride * h);
+ for (int j = 0; j < h; j++, dst += stride)
+ for (int i = 0; i < w; i++, src += 3)
+ if (src[0] == r && src[1] == g && src[2] == b)
+ dst[i] = 0;
+ cairo_surface_mark_dirty(surface);
+ bmpData->m_mask = new wxMask(surface);
+ }
+}
+#else
+wxBitmap::wxBitmap(const wxImage& image, int depth)
+{
+ wxCHECK_RET(image.IsOk(), "invalid image");