First import
[xorg_rtime.git] / xorg-server-1.4 / cfb / cfbbres.c
blobfa1ee137979a8063de722b3c42b0ed9061ae4206
1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
26 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28 All Rights Reserved
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44 SOFTWARE.
46 ******************************************************************/
47 #ifdef HAVE_DIX_CONFIG_H
48 #include <dix-config.h>
49 #endif
51 #include <X11/X.h>
52 #include "misc.h"
53 #include "cfb.h"
54 #include "cfbmskbits.h"
55 #include "servermd.h"
56 #include "miline.h"
58 /* Solid bresenham line */
59 /* NOTES
60 e2 is used less often than e1, so it's not in a register
63 void
64 cfbBresS(rop, and, xor, addrl, nlwidth, signdx, signdy, axis, x1, y1, e, e1,
65 e2, len)
66 int rop;
67 CfbBits and, xor;
68 CfbBits *addrl; /* pointer to base of bitmap */
69 int nlwidth; /* width in longwords of bitmap */
70 register int signdx;
71 int 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 */
76 int e2;
77 int len; /* length of line */
79 register int e3 = e2-e1;
80 #if PSZ == 24
81 CfbBits piQxelXor[3],piQxelAnd[3];
82 char *addrb;
83 int nlwidth3, signdx3;
84 #endif
85 #ifdef PIXEL_ADDR
86 register PixelType *addrp; /* Pixel pointer */
88 if (len == 0)
89 return;
90 /* point to first point */
91 nlwidth <<= PWSH;
92 #if PSZ == 24
93 addrp = (PixelType *)(addrl) + (y1 * nlwidth);
94 addrb = (char *)addrp + x1 * 3;
96 piQxelXor[0] = (xor << 24) | xor;
97 piQxelXor[1] = (xor << 16)| (xor >> 8);
98 piQxelXor[2] = (xor << 8) | (xor >> 16);
99 piQxelAnd[0] = (and << 24) | and;
100 piQxelAnd[1] = (and << 16)| (and >> 8);
101 piQxelAnd[2] = (and << 8) | (and >> 16);
102 #else
103 addrp = (PixelType *)(addrl) + (y1 * nlwidth) + x1;
104 #endif
105 if (signdy < 0)
106 nlwidth = -nlwidth;
107 e = e-e1; /* to make looping easier */
108 #if PSZ == 24
109 nlwidth3 = nlwidth * sizeof (CfbBits);
110 signdx3 = signdx * 3;
111 #endif
113 if (axis == Y_AXIS)
115 int t;
117 t = nlwidth;
118 nlwidth = signdx;
119 signdx = t;
120 #if PSZ == 24
121 t = nlwidth3;
122 nlwidth3 = signdx3;
123 signdx3 = t;
124 #endif
126 if (rop == GXcopy)
128 --len;
129 #if PSZ == 24
130 #define body_copy \
131 addrp = (PixelType *)((unsigned long)addrb & ~0x03); \
132 switch((unsigned long)addrb & 3){ \
133 case 0: \
134 *addrp = ((*addrp)&0xFF000000)|(piQxelXor[0] & 0xFFFFFF); \
135 break; \
136 case 1: \
137 *addrp = ((*addrp)&0xFF)|(piQxelXor[2] & 0xFFFFFF00); \
138 break; \
139 case 3: \
140 *addrp = ((*addrp)&0xFFFFFF)|(piQxelXor[0] & 0xFF000000); \
141 *(addrp+1) = ((*(addrp+1))&0xFFFF0000)|(piQxelXor[1] & 0xFFFF); \
142 break; \
143 case 2: \
144 *addrp = ((*addrp)&0xFFFF)|(piQxelXor[1] & 0xFFFF0000); \
145 *(addrp+1) = ((*(addrp+1))&0xFFFFFF00)|(piQxelXor[2] & 0xFF); \
146 break; \
148 #define body {\
149 body_copy \
150 addrb += signdx3; \
151 e += e1; \
152 if (e >= 0) \
154 addrb += nlwidth3; \
155 e += e3; \
158 #else /* PSZ == 24 */
159 #define body {\
160 *addrp = xor; \
161 addrp += signdx; \
162 e += e1; \
163 if (e >= 0) \
165 addrp += nlwidth; \
166 e += e3; \
169 #endif /* PSZ == 24 */
170 while (len >= 4)
172 body body body body
173 len -= 4;
175 switch (len)
177 case 3: body case 2: body case 1: body
179 #undef body
180 #if PSZ == 24
181 body_copy
182 # undef body_copy
183 #else
184 *addrp = xor;
185 #endif
187 else /* not GXcopy */
189 while(len--)
191 #if PSZ == 24
192 addrp = (PixelType *)((unsigned long)addrb & ~0x03);
193 switch((unsigned long)addrb & 3){
194 case 0:
195 *addrp = (*addrp & (piQxelAnd[0]|0xFF000000))
196 ^ (piQxelXor[0] & 0xFFFFFF);
197 break;
198 case 1:
199 *addrp = (*addrp & (piQxelAnd[2]|0xFF))
200 ^ (piQxelXor[2] & 0xFFFFFF00);
201 break;
202 case 3:
203 *addrp = (*addrp & (piQxelAnd[0]|0xFFFFFF))
204 ^ (piQxelXor[0] & 0xFF000000);
205 *(addrp+1) = (*(addrp+1) & (piQxelAnd[1]|0xFFFF0000))
206 ^ (piQxelXor[1] & 0xFFFF);
207 break;
208 case 2:
209 *addrp = (*addrp & (piQxelAnd[1]|0xFFFF))
210 ^ (piQxelXor[1] & 0xFFFF0000);
211 *(addrp+1) = (*(addrp+1) & (piQxelAnd[2]|0xFFFFFF00))
212 ^ (piQxelXor[2] & 0xFF);
213 break;
215 e += e1;
216 if (e >= 0)
218 addrb += nlwidth3;
219 e += e3;
221 addrb += signdx3;
222 #else /* PSZ == 24 */
223 *addrp = DoRRop (*addrp, and, xor);
224 e += e1;
225 if (e >= 0)
227 addrp += nlwidth;
228 e += e3;
230 addrp += signdx;
231 #endif /* PSZ == 24 */
234 #else /* !PIXEL_ADDR */
235 register CfbBits tmp, bit;
236 CfbBits leftbit, rightbit;
238 /* point to longword containing first point */
239 #if PSZ == 24
240 addrl = (addrl + (y1 * nlwidth) + ((x1 * 3) >>2);
241 #else
242 addrl = (addrl + (y1 * nlwidth) + (x1 >> PWSH));
243 #endif
244 if (signdy < 0)
245 nlwidth = -nlwidth;
246 e = e-e1; /* to make looping easier */
248 leftbit = cfbmask[0];
249 #if PSZ == 24
250 rightbit = cfbmask[(PPW-1)<<1];
251 bit = cfbmask[(x1 & 3)<<1];
252 #else
253 rightbit = cfbmask[PPW-1];
254 bit = cfbmask[x1 & PIM];
255 #endif
257 if (axis == X_AXIS)
259 if (signdx > 0)
261 while (len--)
263 *addrl = DoMaskRRop (*addrl, and, xor, bit);
264 bit = SCRRIGHT(bit,1);
265 e += e1;
266 if (e >= 0)
268 addrl += nlwidth;
269 e += e3;
271 if (!bit)
273 bit = leftbit;
274 addrl++;
278 else
280 while (len--)
282 *addrl = DoMaskRRop (*addrl, and, xor, bit);
283 e += e1;
284 bit = SCRLEFT(bit,1);
285 if (e >= 0)
287 addrl += nlwidth;
288 e += e3;
290 if (!bit)
292 bit = rightbit;
293 addrl--;
297 } /* if X_AXIS */
298 else
300 if (signdx > 0)
302 while(len--)
304 *addrl = DoMaskRRop (*addrl, and, xor, bit);
305 e += e1;
306 if (e >= 0)
308 bit = SCRRIGHT(bit,1);
309 if (!bit)
311 bit = leftbit;
312 addrl++;
314 e += e3;
316 addrl += nlwidth;
319 else
321 while(len--)
323 *addrl = DoMaskRRop (*addrl, and, xor, bit);
324 e += e1;
325 if (e >= 0)
327 bit = SCRLEFT(bit,1);
328 if (!bit)
330 bit = rightbit;
331 addrl--;
333 e += e3;
335 addrl += nlwidth;
338 } /* else Y_AXIS */
339 #endif