mipolygen.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /***********************************************************
  2. Copyright 1987, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  20. All Rights Reserved
  21. Permission to use, copy, modify, and distribute this software and its
  22. documentation for any purpose and without fee is hereby granted,
  23. provided that the above copyright notice appear in all copies and that
  24. both that copyright notice and this permission notice appear in
  25. supporting documentation, and that the name of Digital not be
  26. used in advertising or publicity pertaining to distribution of the
  27. software without specific, written prior permission.
  28. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  29. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  30. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  31. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  32. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  33. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  34. SOFTWARE.
  35. ******************************************************************/
  36. #ifdef HAVE_DIX_CONFIG_H
  37. #include <dix-config.h>
  38. #endif
  39. #include <X11/X.h>
  40. #include "gcstruct.h"
  41. #include "miscanfill.h"
  42. #include "mipoly.h"
  43. #include "pixmap.h"
  44. #include "mi.h"
  45. /*
  46. *
  47. * Written by Brian Kelleher; Oct. 1985
  48. *
  49. * Routine to fill a polygon. Two fill rules are
  50. * supported: frWINDING and frEVENODD.
  51. *
  52. * See fillpoly.h for a complete description of the algorithm.
  53. */
  54. Bool
  55. miFillGeneralPoly(dst, pgc, count, ptsIn)
  56. DrawablePtr dst;
  57. GCPtr pgc;
  58. int count; /* number of points */
  59. DDXPointPtr ptsIn; /* the points */
  60. {
  61. EdgeTableEntry *pAET; /* the Active Edge Table */
  62. int y; /* the current scanline */
  63. int nPts = 0; /* number of pts in buffer */
  64. EdgeTableEntry *pWETE; /* Winding Edge Table */
  65. ScanLineList *pSLL; /* Current ScanLineList */
  66. DDXPointPtr ptsOut; /* ptr to output buffers */
  67. int *width;
  68. DDXPointRec FirstPoint[NUMPTSTOBUFFER]; /* the output buffers */
  69. int FirstWidth[NUMPTSTOBUFFER];
  70. EdgeTableEntry *pPrevAET; /* previous AET entry */
  71. EdgeTable ET; /* Edge Table header node */
  72. EdgeTableEntry AET; /* Active ET header node */
  73. EdgeTableEntry *pETEs; /* Edge Table Entries buff */
  74. ScanLineListBlock SLLBlock; /* header for ScanLineList */
  75. int fixWAET = 0;
  76. if (count < 3)
  77. return(TRUE);
  78. if(!(pETEs = (EdgeTableEntry *)
  79. ALLOCATE_LOCAL(sizeof(EdgeTableEntry) * count)))
  80. return(FALSE);
  81. ptsOut = FirstPoint;
  82. width = FirstWidth;
  83. if (!miCreateETandAET(count, ptsIn, &ET, &AET, pETEs, &SLLBlock))
  84. {
  85. DEALLOCATE_LOCAL(pETEs);
  86. return(FALSE);
  87. }
  88. pSLL = ET.scanlines.next;
  89. if (pgc->fillRule == EvenOddRule)
  90. {
  91. /*
  92. * for each scanline
  93. */
  94. for (y = ET.ymin; y < ET.ymax; y++)
  95. {
  96. /*
  97. * Add a new edge to the active edge table when we
  98. * get to the next edge.
  99. */
  100. if (pSLL && y == pSLL->scanline)
  101. {
  102. miloadAET(&AET, pSLL->edgelist);
  103. pSLL = pSLL->next;
  104. }
  105. pPrevAET = &AET;
  106. pAET = AET.next;
  107. /*
  108. * for each active edge
  109. */
  110. while (pAET)
  111. {
  112. ptsOut->x = pAET->bres.minor;
  113. ptsOut++->y = y;
  114. *width++ = pAET->next->bres.minor - pAET->bres.minor;
  115. nPts++;
  116. /*
  117. * send out the buffer when its full
  118. */
  119. if (nPts == NUMPTSTOBUFFER)
  120. {
  121. (*pgc->ops->FillSpans)(dst, pgc,
  122. nPts, FirstPoint, FirstWidth,
  123. 1);
  124. ptsOut = FirstPoint;
  125. width = FirstWidth;
  126. nPts = 0;
  127. }
  128. EVALUATEEDGEEVENODD(pAET, pPrevAET, y)
  129. EVALUATEEDGEEVENODD(pAET, pPrevAET, y);
  130. }
  131. miInsertionSort(&AET);
  132. }
  133. }
  134. else /* default to WindingNumber */
  135. {
  136. /*
  137. * for each scanline
  138. */
  139. for (y = ET.ymin; y < ET.ymax; y++)
  140. {
  141. /*
  142. * Add a new edge to the active edge table when we
  143. * get to the next edge.
  144. */
  145. if (pSLL && y == pSLL->scanline)
  146. {
  147. miloadAET(&AET, pSLL->edgelist);
  148. micomputeWAET(&AET);
  149. pSLL = pSLL->next;
  150. }
  151. pPrevAET = &AET;
  152. pAET = AET.next;
  153. pWETE = pAET;
  154. /*
  155. * for each active edge
  156. */
  157. while (pAET)
  158. {
  159. /*
  160. * if the next edge in the active edge table is
  161. * also the next edge in the winding active edge
  162. * table.
  163. */
  164. if (pWETE == pAET)
  165. {
  166. ptsOut->x = pAET->bres.minor;
  167. ptsOut++->y = y;
  168. *width++ = pAET->nextWETE->bres.minor - pAET->bres.minor;
  169. nPts++;
  170. /*
  171. * send out the buffer
  172. */
  173. if (nPts == NUMPTSTOBUFFER)
  174. {
  175. (*pgc->ops->FillSpans)(dst, pgc, nPts, FirstPoint,
  176. FirstWidth, 1);
  177. ptsOut = FirstPoint;
  178. width = FirstWidth;
  179. nPts = 0;
  180. }
  181. pWETE = pWETE->nextWETE;
  182. while (pWETE != pAET)
  183. EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET);
  184. pWETE = pWETE->nextWETE;
  185. }
  186. EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET);
  187. }
  188. /*
  189. * reevaluate the Winding active edge table if we
  190. * just had to resort it or if we just exited an edge.
  191. */
  192. if (miInsertionSort(&AET) || fixWAET)
  193. {
  194. micomputeWAET(&AET);
  195. fixWAET = 0;
  196. }
  197. }
  198. }
  199. /*
  200. * Get any spans that we missed by buffering
  201. */
  202. (*pgc->ops->FillSpans)(dst, pgc, nPts, FirstPoint, FirstWidth, 1);
  203. DEALLOCATE_LOCAL(pETEs);
  204. miFreeStorage(SLLBlock.next);
  205. return(TRUE);
  206. }