Path: utzoo!utgpu!watserv1!watmath!att!tut.cis.ohio-state.edu!cs.utexas.edu!samsung!usc!snorkelwacker!bloom-beacon!EXPO.LCS.MIT.EDU!keith From: keith@EXPO.LCS.MIT.EDU (Keith Packard) Newsgroups: comp.windows.x Subject: Re: Long query about color XOR'ing Message-ID: <9004121959.AA14701@xenon.lcs.mit.edu> Date: 12 Apr 90 19:59:26 GMT References: <192@cvbnetPrime.COM> Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 45 To use CopyPlane in XOR mode, you need to set up the fg and bg values in the GC so that the fg value will result in the desired color in the destination, while the bg value will not modify the existing bits. The bg value is simple, the only value which will leave the bits unmolested is 0. For the fg value, remember that XOR mode effectively inverts the destination bits which match the portions of the fg which are set, so choose the fg value so that it transforms the desination from the original background to the desired pixel value: Original desination: GC fg value: result: background ^ fg = color[i] A simple boolean exercise leaves fg = background ^ color[i] Or, in your original parlance: for(i = 0 ; i < MAX_COLORS ; i++) { for(j = 0 ; j < MAX_DRAW_FUNCS ; j++) { switch(j) { case DRAW_XOR: values.function = GXxor; values.background = 0; values.foreground = vid->color[i] ^ vid->bg; As an aside, your code had a special case for depth-1 images. Rest assured that the server performs CopyPlane using the same code as CopyArea when the destination is 1 bit deep, so you can replace that with: #define draw_picture(w,x,y,pic,func,_color) \ { \ int tmp_x = x - pic->offset_x; \ int tmp_y = y - pic->offset_y; \ if(x > -pic->offset_x && tmp_x < vid->win[w].width && \ y > -pic->offset_y && tmp_y < vid->win[w].height) { \ XCopyPlane(vid->dpy,vid->pixid[pic->pixmap],vid->win[w].id, \ vid->graph_gc[func][_color],0,0,pic->width,pic->height, \ tmp_x,tmp_y, 1);\ } \ }