[comp.windows.x] Combining Pixmaps in X11

foonberg@AEROSPACE.AERO.ORG (Alan M. Foonberg) (05/19/88)

I'm looking for a color gcontext function which says essentially:

	"If the source is not white, let the result be the source.
	 If the source is white, let the result be the destination."

I can't seem to find a gcontext function which, by using its
bit by bit techniques, yields the desired results.  Am I missing
something obvious?

Alan Foonberg
foonberg@aerospace.aero.org

toddb%tekcrl.CRL@tektronix.tek.COM (Todd Brunhoff) (05/20/88)

>> I'm looking for a color gcontext function which says essentially:
>> 
>> 	"If the source is not white, let the result be the source.
>> 	 If the source is white, let the result be the destination."

In general, you cannot know ahead of time what the values of pixels
are, because X11 (unlike X10) makes no assurances.  However, if you
want to take a novice's advice...

If you know that "not white" is 0 and that "white" is the compliment
of 0, then GXand will do the trick:

		source
		0    1
	      --------
    dest    0 | 0    0
              |
            1 | 0    1

For the inverse, if you know that "white" is 0 and that "not white"
is the compliment of 0, then GXor will do the work:

		source
		0    1
	      --------
    dest    0 | 0    1
              |
            1 | 1    1

The problem with these is that it assumes only two colors, black and
white.  For instance, let's say you have a screen with depth=8 and three
colors in your pixmap: white (0xff), black (0x00), yellow (0x55) and
blue (0x3c).  Then GXand doesn't quite work, because of the two new
pixels in the boxes below (value 0x10).  It gets worse for other
operations like GXequiv, etc.

		source
		00   ff   55   3c
	      --------------------
    dest   00 | 00   00   55   3c
              |
           ff | 00   ff   55   3c
              |               ----
           55 | 00   55   55  |10|
              |          ---- ----
           3c | 00   3c  |10|  3c
                         ----

The moral of the story is:
   - two-operand rasterops (e.g. GXcopy is one operand) are only good
     when you know that all combinations of source and destination for
     a given operation yield only pixels that already exist in the source
     and destination (aka, closure).

---------------
Usenet:       {ucbvax,decvax,allegra,uw-beaver,hplabs}!tektronix!crl!toddb
{CS,ARPA}net: toddb%crl.tek.csnet@relay.cs.net                       c--Q Q
US:           Todd Brunhoff; Visual Systems Lab; Tektronix, Inc.         `
              Box 500  MS 50-662, Beaverton OR 97077                     -
Phone:        (503) 627-1121