Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!mit-eddie!bloom-beacon!ZIA.AOC.NRAO.EDU!cflatter From: cflatter@ZIA.AOC.NRAO.EDU (Chris Flatters) Newsgroups: comp.windows.x Subject: Re: GXinvert & planes Message-ID: <9012112324.AA03770@zia.aoc.nrao.edu> Date: 11 Dec 90 23:24:01 GMT Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 47 Brian Powell writes: > I was trying to invert some text (drawn with Xlib) to show a selection. > At first, I made a GC with a function of GXinvert, and a plane_mask of the > default AllPlanes. This worked fine under OpenWindows, but failed under > the Sun MIT server (it drew all black). > I went looking for some sample client code, and found a couple of > different examples where the plane_mask was set to the exclusive-or of the > foreground and background colors. I tried this, and it worked. But I didn't > understand why. Perhaps it's because I'm not a color guru. Suppose that the bits in the index of the background colour are b(0) ... b(depth-1) and the bits in the index of the foreground colour are f(0) ... f(depth-1). Applying GXinvert to a colour with index c (with bits c(0) ... c(depth-1) will produce a colour with bits not(c(0)) ... not(c(depth-1). In order for this to reverse the foreground and background colours we require f(i) = not(b(i)) for all i: 0..depth-1 This is clearly not true in all cases. Take for example the case where the foreground has index 1 (0000 0001 in binary) and the background has index 0 (0000 0000): the inverted bit patterns are 1111 1110 and 1111 1111. This case is interesting since black appears both at index 1 and 254 in the initial X11/NeWS colormap on 8-bit colour displays and white appears at indices 0 and 255: thus a straight invert of the display will appear to work. Suppose we now add a plane mask with bits m(i). If the initial colour at a given pixel is c then the output bits are (m(i) and not(c(i))) or (not(m(i)) and c(i)) (recall that if the i-th bit of the mask is 0 then the source pixel is unchanged). If we set the mask to the exclusive or of f and b the the output bits are o(c(i)) = ((f(i) xor b(i)) and not(c(i))) or (not (f(i) xor b(i)) and c(i)) You may verify that o(f(i)) = b(i) and o(b(i)) = f(i) (as required) by Boolean algebra or by constructing truth tables. Chris Flatters