]> git.saurik.com Git - wxWidgets.git/commitdiff
Bit fiddling part 4.
authorRobert Roebling <robert@roebling.de>
Tue, 10 Nov 1998 19:18:37 +0000 (19:18 +0000)
committerRobert Roebling <robert@roebling.de>
Tue, 10 Nov 1998 19:18:37 +0000 (19:18 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@978 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/image/image.cpp
src/gtk/bitmap.cpp
src/gtk/colour.cpp
src/gtk1/bitmap.cpp
src/gtk1/colour.cpp

index c93a84b6a3e08cb899f1dc9f21a06d551ed330da..fac7bf1a8768a79e88b977d1ef91afc8d5f171ea 100644 (file)
@@ -29,6 +29,7 @@ class MyCanvas: public wxScrolledWindow
     void OnPaint( wxPaintEvent &event );
     
     wxBitmap  *my_horse;
+    wxBitmap  *my_square;
     
   DECLARE_EVENT_TABLE()
 };
@@ -83,20 +84,24 @@ MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id, const wxPoint &pos, c
   wxMemoryDC dc;
   dc.SelectObject( bitmap );
   dc.SetBrush( wxBrush( "orange", wxSOLID ) );
-  dc.SetPen( *wxTRANSPARENT_PEN );
+  dc.SetPen( *wxWHITE_PEN );
   dc.DrawRectangle( 0, 0, 100, 100 );
   dc.SelectObject( wxNullBitmap );
   
   image = bitmap.ConvertToImage();
   image.SaveFile( "../test.png", wxBITMAP_TYPE_PNG );
   
-  image.LoadFile( "../test.png", wxBITMAP_TYPE_PNG );
+  image.LoadFile( "../horse.png", wxBITMAP_TYPE_PNG );
   my_horse = new wxBitmap( image );
+  
+  image.LoadFile( "../test.png", wxBITMAP_TYPE_PNG );
+  my_square = new wxBitmap( image );
 }
 
 MyCanvas::~MyCanvas(void)
 {
   delete my_horse;
+  delete my_square;
 }
 
 void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
@@ -105,12 +110,14 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
   PrepareDC( dc );
 
   dc.DrawText( "Loaded image", 30, 100 );
-  if (my_horse->Ok()) dc.DrawBitmap( *my_horse, 30, 120 );
+  if (my_square->Ok()) dc.DrawBitmap( *my_square, 30, 120 );
   
   dc.DrawText( "Drawn directly", 150, 100 );
   dc.SetBrush( wxBrush( "orange", wxSOLID ) );
-  dc.SetPen( *wxTRANSPARENT_PEN );
+  dc.SetPen( *wxWHITE_PEN );
   dc.DrawRectangle( 150, 120, 100, 100 );
+  
+  if (my_horse->Ok()) dc.DrawBitmap( *my_horse, 30, 240 );
 }
 
 // MyFrame
index 011930fbd104ce7438a7eaa3d9e59b2830ff69ad..9d7cbed51a32b5dc38d83777ae4f9c7bd805d043 100644 (file)
@@ -137,7 +137,6 @@ wxBitmap::wxBitmap( char **bits )
     gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
   
     M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth;  // ?
-   
     if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
 }
   
@@ -411,17 +410,18 @@ wxBitmap::wxBitmap( const wxImage &image )
   
     // Retrieve depth  
   
-    M_BMPDATA->m_bpp = data_image->depth;
-  
-    int render_depth = 8;
-    if (M_BMPDATA->m_bpp > 8) render_depth = M_BMPDATA->m_bpp;
-  
+    GdkVisual *visual = gdk_window_get_visual( M_BMPDATA->m_pixmap );
+    if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent );
+    int bpp = visual->depth;
+    if ((bpp == 16) && (visual->red_mask == 0xfc00)) bpp = 15;
+    if (bpp < 8) bpp = 8;
+    
     // Render
 
     enum byte_order { RGB, RBG, BRG, BGR, GRB, GBR };
     byte_order b_o = RGB;
   
-    if (render_depth >= 24)
+    if (bpp >= 24)
     {
         GdkVisual *visual = gdk_visual_get_system();
         if ((visual->red_mask > visual->green_mask) && (visual->green_mask > visual->blue_mask))      b_o = RGB;
@@ -458,7 +458,7 @@ wxBitmap::wxBitmap( const wxImage &image )
                    gdk_image_put_pixel( mask_image, x, y, 0 );
            }
        
-           switch (render_depth)
+           switch (bpp)
            {
                case 8:
                {
@@ -554,7 +554,8 @@ wxImage wxBitmap::ConvertToImage() const
     GdkVisual *visual = gdk_window_get_visual( M_BMPDATA->m_pixmap );
     if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent );
     int bpp = visual->depth;
-  
+    if ((bpp == 16) && (visual->red_mask == 0xfc00)) bpp = 15;
+
     GdkColormap *cmap = gtk_widget_get_default_colormap();
   
     long pos = 0;
index 09479c1230fb276307061b36be1391825c48cc39..988809e579d7ed368163930a467907979100e370 100644 (file)
@@ -208,6 +208,8 @@ void wxColour::CalcPixel( GdkColormap *cmap )
     M_COLDATA->m_hasPixel = gdk_color_alloc( cmap, &M_COLDATA->m_color );
   }
   
+  int p = M_COLDATA->m_color.pixel;
+  
   M_COLDATA->m_colormap = cmap;
 }
 
index 011930fbd104ce7438a7eaa3d9e59b2830ff69ad..9d7cbed51a32b5dc38d83777ae4f9c7bd805d043 100644 (file)
@@ -137,7 +137,6 @@ wxBitmap::wxBitmap( char **bits )
     gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) );
   
     M_BMPDATA->m_bpp = gdk_window_get_visual( parent )->depth;  // ?
-   
     if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this);
 }
   
@@ -411,17 +410,18 @@ wxBitmap::wxBitmap( const wxImage &image )
   
     // Retrieve depth  
   
-    M_BMPDATA->m_bpp = data_image->depth;
-  
-    int render_depth = 8;
-    if (M_BMPDATA->m_bpp > 8) render_depth = M_BMPDATA->m_bpp;
-  
+    GdkVisual *visual = gdk_window_get_visual( M_BMPDATA->m_pixmap );
+    if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent );
+    int bpp = visual->depth;
+    if ((bpp == 16) && (visual->red_mask == 0xfc00)) bpp = 15;
+    if (bpp < 8) bpp = 8;
+    
     // Render
 
     enum byte_order { RGB, RBG, BRG, BGR, GRB, GBR };
     byte_order b_o = RGB;
   
-    if (render_depth >= 24)
+    if (bpp >= 24)
     {
         GdkVisual *visual = gdk_visual_get_system();
         if ((visual->red_mask > visual->green_mask) && (visual->green_mask > visual->blue_mask))      b_o = RGB;
@@ -458,7 +458,7 @@ wxBitmap::wxBitmap( const wxImage &image )
                    gdk_image_put_pixel( mask_image, x, y, 0 );
            }
        
-           switch (render_depth)
+           switch (bpp)
            {
                case 8:
                {
@@ -554,7 +554,8 @@ wxImage wxBitmap::ConvertToImage() const
     GdkVisual *visual = gdk_window_get_visual( M_BMPDATA->m_pixmap );
     if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent );
     int bpp = visual->depth;
-  
+    if ((bpp == 16) && (visual->red_mask == 0xfc00)) bpp = 15;
+
     GdkColormap *cmap = gtk_widget_get_default_colormap();
   
     long pos = 0;
index 09479c1230fb276307061b36be1391825c48cc39..988809e579d7ed368163930a467907979100e370 100644 (file)
@@ -208,6 +208,8 @@ void wxColour::CalcPixel( GdkColormap *cmap )
     M_COLDATA->m_hasPixel = gdk_color_alloc( cmap, &M_COLDATA->m_color );
   }
   
+  int p = M_COLDATA->m_color.pixel;
+  
   M_COLDATA->m_colormap = cmap;
 }