deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/*
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Id: fbrop.h,v 1.1 1999/11/02 03:54:45 keithp Exp $
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Copyright © 1998 Keith Packard
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Permission to use, copy, modify, distribute, and sell this software and its
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * documentation for any purpose is hereby granted without fee, provided that
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * the above copyright notice appear in all copies and that both that
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * copyright notice and this permission notice appear in supporting
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * documentation, and that the name of Keith Packard not be used in
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * advertising or publicity pertaining to distribution of the software without
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * specific, written prior permission. Keith Packard makes no
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * representations about the suitability of this software for any purpose. It
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * is provided "as is" without express or implied warranty.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync *
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * PERFORMANCE OF THIS SOFTWARE.
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#ifndef _FBROP_H_
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define _FBROP_H_
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsynctypedef struct _mergeRopBits {
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync FbBits ca1, cx1, ca2, cx2;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync} FbMergeRopRec, *FbMergeRopPtr;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncextern const FbMergeRopRec FbMergeRopBits[16];
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbDeclareMergeRop() FbBits _ca1, _cx1, _ca2, _cx2;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbDeclarePrebuiltMergeRop() FbBits _cca, _ccx;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbInitializeMergeRop(alu,pm) {\
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync const FbMergeRopRec *_bits; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync _bits = &FbMergeRopBits[alu]; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync _ca1 = _bits->ca1 & pm; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync _cx1 = _bits->cx1 | ~pm; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync _ca2 = _bits->ca2 & pm; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync _cx2 = _bits->cx2 & pm; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync}
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbDestInvarientRop(alu,pm) ((pm) == FB_ALLONES && \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync (((alu) >> 1 & 5) == ((alu) & 5)))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbDestInvarientMergeRop() (_ca1 == 0 && _cx1 == 0)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/* AND has higher precedence than XOR */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbDoMergeRop(src, dst) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync (((dst) & (((src) & _ca1) ^ _cx1)) ^ (((src) & _ca2) ^ _cx2))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbDoDestInvarientMergeRop(src) (((src) & _ca2) ^ _cx2)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbDoMaskMergeRop(src, dst, mask) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync (((dst) & ((((src) & _ca1) ^ _cx1) | ~(mask))) ^ ((((src) & _ca2) ^ _cx2) & (mask)))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbDoLeftMaskByteMergeRop(dst, src, lb, l) { \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync FbBits __xor = ((src) & _ca2) ^ _cx2; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync FbDoLeftMaskByteRRop(dst,lb,l,((src) & _ca1) ^ _cx1,__xor); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync}
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbDoRightMaskByteMergeRop(dst, src, rb, r) { \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync FbBits __xor = ((src) & _ca2) ^ _cx2; \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync FbDoRightMaskByteRRop(dst,rb,r,((src) & _ca1) ^ _cx1,__xor); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync}
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbDoRRop(dst, and, xor) (((dst) & (and)) ^ (xor))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbDoMaskRRop(dst, and, xor, mask) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync (((dst) & ((and) | ~(mask))) ^ (xor & mask))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/*
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Take a single bit (0 or 1) and generate a full mask
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define fbFillFromBit(b,t) (~((t) ((b) & 1)-1))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define fbXorT(rop,fg,pm,t) ((((fg) & fbFillFromBit((rop) >> 1,t)) | \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync (~(fg) & fbFillFromBit((rop) >> 3,t))) & (pm))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define fbAndT(rop,fg,pm,t) ((((fg) & fbFillFromBit (rop ^ (rop>>1),t)) | \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync (~(fg) & fbFillFromBit((rop>>2) ^ (rop>>3),t))) | \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync ~(pm))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define fbXor(rop,fg,pm) fbXorT(rop,fg,pm,FbBits)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define fbAnd(rop,fg,pm) fbAndT(rop,fg,pm,FbBits)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define fbXorStip(rop,fg,pm) fbXorT(rop,fg,pm,FbStip)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define fbAndStip(rop,fg,pm) fbAndT(rop,fg,pm,FbStip)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/*
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Stippling operations;
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncextern const FbBits fbStipple16Bits[256]; /* half of table */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbStipple16Bits(b) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync (fbStipple16Bits[(b)&0xff] | fbStipple16Bits[(b) >> 8] << FB_HALFUNIT)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncextern const FbBits fbStipple8Bits[256];
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncextern const FbBits fbStipple4Bits[16];
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncextern const FbBits fbStipple2Bits[4];
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncextern const FbBits fbStipple1Bits[2];
deb4998ba50060c48cce222fd18a8eed053918d7vboxsyncextern const FbBits *const fbStippleTable[];
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbStippleRRop(dst, b, fa, fx, ba, bx) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync (FbDoRRop(dst, fa, fx) & b) | (FbDoRRop(dst, ba, bx) & ~b)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbStippleRRopMask(dst, b, fa, fx, ba, bx, m) \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync (FbDoMaskRRop(dst, fa, fx, m) & (b)) | (FbDoMaskRRop(dst, ba, bx, m) & ~(b))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbDoLeftMaskByteStippleRRop(dst, b, fa, fx, ba, bx, lb, l) { \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync FbBits __xor = ((fx) & (b)) | ((bx) & ~(b)); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync FbDoLeftMaskByteRRop(dst, lb, l, ((fa) & (b)) | ((ba) & ~(b)), __xor); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync}
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbDoRightMaskByteStippleRRop(dst, b, fa, fx, ba, bx, rb, r) { \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync FbBits __xor = ((fx) & (b)) | ((bx) & ~(b)); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync FbDoRightMaskByteRRop(dst, rb, r, ((fa) & (b)) | ((ba) & ~(b)), __xor); \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync}
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbOpaqueStipple(b, fg, bg) (((fg) & (b)) | ((bg) & ~(b)))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync/*
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * Compute rop for using tile code for 1-bit dest stipples; modifies
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync * existing rop to flip depending on pixel values
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync */
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbStipple1RopPick(alu,b) (((alu) >> (2 - (((b) & 1) << 1))) & 3)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbOpaqueStipple1Rop(alu,fg,bg) (FbStipple1RopPick(alu,fg) | \
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync (FbStipple1RopPick(alu,bg) << 2))
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#define FbStipple1Rop(alu,fg) (FbStipple1RopPick(alu,fg) | 4)
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync
deb4998ba50060c48cce222fd18a8eed053918d7vboxsync#endif