X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5ca21fe7bfda18e2da4e17eb529c4dfa0c824db2..dc2513650dce762388f5469360cbb0ac84dcc2d0:/src/gtk/bitmap.cpp diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 5bbc25c7ad..6ab6bcb628 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -2,7 +2,6 @@ // Name: src/gtk/bitmap.cpp // Purpose: // Author: Robert Roebling -// RCS-ID: $Id$ // Copyright: (c) 1998 Robert Roebling // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -273,6 +272,46 @@ bool wxMask::InitFromMonoBitmap(const wxBitmap& bitmap) return true; } +wxBitmap wxMask::GetBitmap() const +{ + wxBitmap bitmap; + if (m_bitmap) + { +#ifdef __WXGTK3__ + cairo_surface_t* mask = m_bitmap; + const int w = cairo_image_surface_get_width(mask); + const int h = cairo_image_surface_get_height(mask); + GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, w, h); + const guchar* src = cairo_image_surface_get_data(mask); + guchar* dst = gdk_pixbuf_get_pixels(pixbuf); + const int stride_src = cairo_image_surface_get_stride(mask); + const int stride_dst = gdk_pixbuf_get_rowstride(pixbuf); + for (int j = 0; j < h; j++, src += stride_src, dst += stride_dst) + { + guchar* d = dst; + for (int i = 0; i < w; i++, d += 3) + { + d[0] = src[i]; + d[1] = src[i]; + d[2] = src[i]; + } + } + bitmap = wxBitmap(pixbuf, 1); +#else + GdkPixmap* mask = m_bitmap; + int w, h; + gdk_drawable_get_size(mask, &w, &h); + GdkPixmap* pixmap = gdk_pixmap_new(mask, w, h, -1); + GdkGC* gc = gdk_gc_new(pixmap); + gdk_gc_set_function(gc, GDK_COPY_INVERT); + gdk_draw_drawable(pixmap, gc, mask, 0, 0, 0, 0, w, h); + g_object_unref(gc); + bitmap = wxBitmap(pixmap); +#endif + } + return bitmap; +} + #ifdef __WXGTK3__ wxMask::operator cairo_surface_t*() const #else @@ -909,46 +948,6 @@ void wxBitmap::SetMask( wxMask *mask ) M_BMPDATA->m_mask = mask; } -wxBitmap wxMask::GetBitmap() const -{ - wxBitmap bitmap; - if (m_bitmap) - { -#ifdef __WXGTK3__ - cairo_surface_t* mask = m_bitmap; - const int w = cairo_image_surface_get_width(mask); - const int h = cairo_image_surface_get_height(mask); - GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, w, h); - const guchar* src = cairo_image_surface_get_data(mask); - guchar* dst = gdk_pixbuf_get_pixels(pixbuf); - const int stride_src = cairo_image_surface_get_stride(mask); - const int stride_dst = gdk_pixbuf_get_rowstride(pixbuf); - for (int j = 0; j < h; j++, src += stride_src, dst += stride_dst) - { - guchar* d = dst; - for (int i = 0; i < w; i++, d += 3) - { - d[0] = src[i]; - d[1] = src[i]; - d[2] = src[i]; - } - } - bitmap = wxBitmap(pixbuf, 1); -#else - GdkPixmap* mask = m_bitmap; - int w, h; - gdk_drawable_get_size(mask, &w, &h); - GdkPixmap* pixmap = gdk_pixmap_new(mask, w, h, -1); - GdkGC* gc = gdk_gc_new(pixmap); - gdk_gc_set_function(gc, GDK_COPY_INVERT); - gdk_draw_drawable(pixmap, gc, mask, 0, 0, 0, 0, w, h); - g_object_unref(gc); - bitmap = wxBitmap(pixmap); -#endif - } - return bitmap; -} - bool wxBitmap::CopyFromIcon(const wxIcon& icon) { *this = icon; @@ -1048,39 +1047,54 @@ bool wxBitmap::SaveFile( const wxString &name, wxBitmapType type, const wxPalett { wxCHECK_MSG( IsOk(), false, wxT("invalid bitmap") ); -#if wxUSE_IMAGE - wxImage image = ConvertToImage(); - if (image.IsOk() && image.SaveFile(name, type)) - return true; -#endif const char* type_name = NULL; switch (type) { + case wxBITMAP_TYPE_ANI: type_name = "ani"; break; case wxBITMAP_TYPE_BMP: type_name = "bmp"; break; + case wxBITMAP_TYPE_GIF: type_name = "gif"; break; case wxBITMAP_TYPE_ICO: type_name = "ico"; break; case wxBITMAP_TYPE_JPEG: type_name = "jpeg"; break; + case wxBITMAP_TYPE_PCX: type_name = "pcx"; break; case wxBITMAP_TYPE_PNG: type_name = "png"; break; + case wxBITMAP_TYPE_PNM: type_name = "pnm"; break; + case wxBITMAP_TYPE_TGA: type_name = "tga"; break; + case wxBITMAP_TYPE_TIFF: type_name = "tiff"; break; + case wxBITMAP_TYPE_XBM: type_name = "xbm"; break; + case wxBITMAP_TYPE_XPM: type_name = "xpm"; break; default: break; } - return type_name && - gdk_pixbuf_save(GetPixbuf(), wxGTK_CONV_FN(name), type_name, NULL, NULL); + if (type_name && + gdk_pixbuf_save(GetPixbuf(), wxGTK_CONV_FN(name), type_name, NULL, NULL)) + { + return true; + } +#if wxUSE_IMAGE + return ConvertToImage().SaveFile(name, type); +#else + return false; +#endif } bool wxBitmap::LoadFile( const wxString &name, wxBitmapType type ) { + GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file(wxGTK_CONV_FN(name), NULL); + if (pixbuf) + { + *this = wxBitmap(pixbuf); + return true; + } #if wxUSE_IMAGE wxImage image; if (image.LoadFile(name, type) && image.IsOk()) - *this = wxBitmap(image); - else -#endif { - wxUnusedVar(type); // The type is detected automatically by GDK. - - *this = wxBitmap(gdk_pixbuf_new_from_file(wxGTK_CONV_FN(name), NULL)); + *this = wxBitmap(image); + return true; } - - return IsOk(); +#else + wxUnusedVar(type); +#endif + return false; } #if wxUSE_PALETTE