Xref: utzoo comp.windows.x:34018 comp.windows.open-look:869 Path: utzoo!attcan!uunet!mstan!chuck From: chuck@Morgan.COM (Chuck Ocheret) Newsgroups: comp.windows.x,comp.windows.open-look Subject: Re: Xor'ing of colors problems Message-ID: <2846@s5.Morgan.COM> Date: 28 Feb 91 00:52:11 GMT References: <26@ftms.UUCP> Organization: Morgan Stanley, & Co., Inc. / New York City, NY Lines: 50 > We are using OpenLook under SunOS 4.1. The programmer is using the GXxor > function in the graphics context for Xlib calls. We get the following results: > > draw color background result expect > > black black white black > white white tan(?) black > red red white black > red blue aquamarine(?)/ magenta > cyan > blue blue white black > > Can someone explain why we are not getting the expected results? Is there > a formula that can be used to determine ahead of time what the results will > be? Xoring pixels operates on bits, not on names. Depending on your server and the Visual you are using you cannot expect particular colors to have particular pixel values. Basically, colors can be allocated to arbitrary cells in the colormap. To accomplish what it looks like you are trying to do you should be Xor drawing with your foreground pixel set to a value which is an Xor of the displayed pixel and the desired color's pixel. For example, let's say that you allocate the following colors on a 4 bit deep display. color name pixel allocated(treat these as completely arbitrary) ---------- --------------- red 0x5 blue 0xf magenta 0x8 green 0xa Let's also say that most of your window has been drawn in blue and you want to do Xor drawing (e.g. rubber band line) that appears magenta. Don't try to draw in red 0x5 (Xor does not do color blending unless you are real lucky with your color map). If you were to Xor draw in red the blue pixels will get changed from 0xf to 0xa = green. Draw with the pixel value set to blue^magenta = 0xf^0x8 = 0x7 (^ is Xor). The funny thing is that you may never have allocated color cell 0x7. When you Xor draw with 0x7 over the blue 0xf background, the pixels are changed to magenta 0x8. ~chuck -- +--------------------+ Chuck Ocheret +---------------+ |chuck@fid.Morgan.COM| Morgan Stanley & Co., Inc. |(212) 703-4474 | | Duty now ... |19th Floor, 1251 Avenue of the Americas|for the future.| +--------------------+ New York, N.Y. 10020 USA +---------------+