miline.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. Copyright 1994, 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. */
  20. #ifndef MILINE_H
  21. #include "screenint.h"
  22. /*
  23. * Public definitions used for configuring basic pixelization aspects
  24. * of the sample implementation line-drawing routines provided in
  25. * {mfb,mi,cfb*} at run-time.
  26. */
  27. #define XDECREASING 4
  28. #define YDECREASING 2
  29. #define YMAJOR 1
  30. #define OCTANT1 (1 << (YDECREASING))
  31. #define OCTANT2 (1 << (YDECREASING|YMAJOR))
  32. #define OCTANT3 (1 << (XDECREASING|YDECREASING|YMAJOR))
  33. #define OCTANT4 (1 << (XDECREASING|YDECREASING))
  34. #define OCTANT5 (1 << (XDECREASING))
  35. #define OCTANT6 (1 << (XDECREASING|YMAJOR))
  36. #define OCTANT7 (1 << (YMAJOR))
  37. #define OCTANT8 (1 << (0))
  38. #define XMAJOROCTANTS (OCTANT1 | OCTANT4 | OCTANT5 | OCTANT8)
  39. #define DEFAULTZEROLINEBIAS (OCTANT2 | OCTANT3 | OCTANT4 | OCTANT5)
  40. /*
  41. * Devices can configure the rendering of routines in mi, mfb, and cfb*
  42. * by specifying a thin line bias to be applied to a particular screen
  43. * using the following function. The bias parameter is an OR'ing of
  44. * the appropriate OCTANT constants defined above to indicate which
  45. * octants to bias a line to prefer an axial step when the Bresenham
  46. * error term is exactly zero. The octants are mapped as follows:
  47. *
  48. * \ | /
  49. * \ 3 | 2 /
  50. * \ | /
  51. * 4 \ | / 1
  52. * \|/
  53. * -----------
  54. * /|\
  55. * 5 / | \ 8
  56. * / | \
  57. * / 6 | 7 \
  58. * / | \
  59. *
  60. * For more information, see "Ambiguities in Incremental Line Rastering,"
  61. * Jack E. Bresenham, IEEE CG&A, May 1987.
  62. */
  63. extern void miSetZeroLineBias(
  64. ScreenPtr /* pScreen */,
  65. unsigned int /* bias */
  66. );
  67. /*
  68. * Private definitions needed for drawing thin (zero width) lines
  69. * Used by the mi, mfb, and all cfb* components.
  70. */
  71. #define X_AXIS 0
  72. #define Y_AXIS 1
  73. #define OUT_LEFT 0x08
  74. #define OUT_RIGHT 0x04
  75. #define OUT_ABOVE 0x02
  76. #define OUT_BELOW 0x01
  77. #define OUTCODES(_result, _x, _y, _pbox) \
  78. if ( (_x) < (_pbox)->x1) (_result) |= OUT_LEFT; \
  79. else if ( (_x) >= (_pbox)->x2) (_result) |= OUT_RIGHT; \
  80. if ( (_y) < (_pbox)->y1) (_result) |= OUT_ABOVE; \
  81. else if ( (_y) >= (_pbox)->y2) (_result) |= OUT_BELOW;
  82. #define MIOUTCODES(outcode, x, y, xmin, ymin, xmax, ymax) \
  83. {\
  84. if (x < xmin) outcode |= OUT_LEFT;\
  85. if (x > xmax) outcode |= OUT_RIGHT;\
  86. if (y < ymin) outcode |= OUT_ABOVE;\
  87. if (y > ymax) outcode |= OUT_BELOW;\
  88. }
  89. #define SWAPINT(i, j) \
  90. { register int _t = i; i = j; j = _t; }
  91. #define SWAPPT(i, j) \
  92. { DDXPointRec _t; _t = i; i = j; j = _t; }
  93. #define SWAPINT_PAIR(x1, y1, x2, y2)\
  94. { int t = x1; x1 = x2; x2 = t;\
  95. t = y1; y1 = y2; y2 = t;\
  96. }
  97. #define miGetZeroLineBias(_pScreen) \
  98. ((miZeroLineScreenIndex < 0) ? \
  99. 0 : ((_pScreen)->devPrivates[miZeroLineScreenIndex].uval))
  100. #define CalcLineDeltas(_x1,_y1,_x2,_y2,_adx,_ady,_sx,_sy,_SX,_SY,_octant) \
  101. (_octant) = 0; \
  102. (_sx) = (_SX); \
  103. if (((_adx) = (_x2) - (_x1)) < 0) { \
  104. (_adx) = -(_adx); \
  105. (_sx = -(_sx)); \
  106. (_octant) |= XDECREASING; \
  107. } \
  108. (_sy) = (_SY); \
  109. if (((_ady) = (_y2) - (_y1)) < 0) { \
  110. (_ady) = -(_ady); \
  111. (_sy = -(_sy)); \
  112. (_octant) |= YDECREASING; \
  113. }
  114. #define SetYMajorOctant(_octant) ((_octant) |= YMAJOR)
  115. #define FIXUP_ERROR(_e, _octant, _bias) \
  116. (_e) -= (((_bias) >> (_octant)) & 1)
  117. #define IsXMajorOctant(_octant) (!((_octant) & YMAJOR))
  118. #define IsYMajorOctant(_octant) ((_octant) & YMAJOR)
  119. #define IsXDecreasingOctant(_octant) ((_octant) & XDECREASING)
  120. #define IsYDecreasingOctant(_octant) ((_octant) & YDECREASING)
  121. extern int miZeroLineScreenIndex;
  122. extern int miZeroClipLine(
  123. int /*xmin*/,
  124. int /*ymin*/,
  125. int /*xmax*/,
  126. int /*ymax*/,
  127. int * /*new_x1*/,
  128. int * /*new_y1*/,
  129. int * /*new_x2*/,
  130. int * /*new_y2*/,
  131. unsigned int /*adx*/,
  132. unsigned int /*ady*/,
  133. int * /*pt1_clipped*/,
  134. int * /*pt2_clipped*/,
  135. int /*octant*/,
  136. unsigned int /*bias*/,
  137. int /*oc1*/,
  138. int /*oc2*/
  139. );
  140. #endif /* MILINE_H */