+
+ M_BMPDATA->m_bpp = visual->depth; // Can we get a different depth from create_from_xpm_d() ?
+
+ return TRUE;
+}
+
+bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
+{
+ UnRef();
+
+ wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") )
+ wxCHECK_MSG( depth == -1 || depth == 1, FALSE, wxT("invalid bitmap depth") )
+
+ m_refData = new wxBitmapRefData();
+
+ // ------
+ // convertion to mono bitmap:
+ // ------
+ if (depth == 1)
+ {
+ int width = image.GetWidth();
+ int height = image.GetHeight();
+
+ SetHeight( height );
+ SetWidth( width );
+
+ SetBitmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ) );
+
+ SetDepth( 1 );
+
+ GdkVisual *visual = wxTheApp->GetGdkVisual();
+
+ // Create picture image
+
+ unsigned char *data_data = (unsigned char*)malloc( ((width >> 3)+8) * height );
+
+ GdkImage *data_image =
+ gdk_image_new_bitmap( visual, data_data, width, height );
+
+ // Create mask image
+
+ GdkImage *mask_image = (GdkImage*) NULL;
+
+ if (image.HasMask())
+ {
+ unsigned char *mask_data = (unsigned char*)malloc( ((width >> 3)+8) * height );
+
+ mask_image = gdk_image_new_bitmap( visual, mask_data, width, height );
+
+ wxMask *mask = new wxMask();
+ mask->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 );
+
+ SetMask( mask );
+ }
+
+ int r_mask = image.GetMaskRed();
+ int g_mask = image.GetMaskGreen();
+ int b_mask = image.GetMaskBlue();
+
+ unsigned char* data = image.GetData();
+
+ int index = 0;
+ for (int y = 0; y < height; y++)
+ {
+ for (int x = 0; x < width; x++)
+ {
+ int r = data[index];
+ index++;
+ int g = data[index];
+ index++;
+ int b = data[index];
+ index++;
+
+ if (image.HasMask())
+ {
+ if ((r == r_mask) && (b == b_mask) && (g == g_mask))
+ gdk_image_put_pixel( mask_image, x, y, 1 );
+ else
+ gdk_image_put_pixel( mask_image, x, y, 0 );
+ }
+
+ if ((r == 255) && (b == 255) && (g == 255))
+ gdk_image_put_pixel( data_image, x, y, 1 );
+ else
+ gdk_image_put_pixel( data_image, x, y, 0 );
+
+ } // for
+ } // for
+
+ // Blit picture
+
+ GdkGC *data_gc = gdk_gc_new( GetBitmap() );
+
+ gdk_draw_image( GetBitmap(), data_gc, data_image, 0, 0, 0, 0, width, height );
+
+ gdk_image_destroy( data_image );
+ gdk_gc_unref( data_gc );
+
+ // Blit mask
+
+ if (image.HasMask())
+ {
+ GdkGC *mask_gc = gdk_gc_new( GetMask()->GetBitmap() );
+
+ gdk_draw_image( GetMask()->GetBitmap(), mask_gc, mask_image, 0, 0, 0, 0, width, height );
+
+ gdk_image_destroy( mask_image );
+ gdk_gc_unref( mask_gc );
+ }
+ }
+
+ // ------
+ // convertion to colour bitmap:
+ // ------
+ else
+ {
+ int width = image.GetWidth();
+ int height = image.GetHeight();