//-----------------------------------------------------------------------------
-#define M_BMPDATA wx_static_cast(wxBitmapRefData*, m_refData)
+#define M_BMPDATA static_cast<wxBitmapRefData*>(m_refData)
IMPLEMENT_DYNAMIC_CLASS(wxBitmap,wxGDIObject)
wxCHECK2_MSG(bits != NULL, return, wxT("invalid bitmap data"));
GdkBitmap* mask = NULL;
- SetPixmap(gdk_pixmap_create_from_xpm_d(wxGetRootWindow()->window, &mask, NULL, wx_const_cast(char**, bits)));
+ SetPixmap(gdk_pixmap_create_from_xpm_d(wxGetRootWindow()->window, &mask, NULL, const_cast<char**>(bits)));
if (M_BMPDATA->m_pixmap != NULL && mask != NULL)
{
return false;
}
+ const GdkVisual* visual = wxTheApp->GetGdkVisual();
+
if (depth == 32)
{
SetPixbuf(gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, width, height), 32);
+ // must initialize alpha, otherwise GetPixmap()
+ // will create a mask out of garbage
+ gdk_pixbuf_fill(M_BMPDATA->m_pixbuf, 0x000000ff);
+ } else
+ if (depth == 24)
+ {
+ if (visual->depth == depth)
+ SetPixmap(gdk_pixmap_new(wxGetRootWindow()->window, width, height, depth));
+ else
+ SetPixbuf(gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, width, height), 24);
}
else
{
if (depth != 1)
{
- const GdkVisual* visual = wxTheApp->GetGdkVisual();
if (depth == -1)
depth = visual->depth;
-
- wxCHECK_MSG(depth == visual->depth, false, wxT("invalid bitmap depth"));
}
-
SetPixmap(gdk_pixmap_new(wxGetRootWindow()->window, width, height, depth));
}
return Ok();
}
-wxBitmap wxBitmap::Rescale(int clipx, int clipy, int clipwidth, int clipheight,
- int width, int height) const
-{
- wxBitmap bmp;
-
- wxCHECK_MSG(Ok(), bmp, wxT("invalid bitmap"));
-
- width = wxMax(width, 1);
- height = wxMax(height, 1);
-
- const double scale_x = double(width) / clipwidth;
- const double scale_y = double(height) / clipheight;
-
- // Converting to pixbuf, scaling with gdk_pixbuf_scale, and converting
- // back, is faster than scaling pixmap ourselves.
-
- // use pixbuf if already available,
- // otherwise create temporary pixbuf from pixmap
- GdkPixbuf* pixbuf = M_BMPDATA->m_pixbuf;
- if (pixbuf)
- g_object_ref(pixbuf);
- else
- pixbuf = gdk_pixbuf_get_from_drawable(
- NULL, M_BMPDATA->m_pixmap, NULL,
- 0, 0, 0, 0, M_BMPDATA->m_width, M_BMPDATA->m_height);
-
- // new pixbuf for scaled wxBitmap
- GdkPixbuf* pixbuf_scaled = gdk_pixbuf_new(
- GDK_COLORSPACE_RGB, gdk_pixbuf_get_has_alpha(pixbuf), 8, width, height);
-
- // GDK_INTERP_NEAREST is the lowest-quality method for continuous-tone
- // images, but the only one which preserves sharp edges
- gdk_pixbuf_scale(
- pixbuf, pixbuf_scaled,
- 0, 0, width, height, -clipx*scale_x, -clipy*scale_y, scale_x, scale_y,
- GDK_INTERP_NEAREST);
-
- g_object_unref(pixbuf);
- bmp.SetPixbuf(pixbuf_scaled, M_BMPDATA->m_bpp);
-
- if (M_BMPDATA->m_mask)
- {
- pixbuf = gdk_pixbuf_get_from_drawable(
- NULL, M_BMPDATA->m_mask->m_bitmap, NULL,
- 0, 0, 0, 0, M_BMPDATA->m_width, M_BMPDATA->m_height);
-
- pixbuf_scaled = gdk_pixbuf_new(
- GDK_COLORSPACE_RGB, false, 8, width, height);
-
- gdk_pixbuf_scale(
- pixbuf, pixbuf_scaled,
- 0, 0, width, height, -clipx, -clipy, scale_x, scale_y,
- GDK_INTERP_NEAREST);
-
- g_object_unref(pixbuf);
-
- // use existing functionality to create mask from scaled pixbuf
- wxBitmap maskbmp;
- maskbmp.SetPixbuf(pixbuf_scaled);
- bmp.SetMask(new wxMask(maskbmp, *wxBLACK));
- }
- return bmp;
-}
-
#if wxUSE_IMAGE
bool wxBitmap::CreateFromImage(const wxImage& image, int depth)
if (M_BMPDATA->m_pixbuf == NULL)
{
+
int width = GetWidth();
int height = GetHeight();
M_BMPDATA->m_pixbuf = 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)
{
void* bits = NULL;
GdkPixbuf *pixbuf = GetPixbuf();
const bool hasAlpha = HasAlpha();
+
// allow access if bpp is valid and matches existence of alpha
if ( pixbuf && ((bpp == 24 && !hasAlpha) || (bpp == 32 && hasAlpha)) )
{
wxGDIRefData* wxBitmap::CloneGDIRefData(const wxGDIRefData* data) const
{
- const wxBitmapRefData* oldRef = wx_static_cast(const wxBitmapRefData*, data);
+ const wxBitmapRefData* oldRef = static_cast<const wxBitmapRefData*>(data);
wxBitmapRefData* newRef = new wxBitmapRefData;
newRef->m_width = oldRef->m_width;
newRef->m_height = oldRef->m_height;