mi_spans.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* This file is part of the GNU libxmi package.
  2. Copyright (C) 1985, 1986, 1987, 1988, 1989, X Consortium. For an
  3. associated permission notice, see the accompanying file README-X.
  4. GNU enhancements Copyright (C) 1998, 1999, 2000, 2005, Free Software
  5. Foundation, Inc.
  6. The GNU libxmi package is free software. You may redistribute it
  7. and/or modify it under the terms of the GNU General Public License as
  8. published by the Free Software foundation; either version 2, or (at your
  9. option) any later version.
  10. The GNU libxmi package is distributed in the hope that it will be
  11. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. General Public License for more details.
  14. You should have received a copy of the GNU General Public License along
  15. with the GNU plotutils package; see the file COPYING. If not, write to
  16. the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
  17. Boston, MA 02110-1301, USA. */
  18. /* This is the public include file for the miPaintedSet module, contained
  19. in mi_spans.c. */
  20. /* A Spans structure is a sorted list of spans, i.e. a list of point ranges
  21. [xmin,xmax], sorted in increasing y order. There may be more than one
  22. span at a given y. */
  23. typedef struct
  24. {
  25. int count; /* number of spans */
  26. miPoint *points; /* pointer to list of start points */
  27. unsigned int *widths; /* pointer to list of widths */
  28. } Spans;
  29. /* A SpanGroup is an unsorted list of Spans's, associated with a particular
  30. pixel value.
  31. A SpanGroup is allowed to include more than a single Spans because most
  32. libxmi drawing functions write out multiple Spans's. */
  33. typedef struct
  34. {
  35. miPixel pixel; /* pixel value */
  36. Spans *group; /* Spans slots */
  37. int size; /* number of Spans slots allocated */
  38. int count; /* number of Spans slots filled */
  39. int ymin, ymax; /* min, max y values over all Spans's */
  40. } SpanGroup;
  41. /* A miPaintedSet structure is an array of SpanGroups, specifying the
  42. partition into differently painted subsets. There is at most one
  43. SpanGroup for any pixel. */
  44. typedef struct lib_miPaintedSet
  45. {
  46. SpanGroup **groups; /* SpanGroup slots */
  47. int size; /* number of SpanGroup slots allocated */
  48. int ngroups; /* number of SpanGroup slots filled */
  49. } _miPaintedSet;
  50. /* libxmi's low-level painting macro. It `paints' a Spans, i.e. a list of
  51. spans assumed to be in y-increasing order, to a miPaintedSet with a
  52. specified pixel value. To do this, it invokes the lower-level function
  53. miAddSpansToPaintedSet() in mi_spans.c.
  54. The passed point and width arrays should have been allocated on the
  55. heap, since they will be eventually freed; e.g., when the miPaintedSet
  56. is cleared or deallocated. */
  57. #define MI_PAINT_SPANS(paintedSet, pixel, numSpans, ppts, pwidths) \
  58. {\
  59. Spans spanRec;\
  60. if (numSpans > 0) \
  61. { \
  62. spanRec.points = (ppts);\
  63. spanRec.widths = (pwidths);\
  64. spanRec.count = (numSpans);\
  65. miAddSpansToPaintedSet (&spanRec, (paintedSet), (pixel));\
  66. } \
  67. else \
  68. { \
  69. free (ppts); \
  70. free (pwidths); \
  71. } \
  72. }
  73. /* A wrapper for MI_PAINT_SPANS() that can be applied to a span array
  74. (i.e. to a point and width array) that can't be freed, so must be
  75. copied. We try not to use this. */
  76. #define MI_COPY_AND_PAINT_SPANS(paintedSet, pixel, nPts, FirstPoint, FirstWidth) \
  77. {\
  78. if ((nPts) > 0) \
  79. { \
  80. miPoint *ppt, *pptInit, *oldppt; \
  81. unsigned int *pwidth, *pwidthInit, *oldpwidth; \
  82. int ptsCounter; \
  83. ppt = pptInit = (miPoint *) mi_xmalloc ((nPts) * sizeof (miPoint));\
  84. pwidth = pwidthInit = (unsigned int *) mi_xmalloc ((nPts) * sizeof (unsigned int));\
  85. oldppt = FirstPoint;\
  86. oldpwidth = FirstWidth;\
  87. for (ptsCounter = (nPts); --ptsCounter >= 0; )\
  88. {\
  89. *ppt++ = *oldppt++;\
  90. *pwidth++ = *oldpwidth++;\
  91. }\
  92. MI_PAINT_SPANS(paintedSet, pixel, (nPts), pptInit, pwidthInit)\
  93. } \
  94. }
  95. /* miPaintedSet manipulation routines (other than public) */
  96. extern void miAddSpansToPaintedSet (const Spans *spans, miPaintedSet *paintedSet, miPixel pixel);
  97. extern void miQuickSortSpansY (miPoint *points, unsigned int *widths, int numSpans);
  98. extern void miUniquifyPaintedSet (miPaintedSet *paintedSet);