1 /************************************************************
3 Copyright (c) 1989 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.
26 ********************************************************/
28 /* $XConsortium: cfbzerarc.c /main/24 1995/12/06 16:58:51 dpw $ */
29 /* $XFree86: xc/programs/Xserver/cfb/cfbzerarc.c,v 3.0 1996/06/29 09:05:57 dawes Exp $ */
32 * "Algorithm for drawing ellipses or hyperbolae with a digital plotter"
33 * by M. L. V. Pitteway
34 * The Computer Journal, November 1967, Volume 10, Number 3, pp. 282-289
38 #include "Xprotostr.h"
39 #include "miscstruct.h"
41 #include "pixmapstr.h"
42 #include "scrnintstr.h"
44 #include "cfbmskbits.h"
52 RROP_NAME(cfbZeroArcSS8) (pDraw, pGC, arc)
61 register PixelType *yorgp, *yorgop;
63 int xorg, xorg3, xorgo, xorgo3;
68 int npwidth, dyoffset;
69 register int y, a, b, d, mask;
70 register int k1, k3, dx, dy;
72 cfbGetPixelWidthAndPointer(pDraw,npwidth, addrp)
75 do360 = miZeroArcSetup(arc, &info, TRUE);
76 yorgp = addrp + ((info.yorg + pDraw->y) * npwidth);
77 yorgop = addrp + ((info.yorgo + pDraw->y) * npwidth);
78 info.xorg += pDraw->x;
79 info.xorgo += pDraw->x;
83 info.xorg = (info.xorg * 3) >> 2;
86 info.xorgo = (info.xorgo * 3) >> 2;
89 yoffset = y ? npwidth : 0;
91 mask = info.initialMask;
92 if (!(arc->width & 1))
96 RROP_SOLID24((yorgp + info.xorgo), xorgo);
98 RROP_SOLID24((yorgop + info.xorgo), xorgo);
101 RROP_SOLID((yorgp + info.xorgo));
103 RROP_SOLID((yorgop + info.xorgo));
104 #endif /* PSZ == 24 */
106 if (!info.end.x || !info.end.y)
108 mask = info.end.mask;
109 info.end = info.altend;
111 if (do360 && (arc->width == arc->height) && !(arc->width & 1))
113 register int xoffset = npwidth;
115 PixelType *yorghb = yorgp + (info.h * npwidth);
116 register int tmp1, tmp2, tmp1_3, tmp2_3;
118 tmp1 = xorg + info.h;
120 tmp2 = xorg - info.h;
124 xtmp = (xorg3 + x * 3) >> 2;
125 RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
126 RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
127 xtmp = (xorg3 - x * 3) >> 2;
128 RROP_SOLID24(yorgp + yoffset + xtmp, xorg - x);
129 RROP_SOLID24(yorgop - yoffset + xtmp, xorg - x);
132 xtmp = (tmp1_3 - y * 3) >> 2;
133 RROP_SOLID24(yorghb - xoffset + xtmp, tmp1 - y);
134 RROP_SOLID24(yorghb + xoffset + xtmp, tmp1 - y);
135 xtmp = (tmp2_3 + y * 3) >> 2;
136 RROP_SOLID24(yorghb - xoffset + xtmp, tmp2 + y);
137 RROP_SOLID24(yorghb + xoffset + xtmp, tmp2 + y);
139 MIARCCIRCLESTEP(yoffset += npwidth;);
142 PixelType *yorghb = yorgp + (info.h * npwidth) + info.xorg;
143 PixelType *yorgohb = yorghb - info.h;
150 RROP_SOLID(yorgp + yoffset + x);
151 RROP_SOLID(yorgp + yoffset - x);
152 RROP_SOLID(yorgop - yoffset - x);
153 RROP_SOLID(yorgop - yoffset + x);
156 RROP_SOLID(yorghb - xoffset - y);
157 RROP_SOLID(yorgohb - xoffset + y);
158 RROP_SOLID(yorgohb + xoffset + y);
159 RROP_SOLID(yorghb + xoffset - y);
161 MIARCCIRCLESTEP(yoffset += npwidth;);
165 #endif /* PSZ == 24 */
167 yoffset = info.h * npwidth;
171 while (y < info.h || x < info.w)
173 MIARCOCTANTSHIFT(dyoffset = npwidth;);
175 xtmp = (xorg3 + x * 3) >> 2;
176 RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
177 RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
178 xtmp = (xorgo3 - x * 3) >> 2;
179 RROP_SOLID24(yorgp + yoffset + xtmp, xorgo - x);
180 RROP_SOLID24(yorgop - yoffset + xtmp, xorgo - x);
182 RROP_SOLID(yorgp + yoffset + info.xorg + x);
183 RROP_SOLID(yorgp + yoffset + info.xorgo - x);
184 RROP_SOLID(yorgop - yoffset + info.xorgo - x);
185 RROP_SOLID(yorgop - yoffset + info.xorg + x);
187 MIARCSTEP(yoffset += dyoffset;, yoffset += npwidth;);
192 while (y < info.h || x < info.w)
194 MIARCOCTANTSHIFT(dyoffset = npwidth;);
195 if ((x == info.start.x) || (y == info.start.y))
197 mask = info.start.mask;
198 info.start = info.altstart;
202 xtmp = (xorg3 + x * 3) >> 2;
203 RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
206 xtmp = (xorgo3 - x * 3) >> 2;
207 RROP_SOLID24(yorgp + yoffset + xtmp, xorgo - x);
210 xtmp = (xorgo3 - x * 3) >> 2;
211 RROP_SOLID24(yorgop - yoffset + xtmp, xorgo - x);
214 xtmp = (xorg3 + x * 3) >> 2;
215 RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
219 RROP_SOLID(yorgp + yoffset + info.xorg + x);
221 RROP_SOLID(yorgp + yoffset + info.xorgo - x);
223 RROP_SOLID(yorgop - yoffset + info.xorgo - x);
225 RROP_SOLID(yorgop - yoffset + info.xorg + x);
226 #endif /* PSZ == 24 */
227 if ((x == info.end.x) || (y == info.end.y))
229 mask = info.end.mask;
230 info.end = info.altend;
232 MIARCSTEP(yoffset += dyoffset;, yoffset += npwidth;);
235 if ((x == info.start.x) || (y == info.start.y))
236 mask = info.start.mask;
239 xtmp = (xorg3 + x * 3) >> 2;
240 RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
243 xtmp = (xorgo3 - x * 3) >> 2;
244 RROP_SOLID24(yorgop - yoffset + xtmp, xorgo - x);
248 RROP_SOLID(yorgp + yoffset + info.xorg + x);
250 RROP_SOLID(yorgop - yoffset + info.xorgo - x);
251 #endif /* PSZ == 24 */
256 xtmp = (xorgo3 - x * 3) >> 2;
257 RROP_SOLID24(yorgp + yoffset + xtmp, xorgo - x);
260 xtmp = (xorg3 + x * 3) >> 2;
261 RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
265 RROP_SOLID(yorgp + yoffset + info.xorgo - x);
267 RROP_SOLID(yorgop - yoffset + info.xorg + x);
268 #endif /* PSZ == 24 */
273 RROP_NAME (cfbZeroPolyArcSS8) (pDraw, pGC, narcs, parcs)
274 register DrawablePtr pDraw;
285 cclip = cfbGetCompositeClip(pGC);
286 for (arc = parcs, i = narcs; --i >= 0; arc++)
288 if (miCanZeroArc(arc))
290 box.x1 = arc->x + pDraw->x;
291 box.y1 = arc->y + pDraw->y;
293 * Because box.x2 and box.y2 get truncated to 16 bits, and the
294 * RECT_IN_REGION test treats the resulting number as a signed
295 * integer, the RECT_IN_REGION test alone can go the wrong way.
296 * This can result in a server crash because the rendering
297 * routines in this file deal directly with cpu addresses
298 * of pixels to be stored, and do not clip or otherwise check
299 * that all such addresses are within their respective pixmaps.
300 * So we only allow the RECT_IN_REGION test to be used for
301 * values that can be expressed correctly in a signed short.
303 x2 = box.x1 + (int)arc->width + 1;
305 y2 = box.y1 + (int)arc->height + 1;
307 if ( (x2 <= MAXSHORT) && (y2 <= MAXSHORT) &&
308 (RECT_IN_REGION(pDraw->pScreen, cclip, &box) == rgnIN) )
309 RROP_NAME (cfbZeroArcSS8) (pDraw, pGC, arc);
311 miZeroPolyArc(pDraw, pGC, 1, arc);
314 miPolyArc(pDraw, pGC, 1, arc);