Bit fiddling part 4.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@978 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -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
|
||||
|
@@ -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,6 +554,7 @@ 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();
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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,6 +554,7 @@ 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();
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user