1 dawes 3.2 /* $XFree86: xc/programs/Xserver/cfb/cfbbresd.c,v 3.1 1996/08/25 14:05:42 dawes Exp $ */
|
2 dawes 1.1 /***********************************************************
3
|
4 dawes 3.2 Copyright 1987, 1998 The Open Group
|
5 dawes 1.1
|
6 dawes 3.2 All Rights Reserved.
|
7 dawes 1.1
8 The above copyright notice and this permission notice shall be included in
9 all copies or substantial portions of the Software.
10
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
14 dawes 3.2 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
15 dawes 1.1 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
|
18 dawes 3.2 Except as contained in this notice, the name of The Open Group shall not be
|
19 dawes 1.1 used in advertising or otherwise to promote the sale, use or other dealings
|
20 dawes 3.2 in this Software without prior written authorization from The Open Group.
|
21 dawes 1.1
22
23 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
24
25 All Rights Reserved
26
27 Permission to use, copy, modify, and distribute this software and its
28 documentation for any purpose and without fee is hereby granted,
29 provided that the above copyright notice appear in all copies and that
30 both that copyright notice and this permission notice appear in
31 supporting documentation, and that the name of Digital not be
32 used in advertising or publicity pertaining to distribution of the
33 software without specific, written prior permission.
34
35 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
36 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
37 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
38 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
39 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
40 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
41 SOFTWARE.
42 dawes 1.1
43 ******************************************************************/
|
44 dawes 3.2 /* $TOG: cfbbresd.c /main/17 1998/02/09 14:04:47 kaleb $ */
|
45 dawes 1.1 #include "X.h"
46 #include "misc.h"
47 #include "cfb.h"
48 #include "cfbmskbits.h"
49 #include "miline.h"
50
51 /* Dashed bresenham line */
52
53 void
54 cfbBresD(rrops,
55 pdashIndex, pDash, numInDashList, pdashOffset, isDoubleDash,
56 addrl, nlwidth,
57 signdx, signdy, axis, x1, y1, e, e1, e2, len)
58 cfbRRopPtr rrops;
59 int *pdashIndex; /* current dash */
60 unsigned char *pDash; /* dash list */
61 int numInDashList; /* total length of dash list */
62 int *pdashOffset; /* offset into current dash */
63 int isDoubleDash;
64 unsigned long *addrl; /* pointer to base of bitmap */
65 int nlwidth; /* width in longwords of bitmap */
66 dawes 1.1 int signdx, signdy; /* signs of directions */
67 int axis; /* major axis (Y_AXIS or X_AXIS) */
68 int x1, y1; /* initial point */
69 register int e; /* error accumulator */
70 register int e1; /* bresenham increments */
71 int e2;
72 int len; /* length of line */
73 {
74 #ifdef PIXEL_ADDR
75 register PixelType *addrp;
76 #endif
77 register int e3 = e2-e1;
78 int dashIndex;
79 int dashOffset;
80 int dashRemaining;
81 unsigned long xorFg, andFg, xorBg, andBg;
82 Bool isCopy;
83 int thisDash;
|
84 dawes 3.0 #if PSZ == 24
85 unsigned long xorPiQxlFg[3], andPiQxlFg[3], xorPiQxlBg[3], andPiQxlBg[3];
86 char *addrb;
87 int signdx3, signdy3;
88 #endif
|
89 dawes 1.1
90 dashOffset = *pdashOffset;
91 dashIndex = *pdashIndex;
92 isCopy = (rrops[0].rop == GXcopy && rrops[1].rop == GXcopy);
|
93 dawes 3.0 #if PSZ == 24
94 xorFg = rrops[0].xor & 0xffffff;
95 andFg = rrops[0].and & 0xffffff;
96 xorBg = rrops[1].xor & 0xffffff;
97 andBg = rrops[1].and & 0xffffff;
98 xorPiQxlFg[0] = xorFg | (xorFg << 24);
99 xorPiQxlFg[1] = (xorFg >> 8) | (xorFg << 16);
100 xorPiQxlFg[2] = (xorFg >> 16) | (xorFg << 8);
101 andPiQxlFg[0] = andFg | (andFg << 24);
102 andPiQxlFg[1] = (andFg >> 8) | (andFg << 16);
103 andPiQxlFg[2] = (andFg >> 16) | (andFg << 8);
104 xorPiQxlBg[0] = xorBg | (xorBg << 24);
105 xorPiQxlBg[1] = (xorBg >> 8) | (xorBg << 16);
106 xorPiQxlBg[2] = (xorBg >> 16) | (xorBg << 8);
107 andPiQxlBg[0] = andBg | (andBg << 24);
108 andPiQxlBg[1] = (andBg >> 8) | (andBg << 16);
109 andPiQxlBg[2] = (andFg >> 16) | (andBg << 8);
110 #else
|
111 dawes 1.1 xorFg = rrops[0].xor;
112 andFg = rrops[0].and;
113 xorBg = rrops[1].xor;
114 andBg = rrops[1].and;
|
115 dawes 3.0 #endif
|
116 dawes 1.1 dashRemaining = pDash[dashIndex] - dashOffset;
117 if ((thisDash = dashRemaining) >= len)
118 {
119 thisDash = len;
120 dashRemaining -= len;
121 }
122 e = e-e1; /* to make looping easier */
123
124 #define BresStep(minor,major) {if ((e += e1) >= 0) { e += e3; minor; } major;}
125
126 #define NextDash {\
127 dashIndex++; \
128 if (dashIndex == numInDashList) \
129 dashIndex = 0; \
130 dashRemaining = pDash[dashIndex]; \
131 if ((thisDash = dashRemaining) >= len) \
132 { \
133 dashRemaining -= len; \
134 thisDash = len; \
135 } \
136 }
137 dawes 1.1
138 #ifdef PIXEL_ADDR
139
|
140 dawes 3.0 #if PSZ == 24
141 #define Loop(store) while (thisDash--) {\
142 store; \
143 BresStep(addrb+=signdy3,addrb+=signdx3) \
144 }
145 /* point to first point */
146 nlwidth <<= PWSH;
147 addrp = (PixelType *)(addrl) + (y1 * nlwidth);
148 addrb = (char *)addrp + x1 * 3;
149
150 #else
|
151 dawes 1.1 #define Loop(store) while (thisDash--) {\
152 store; \
153 BresStep(addrp+=signdy,addrp+=signdx) \
154 }
155 /* point to first point */
156 nlwidth <<= PWSH;
157 addrp = (PixelType *)(addrl) + (y1 * nlwidth) + x1;
|
158 dawes 3.0 #endif
|
159 dawes 1.1 signdy *= nlwidth;
|
160 dawes 3.0 #if PSZ == 24
161 signdx3 = signdx * 3;
162 signdy3 = signdy * sizeof (long);
163 #endif
|
164 dawes 1.1 if (axis == Y_AXIS)
165 {
166 int t;
167
168 t = signdx;
169 signdx = signdy;
170 signdy = t;
|
171 dawes 3.0 #if PSZ == 24
172 t = signdx3;
173 signdx3 = signdy3;
174 signdy3 = t;
175 #endif
|
176 dawes 1.1 }
177
178 if (isCopy)
179 {
|
180 dawes 3.0 #if PSZ == 24
181 #define body_copy(pix) { \
|
182 dawes 3.1 addrp = (PixelType *)((unsigned long)addrb & ~0x03); \
|
183 dawes 3.0 switch((unsigned long)addrb & 3){ \
184 case 0: \
185 *addrp = (*addrp & 0xFF000000)|((pix)[0] & 0xFFFFFF); \
186 break; \
187 case 1: \
188 *addrp = (*addrp & 0xFF)|((pix)[2] & 0xFFFFFF00); \
189 break; \
190 case 3: \
191 *addrp = (*addrp & 0xFFFFFF)|((pix)[0] & 0xFF000000); \
192 *(addrp+1) = (*(addrp+1) & 0xFFFF0000)|((pix)[1] & 0xFFFF); \
193 break; \
194 case 2: \
195 *addrp = (*addrp & 0xFFFF)|((pix)[1] & 0xFFFF0000); \
196 *(addrp+1) = (*(addrp+1) & 0xFFFFFF00)|((pix)[2] & 0xFF); \
197 break; \
198 } \
199 }
200 #endif /* PSZ == 24 */
201
|
202 dawes 1.1 for (;;)
203 {
204 len -= thisDash;
205 if (dashIndex & 1) {
206 if (isDoubleDash) {
|
207 dawes 3.0 #if PSZ == 24
208 Loop(body_copy(xorPiQxlBg))
209 #else
|
210 dawes 1.1 Loop(*addrp = xorBg)
|
211 dawes 3.0 #endif
|
212 dawes 1.1 } else {
213 Loop(;)
214 }
215 } else {
|
216 dawes 3.0 #if PSZ == 24
217 Loop(body_copy(xorPiQxlFg))
218 #else
|
219 dawes 1.1 Loop(*addrp = xorFg)
|
220 dawes 3.0 #endif
|
221 dawes 1.1 }
222 if (!len)
223 break;
224 NextDash
225 }
|
226 dawes 3.0 #undef body_copy
|
227 dawes 1.1 }
228 else
229 {
|
230 dawes 3.0 #define body_set(and, xor) { \
|
231 dawes 3.1 addrp = (PixelType *)((unsigned long)addrb & ~0x03); \
|
232 dawes 3.0 switch((unsigned long)addrb & 3){ \
233 case 0: \
234 *addrp = (*addrp & ((and)[0]|0xFF000000)) ^ ((xor)[0] & 0xFFFFFF); \
235 break; \
236 case 1: \
237 *addrp = (*addrp & ((and)[2]|0xFF)) ^ ((xor)[2] & 0xFFFFFF00); \
238 break; \
239 case 3: \
240 *addrp = (*addrp & ((and)[0]|0xFFFFFF)) ^ ((xor)[0] & 0xFF000000); \
241 *(addrp+1)=(*(addrp+1)&((and)[1]|0xFFFF0000)) ^ ((xor)[1]&0xFFFF); \
242 break; \
243 case 2: \
244 *addrp = (*addrp & ((and)[1]|0xFFFF)) ^ ((xor)[1] & 0xFFFF0000); \
245 *(addrp+1)=(*(addrp+1)&((and)[2]|0xFFFFFF00)) ^ ((xor)[2] & 0xFF); \
246 break; \
247 } \
248 }
249
|
250 dawes 1.1 for (;;)
251 {
252 len -= thisDash;
253 if (dashIndex & 1) {
254 if (isDoubleDash) {
|
255 dawes 3.0 #if PSZ == 24
256 Loop(body_set(andPiQxlBg, xorPiQxlBg))
257 #else
|
258 dawes 1.1 Loop(*addrp = DoRRop(*addrp,andBg, xorBg))
|
259 dawes 3.0 #endif
|
260 dawes 1.1 } else {
261 Loop(;)
262 }
263 } else {
|
264 dawes 3.0 #if PSZ == 24
265 Loop(body_set(andPiQxlFg, xorPiQxlFg))
266 #else
|
267 dawes 1.1 Loop(*addrp = DoRRop(*addrp,andFg, xorFg))
|
268 dawes 3.0 #endif
|
269 dawes 1.1 }
270 if (!len)
271 break;
272 NextDash
273 }
|
274 dawes 3.0 #undef body_set
|
275 dawes 1.1 }
276 #else /* !PIXEL_ADDR */
277 {
278 register unsigned long tmp;
279 unsigned long startbit, bit;
280
281 /* point to longword containing first point */
|
282 dawes 3.0 #if PSZ == 24
283 addrl = (addrl + (y1 * nlwidth) + ((x1*3) >> 2);
284 #else
|
285 dawes 1.1 addrl = (addrl + (y1 * nlwidth) + (x1 >> PWSH));
|
286 dawes 3.0 #endif
|
287 dawes 1.1 signdy = signdy * nlwidth;
288
289 if (signdx > 0)
290 startbit = cfbmask[0];
291 else
|
292 dawes 3.0 #if PSZ == 24
293 startbit = cfbmask[(PPW-1)<<1];
294 bit = cfbmask[(x1 & 3)<<1];
295 #else
|
296 dawes 1.1 startbit = cfbmask[PPW-1];
297 bit = cfbmask[x1 & PIM];
|
298 dawes 3.0 #endif
|
299 dawes 1.1
|
300 dawes 3.0 #if PSZ == 24
|
301 dawes 1.1 #define X_Loop(store) while(thisDash--) {\
302 store; \
303 BresStep(addrl += signdy, \
304 if (signdx > 0) \
305 bit = SCRRIGHT(bit,1); \
306 else \
307 bit = SCRLEFT(bit,1); \
308 if (!bit) \
309 { \
310 bit = startbit; \
311 addrl += signdx; \
312 }) \
313 }
314 #define Y_Loop(store) while(thisDash--) {\
315 store; \
316 BresStep(if (signdx > 0) \
317 bit = SCRRIGHT(bit,1); \
318 else \
319 bit = SCRLEFT(bit,1); \
320 if (!bit) \
321 { \
322 dawes 1.1 bit = startbit; \
323 addrl += signdx; \
324 }, \
325 addrl += signdy) \
326 }
|
327 dawes 3.0 #else
328 #define X_Loop(store) while(thisDash--) {\
329 store; \
330 BresStep(addrl += signdy, \
331 if (signdx > 0) \
332 bit = SCRRIGHT(bit,1); \
333 else \
334 bit = SCRLEFT(bit,1); \
335 if (!bit) \
336 { \
337 bit = startbit; \
338 addrl += signdx; \
339 }) \
340 }
341 #define Y_Loop(store) while(thisDash--) {\
342 store; \
343 BresStep(if (signdx > 0) \
344 bit = SCRRIGHT(bit,1); \
345 else \
346 bit = SCRLEFT(bit,1); \
347 if (!bit) \
348 dawes 3.0 { \
349 bit = startbit; \
350 addrl += signdx; \
351 }, \
352 addrl += signdy) \
353 }
354 #endif
|
355 dawes 1.1
356 if (axis == X_AXIS)
357 {
358 for (;;)
359 {
360 len -= thisDash;
361 if (dashIndex & 1) {
362 if (isDoubleDash) {
363 X_Loop(*addrl = DoMaskRRop(*addrl, andBg, xorBg, bit));
364 } else {
365 X_Loop(;)
366 }
367 } else {
368 X_Loop(*addrl = DoMaskRRop(*addrl, andFg, xorFg, bit));
369 }
370 if (!len)
371 break;
372 NextDash
373 }
374 } /* if X_AXIS */
375 else
376 dawes 1.1 {
377 for (;;)
378 {
379 len -= thisDash;
380 if (dashIndex & 1) {
381 if (isDoubleDash) {
382 Y_Loop(*addrl = DoMaskRRop(*addrl, andBg, xorBg, bit));
383 } else {
384 Y_Loop(;)
385 }
386 } else {
387 Y_Loop(*addrl = DoMaskRRop(*addrl, andFg, xorFg, bit));
388 }
389 if (!len)
390 break;
391 NextDash
392 }
393 } /* else Y_AXIS */
394 }
395 #endif
396 *pdashIndex = dashIndex;
397 dawes 1.1 *pdashOffset = pDash[dashIndex] - dashRemaining;
398 }
|