- wxCHECK_MSG( image.IsOk(), false, wxT("invalid image") );
- wxCHECK_MSG( depth == -1 || depth == 1, false, wxT("invalid bitmap depth") );
-
- if (image.GetWidth() <= 0 || image.GetHeight() <= 0)
- return false;
-
- // create pixbuf if image has alpha and requested depth is compatible
- if (image.HasAlpha() && (depth == -1 || depth == 32))
- return CreateFromImageAsPixbuf(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");