From e8fdc26406cd8bd822955c9d1f12be86781ad379 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 10 Nov 1998 19:18:37 +0000 Subject: [PATCH] Bit fiddling part 4. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@978 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/image/image.cpp | 15 +++++++++++---- src/gtk/bitmap.cpp | 19 ++++++++++--------- src/gtk/colour.cpp | 2 ++ src/gtk1/bitmap.cpp | 19 ++++++++++--------- src/gtk1/colour.cpp | 2 ++ 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/samples/image/image.cpp b/samples/image/image.cpp index c93a84b6a3..fac7bf1a87 100644 --- a/samples/image/image.cpp +++ b/samples/image/image.cpp @@ -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 diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 011930fbd1..9d7cbed51a 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -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; diff --git a/src/gtk/colour.cpp b/src/gtk/colour.cpp index 09479c1230..988809e579 100644 --- a/src/gtk/colour.cpp +++ b/src/gtk/colour.cpp @@ -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; } diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp index 011930fbd1..9d7cbed51a 100644 --- a/src/gtk1/bitmap.cpp +++ b/src/gtk1/bitmap.cpp @@ -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; diff --git a/src/gtk1/colour.cpp b/src/gtk1/colour.cpp index 09479c1230..988809e579 100644 --- a/src/gtk1/colour.cpp +++ b/src/gtk1/colour.cpp @@ -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; } -- 2.45.2