2
* Id: fbrop.h,v 1.1 1999/11/02 03:54:45 keithp Exp $
4
* Copyright © 1998 Keith Packard
6
* Permission to use, copy, modify, distribute, and sell this software and its
7
* documentation for any purpose is hereby granted without fee, provided that
8
* the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the name of Keith Packard not be used in
11
* advertising or publicity pertaining to distribution of the software without
12
* specific, written prior permission. Keith Packard makes no
13
* representations about the suitability of this software for any purpose. It
14
* is provided "as is" without express or implied warranty.
16
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
* PERFORMANCE OF THIS SOFTWARE.
28
typedef struct _mergeRopBits {
29
FbBits ca1, cx1, ca2, cx2;
30
} FbMergeRopRec, *FbMergeRopPtr;
32
extern const FbMergeRopRec FbMergeRopBits[16];
34
#define FbDeclareMergeRop() FbBits _ca1, _cx1, _ca2, _cx2;
35
#define FbDeclarePrebuiltMergeRop() FbBits _cca, _ccx;
37
#define FbInitializeMergeRop(alu,pm) {\
38
const FbMergeRopRec *_bits; \
39
_bits = &FbMergeRopBits[alu]; \
40
_ca1 = _bits->ca1 & pm; \
41
_cx1 = _bits->cx1 | ~pm; \
42
_ca2 = _bits->ca2 & pm; \
43
_cx2 = _bits->cx2 & pm; \
46
#define FbDestInvarientRop(alu,pm) ((pm) == FB_ALLONES && \
47
(((alu) >> 1 & 5) == ((alu) & 5)))
49
#define FbDestInvarientMergeRop() (_ca1 == 0 && _cx1 == 0)
51
/* AND has higher precedence than XOR */
53
#define FbDoMergeRop(src, dst) \
54
(((dst) & (((src) & _ca1) ^ _cx1)) ^ (((src) & _ca2) ^ _cx2))
56
#define FbDoDestInvarientMergeRop(src) (((src) & _ca2) ^ _cx2)
58
#define FbDoMaskMergeRop(src, dst, mask) \
59
(((dst) & ((((src) & _ca1) ^ _cx1) | ~(mask))) ^ ((((src) & _ca2) ^ _cx2) & (mask)))
61
#define FbDoLeftMaskByteMergeRop(dst, src, lb, l) { \
62
FbBits __xor = ((src) & _ca2) ^ _cx2; \
63
FbDoLeftMaskByteRRop(dst,lb,l,((src) & _ca1) ^ _cx1,__xor); \
66
#define FbDoRightMaskByteMergeRop(dst, src, rb, r) { \
67
FbBits __xor = ((src) & _ca2) ^ _cx2; \
68
FbDoRightMaskByteRRop(dst,rb,r,((src) & _ca1) ^ _cx1,__xor); \
71
#define FbDoRRop(dst, and, xor) (((dst) & (and)) ^ (xor))
73
#define FbDoMaskRRop(dst, and, xor, mask) \
74
(((dst) & ((and) | ~(mask))) ^ (xor & mask))
77
* Take a single bit (0 or 1) and generate a full mask
79
#define fbFillFromBit(b,t) (~((t) ((b) & 1)-1))
81
#define fbXorT(rop,fg,pm,t) ((((fg) & fbFillFromBit((rop) >> 1,t)) | \
82
(~(fg) & fbFillFromBit((rop) >> 3,t))) & (pm))
84
#define fbAndT(rop,fg,pm,t) ((((fg) & fbFillFromBit (rop ^ (rop>>1),t)) | \
85
(~(fg) & fbFillFromBit((rop>>2) ^ (rop>>3),t))) | \
88
#define fbXor(rop,fg,pm) fbXorT(rop,fg,pm,FbBits)
90
#define fbAnd(rop,fg,pm) fbAndT(rop,fg,pm,FbBits)
92
#define fbXorStip(rop,fg,pm) fbXorT(rop,fg,pm,FbStip)
94
#define fbAndStip(rop,fg,pm) fbAndT(rop,fg,pm,FbStip)
97
* Stippling operations;
100
extern const FbBits fbStipple16Bits[256]; /* half of table */
101
#define FbStipple16Bits(b) \
102
(fbStipple16Bits[(b)&0xff] | fbStipple16Bits[(b) >> 8] << FB_HALFUNIT)
103
extern const FbBits fbStipple8Bits[256];
104
extern const FbBits fbStipple4Bits[16];
105
extern const FbBits fbStipple2Bits[4];
106
extern const FbBits fbStipple1Bits[2];
107
extern const FbBits *const fbStippleTable[];
109
#define FbStippleRRop(dst, b, fa, fx, ba, bx) \
110
(FbDoRRop(dst, fa, fx) & b) | (FbDoRRop(dst, ba, bx) & ~b)
112
#define FbStippleRRopMask(dst, b, fa, fx, ba, bx, m) \
113
(FbDoMaskRRop(dst, fa, fx, m) & (b)) | (FbDoMaskRRop(dst, ba, bx, m) & ~(b))
115
#define FbDoLeftMaskByteStippleRRop(dst, b, fa, fx, ba, bx, lb, l) { \
116
FbBits __xor = ((fx) & (b)) | ((bx) & ~(b)); \
117
FbDoLeftMaskByteRRop(dst, lb, l, ((fa) & (b)) | ((ba) & ~(b)), __xor); \
120
#define FbDoRightMaskByteStippleRRop(dst, b, fa, fx, ba, bx, rb, r) { \
121
FbBits __xor = ((fx) & (b)) | ((bx) & ~(b)); \
122
FbDoRightMaskByteRRop(dst, rb, r, ((fa) & (b)) | ((ba) & ~(b)), __xor); \
125
#define FbOpaqueStipple(b, fg, bg) (((fg) & (b)) | ((bg) & ~(b)))
128
* Compute rop for using tile code for 1-bit dest stipples; modifies
129
* existing rop to flip depending on pixel values
131
#define FbStipple1RopPick(alu,b) (((alu) >> (2 - (((b) & 1) << 1))) & 3)
133
#define FbOpaqueStipple1Rop(alu,fg,bg) (FbStipple1RopPick(alu,fg) | \
134
(FbStipple1RopPick(alu,bg) << 2))
136
#define FbStipple1Rop(alu,fg) (FbStipple1RopPick(alu,fg) | 4)