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