xref: /OK3568_Linux_fs/external/xserver/mi/mifillarc.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /************************************************************
2*4882a593Smuzhiyun 
3*4882a593Smuzhiyun Copyright 1989, 1998  The Open Group
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun Permission to use, copy, modify, distribute, and sell this software and its
6*4882a593Smuzhiyun documentation for any purpose is hereby granted without fee, provided that
7*4882a593Smuzhiyun the above copyright notice appear in all copies and that both that
8*4882a593Smuzhiyun copyright notice and this permission notice appear in supporting
9*4882a593Smuzhiyun documentation.
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun The above copyright notice and this permission notice shall be included in
12*4882a593Smuzhiyun all copies or substantial portions of the Software.
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*4882a593Smuzhiyun IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*4882a593Smuzhiyun FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17*4882a593Smuzhiyun OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18*4882a593Smuzhiyun AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19*4882a593Smuzhiyun CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun Except as contained in this notice, the name of The Open Group shall not be
22*4882a593Smuzhiyun used in advertising or otherwise to promote the sale, use or other dealings
23*4882a593Smuzhiyun in this Software without prior written authorization from The Open Group.
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun ********************************************************/
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #ifndef __MIFILLARC_H__
28*4882a593Smuzhiyun #define __MIFILLARC_H__
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #define FULLCIRCLE (360 * 64)
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun typedef struct _miFillArc {
33*4882a593Smuzhiyun     int xorg, yorg;
34*4882a593Smuzhiyun     int y;
35*4882a593Smuzhiyun     int dx, dy;
36*4882a593Smuzhiyun     int e;
37*4882a593Smuzhiyun     int ym, yk, xm, xk;
38*4882a593Smuzhiyun } miFillArcRec;
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun /* could use 64-bit integers */
41*4882a593Smuzhiyun typedef struct _miFillArcD {
42*4882a593Smuzhiyun     int xorg, yorg;
43*4882a593Smuzhiyun     int y;
44*4882a593Smuzhiyun     int dx, dy;
45*4882a593Smuzhiyun     double e;
46*4882a593Smuzhiyun     double ym, yk, xm, xk;
47*4882a593Smuzhiyun } miFillArcDRec;
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun #define miFillArcEmpty(arc) (!(arc)->angle2 || \
50*4882a593Smuzhiyun 			     !(arc)->width || !(arc)->height || \
51*4882a593Smuzhiyun 			     (((arc)->width == 1) && ((arc)->height & 1)))
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun #define miCanFillArc(arc) (((arc)->width == (arc)->height) || \
54*4882a593Smuzhiyun 			   (((arc)->width <= 800) && ((arc)->height <= 800)))
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun #define MIFILLARCSETUP() \
57*4882a593Smuzhiyun     x = 0; \
58*4882a593Smuzhiyun     y = info.y; \
59*4882a593Smuzhiyun     e = info.e; \
60*4882a593Smuzhiyun     xk = info.xk; \
61*4882a593Smuzhiyun     xm = info.xm; \
62*4882a593Smuzhiyun     yk = info.yk; \
63*4882a593Smuzhiyun     ym = info.ym; \
64*4882a593Smuzhiyun     dx = info.dx; \
65*4882a593Smuzhiyun     dy = info.dy; \
66*4882a593Smuzhiyun     xorg = info.xorg; \
67*4882a593Smuzhiyun     yorg = info.yorg
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun #define MIFILLARCSTEP(slw) \
70*4882a593Smuzhiyun     e += yk; \
71*4882a593Smuzhiyun     while (e >= 0) \
72*4882a593Smuzhiyun     { \
73*4882a593Smuzhiyun 	x++; \
74*4882a593Smuzhiyun 	xk -= xm; \
75*4882a593Smuzhiyun 	e += xk; \
76*4882a593Smuzhiyun     } \
77*4882a593Smuzhiyun     y--; \
78*4882a593Smuzhiyun     yk -= ym; \
79*4882a593Smuzhiyun     slw = (x << 1) + dx; \
80*4882a593Smuzhiyun     if ((e == xk) && (slw > 1)) \
81*4882a593Smuzhiyun 	slw--
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun #define MIFILLCIRCSTEP(slw) MIFILLARCSTEP(slw)
84*4882a593Smuzhiyun #define MIFILLELLSTEP(slw) MIFILLARCSTEP(slw)
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun #define miFillArcLower(slw) (((y + dy) != 0) && ((slw > 1) || (e != xk)))
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun typedef struct _miSliceEdge {
89*4882a593Smuzhiyun     int x;
90*4882a593Smuzhiyun     int stepx;
91*4882a593Smuzhiyun     int deltax;
92*4882a593Smuzhiyun     int e;
93*4882a593Smuzhiyun     int dy;
94*4882a593Smuzhiyun     int dx;
95*4882a593Smuzhiyun } miSliceEdgeRec, *miSliceEdgePtr;
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun typedef struct _miArcSlice {
98*4882a593Smuzhiyun     miSliceEdgeRec edge1, edge2;
99*4882a593Smuzhiyun     int min_top_y, max_top_y;
100*4882a593Smuzhiyun     int min_bot_y, max_bot_y;
101*4882a593Smuzhiyun     Bool edge1_top, edge2_top;
102*4882a593Smuzhiyun     Bool flip_top, flip_bot;
103*4882a593Smuzhiyun } miArcSliceRec;
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun #define MIARCSLICESTEP(edge) \
106*4882a593Smuzhiyun     edge.x -= edge.stepx; \
107*4882a593Smuzhiyun     edge.e -= edge.dx; \
108*4882a593Smuzhiyun     if (edge.e <= 0) \
109*4882a593Smuzhiyun     { \
110*4882a593Smuzhiyun 	edge.x -= edge.deltax; \
111*4882a593Smuzhiyun 	edge.e += edge.dy; \
112*4882a593Smuzhiyun     }
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun #define miFillSliceUpper(slice) \
115*4882a593Smuzhiyun 		((y >= slice.min_top_y) && (y <= slice.max_top_y))
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun #define miFillSliceLower(slice) \
118*4882a593Smuzhiyun 		((y >= slice.min_bot_y) && (y <= slice.max_bot_y))
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun #define MIARCSLICEUPPER(xl,xr,slice,slw) \
121*4882a593Smuzhiyun     xl = xorg - x; \
122*4882a593Smuzhiyun     xr = xl + slw - 1; \
123*4882a593Smuzhiyun     if (slice.edge1_top && (slice.edge1.x < xr)) \
124*4882a593Smuzhiyun 	xr = slice.edge1.x; \
125*4882a593Smuzhiyun     if (slice.edge2_top && (slice.edge2.x > xl)) \
126*4882a593Smuzhiyun 	xl = slice.edge2.x;
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun #define MIARCSLICELOWER(xl,xr,slice,slw) \
129*4882a593Smuzhiyun     xl = xorg - x; \
130*4882a593Smuzhiyun     xr = xl + slw - 1; \
131*4882a593Smuzhiyun     if (!slice.edge1_top && (slice.edge1.x > xl)) \
132*4882a593Smuzhiyun 	xl = slice.edge1.x; \
133*4882a593Smuzhiyun     if (!slice.edge2_top && (slice.edge2.x < xr)) \
134*4882a593Smuzhiyun 	xr = slice.edge2.x;
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun #define MIWIDEARCSETUP(x,y,dy,slw,e,xk,xm,yk,ym) \
137*4882a593Smuzhiyun     x = 0; \
138*4882a593Smuzhiyun     y = slw >> 1; \
139*4882a593Smuzhiyun     yk = y << 3; \
140*4882a593Smuzhiyun     xm = 8; \
141*4882a593Smuzhiyun     ym = 8; \
142*4882a593Smuzhiyun     if (dy) \
143*4882a593Smuzhiyun     { \
144*4882a593Smuzhiyun 	xk = 0; \
145*4882a593Smuzhiyun 	if (slw & 1) \
146*4882a593Smuzhiyun 	    e = -1; \
147*4882a593Smuzhiyun 	else \
148*4882a593Smuzhiyun 	    e = -(y << 2) - 2; \
149*4882a593Smuzhiyun     } \
150*4882a593Smuzhiyun     else \
151*4882a593Smuzhiyun     { \
152*4882a593Smuzhiyun 	y++; \
153*4882a593Smuzhiyun 	yk += 4; \
154*4882a593Smuzhiyun 	xk = -4; \
155*4882a593Smuzhiyun 	if (slw & 1) \
156*4882a593Smuzhiyun 	    e = -(y << 2) - 3; \
157*4882a593Smuzhiyun 	else \
158*4882a593Smuzhiyun 	    e = - (y << 3); \
159*4882a593Smuzhiyun     }
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun #define MIFILLINARCSTEP(slw) \
162*4882a593Smuzhiyun     ine += inyk; \
163*4882a593Smuzhiyun     while (ine >= 0) \
164*4882a593Smuzhiyun     { \
165*4882a593Smuzhiyun 	inx++; \
166*4882a593Smuzhiyun 	inxk -= inxm; \
167*4882a593Smuzhiyun 	ine += inxk; \
168*4882a593Smuzhiyun     } \
169*4882a593Smuzhiyun     iny--; \
170*4882a593Smuzhiyun     inyk -= inym; \
171*4882a593Smuzhiyun     slw = (inx << 1) + dx; \
172*4882a593Smuzhiyun     if ((ine == inxk) && (slw > 1)) \
173*4882a593Smuzhiyun 	slw--
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun #define miFillInArcLower(slw) (((iny + dy) != 0) && \
176*4882a593Smuzhiyun 			       ((slw > 1) || (ine != inxk)))
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun #endif                          /* __MIFILLARC_H__ */
179