// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
if (!image.Ok()) return FALSE;
m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, image.GetWidth(), image.GetHeight(), 1 );
if (!image.Ok()) return FALSE;
m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, image.GetWidth(), image.GetHeight(), 1 );
- if (m_pixmap) gdk_pixmap_unref( m_pixmap );
- if (m_bitmap) gdk_bitmap_unref( m_bitmap );
- if (m_mask) delete m_mask;
- if (m_palette) delete m_palette;
+ if (m_pixmap)
+ gdk_pixmap_unref( m_pixmap );
+ if (m_bitmap)
+ gdk_bitmap_unref( m_bitmap );
+ delete m_mask;
+ delete m_palette;
- wxCHECK_MSG( (depth == visual->depth) ||
- (depth == 1), FALSE, wxT("invalid bitmap depth") )
+ wxCHECK_MSG( (depth == visual->depth) || (depth == 1), FALSE,
+ wxT("invalid bitmap depth") )
wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") )
wxCHECK_MSG( depth == -1 || depth == 1, FALSE, wxT("invalid bitmap depth") )
wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") )
wxCHECK_MSG( depth == -1 || depth == 1, FALSE, wxT("invalid bitmap depth") )
SetBitmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ) );
SetDepth( 1 );
SetBitmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ) );
SetDepth( 1 );
SetPixmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, -1 ) );
SetPixmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, -1 ) );
- // Retrieve depth, using XVisualInfo from app, if set
- GdkVisual *visual;
- if (wxTheApp->m_glVisualInfo)
- {
- visual = gdkx_visual_get( ((XVisualInfo *) wxTheApp->m_glVisualInfo)->visualid );
- }
- else
- {
- visual = gdk_window_get_visual( wxGetRootWindow()->window );
- }
- wxASSERT( visual );
+ GdkVisual *visual = wxTheApp->GetGdkVisual();
// visuals are not supported by GDK so we do these ourselves, too.
// 15-bit and 16-bit should actually work and 24-bit certainly does.
// visuals are not supported by GDK so we do these ourselves, too.
// 15-bit and 16-bit should actually work and 24-bit certainly does.
else if ((visual->blue_mask > visual->red_mask) && (visual->red_mask > visual->green_mask)) b_o = BRG;
else if ((visual->blue_mask > visual->green_mask) && (visual->green_mask > visual->red_mask)) b_o = BGR;
else if ((visual->green_mask > visual->red_mask) && (visual->red_mask > visual->blue_mask)) b_o = GRB;
else if ((visual->blue_mask > visual->red_mask) && (visual->red_mask > visual->green_mask)) b_o = BRG;
else if ((visual->blue_mask > visual->green_mask) && (visual->green_mask > visual->red_mask)) b_o = BGR;
else if ((visual->green_mask > visual->red_mask) && (visual->red_mask > visual->blue_mask)) b_o = GRB;
gdk_image_put_pixel( data_image, x, y, pixel );
gdk_image_put_pixel( data_image, x, y, pixel );
- case RGB: pixel = ((r & 0xf8) << 7) | ((g & 0xfc) << 2) | ((b & 0xf8) >> 3); break;
- case RBG: pixel = ((r & 0xf8) << 7) | ((b & 0xfc) << 2) | ((g & 0xf8) >> 3); break;
- case GRB: pixel = ((g & 0xf8) << 7) | ((r & 0xfc) << 2) | ((b & 0xf8) >> 3); break;
- case GBR: pixel = ((g & 0xf8) << 7) | ((b & 0xfc) << 2) | ((r & 0xf8) >> 3); break;
- case BRG: pixel = ((b & 0xf8) << 7) | ((r & 0xfc) << 2) | ((g & 0xf8) >> 3); break;
- case BGR: pixel = ((b & 0xf8) << 7) | ((g & 0xfc) << 2) | ((r & 0xf8) >> 3); break;
+ case RGB: pixel = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); break;
+ case RBG: pixel = ((r & 0xf8) << 8) | ((b & 0xfc) << 3) | ((g & 0xf8) >> 3); break;
+ case GRB: pixel = ((g & 0xf8) << 8) | ((r & 0xfc) << 3) | ((b & 0xf8) >> 3); break;
+ case GBR: pixel = ((g & 0xf8) << 8) | ((b & 0xfc) << 3) | ((r & 0xf8) >> 3); break;
+ case BRG: pixel = ((b & 0xf8) << 8) | ((r & 0xfc) << 3) | ((g & 0xf8) >> 3); break;
+ case BGR: pixel = ((b & 0xf8) << 8) | ((g & 0xfc) << 3) | ((r & 0xf8) >> 3); break;
}
gdk_image_put_pixel( data_image, x, y, pixel );
break;
}
gdk_image_put_pixel( data_image, x, y, pixel );
break;
+ // the colour used as transparent one in wxImage and the one it is replaced
+ // with when it really occurs in the bitmap
+ static const int MASK_RED = 1;
+ static const int MASK_GREEN = 2;
+ static const int MASK_BLUE = 3;
+ static const int MASK_BLUE_REPLACEMENT = 2;
+
red_shift_right = visual->red_shift;
red_shift_left = 8-visual->red_prec;
green_shift_right = visual->green_shift;
red_shift_right = visual->red_shift;
red_shift_left = 8-visual->red_prec;
green_shift_right = visual->green_shift;
- data[pos] = 16;
- data[pos+1] = 16;
- data[pos+2] = 16;
+ data[pos] = MASK_RED;
+ data[pos+1] = MASK_GREEN;
+ data[pos+2] = MASK_BLUE;
+ }
+ else if ( data[pos] == MASK_RED &&
+ data[pos+1] == MASK_GREEN &&
+ data[pos+2] == MASK_BLUE )
+ {
+ data[pos+2] = MASK_BLUE_REPLACEMENT;
wxBitmap::wxBitmap( const char bits[], int width, int height, int WXUNUSED(depth))
{
wxBitmap::wxBitmap( const char bits[], int width, int height, int WXUNUSED(depth))
{
- M_BMPDATA->m_mask = (wxMask *) NULL;
- M_BMPDATA->m_bitmap =
- gdk_bitmap_create_from_data( wxGetRootWindow()->window, (gchar *) bits, width, height );
- M_BMPDATA->m_width = width;
- M_BMPDATA->m_height = height;
- M_BMPDATA->m_bpp = 1;
+ M_BMPDATA->m_mask = (wxMask *) NULL;
+ M_BMPDATA->m_bitmap = gdk_bitmap_create_from_data
+ (
+ wxGetRootWindow()->window,
+ (gchar *) bits,
+ width,
+ height
+ );
+ M_BMPDATA->m_width = width;
+ M_BMPDATA->m_height = height;
+ M_BMPDATA->m_bpp = 1;
- M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm( wxGetRootWindow()->window, &mask, NULL, name.fn_str() );
+ M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm
+ (
+ wxGetRootWindow()->window,
+ &mask,
+ NULL,
+ name.fn_str()
+ );
- if (!image.LoadFile( name, type )) return FALSE;
- if (image.Ok()) *this = image.ConvertToBitmap();
- else return FALSE;
+ if ( !image.LoadFile( name, type ) || !image.Ok() )
+ return FALSE;
+
+ *this = wxBitmap(image);