- // convert alpha channel to mask, if it is present:
- wxImage image(img);
- image.ConvertAlphaToMask();
-
- int width = image.GetWidth();
- int height = image.GetHeight();
-
- SetHeight( height );
- SetWidth( width );
-
- SetPixmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ) );
-
- SetDepth( 1 );
-
- // Create picture image
-
- GdkGC* data_gc = gdk_gc_new(M_BMPDATA->m_pixmap);
- GdkColor color;
- color.pixel = 1;
- gdk_gc_set_foreground(data_gc, &color);
- gdk_draw_rectangle(M_BMPDATA->m_pixmap, data_gc, true, 0, 0, width, height);
- GdkImage* data_image = gdk_drawable_get_image(M_BMPDATA->m_pixmap, 0, 0, width, height);
-
- // Create mask image
-
- GdkImage *mask_image = (GdkImage*) NULL;
- GdkGC* mask_gc = NULL;
-
- if (image.HasMask())
- {
- wxMask *mask = new wxMask();
- mask->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 );
- mask_gc = gdk_gc_new(mask->m_bitmap);
- gdk_gc_set_foreground(mask_gc, &color);
- gdk_draw_rectangle(mask->m_bitmap, mask_gc, true, 0, 0, width, height);
- mask_image = gdk_drawable_get_image(mask->m_bitmap, 0, 0, width, height);
-
- 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 (mask_image != NULL)
- {
- if ((r == r_mask) && (b == b_mask) && (g == g_mask))
- gdk_image_put_pixel( mask_image, x, y, 0 );
- }
-
- if ((r == 255) && (b == 255) && (g == 255))
- gdk_image_put_pixel( data_image, x, y, 0 );
-
- } // for
- } // for
-
- // Blit picture
-
- gdk_draw_image( GetPixmap(), data_gc, data_image, 0, 0, 0, 0, width, height );
-
- g_object_unref (data_image);
- g_object_unref (data_gc);
-
- // Blit mask
-
- if (mask_image != NULL)
- {
- gdk_draw_image( GetMask()->GetBitmap(), mask_gc, mask_image, 0, 0, 0, 0, width, height );