Annotation of researchv9/X11/src/X.V11R1/server/ddx/mi/miscanfill.h, revision 1.1

1.1     ! root        1: /* $Header: miscanfill.h,v 1.1 87/09/11 07:20:22 toddb Exp $ */
        !             2: #ifndef SCANFILLINCLUDED
        !             3: #define SCANFILLINCLUDED
        !             4: /*
        !             5:  *     scanfill.h
        !             6:  *
        !             7:  *     Written by Brian Kelleher; Jan 1985
        !             8:  *
        !             9:  *     This file contains a few macros to help track
        !            10:  *     the edge of a filled object.  The object is assumed
        !            11:  *     to be filled in scanline order, and thus the
        !            12:  *     algorithm used is an extension of Bresenham's line
        !            13:  *     drawing algorithm which assumes that y is always the
        !            14:  *     major axis.
        !            15:  *     Since these pieces of code are the same for any filled shape,
        !            16:  *     it is more convenient to gather the library in one
        !            17:  *     place, but since these pieces of code are also in
        !            18:  *     the inner loops of output primitives, procedure call
        !            19:  *     overhead is out of the question.
        !            20:  *     See the author for a derivation if needed.
        !            21:  */
        !            22: 
        !            23: 
        !            24: /*
        !            25:  *  In scan converting polygons, we want to choose those pixels
        !            26:  *  which are inside the polygon.  Thus, we add .5 to the starting
        !            27:  *  x coordinate for both left and right edges.  Now we choose the
        !            28:  *  first pixel which is inside the pgon for the left edge and the
        !            29:  *  first pixel which is outside the pgon for the right edge.
        !            30:  *  Draw the left pixel, but not the right.
        !            31:  *
        !            32:  *  How to add .5 to the starting x coordinate:
        !            33:  *      If the edge is moving to the right, then subtract dy from the
        !            34:  *  error term from the general form of the algorithm.
        !            35:  *      If the edge is moving to the left, then add dy to the error term.
        !            36:  *
        !            37:  *  The reason for the difference between edges moving to the left
        !            38:  *  and edges moving to the right is simple:  If an edge is moving
        !            39:  *  to the right, then we want the algorithm to flip immediately.
        !            40:  *  If it is moving to the left, then we don't want it to flip until
        !            41:  *  we traverse an entire pixel.
        !            42:  */
        !            43: #define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \
        !            44:     int dx;      /* local storage */ \
        !            45: \
        !            46:     /* \
        !            47:      *  if the edge is horizontal, then it is ignored \
        !            48:      *  and assumed not to be processed.  Otherwise, do this stuff. \
        !            49:      */ \
        !            50:     if ((dy) != 0) { \
        !            51:         xStart = (x1); \
        !            52:         dx = (x2) - xStart; \
        !            53:         if (dx < 0) { \
        !            54:             m = dx / (dy); \
        !            55:             m1 = m - 1; \
        !            56:             incr1 = -2 * dx + 2 * (dy) * m1; \
        !            57:             incr2 = -2 * dx + 2 * (dy) * m; \
        !            58:             d = 2 * m * (dy) - 2 * dx - 2 * (dy); \
        !            59:         } else { \
        !            60:             m = dx / (dy); \
        !            61:             m1 = m + 1; \
        !            62:             incr1 = 2 * dx - 2 * (dy) * m1; \
        !            63:             incr2 = 2 * dx - 2 * (dy) * m; \
        !            64:             d = -2 * m * (dy) + 2 * dx; \
        !            65:         } \
        !            66:     } \
        !            67: }
        !            68: 
        !            69: #define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \
        !            70:     if (m1 > 0) { \
        !            71:         if (d > 0) { \
        !            72:             minval += m1; \
        !            73:             d += incr1; \
        !            74:         } \
        !            75:         else { \
        !            76:             minval += m; \
        !            77:             d += incr2; \
        !            78:         } \
        !            79:     } else {\
        !            80:         if (d >= 0) { \
        !            81:             minval += m1; \
        !            82:             d += incr1; \
        !            83:         } \
        !            84:         else { \
        !            85:             minval += m; \
        !            86:             d += incr2; \
        !            87:         } \
        !            88:     } \
        !            89: }
        !            90: 
        !            91: 
        !            92: /*
        !            93:  *     This structure contains all of the information needed
        !            94:  *     to run the bresenham algorithm.
        !            95:  *     The variables may be hardcoded into the declarations
        !            96:  *     instead of using this structure to make use of
        !            97:  *     register declarations.
        !            98:  */
        !            99: typedef struct {
        !           100:     int minor;         /* minor axis        */
        !           101:     int d;           /* decision variable */
        !           102:     int m, m1;       /* slope and slope+1 */
        !           103:     int incr1, incr2; /* error increments */
        !           104: } BRESINFO;
        !           105: 
        !           106: 
        !           107: #define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \
        !           108:        BRESINITPGON(dmaj, min1, min2, bres.minor, bres.d, \
        !           109:                      bres.m, bres.m1, bres.incr1, bres.incr2)
        !           110: 
        !           111: #define BRESINCRPGONSTRUCT(bres) \
        !           112:         BRESINCRPGON(bres.d, bres.minor, bres.m, bres.m1, bres.incr1, bres.incr2)
        !           113: 
        !           114: 
        !           115: #endif SCANFILLINCLUDED

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.