-
- switch (bpp)
- {
- case 8:
- {
- int pixel = -1;
- if (wxTheApp->m_colorCube)
- {
- pixel = wxTheApp->m_colorCube[ ((r & 0xf8) << 7) + ((g & 0xf8) << 2) + ((b & 0xf8) >> 3) ];
- }
- else
- {
- GdkColormap *cmap = gtk_widget_get_default_colormap();
- GdkColor *colors = cmap->colors;
- int max = 3 * (65536);
-
- for (int i = 0; i < cmap->size; i++)
- {
- int rdiff = (r << 8) - colors[i].red;
- int gdiff = (g << 8) - colors[i].green;
- int bdiff = (b << 8) - colors[i].blue;
- int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff);
- if (sum < max) { pixel = i; max = sum; }
- }
- }
-
- gdk_image_put_pixel( data_image, x, y, pixel );
-
- break;
- }
- case 12: // SGI only
- {
- guint32 pixel = 0;
- switch (b_o)
- {
- case RGB: pixel = ((r & 0xf0) << 4) | (g & 0xf0) | ((b & 0xf0) >> 4); break;
- case RBG: pixel = ((r & 0xf0) << 4) | (b & 0xf0) | ((g & 0xf0) >> 4); break;
- case GRB: pixel = ((g & 0xf0) << 4) | (r & 0xf0) | ((b & 0xf0) >> 4); break;
- case GBR: pixel = ((g & 0xf0) << 4) | (b & 0xf0) | ((r & 0xf0) >> 4); break;
- case BRG: pixel = ((b & 0xf0) << 4) | (r & 0xf0) | ((g & 0xf0) >> 4); break;
- case BGR: pixel = ((b & 0xf0) << 4) | (g & 0xf0) | ((r & 0xf0) >> 4); break;
- }
- gdk_image_put_pixel( data_image, x, y, pixel );
- break;
- }
- case 15:
- {
- guint32 pixel = 0;
- switch (b_o)
- {
- case RGB: pixel = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); break;
- case RBG: pixel = ((r & 0xf8) << 7) | ((b & 0xf8) << 2) | ((g & 0xf8) >> 3); break;
- case GRB: pixel = ((g & 0xf8) << 7) | ((r & 0xf8) << 2) | ((b & 0xf8) >> 3); break;
- case GBR: pixel = ((g & 0xf8) << 7) | ((b & 0xf8) << 2) | ((r & 0xf8) >> 3); break;
- case BRG: pixel = ((b & 0xf8) << 7) | ((r & 0xf8) << 2) | ((g & 0xf8) >> 3); break;
- case BGR: pixel = ((b & 0xf8) << 7) | ((g & 0xf8) << 2) | ((r & 0xf8) >> 3); break;
- }
- gdk_image_put_pixel( data_image, x, y, pixel );
- break;
- }
- case 16:
- {
- // I actually don't know if for 16-bit displays, it is alway the green
- // component or the second component which has 6 bits.
- guint32 pixel = 0;
- switch (b_o)
- {
- 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;
- }
- case 32:
- case 24:
- {
- guint32 pixel = 0;
- switch (b_o)
- {
- case RGB: pixel = (r << 16) | (g << 8) | b; break;
- case RBG: pixel = (r << 16) | (b << 8) | g; break;
- case BRG: pixel = (b << 16) | (r << 8) | g; break;
- case BGR: pixel = (b << 16) | (g << 8) | r; break;
- case GRB: pixel = (g << 16) | (r << 8) | b; break;
- case GBR: pixel = (g << 16) | (b << 8) | r; break;
- }
- gdk_image_put_pixel( data_image, x, y, pixel );
- break;
- }
- default: break;
- }
- } // for
- } // for
-
- // Blit picture
-
- GdkGC *data_gc = gdk_gc_new( GetPixmap() );
-
- gdk_draw_image( GetPixmap(), data_gc, data_image, 0, 0, 0, 0, width, height );
-
- gdk_image_destroy( data_image );
- g_object_unref (G_OBJECT (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 );
- g_object_unref (G_OBJECT (mask_gc));
+ }
+ else
+ {
+ const wxByte r_mask = image.GetMaskRed();
+ const wxByte g_mask = image.GetMaskGreen();
+ const wxByte b_mask = image.GetMaskBlue();
+ const wxByte* in = image.GetData();
+ for (int y = 0; y < h; y++)
+ {
+ for (int x = 0; x < w; x++, in += 3, bit_index++)
+ if (in[0] == r_mask && in[1] == g_mask && in[2] == b_mask)
+ out[bit_index >> 3] ^= 1 << (bit_index & 7);
+ bit_index = (bit_index + 7) & ~7u;
+ }
+ }
+ SetMask(new wxMask(gdk_bitmap_create_from_data(M_BMPDATA->m_pixmap, (char*)out, w, h)));
+ delete[] out;