1 /***********************************************************
3 Copyright (c) 1987 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.
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47 ******************************************************************/
48 /* $XConsortium: mipolygen.c,v 5.2 94/04/17 20:27:43 dpw Exp $ */
51 #include "miscanfill.h"
57 * Written by Brian Kelleher; Oct. 1985
59 * Routine to fill a polygon. Two fill rules are
60 * supported: frWINDING and frEVENODD.
62 * See fillpoly.h for a complete description of the algorithm.
66 miFillGeneralPoly(dst, pgc, count, ptsIn)
69 int count; /* number of points */
70 DDXPointPtr ptsIn; /* the points */
72 register EdgeTableEntry *pAET; /* the Active Edge Table */
73 register int y; /* the current scanline */
74 register int nPts = 0; /* number of pts in buffer */
75 register EdgeTableEntry *pWETE; /* Winding Edge Table */
76 register ScanLineList *pSLL; /* Current ScanLineList */
77 register DDXPointPtr ptsOut; /* ptr to output buffers */
79 DDXPointRec FirstPoint[NUMPTSTOBUFFER]; /* the output buffers */
80 int FirstWidth[NUMPTSTOBUFFER];
81 EdgeTableEntry *pPrevAET; /* previous AET entry */
82 EdgeTable ET; /* Edge Table header node */
83 EdgeTableEntry AET; /* Active ET header node */
84 EdgeTableEntry *pETEs; /* Edge Table Entries buff */
85 ScanLineListBlock SLLBlock; /* header for ScanLineList */
91 if(!(pETEs = (EdgeTableEntry *)
92 ALLOCATE_LOCAL(sizeof(EdgeTableEntry) * count)))
96 if (!miCreateETandAET(count, ptsIn, &ET, &AET, pETEs, &SLLBlock))
98 DEALLOCATE_LOCAL(pETEs);
101 pSLL = ET.scanlines.next;
103 if (pgc->fillRule == EvenOddRule)
108 for (y = ET.ymin; y < ET.ymax; y++)
111 * Add a new edge to the active edge table when we
112 * get to the next edge.
114 if (pSLL && y == pSLL->scanline)
116 miloadAET(&AET, pSLL->edgelist);
123 * for each active edge
127 ptsOut->x = pAET->bres.minor;
129 *width++ = pAET->next->bres.minor - pAET->bres.minor;
133 * send out the buffer when its full
135 if (nPts == NUMPTSTOBUFFER)
137 (*pgc->ops->FillSpans)(dst, pgc,
138 nPts, FirstPoint, FirstWidth,
144 EVALUATEEDGEEVENODD(pAET, pPrevAET, y)
145 EVALUATEEDGEEVENODD(pAET, pPrevAET, y);
147 miInsertionSort(&AET);
150 else /* default to WindingNumber */
155 for (y = ET.ymin; y < ET.ymax; y++)
158 * Add a new edge to the active edge table when we
159 * get to the next edge.
161 if (pSLL && y == pSLL->scanline)
163 miloadAET(&AET, pSLL->edgelist);
172 * for each active edge
177 * if the next edge in the active edge table is
178 * also the next edge in the winding active edge
183 ptsOut->x = pAET->bres.minor;
185 *width++ = pAET->nextWETE->bres.minor - pAET->bres.minor;
189 * send out the buffer
191 if (nPts == NUMPTSTOBUFFER)
193 (*pgc->ops->FillSpans)(dst, pgc, nPts, FirstPoint,
200 pWETE = pWETE->nextWETE;
201 while (pWETE != pAET)
202 EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET);
203 pWETE = pWETE->nextWETE;
205 EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET);
209 * reevaluate the Winding active edge table if we
210 * just had to resort it or if we just exited an edge.
212 if (miInsertionSort(&AET) || fixWAET)
221 * Get any spans that we missed by buffering
223 (*pgc->ops->FillSpans)(dst, pgc, nPts, FirstPoint, FirstWidth, 1);
224 DEALLOCATE_LOCAL(pETEs);
225 miFreeStorage(SLLBlock.next);