X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/357f4c818d25cd63efc90363cc48d79c76f2faf1..8a31648287be0ef976f133de2786b137f1e98340:/src/gtk/bitmap.cpp?ds=sidebyside diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index b26bafcff7..ea8cf8d88f 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -207,7 +207,7 @@ bool wxMask::InitFromMonoBitmap(const wxBitmap& bitmap) return true; } -GdkBitmap *wxMask::GetBitmap() const +GdkPixmap* wxMask::GetBitmap() const { return m_bitmap; } @@ -231,6 +231,13 @@ public: int m_height; int m_bpp; bool m_alphaRequested; + +private: + // We don't provide a copy ctor as copying m_pixmap and m_pixbuf properly + // is expensive and we don't want to do it implicitly (and possibly + // accidentally). wxBitmap::CloneGDIRefData() which does need to do it does + // it explicitly itself. + wxDECLARE_NO_COPY_CLASS(wxBitmapRefData); }; wxBitmapRefData::wxBitmapRefData(int width, int height, int depth) @@ -317,13 +324,11 @@ bool wxBitmap::CreateFromImage(const wxImage& image, int depth) UnRef(); 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)) + if (depth == 32 || (depth == -1 && image.HasAlpha())) return CreateFromImageAsPixbuf(image); // otherwise create pixmap, if alpha is present it will be converted to mask @@ -415,8 +420,6 @@ bool wxBitmap::CreateFromImageAsPixmap(const wxImage& image, int depth) bool wxBitmap::CreateFromImageAsPixbuf(const wxImage& image) { - wxASSERT(image.HasAlpha()); - int width = image.GetWidth(); int height = image.GetHeight(); @@ -434,12 +437,13 @@ bool wxBitmap::CreateFromImageAsPixbuf(const wxImage& image) for (int y = 0; y < height; y++, out += rowpad) { - for (int x = 0; x < width; x++, alpha++, out += 4, in += 3) + for (int x = 0; x < width; x++, out += 4, in += 3) { out[0] = in[0]; out[1] = in[1]; out[2] = in[2]; - out[3] = *alpha; + if (alpha) + out[3] = *alpha++; } } @@ -606,10 +610,8 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const rect.y + h <= bmpData->m_height, ret, wxT("invalid bitmap region")); - wxBitmapRefData* newRef = new wxBitmapRefData(*bmpData); + wxBitmapRefData * const newRef = new wxBitmapRefData(w, h, bmpData->m_bpp); ret.m_refData = newRef; - newRef->m_width = w; - newRef->m_height = h; if (bmpData->m_pixbuf) { @@ -626,7 +628,6 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const newRef->m_pixmap, gc, bmpData->m_pixmap, rect.x, rect.y, 0, 0, w, h); g_object_unref(gc); } - newRef->m_mask = NULL; if (bmpData->m_mask && bmpData->m_mask->m_bitmap) { GdkPixmap* sub_mask = gdk_pixmap_new(bmpData->m_mask->m_bitmap, w, h, 1); @@ -861,7 +862,9 @@ wxGDIRefData* wxBitmap::CreateGDIRefData() const wxGDIRefData* wxBitmap::CloneGDIRefData(const wxGDIRefData* data) const { const wxBitmapRefData* oldRef = static_cast(data); - wxBitmapRefData* newRef = new wxBitmapRefData(*oldRef); + wxBitmapRefData * const newRef = new wxBitmapRefData(oldRef->m_width, + oldRef->m_height, + oldRef->m_bpp); if (oldRef->m_pixmap != NULL) { newRef->m_pixmap = gdk_pixmap_new(