- 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
- 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
- 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA,
- 0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA
- };
- GC gc;
- Pixmap ipixmap, stipple;
- unsigned width, height, depth;
-
- Window window; /* These return values */
- unsigned border; /* from XGetGeometry() */
- int x, y; /* are not needed. */
-
- ipixmap = 0;
-
- if ( NULL == display || 0 == pixmap )
- return ipixmap;
-
- if ( 0 == XGetGeometry( display, pixmap, &window, &x, &y,
- &width, &height, &border, &depth )
- )
- return ipixmap; /* BadDrawable: probably an invalid pixmap */
-
- /* Get the stipple pixmap to be used to 'gray-out' the argument pixmap.
+ int r = data[index];
+ index++;
+ int g = data[index];
+ index++;
+ int b = data[index];
+ index++;
+
+ if (hasMask)
+ {
+ if ((r == r_mask) && (b == b_mask) && (g == g_mask))
+ XPutPixel( mask_image, x, y, 0 );
+ else
+ XPutPixel( mask_image, x, y, 1 );
+ }
+
+ switch (bpp)
+ {
+ case 8:
+ {
+#if 0 // Old, slower code
+ int pixel = -1;
+ /*
+ if (wxTheApp->m_colorCube)
+ {
+ pixel = wxTheApp->m_colorCube
+ [ ((r & 0xf8) << 7) + ((g & 0xf8) << 2) + ((b & 0xf8) >> 3) ];
+ }
+ else
+ {
+ */
+ int max = 3 * (65536);
+ for (int i = 0; i < 256; 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; }
+ }
+ /*
+ }
+ */
+#endif
+
+ // And this is all to get the 'right' color...
+ int pixel = scolor.SearchColor( r, g, b );
+ XPutPixel( data_image, x, y, pixel );
+ break;
+ }
+ case 15:
+ {
+ int pixel = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3);
+ XPutPixel( data_image, x, y, pixel );
+ break;
+ }
+ case 16:
+ {
+ int pixel = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3);
+ XPutPixel( data_image, x, y, pixel );
+ break;
+ }
+ case 32:
+ case 24:
+ {
+ int 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;
+ }
+ XPutPixel( data_image, x, y, pixel );
+ }
+ default: break;
+ }
+ } // for
+ } // for
+
+ // Blit picture
+
+ XGCValues gcvalues;
+ gcvalues.foreground = BlackPixel( dpy, DefaultScreen( dpy ) );
+ GC gc = XCreateGC( dpy, RootWindow ( dpy, DefaultScreen(dpy) ), GCForeground, &gcvalues );
+ XPutImage( dpy, (Drawable)GetPixmap(), gc, data_image, 0, 0, 0, 0, width, height );
+
+ XDestroyImage( data_image );
+ XFreeGC( dpy, gc );
+
+ // Blit mask
+ if (image.HasMask())
+ {
+ wxBitmap maskBitmap(width, height, 1);
+
+ GC gcMask = XCreateGC( dpy, (Pixmap) maskBitmap.GetPixmap(), (XtGCMask) 0, (XGCValues*)NULL );
+ XPutImage( dpy, (Drawable)maskBitmap.GetPixmap(), gcMask, mask_image, 0, 0, 0, 0, width, height );
+
+ XDestroyImage( mask_image );
+ XFreeGC( dpy, gcMask );
+
+ wxMask* mask = new wxMask;
+ mask->SetPixmap(maskBitmap.GetPixmap());
+
+ SetMask(mask);
+
+ maskBitmap.SetPixmapNull();
+ }
+
+
+ return TRUE;
+}
+
+wxImage wxBitmap::ConvertToImage() const
+{
+ wxImage image;
+
+ wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") );
+
+ Display *dpy = (Display*) wxGetDisplay();
+ Visual* vis = DefaultVisual( dpy, DefaultScreen( dpy ) );
+ int bpp = DefaultDepth( dpy, DefaultScreen( dpy ) );
+
+ XImage *ximage = XGetImage( dpy,
+ (Drawable)GetPixmap(),
+ 0, 0,
+ GetWidth(), GetHeight(),
+ AllPlanes, ZPixmap );
+
+ wxCHECK_MSG( ximage, wxNullImage, wxT("couldn't create image") );
+
+ image.Create( GetWidth(), GetHeight() );
+ char unsigned *data = image.GetData();
+
+ if (!data)
+ {
+ XDestroyImage( ximage );
+ wxFAIL_MSG( wxT("couldn't create image") );
+ return wxNullImage;
+ }
+
+ /*
+ GdkImage *gdk_image_mask = (GdkImage*) NULL;
+ if (GetMask())
+ {
+ gdk_image_mask = gdk_image_get( GetMask()->GetBitmap(),
+ 0, 0,
+ GetWidth(), GetHeight() );
+
+ image.SetMaskColour( 16, 16, 16 ); // anything unlikely and dividable
+ }