1 /***********************************************************
3 Copyright (c) 1987 X Consortium
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of the X Consortium shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from the X Consortium.
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47 ******************************************************************/
48 /* $XConsortium: cfbbresd.c,v 1.16 94/04/17 20:28:45 dpw Exp $ */
49 /* $XFree86: xc/programs/Xserver/cfb/cfbbresd.c,v 3.1 1996/08/25 14:05:42 dawes Exp $ */
53 #include "cfbmskbits.h"
56 /* Dashed bresenham line */
60 pdashIndex, pDash, numInDashList, pdashOffset, isDoubleDash,
62 signdx, signdy, axis, x1, y1, e, e1, e2, len)
64 int *pdashIndex; /* current dash */
65 unsigned char *pDash; /* dash list */
66 int numInDashList; /* total length of dash list */
67 int *pdashOffset; /* offset into current dash */
69 unsigned long *addrl; /* pointer to base of bitmap */
70 int nlwidth; /* width in longwords of bitmap */
71 int signdx, signdy; /* signs of directions */
72 int axis; /* major axis (Y_AXIS or X_AXIS) */
73 int x1, y1; /* initial point */
74 register int e; /* error accumulator */
75 register int e1; /* bresenham increments */
77 int len; /* length of line */
80 register PixelType *addrp;
82 register int e3 = e2-e1;
86 unsigned long xorFg, andFg, xorBg, andBg;
90 unsigned long xorPiQxlFg[3], andPiQxlFg[3], xorPiQxlBg[3], andPiQxlBg[3];
95 dashOffset = *pdashOffset;
96 dashIndex = *pdashIndex;
97 isCopy = (rrops[0].rop == GXcopy && rrops[1].rop == GXcopy);
99 xorFg = rrops[0].xor & 0xffffff;
100 andFg = rrops[0].and & 0xffffff;
101 xorBg = rrops[1].xor & 0xffffff;
102 andBg = rrops[1].and & 0xffffff;
103 xorPiQxlFg[0] = xorFg | (xorFg << 24);
104 xorPiQxlFg[1] = (xorFg >> 8) | (xorFg << 16);
105 xorPiQxlFg[2] = (xorFg >> 16) | (xorFg << 8);
106 andPiQxlFg[0] = andFg | (andFg << 24);
107 andPiQxlFg[1] = (andFg >> 8) | (andFg << 16);
108 andPiQxlFg[2] = (andFg >> 16) | (andFg << 8);
109 xorPiQxlBg[0] = xorBg | (xorBg << 24);
110 xorPiQxlBg[1] = (xorBg >> 8) | (xorBg << 16);
111 xorPiQxlBg[2] = (xorBg >> 16) | (xorBg << 8);
112 andPiQxlBg[0] = andBg | (andBg << 24);
113 andPiQxlBg[1] = (andBg >> 8) | (andBg << 16);
114 andPiQxlBg[2] = (andFg >> 16) | (andBg << 8);
116 xorFg = rrops[0].xor;
117 andFg = rrops[0].and;
118 xorBg = rrops[1].xor;
119 andBg = rrops[1].and;
121 dashRemaining = pDash[dashIndex] - dashOffset;
122 if ((thisDash = dashRemaining) >= len)
125 dashRemaining -= len;
127 e = e-e1; /* to make looping easier */
129 #define BresStep(minor,major) {if ((e += e1) >= 0) { e += e3; minor; } major;}
133 if (dashIndex == numInDashList) \
135 dashRemaining = pDash[dashIndex]; \
136 if ((thisDash = dashRemaining) >= len) \
138 dashRemaining -= len; \
146 #define Loop(store) while (thisDash--) {\
148 BresStep(addrb+=signdy3,addrb+=signdx3) \
150 /* point to first point */
152 addrp = (PixelType *)(addrl) + (y1 * nlwidth);
153 addrb = (char *)addrp + x1 * 3;
156 #define Loop(store) while (thisDash--) {\
158 BresStep(addrp+=signdy,addrp+=signdx) \
160 /* point to first point */
162 addrp = (PixelType *)(addrl) + (y1 * nlwidth) + x1;
166 signdx3 = signdx * 3;
167 signdy3 = signdy * sizeof (long);
186 #define body_copy(pix) { \
187 addrp = (PixelType *)((unsigned long)addrb & ~0x03); \
188 switch((unsigned long)addrb & 3){ \
190 *addrp = (*addrp & 0xFF000000)|((pix)[0] & 0xFFFFFF); \
193 *addrp = (*addrp & 0xFF)|((pix)[2] & 0xFFFFFF00); \
196 *addrp = (*addrp & 0xFFFFFF)|((pix)[0] & 0xFF000000); \
197 *(addrp+1) = (*(addrp+1) & 0xFFFF0000)|((pix)[1] & 0xFFFF); \
200 *addrp = (*addrp & 0xFFFF)|((pix)[1] & 0xFFFF0000); \
201 *(addrp+1) = (*(addrp+1) & 0xFFFFFF00)|((pix)[2] & 0xFF); \
205 #endif /* PSZ == 24 */
213 Loop(body_copy(xorPiQxlBg))
222 Loop(body_copy(xorPiQxlFg))
235 #define body_set(and, xor) { \
236 addrp = (PixelType *)((unsigned long)addrb & ~0x03); \
237 switch((unsigned long)addrb & 3){ \
239 *addrp = (*addrp & ((and)[0]|0xFF000000)) ^ ((xor)[0] & 0xFFFFFF); \
242 *addrp = (*addrp & ((and)[2]|0xFF)) ^ ((xor)[2] & 0xFFFFFF00); \
245 *addrp = (*addrp & ((and)[0]|0xFFFFFF)) ^ ((xor)[0] & 0xFF000000); \
246 *(addrp+1)=(*(addrp+1)&((and)[1]|0xFFFF0000)) ^ ((xor)[1]&0xFFFF); \
249 *addrp = (*addrp & ((and)[1]|0xFFFF)) ^ ((xor)[1] & 0xFFFF0000); \
250 *(addrp+1)=(*(addrp+1)&((and)[2]|0xFFFFFF00)) ^ ((xor)[2] & 0xFF); \
261 Loop(body_set(andPiQxlBg, xorPiQxlBg))
263 Loop(*addrp = DoRRop(*addrp,andBg, xorBg))
270 Loop(body_set(andPiQxlFg, xorPiQxlFg))
272 Loop(*addrp = DoRRop(*addrp,andFg, xorFg))
281 #else /* !PIXEL_ADDR */
283 register unsigned long tmp;
284 unsigned long startbit, bit;
286 /* point to longword containing first point */
288 addrl = (addrl + (y1 * nlwidth) + ((x1*3) >> 2);
290 addrl = (addrl + (y1 * nlwidth) + (x1 >> PWSH));
292 signdy = signdy * nlwidth;
295 startbit = cfbmask[0];
298 startbit = cfbmask[(PPW-1)<<1];
299 bit = cfbmask[(x1 & 3)<<1];
301 startbit = cfbmask[PPW-1];
302 bit = cfbmask[x1 & PIM];
306 #define X_Loop(store) while(thisDash--) {\
308 BresStep(addrl += signdy, \
310 bit = SCRRIGHT(bit,1); \
312 bit = SCRLEFT(bit,1); \
319 #define Y_Loop(store) while(thisDash--) {\
321 BresStep(if (signdx > 0) \
322 bit = SCRRIGHT(bit,1); \
324 bit = SCRLEFT(bit,1); \
333 #define X_Loop(store) while(thisDash--) {\
335 BresStep(addrl += signdy, \
337 bit = SCRRIGHT(bit,1); \
339 bit = SCRLEFT(bit,1); \
346 #define Y_Loop(store) while(thisDash--) {\
348 BresStep(if (signdx > 0) \
349 bit = SCRRIGHT(bit,1); \
351 bit = SCRLEFT(bit,1); \
368 X_Loop(*addrl = DoMaskRRop(*addrl, andBg, xorBg, bit));
373 X_Loop(*addrl = DoMaskRRop(*addrl, andFg, xorFg, bit));
387 Y_Loop(*addrl = DoMaskRRop(*addrl, andBg, xorBg, bit));
392 Y_Loop(*addrl = DoMaskRRop(*addrl, andFg, xorFg, bit));
401 *pdashIndex = dashIndex;
402 *pdashOffset = pDash[dashIndex] - dashRemaining;