[comp.windows.x] X11R1 bug

turner@daisy.UUCP (Jim Turner) (02/27/88)

has anyone else encountered this problem or am I doing something wrong ??

VERSION:
	X11 release 1
SYNOPSIS:
	xor mode in XPutImage does not work
DESCRIPTION:
	/* see comments in code */
REPEAT-BY:
/*
	I try to use XPutImage to put a image onto a window and later 
	erase it by setting the gc's function to xor, it doesn't work. 
	As a matter of fact, all functions give same result: they
	simply copy the image onto the drawable just as if you've
	specified GXcopy.
*/

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#define TRUE     1
#define FALSE    0

extern int         XBeep();

#define clock_width 32
#define clock_height 32
static char clock_bits[] = {
   0x00, 0xf0, 0x07, 0x00, 0x00, 0xfe, 0x3f, 0x00, 0x80, 0x8f, 0xf8, 0x00,
   0xc0, 0x81, 0xc0, 0x01, 0x60, 0x80, 0x00, 0x03, 0x70, 0x00, 0x00, 0x06,
   0x98, 0x00, 0x00, 0x0e, 0x0c, 0xc0, 0x00, 0x19, 0x0c, 0xc0, 0x00, 0x18,
   0x06, 0xc0, 0x00, 0x30, 0x06, 0xc0, 0x00, 0x30, 0x06, 0xc0, 0x00, 0x30,
   0x03, 0xc0, 0x00, 0x60, 0x03, 0xc0, 0x00, 0x60, 0x03, 0xc0, 0x7f, 0x60,
   0xdf, 0xff, 0x7f, 0x7c, 0x03, 0xc0, 0x7f, 0x60, 0x03, 0x00, 0x00, 0x60,
   0x03, 0x00, 0x00, 0x60, 0x06, 0x00, 0x00, 0x30, 0x06, 0x00, 0x00, 0x30,
   0x06, 0x00, 0x00, 0x30, 0x8c, 0x00, 0x00, 0x18, 0x4c, 0x00, 0x00, 0x18,
   0x38, 0x00, 0x00, 0x0c, 0x30, 0x00, 0x00, 0x06, 0x60, 0x80, 0x00, 0x03,
   0xc0, 0x81, 0xc0, 0x01, 0x80, 0x8f, 0xf8, 0x00, 0x00, 0xfe, 0x3f, 0x00,
   0x00, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00};

static Window         w1;
static Display	      *display_ptr;
static int            screen_width=400,   screen_height=400;
static int            screen_x = 0,   screen_y = 0;
 
main()
{
  int                  volume = 70, screen =0;
  unsigned long        event_mask;
  XSetWindowAttributes w_att;
  unsigned long        w_mask;
  GC		gc;

/* open display and create a window */
  display_ptr = XOpenDisplay("unix:0.0");
  if (display_ptr == 0) {
     printf("Can not open display\n");
     return;
  }

  event_mask = 0;
  w_mask = CWEventMask | CWOverrideRedirect | CWBackPixel;
  w_att.background_pixel = WhitePixel(display_ptr, screen);
  w_att.event_mask = event_mask;
  w_att.override_redirect = TRUE;

  XSync(display_ptr, 1);

  w1 = XCreateWindow(display_ptr, RootWindow(display_ptr, screen), screen_x, screen_y, screen_width, 
                     screen_height, 2, CopyFromParent , InputOutput, 
		     CopyFromParent, w_mask, &w_att);


  XMapWindow(display_ptr, w1);
  XFlush (display_ptr);

  XBell(display_ptr, volume);

/*********************************************************************\
*                    Testing XPutImage                                *
\*********************************************************************/
XGCValues gcvalue;
static XImage image;
  gcvalue.foreground = 1;
  gcvalue.background = WhitePixel(display_ptr,
                                  DefaultScreen(display_ptr));
  gc = XCreateGC(display_ptr, w1, GCForeground+GCBackground, &gcvalue);
  XSetFunction(display_ptr, gc, GXxor);
  image.height = clock_height;
  image.width = clock_width;
  image.xoffset = 0;
  image.format = XYBitmap;
  image.data = (char *)clock_bits;
  image.byte_order = LSBFirst;
  image.bitmap_unit = 8;
  image.bitmap_bit_order = LSBFirst;
  image.bitmap_pad = 16;
  image.bytes_per_line = 4;
  image.depth = 1;

  /* Put image with xor mode */
  XPutImage(display_ptr, w1, gc, &image, 0, 0, 300, 300, 32, 32);
  XFlush (display_ptr);
   printf("Enter anything to invert the image > ");
   getchar();
   printf("\n");

  /* Put image again with xor mode */
  XPutImage(display_ptr, w1, gc, &image, 0, 0, 300, 300, 32, 32);
  XFreeGC(display_ptr, gc);
  XFlush (display_ptr);
   printf("PutImage #2 to w1 done.\n");
   printf("Enter anything to continue > ");
   getchar();
   printf("\n");
}


FIX:

-- 
Laissez les bons temps rouler                     -  Queen Ida
...{decwrl|ucbvax}!imagen!atari!daisy!turner (James M. Turner)
Daisy Systems, 700 E. Middlefield Rd, P.O. Box 7006, 
Mountain View CA 94039-7006.                          (415)960-0123