mouse@LARRY.MCRCIM.MCGILL.EDU (10/13/90)
> I'm having some trouble with code that tries to reverse a pixmap. > The code works on a monochrome system but fails in the XCopyArea with > a BadMatch error on a 8 bit color system. The pixmap was created > with XCreateBitmapFromData. Here's the code: > drawable = RootWindow(display,DefaultScreen(display)); ... > rev_gc = XCreateGC (display, drawable, v_mask, &values); ... > XCopyArea (display, pixmap, pixmap, rev_gc, 0, 0, width, height, 0, 0); There's your problem. rev_gc can't be used when writing into drawables of a different root or depth than the root window. In particular, if the root window is not one bit deep, it cannot be used to write into a one-bit-deep drawable. (Since `pixmap' was created with XCreateBitmapFromData, it will be one bit deep.) Try instead rev_gc = XCreateGC(disp,pixmap,v_mask,&values); From the Xlib document on XCreateGC: To create a new GC that is usable on a given screen with a depth of drawable, use XCreateGC. GC XCreateGC(display, d, valuemask, values) Display *display; Drawable d; .... d Specifies the drawable. .... [...] The GC can be used with any destination drawable having the same root and depth as the specified drawable. Use with other drawables results in a BadMatch error. > I think is has something to do with the depth of the pixmap not > matching the depth of the display. Yup :-) More precisely, though, the depth of the pixmap doesn't match the depth of the GC, because when you created the GC you gave a drawable whose depth was that of the root window rather than that of the pixmap. Your code works in precisely those situations where these depths are the same. der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu