Initial commit
[xorg_rtime.git] / xorg-server-1.4 / afb / afbzerarc.c
blob2cc30687ff5c7a5c504347de637a44b8552b60eb
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 ********************************************************/
29 /* Derived from:
30 * "Algorithm for drawing ellipses or hyperbolae with a digital plotter"
31 * by M. L. V. Pitteway
32 * The Computer Journal, November 1967, Volume 10, Number 3, pp. 282-289
35 #ifdef HAVE_DIX_CONFIG_H
36 #include <dix-config.h>
37 #endif
39 #include <X11/X.h>
40 #include <X11/Xprotostr.h>
41 #include "regionstr.h"
42 #include "gcstruct.h"
43 #include "pixmapstr.h"
44 #include "scrnintstr.h"
45 #include "afb.h"
46 #include "maskbits.h"
47 #include "mizerarc.h"
48 #include "mi.h"
51 * Note: LEFTMOST must be the bit leftmost in the actual screen
52 * representation. This depends also on the IMAGE_BYTE_ORDER.
53 * LONG2CHARS() takes care of the re-ordering as required. (DHD)
55 #if (BITMAP_BIT_ORDER == MSBFirst)
56 #define LEFTMOST ((PixelType) LONG2CHARS((1 << PLST)))
57 #else
58 #define LEFTMOST ((PixelType) LONG2CHARS(1))
59 #endif
61 #define Pixelate(base,yoff,xoff) \
62 { \
63 paddr = afbScanlineOffset(base, (yoff) + ((xoff)>>PWSH)); \
64 pmask = SCRRIGHT(LEFTMOST, (xoff) & PIM); \
65 for (de = 0; de < depthDst; de++, paddr += sizeDst) /* @@@ NEXT PLANE @@@ */ \
66 switch (rrops[de]) { \
67 case RROP_BLACK: \
68 *paddr &= ~pmask; \
69 break; \
70 case RROP_WHITE: \
71 *paddr |= pmask; \
72 break; \
73 case RROP_INVERT: \
74 *paddr ^= pmask; \
75 break; \
76 case RROP_NOP: \
77 break; \
78 } \
81 #define DoPix(bit,base,yoff,xoff) if (mask & bit) Pixelate(base,yoff,xoff);
83 static void
84 afbZeroArcSS(DrawablePtr pDraw, GCPtr pGC, xArc *arc)
86 miZeroArcRec info;
87 Bool do360;
88 register int de;
89 register int x, y, a, b, d, mask;
90 register int k1, k3, dx, dy;
91 PixelType *addrl;
92 PixelType *yorgl, *yorgol;
93 int nlwidth, yoffset, dyoffset;
94 int sizeDst, depthDst;
95 PixelType pmask;
96 register PixelType *paddr;
97 register unsigned char *rrops;
99 rrops = ((afbPrivGC *)(pGC->devPrivates[afbGCPrivateIndex].ptr))->rrops;
101 afbGetPixelWidthSizeDepthAndPointer(pDraw, nlwidth, sizeDst, depthDst,
102 addrl);
103 do360 = miZeroArcSetup(arc, &info, TRUE);
104 yorgl = addrl + ((info.yorg + pDraw->y) * nlwidth);
105 yorgol = addrl + ((info.yorgo + pDraw->y) * nlwidth);
106 info.xorg += pDraw->x;
107 info.xorgo += pDraw->x;
108 MIARCSETUP();
109 yoffset = y ? nlwidth : 0;
110 dyoffset = 0;
111 mask = info.initialMask;
112 if (!(arc->width & 1)) {
113 DoPix(2, yorgl, 0, info.xorgo);
114 DoPix(8, yorgol, 0, info.xorgo);
116 if (!info.end.x || !info.end.y) {
117 mask = info.end.mask;
118 info.end = info.altend;
120 if (do360 && (arc->width == arc->height) && !(arc->width & 1)) {
121 int xoffset = nlwidth;
122 PixelType *yorghl = afbScanlineDeltaNoBankSwitch(yorgl, info.h, nlwidth);
123 int xorghp = info.xorg + info.h;
124 int xorghn = info.xorg - info.h;
126 while (1) {
127 Pixelate(yorgl, yoffset, info.xorg + x);
128 Pixelate(yorgl, yoffset, info.xorg - x);
129 Pixelate(yorgol, -yoffset, info.xorg - x);
130 Pixelate(yorgol, -yoffset, info.xorg + x);
131 if (a < 0)
132 break;
133 Pixelate(yorghl, -xoffset, xorghp - y);
134 Pixelate(yorghl, -xoffset, xorghn + y);
135 Pixelate(yorghl, xoffset, xorghn + y);
136 Pixelate(yorghl, xoffset, xorghp - y);
137 xoffset += nlwidth;
138 MIARCCIRCLESTEP(yoffset += nlwidth;);
140 x = info.w;
141 yoffset = info.h * nlwidth;
142 } else if (do360) {
143 while (y < info.h || x < info.w) {
144 MIARCOCTANTSHIFT(dyoffset = nlwidth;);
145 Pixelate(yorgl, yoffset, info.xorg + x);
146 Pixelate(yorgl, yoffset, info.xorgo - x);
147 Pixelate(yorgol, -yoffset, info.xorgo - x);
148 Pixelate(yorgol, -yoffset, info.xorg + x);
149 MIARCSTEP(yoffset += dyoffset;, yoffset += nlwidth;);
151 } else {
152 while (y < info.h || x < info.w) {
153 MIARCOCTANTSHIFT(dyoffset = nlwidth;);
154 if ((x == info.start.x) || (y == info.start.y)) {
155 mask = info.start.mask;
156 info.start = info.altstart;
158 DoPix(1, yorgl, yoffset, info.xorg + x);
159 DoPix(2, yorgl, yoffset, info.xorgo - x);
160 DoPix(4, yorgol, -yoffset, info.xorgo - x);
161 DoPix(8, yorgol, -yoffset, info.xorg + x);
162 if ((x == info.end.x) || (y == info.end.y)) {
163 mask = info.end.mask;
164 info.end = info.altend;
166 MIARCSTEP(yoffset += dyoffset;, yoffset += nlwidth;);
169 if ((x == info.start.x) || (y == info.start.y))
170 mask = info.start.mask;
171 DoPix(1, yorgl, yoffset, info.xorg + x);
172 DoPix(4, yorgol, -yoffset, info.xorgo - x);
173 if (arc->height & 1) {
174 DoPix(2, yorgl, yoffset, info.xorgo - x);
175 DoPix(8, yorgol, -yoffset, info.xorg + x);
179 void
180 afbZeroPolyArcSS(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc *parcs)
182 register xArc *arc;
183 register int i;
184 BoxRec box;
185 RegionPtr cclip;
187 cclip = pGC->pCompositeClip;
188 for (arc = parcs, i = narcs; --i >= 0; arc++) {
189 if (miCanZeroArc(arc)) {
190 box.x1 = arc->x + pDraw->x;
191 box.y1 = arc->y + pDraw->y;
192 box.x2 = box.x1 + (int)arc->width + 1;
193 box.y2 = box.y1 + (int)arc->height + 1;
194 if (RECT_IN_REGION(pDraw->pScreen, cclip, &box) == rgnIN)
195 afbZeroArcSS(pDraw, pGC, arc);
196 else
197 miZeroPolyArc(pDraw, pGC, 1, arc);
198 } else
199 miPolyArc(pDraw, pGC, 1, arc);