]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/bitmap.cpp
move frame decorations drawing to the base class
[wxWidgets.git] / src / gtk / bitmap.cpp
index a4c89241aab7317208517130e1da89501a2227ed..fcc84f778605550da17558f24b670e0bb9efb442 100644 (file)
@@ -18,6 +18,7 @@
     #include "wx/icon.h"
     #include "wx/math.h"
     #include "wx/image.h"
+    #include "wx/colour.h"
 #endif
 
 #include "wx/rawbmp.h"
@@ -84,7 +85,7 @@ bool wxMask::Create( const wxBitmap& bitmap,
     // one bit per pixel, each row starts on a byte boundary
     const size_t out_size = size_t((w + 7) / 8) * unsigned(h);
     wxByte* out = new wxByte[out_size];
-    // set bits are white
+    // set bits are unmasked
     memset(out, 0xff, out_size);
     unsigned bit_index = 0;
     if (bitmap.HasPixbuf())
@@ -109,8 +110,11 @@ bool wxMask::Create( const wxBitmap& bitmap,
     {
         GdkImage* image = gdk_drawable_get_image(bitmap.GetPixmap(), 0, 0, w, h);
         GdkColormap* colormap = gdk_image_get_colormap(image);
-        guint32 mask_pixel = 1;
-        if (colormap != NULL)
+        guint32 mask_pixel;
+        if (colormap == NULL)
+            // mono bitmap, white is pixel value 0
+            mask_pixel = guint32(colour.Red() != 255 || colour.Green() != 255 || colour.Blue() != 255);
+        else
         {
             wxColor c(colour);
             c.CalcPixel(colormap);
@@ -181,7 +185,7 @@ class wxBitmapRefData: public wxObjectRefData
 {
 public:
     wxBitmapRefData();
-    ~wxBitmapRefData();
+    virtual ~wxBitmapRefData();
 
     GdkPixmap      *m_pixmap;
     GdkPixbuf      *m_pixbuf;
@@ -299,7 +303,7 @@ wxBitmap wxBitmap::Rescale( int clipx, int clipy, int clipwidth, int clipheight,
     {
         bmp.SetDepth(GetDepth());
         bmp.SetPixbuf(gdk_pixbuf_new(GDK_COLORSPACE_RGB,
-                                     gdk_pixbuf_get_has_alpha(GetPixbuf()),
+                                     true, //gdk_pixbuf_get_has_alpha(GetPixbuf()),
                                      8, width, height));
         gdk_pixbuf_scale(GetPixbuf(), bmp.GetPixbuf(),
                          0, 0, width, height,
@@ -493,7 +497,7 @@ bool wxBitmap::CreateFromImageAsPixmap(const wxImage& image, int depth)
         // one bit per pixel, each row starts on a byte boundary
         const size_t out_size = size_t((w + 7) / 8) * unsigned(h);
         wxByte* out = new wxByte[out_size];
-        // set bits are white
+        // set bits are black
         memset(out, 0xff, out_size);
         const wxByte* in = image.GetData();
         unsigned bit_index = 0;
@@ -566,7 +570,7 @@ bool wxBitmap::CreateFromImageAsPixbuf(const wxImage& image)
     int height = image.GetHeight();
 
     GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
-                                       image.HasAlpha(),
+                                       true, //image.HasAlpha(),
                                        8 /* bits per sample */,
                                        width, height);
     if (!pixbuf)
@@ -577,7 +581,7 @@ bool wxBitmap::CreateFromImageAsPixbuf(const wxImage& image)
     wxASSERT( gdk_pixbuf_get_width(pixbuf) == width );
     wxASSERT( gdk_pixbuf_get_height(pixbuf) == height );
 
-    SetDepth(wxTheApp->GetGdkVisual()->depth);
+    SetDepth(32);
     SetPixbuf(pixbuf);
 
     // Copy the data:
@@ -643,7 +647,7 @@ wxImage wxBitmap::ConvertToImage() const
         GdkPixmap* pixmap_invert = NULL;
         if (GetDepth() == 1)
         {
-            // mono bitmaps are inverted
+            // mono bitmaps are inverted, i.e. 0 is white
             pixmap_invert = gdk_pixmap_new(pixmap, w, h, 1);
             GdkGC* gc = gdk_gc_new(pixmap_invert);
             gdk_gc_set_function(gc, GDK_COPY_INVERT);
@@ -789,7 +793,7 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const
     if (HasPixbuf())
     {
         GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
-                                           gdk_pixbuf_get_has_alpha(GetPixbuf()),
+                                           true, //gdk_pixbuf_get_has_alpha(GetPixbuf()),
                                            8, rect.width, rect.height);
         ret.SetPixbuf(pixbuf);
         ret.SetDepth(M_BMPDATA->m_bpp);
@@ -939,8 +943,10 @@ GdkPixbuf *wxBitmap::GetPixbuf() const
         int width = GetWidth();
         int height = GetHeight();
 
+        // always create the alpha channel so raw bitmap access will work
+        // correctly
         GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB,
-                                           GetMask() != NULL,
+                                           true, // GetMask() != NULL,
                                            8, width, height);
         M_BMPDATA->m_pixbuf =
             gdk_pixbuf_get_from_drawable(pixbuf, M_BMPDATA->m_pixmap, NULL,
@@ -1021,11 +1027,14 @@ void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp)
     if (!pixbuf)
         return NULL;
 
+    if (!gdk_pixbuf_get_has_alpha( pixbuf ))
+        return NULL;
+
 #if 0
     if (gdk_pixbuf_get_has_alpha( pixbuf ))
-        wxPrintf( wxT("Has alpha\n") );
+        wxPrintf( wxT("Has alpha, %d channels\n"), gdk_pixbuf_get_n_channels(pixbuf) );
     else
-        wxPrintf( wxT("No alpha.\n") );
+        wxPrintf( wxT("No alpha, %d channels.\n"), gdk_pixbuf_get_n_channels(pixbuf) );
 #endif
 
     data.m_height = gdk_pixbuf_get_height( pixbuf );