]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/mi/mipoly.h
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / programs / Xserver / mi / mipoly.h
1 /* $XConsortium: mipoly.h,v 1.5 94/04/17 20:27:42 dpw Exp $ */
2 /*
3
4 Copyright (c) 1987  X Consortium
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice shall be included
15 in all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 OTHER DEALINGS IN THE SOFTWARE.
24
25 Except as contained in this notice, the name of the X Consortium shall
26 not be used in advertising or otherwise to promote the sale, use or
27 other dealings in this Software without prior written authorization
28 from the X Consortium.
29
30 */
31
32
33 /*
34  *     fill.h
35  *
36  *     Created by Brian Kelleher; Oct 1985
37  *
38  *     Include file for filled polygon routines.
39  *
40  *     These are the data structures needed to scan
41  *     convert regions.  Two different scan conversion
42  *     methods are available -- the even-odd method, and
43  *     the winding number method.
44  *     The even-odd rule states that a point is inside
45  *     the polygon if a ray drawn from that point in any
46  *     direction will pass through an odd number of
47  *     path segments.
48  *     By the winding number rule, a point is decided
49  *     to be inside the polygon if a ray drawn from that
50  *     point in any direction passes through a different
51  *     number of clockwise and counter-clockwise path
52  *     segments.
53  *
54  *     These data structures are adapted somewhat from
55  *     the algorithm in (Foley/Van Dam) for scan converting
56  *     polygons.
57  *     The basic algorithm is to start at the top (smallest y)
58  *     of the polygon, stepping down to the bottom of
59  *     the polygon by incrementing the y coordinate.  We
60  *     keep a list of edges which the current scanline crosses,
61  *     sorted by x.  This list is called the Active Edge Table (AET)
62  *     As we change the y-coordinate, we update each entry in 
63  *     in the active edge table to reflect the edges new xcoord.
64  *     This list must be sorted at each scanline in case
65  *     two edges intersect.
66  *     We also keep a data structure known as the Edge Table (ET),
67  *     which keeps track of all the edges which the current
68  *     scanline has not yet reached.  The ET is basically a
69  *     list of ScanLineList structures containing a list of
70  *     edges which are entered at a given scanline.  There is one
71  *     ScanLineList per scanline at which an edge is entered.
72  *     When we enter a new edge, we move it from the ET to the AET.
73  *
74  *     From the AET, we can implement the even-odd rule as in
75  *     (Foley/Van Dam).
76  *     The winding number rule is a little trickier.  We also
77  *     keep the EdgeTableEntries in the AET linked by the
78  *     nextWETE (winding EdgeTableEntry) link.  This allows
79  *     the edges to be linked just as before for updating
80  *     purposes, but only uses the edges linked by the nextWETE
81  *     link as edges representing spans of the polygon to
82  *     drawn (as with the even-odd rule).
83  */
84
85 /*
86  * for the winding number rule
87  */
88 #define CLOCKWISE          1
89 #define COUNTERCLOCKWISE  -1 
90
91 typedef struct _EdgeTableEntry {
92      int ymax;             /* ycoord at which we exit this edge. */
93      BRESINFO bres;        /* Bresenham info to run the edge     */
94      struct _EdgeTableEntry *next;       /* next in the list     */
95      struct _EdgeTableEntry *back;       /* for insertion sort   */
96      struct _EdgeTableEntry *nextWETE;   /* for winding num rule */
97      int ClockWise;        /* flag for winding number rule       */
98 } EdgeTableEntry;
99
100
101 typedef struct _ScanLineList{
102      int scanline;              /* the scanline represented */
103      EdgeTableEntry *edgelist;  /* header node              */
104      struct _ScanLineList *next;  /* next in the list       */
105 } ScanLineList;
106
107
108 typedef struct {
109      int ymax;                 /* ymax for the polygon     */
110      int ymin;                 /* ymin for the polygon     */
111      ScanLineList scanlines;   /* header node              */
112 } EdgeTable;
113
114
115 /*
116  * Here is a struct to help with storage allocation
117  * so we can allocate a big chunk at a time, and then take
118  * pieces from this heap when we need to.
119  */
120 #define SLLSPERBLOCK 25
121
122 typedef struct _ScanLineListBlock {
123      ScanLineList SLLs[SLLSPERBLOCK];
124      struct _ScanLineListBlock *next;
125 } ScanLineListBlock;
126
127 /*
128  * number of points to buffer before sending them off
129  * to scanlines() :  Must be an even number
130  */
131 #define NUMPTSTOBUFFER 200
132
133 \f
134 /*
135  *
136  *     a few macros for the inner loops of the fill code where
137  *     performance considerations don't allow a procedure call.
138  *
139  *     Evaluate the given edge at the given scanline.
140  *     If the edge has expired, then we leave it and fix up
141  *     the active edge table; otherwise, we increment the
142  *     x value to be ready for the next scanline.
143  *     The winding number rule is in effect, so we must notify
144  *     the caller when the edge has been removed so he
145  *     can reorder the Winding Active Edge Table.
146  */
147 #define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) { \
148    if (pAET->ymax == y) {          /* leaving this edge */ \
149       pPrevAET->next = pAET->next; \
150       pAET = pPrevAET->next; \
151       fixWAET = 1; \
152       if (pAET) \
153          pAET->back = pPrevAET; \
154    } \
155    else { \
156       BRESINCRPGONSTRUCT(pAET->bres); \
157       pPrevAET = pAET; \
158       pAET = pAET->next; \
159    } \
160 }
161
162
163 /*
164  *     Evaluate the given edge at the given scanline.
165  *     If the edge has expired, then we leave it and fix up
166  *     the active edge table; otherwise, we increment the
167  *     x value to be ready for the next scanline.
168  *     The even-odd rule is in effect.
169  */
170 #define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) { \
171    if (pAET->ymax == y) {          /* leaving this edge */ \
172       pPrevAET->next = pAET->next; \
173       pAET = pPrevAET->next; \
174       if (pAET) \
175          pAET->back = pPrevAET; \
176    } \
177    else { \
178       BRESINCRPGONSTRUCT(pAET->bres); \
179       pPrevAET = pAET; \
180       pAET = pAET->next; \
181    } \
182 }
183
184 /* mipolyutil.c */
185
186 extern Bool miInsertEdgeInET(
187 #if NeedFunctionPrototypes
188     EdgeTable * /*ET*/,
189     EdgeTableEntry * /*ETE*/,
190     int /*scanline*/,
191     ScanLineListBlock ** /*SLLBlock*/,
192     int * /*iSLLBlock*/
193 #endif
194 );
195
196 extern Bool miCreateETandAET(
197 #if NeedFunctionPrototypes
198     int /*count*/,
199     DDXPointPtr /*pts*/,
200     EdgeTable * /*ET*/,
201     EdgeTableEntry * /*AET*/,
202     EdgeTableEntry * /*pETEs*/,
203     ScanLineListBlock * /*pSLLBlock*/
204 #endif
205 );
206
207 extern void miloadAET(
208 #if NeedFunctionPrototypes
209     EdgeTableEntry * /*AET*/,
210     EdgeTableEntry * /*ETEs*/
211 #endif
212 );
213
214 extern void micomputeWAET(
215 #if NeedFunctionPrototypes
216     EdgeTableEntry * /*AET*/
217 #endif
218 );
219
220 extern int miInsertionSort(
221 #if NeedFunctionPrototypes
222     EdgeTableEntry * /*AET*/
223 #endif
224 );
225
226 extern void miFreeStorage(
227 #if NeedFunctionPrototypes
228     ScanLineListBlock * /*pSLLBlock*/
229 #endif
230 );