a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/*
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncCopyright 1987, 1998 The Open Group
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncPermission to use, copy, modify, distribute, and sell this software and its
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncdocumentation for any purpose is hereby granted without fee, provided that
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncthe above copyright notice appear in all copies and that both that
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynccopyright notice and this permission notice appear in supporting
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncdocumentation.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncThe above copyright notice and this permission notice shall be included
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncin all copies or substantial portions of the Software.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncOTHER DEALINGS IN THE SOFTWARE.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncExcept as contained in this notice, the name of The Open Group shall
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncnot be used in advertising or otherwise to promote the sale, use or
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncother dealings in this Software without prior written authorization
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsyncfrom The Open Group.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync*/
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifdef HAVE_DIX_CONFIG_H
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#include <dix-config.h>
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#ifndef SCANFILLINCLUDED
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define SCANFILLINCLUDED
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/*
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * scanfill.h
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Written by Brian Kelleher; Jan 1985
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * This file contains a few macros to help track
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * the edge of a filled object. The object is assumed
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * to be filled in scanline order, and thus the
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * algorithm used is an extension of Bresenham's line
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * drawing algorithm which assumes that y is always the
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * major axis.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Since these pieces of code are the same for any filled shape,
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * it is more convenient to gather the library in one
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * place, but since these pieces of code are also in
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * the inner loops of output primitives, procedure call
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * overhead is out of the question.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * See the author for a derivation if needed.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/*
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * In scan converting polygons, we want to choose those pixels
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * which are inside the polygon. Thus, we add .5 to the starting
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * x coordinate for both left and right edges. Now we choose the
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * first pixel which is inside the pgon for the left edge and the
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * first pixel which is outside the pgon for the right edge.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * Draw the left pixel, but not the right.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * How to add .5 to the starting x coordinate:
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * If the edge is moving to the right, then subtract dy from the
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * error term from the general form of the algorithm.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * If the edge is moving to the left, then add dy to the error term.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync *
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * The reason for the difference between edges moving to the left
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * and edges moving to the right is simple: If an edge is moving
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * to the right, then we want the algorithm to flip immediately.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * If it is moving to the left, then we don't want it to flip until
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * we traverse an entire pixel.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync int dx; /* local storage */ \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync\
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync /* \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * if the edge is horizontal, then it is ignored \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * and assumed not to be processed. Otherwise, do this stuff. \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */ \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if ((dy) != 0) { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync xStart = (x1); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync dx = (x2) - xStart; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (dx < 0) { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync m = dx / (dy); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync m1 = m - 1; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync incr1 = -2 * dx + 2 * (dy) * m1; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync incr2 = -2 * dx + 2 * (dy) * m; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync d = 2 * m * (dy) - 2 * dx - 2 * (dy); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync } else { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync m = dx / (dy); \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync m1 = m + 1; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync incr1 = 2 * dx - 2 * (dy) * m1; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync incr2 = 2 * dx - 2 * (dy) * m; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync d = -2 * m * (dy) + 2 * dx; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync } \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync } \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (m1 > 0) { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (d > 0) { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync minval += m1; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync d += incr1; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync } \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync else { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync minval += m; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync d += incr2; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync } \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync } else {\
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync if (d >= 0) { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync minval += m1; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync d += incr1; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync } \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync else { \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync minval += m; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync d += incr2; \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync } \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync } \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync}
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync/*
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * This structure contains all of the information needed
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * to run the bresenham algorithm.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * The variables may be hardcoded into the declarations
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * instead of using this structure to make use of
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync * register declarations.
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsynctypedef struct {
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync int minor; /* minor axis */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync int d; /* decision variable */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync int m, m1; /* slope and slope+1 */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync int incr1, incr2; /* error increments */
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync} BRESINFO;
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync BRESINITPGON(dmaj, min1, min2, bres.minor, bres.d, \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync bres.m, bres.m1, bres.incr1, bres.incr2)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#define BRESINCRPGONSTRUCT(bres) \
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync BRESINCRPGON(bres.d, bres.minor, bres.m, bres.m1, bres.incr1, bres.incr2)
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync
a5e7ae69e440f6816420fc99599f044e79e716b6vboxsync#endif