2 * $XConsortium: cfbrrop.c,v 1.8 94/04/17 20:28:59 dpw Exp $
4 Copyright (c) 1989 X Consortium
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of the X Consortium shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from the X Consortium.
27 * Author: Keith Packard, MIT X Consortium
30 /* cfb reduced rasterop computations */
36 #include "cfbmskbits.h"
40 * There are four possible operations on each bit in the destination word,
47 * On examination of the reduced rop equation (dst = (dst & and) ^ xor),
48 * these four fall to reduced rops as follows:
53 * or, (if 'and' is expensive) (dst = (dst | or) ^ xor)
58 * The trouble with using this later equation is that trivial
59 * rasterop reduction is more difficult; some common rasterops
60 * use complicated expressions of xor/and instead of the simple
61 * ones while other common rasterops are not made any simpler:
63 * GXcopy: *dst = ~xor instead of *dst = xor
64 * GXand: *dst = *dst & ~or instead of *dst = *dst & and
65 * GXor: *dst = *dst | or instead of *dst = *dst | xor
66 * GXxor: *dst = *dst ^ xor instead of *dst = *dst ^ xor
68 * If you're really set on using this second mechanism, the changes
71 * All that remains is to provide a mechanism for computing and/xor values
72 * based on the raster op and foreground value.
74 * The 16 rops fall as follows, with the associated reduced
75 * rop and/xor and or/xor values. The values in parenthesis following the
76 * reduced values gives an equation using the source value for
77 * the reduced value, and is one of {0, src, ~src, 1} as appropriate.
79 * clear and andReverse copy
81 * dst 0 0 0 0 0 0 0 0 1 0 0 1
82 * 1 0 0 1 0 1 1 0 0 1 0 1
84 * and 0 0 (0) 0 1 (src) 0 1 (src) 0 0 (0)
85 * xor 0 0 (0) 0 0 (0) 0 1 (src) 0 1 (src)
87 * or 1 1 (1) 1 0 (~src) 1 0 (~src) 1 1 (1)
88 * xor 1 1 (1) 1 0 (~src) 1 1 (1) 1 0 (~src)
90 * andInverted noop xor or
92 * dst 0 0 0 0 0 0 0 0 1 0 0 1
93 * 1 1 0 1 1 1 1 1 0 1 1 1
95 * and 1 0 (~src) 1 1 (1) 1 1 (1) 1 0 (~src)
96 * xor 0 0 (0) 0 0 (0) 0 1 (src) 0 1 (src)
98 * or 0 1 (src) 0 0 (0) 0 0 (0) 0 1 (src)
99 * xor 0 1 (src) 0 0 (0) 0 1 (src) 0 0 (0)
101 * nor equiv invert orReverse
102 * src 0 1 0 1 0 1 0 1
103 * dst 0 1 0 0 1 0 0 1 1 0 1 1
104 * 1 0 0 1 0 1 1 0 0 1 0 1
106 * and 1 0 (~src) 1 1 (1) 1 1 (1) 1 0 (~src)
107 * xor 1 0 (~src) 1 0 (~src) 1 1 (1) 1 1 (1)
109 * or 0 1 (src) 0 0 (0) 0 0 (0) 0 1 (src)
110 * xor 1 1 (1) 1 0 (~src) 1 1 (1) 1 0 (~src)
112 * copyInverted orInverted nand set
113 * src 0 1 0 1 0 1 0 1
114 * dst 0 1 0 0 1 0 0 1 1 0 1 1
115 * 1 1 0 1 1 1 1 1 0 1 1 1
117 * and 0 0 (0) 0 1 (src) 0 1 (src) 0 0 (0)
118 * xor 1 0 (~src) 1 0 (~src) 1 1 (1) 1 1 (1)
120 * or 1 1 (1) 1 0 (~src) 1 0 (~src) 1 1 (1)
121 * xor 0 1 (src) 0 0 (0) 0 1 (src) 0 0 (0)
125 cfbReduceRasterOp (rop, fg, pm, andp, xorp)
127 unsigned long fg, pm;
128 unsigned long *andp, *xorp;
130 unsigned long and, xor;
206 /* check for some special cases to reduce computation */
209 /* nothing checks for GXnoop
210 else if (and == ~0 && xor == 0)
217 else if ( (and ^ xor) == ~0) /* fix XBUG 6541 */
220 rrop = GXset; /* rop not reduced */