You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

region.h 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* $Xorg: region.h,v 1.4 2001/02/09 02:03:40 xorgcvs Exp $ */
  2. /************************************************************************
  3. Copyright 1987, 1998 The Open Group
  4. Permission to use, copy, modify, distribute, and sell this software and its
  5. documentation for any purpose is hereby granted without fee, provided that
  6. the above copyright notice appear in all copies and that both that
  7. copyright notice and this permission notice appear in supporting
  8. documentation.
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  15. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  16. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. Except as contained in this notice, the name of The Open Group shall not be
  18. used in advertising or otherwise to promote the sale, use or other dealings
  19. in this Software without prior written authorization from The Open Group.
  20. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  21. All Rights Reserved
  22. Permission to use, copy, modify, and distribute this software and its
  23. documentation for any purpose and without fee is hereby granted,
  24. provided that the above copyright notice appear in all copies and that
  25. both that copyright notice and this permission notice appear in
  26. supporting documentation, and that the name of Digital not be
  27. used in advertising or publicity pertaining to distribution of the
  28. software without specific, written prior permission.
  29. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  30. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  31. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  32. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  33. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  34. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  35. SOFTWARE.
  36. ************************************************************************/
  37. #ifndef _XREGION_H
  38. #define _XREGION_H
  39. typedef struct {
  40. short x1, x2, y1, y2;
  41. } Box, BOX, BoxRec, *BoxPtr;
  42. typedef struct {
  43. short x, y, width, height;
  44. }RECTANGLE, RectangleRec, *RectanglePtr;
  45. #define TRUE 1
  46. #define FALSE 0
  47. #define MAXSHORT 32767
  48. #define MINSHORT -MAXSHORT
  49. #ifndef MAX
  50. #define MAX(a,b) (((a) > (b)) ? (a) : (b))
  51. #endif
  52. #ifndef MIN
  53. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  54. #endif
  55. /*
  56. * clip region
  57. */
  58. typedef struct _XRegion {
  59. long size;
  60. long numRects;
  61. BOX *rects;
  62. BOX extents;
  63. } REGION;
  64. /* Xutil.h contains the declaration:
  65. * typedef struct _XRegion *Region;
  66. */
  67. /* 1 if two BOXs overlap.
  68. * 0 if two BOXs do not overlap.
  69. * Remember, x2 and y2 are not in the region
  70. */
  71. #define EXTENTCHECK(r1, r2) \
  72. ((r1)->x2 > (r2)->x1 && \
  73. (r1)->x1 < (r2)->x2 && \
  74. (r1)->y2 > (r2)->y1 && \
  75. (r1)->y1 < (r2)->y2)
  76. /*
  77. * update region extents
  78. */
  79. #define EXTENTS(r,idRect){\
  80. if((r)->x1 < (idRect)->extents.x1)\
  81. (idRect)->extents.x1 = (r)->x1;\
  82. if((r)->y1 < (idRect)->extents.y1)\
  83. (idRect)->extents.y1 = (r)->y1;\
  84. if((r)->x2 > (idRect)->extents.x2)\
  85. (idRect)->extents.x2 = (r)->x2;\
  86. if((r)->y2 > (idRect)->extents.y2)\
  87. (idRect)->extents.y2 = (r)->y2;\
  88. }
  89. /*
  90. * Check to see if there is enough memory in the present region.
  91. */
  92. #define MEMCHECK(reg, rect, firstrect){\
  93. if ((reg)->numRects >= ((reg)->size - 1)){\
  94. (firstrect) = (BOX *) Xrealloc \
  95. ((char *)(firstrect), (unsigned) (2 * (sizeof(BOX)) * ((reg)->size)));\
  96. if ((firstrect) == 0)\
  97. return(0);\
  98. (reg)->size *= 2;\
  99. (rect) = &(firstrect)[(reg)->numRects];\
  100. }\
  101. }
  102. /* this routine checks to see if the previous rectangle is the same
  103. * or subsumes the new rectangle to add.
  104. */
  105. #define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\
  106. (!(((Reg)->numRects > 0)&&\
  107. ((R-1)->y1 == (Ry1)) &&\
  108. ((R-1)->y2 == (Ry2)) &&\
  109. ((R-1)->x1 <= (Rx1)) &&\
  110. ((R-1)->x2 >= (Rx2))))
  111. /* add a rectangle to the given Region */
  112. #define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\
  113. if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\
  114. CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
  115. (r)->x1 = (rx1);\
  116. (r)->y1 = (ry1);\
  117. (r)->x2 = (rx2);\
  118. (r)->y2 = (ry2);\
  119. EXTENTS((r), (reg));\
  120. (reg)->numRects++;\
  121. (r)++;\
  122. }\
  123. }
  124. /* add a rectangle to the given Region */
  125. #define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\
  126. if ((rx1 < rx2) && (ry1 < ry2) &&\
  127. CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
  128. (r)->x1 = (rx1);\
  129. (r)->y1 = (ry1);\
  130. (r)->x2 = (rx2);\
  131. (r)->y2 = (ry2);\
  132. (reg)->numRects++;\
  133. (r)++;\
  134. }\
  135. }
  136. #define EMPTY_REGION(pReg) pReg->numRects = 0
  137. #define REGION_NOT_EMPTY(pReg) pReg->numRects
  138. #define INBOX(r, x, y) \
  139. ( ( ((r).x2 > x)) && \
  140. ( ((r).x1 <= x)) && \
  141. ( ((r).y2 > y)) && \
  142. ( ((r).y1 <= y)) )
  143. /*
  144. * number of points to buffer before sending them off
  145. * to scanlines() : Must be an even number
  146. */
  147. #define NUMPTSTOBUFFER 200
  148. /*
  149. * used to allocate buffers for points and link
  150. * the buffers together
  151. */
  152. typedef struct _POINTBLOCK {
  153. XPoint pts[NUMPTSTOBUFFER];
  154. struct _POINTBLOCK *next;
  155. } POINTBLOCK;
  156. #endif