Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!oliveb!ames!fxgrp!grady
From: grady@fxgrp (Steven Grady)
Newsgroups: comp.windows.x
Subject: XCopyPlane bug?
Message-ID: <819@fxgrp.UUCP>
Date: 28 Sep 88 22:16:10 GMT
Sender: grady@fxgrp.UUCP
Reply-To: grady@fxgrp (Steven Grady)
Organization: FX Development Group, Inc., Mountain View, CA
Lines: 94

I've come across a bug (I believe) in XV11R2 (running on Ultrix 2.2
on a VAXStation II/GPX).  The following code creates two windows
(not following any of the standard ICC, sorry), each 16x16.
In each it draws a bitmap of 3 concentric circles, or at
least is supposed to.  In the first window, it uses XCopyPlane()
to copy the image directly from a bitmap to a window (depth 8).
In the second window, it uses XCopyPlane() to copy to a depth 8
pixmap, then uses XCopyArea() to draw the image in the window.
The 2nd method works, but the first draw something strange,
which appears to be the upper left of the image in a random
color, expanded to fill the window.  Am I doing something wrong?
Is this a bug in the server?

	Steven
	...!ucbvax!grady
	grady@postgres.berkeley.edu

#include 
#include 
#include 

/* three concentric circles */
#define bar_width 16
#define bar_height 16
static char bar_bits[] = {
   0xe0, 0x03, 0x18, 0x0c, 0x04, 0x10, 0xe2, 0x23, 0x12, 0x24, 0x09, 0x48,
   0xc9, 0x49, 0x49, 0x49, 0xc9, 0x49, 0x09, 0x48, 0x12, 0x24, 0xe2, 0x23,
   0x04, 0x10, 0x18, 0x0c, 0xe0, 0x03, 0x00, 0x00};

main()
{
    Display *dpy;
    Window root,  w1, w2;
    unsigned long scr;
    Pixmap bm;
    unsigned long bl, wh;
    XColor col;
    Colormap cmap;
    unsigned long xgcvMask;
    XGCValues xgcv;
    GC gc;
    XEvent ev;
    int x_hot, y_hot;
    Pixmap pm;

    dpy = XOpenDisplay(NULL);
    root = RootWindow(dpy, scr);
    cmap = DefaultColormap(dpy, scr);
    bl = BlackPixel(dpy, scr);
    wh = WhitePixel(dpy, scr);

    if (!XAllocNamedColor(dpy, cmap, "red", &col, &col)) {
	printf("Couldn't allocate red pixel\n");
	exit(1);
    }

    bm = XCreateBitmapFromData(dpy, root, bar_bits, bar_width, bar_height);
    w1 = XCreateSimpleWindow(dpy, root, 0, 0, bar_width, bar_height,
	    1, bl, wh);

    w2 = XCreateSimpleWindow(dpy, root, 0, 0, bar_width, bar_height,
	    1, bl, wh);

    XSelectInput(dpy, w1, ExposureMask);
    XSelectInput(dpy, w2, ExposureMask);

    printf("Mapping window 1\n");
    XMapWindow(dpy, w1);
    /* wait for the mapping by waiting for the expose */
    XNextEvent(dpy, &ev);

    printf("Mapping window 2\n");
    XMapWindow(dpy, w2);
    /* ditto */
    XNextEvent(dpy, &ev);

    xgcvMask = GCForeground | GCBackground;
    xgcv.foreground = col.pixel;
    xgcv.background = wh;
    gc = XCreateGC(dpy, w1, xgcvMask, &xgcv);

    pm = XCreatePixmap(dpy, root, bar_width, bar_height, 
	    DefaultDepth(dpy, scr));
    XCopyPlane(dpy, bm, w1, gc, 0, 0, bar_width, bar_height, 0, 0, 
	    (unsigned long) 1);

    XCopyPlane(dpy, bm, pm, gc, 0, 0, bar_width, bar_height, 0, 0, 
	    (unsigned long) 1);
    
    XCopyArea(dpy, pm, w2, gc, 0, 0, bar_width, bar_height, 0, 0);

    XFlush(dpy);
    pause();
}