1
/* $TOG: miscanfill.h /main/6 1998/02/09 14:48:35 kaleb $ */
4
Copyright 1987, 1998 The Open Group
8
The above copyright notice and this permission notice shall be included
9
in all copies or substantial portions of the Software.
11
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
15
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
16
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
17
OTHER DEALINGS IN THE SOFTWARE.
19
Except as contained in this notice, the name of The Open Group shall
20
not be used in advertising or otherwise to promote the sale, use or
21
other dealings in this Software without prior written authorization
26
#ifndef SCANFILLINCLUDED
27
#define SCANFILLINCLUDED
31
* Written by Brian Kelleher; Jan 1985
33
* This file contains a few macros to help track
34
* the edge of a filled object. The object is assumed
35
* to be filled in scanline order, and thus the
36
* algorithm used is an extension of Bresenham's line
37
* drawing algorithm which assumes that y is always the
39
* Since these pieces of code are the same for any filled shape,
40
* it is more convenient to gather the library in one
41
* place, but since these pieces of code are also in
42
* the inner loops of output primitives, procedure call
43
* overhead is out of the question.
44
* See the author for a derivation if needed.
49
* In scan converting polygons, we want to choose those pixels
50
* which are inside the polygon. Thus, we add .5 to the starting
51
* x coordinate for both left and right edges. Now we choose the
52
* first pixel which is inside the pgon for the left edge and the
53
* first pixel which is outside the pgon for the right edge.
54
* Draw the left pixel, but not the right.
56
* How to add .5 to the starting x coordinate:
57
* If the edge is moving to the right, then subtract dy from the
58
* error term from the general form of the algorithm.
59
* If the edge is moving to the left, then add dy to the error term.
61
* The reason for the difference between edges moving to the left
62
* and edges moving to the right is simple: If an edge is moving
63
* to the right, then we want the algorithm to flip immediately.
64
* If it is moving to the left, then we don't want it to flip until
65
* we traverse an entire pixel.
67
#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \
68
int dx; /* local storage */ \
71
* if the edge is horizontal, then it is ignored \
72
* and assumed not to be processed. Otherwise, do this stuff. \
80
incr1 = -2 * dx + 2 * (dy) * m1; \
81
incr2 = -2 * dx + 2 * (dy) * m; \
82
d = 2 * m * (dy) - 2 * dx - 2 * (dy); \
86
incr1 = 2 * dx - 2 * (dy) * m1; \
87
incr2 = 2 * dx - 2 * (dy) * m; \
88
d = -2 * m * (dy) + 2 * dx; \
93
#define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \
117
* This structure contains all of the information needed
118
* to run the bresenham algorithm.
119
* The variables may be hardcoded into the declarations
120
* instead of using this structure to make use of
121
* register declarations.
124
int minor; /* minor axis */
125
int d; /* decision variable */
126
int m, m1; /* slope and slope+1 */
127
int incr1, incr2; /* error increments */
131
#define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \
132
BRESINITPGON(dmaj, min1, min2, bres.minor, bres.d, \
133
bres.m, bres.m1, bres.incr1, bres.incr2)
135
#define BRESINCRPGONSTRUCT(bres) \
136
BRESINCRPGON(bres.d, bres.minor, bres.m, bres.m1, bres.incr1, bres.incr2)