105b261ecSmrg/* 205b261ecSmrg 305b261ecSmrgCopyright 1987, 1998 The Open Group 405b261ecSmrg 505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its 605b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that 705b261ecSmrgthe above copyright notice appear in all copies and that both that 805b261ecSmrgcopyright notice and this permission notice appear in supporting 905b261ecSmrgdocumentation. 1005b261ecSmrg 1105b261ecSmrgThe above copyright notice and this permission notice shall be included 1205b261ecSmrgin all copies or substantial portions of the Software. 1305b261ecSmrg 1405b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1505b261ecSmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 1605b261ecSmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 1705b261ecSmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 1805b261ecSmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 1905b261ecSmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2005b261ecSmrgOTHER DEALINGS IN THE SOFTWARE. 2105b261ecSmrg 2205b261ecSmrgExcept as contained in this notice, the name of The Open Group shall 2305b261ecSmrgnot be used in advertising or otherwise to promote the sale, use or 2405b261ecSmrgother dealings in this Software without prior written authorization 2505b261ecSmrgfrom The Open Group. 2605b261ecSmrg 2705b261ecSmrg*/ 2805b261ecSmrg 2905b261ecSmrg#ifdef HAVE_DIX_CONFIG_H 3005b261ecSmrg#include <dix-config.h> 3105b261ecSmrg#endif 3205b261ecSmrg 3305b261ecSmrg#ifndef SCANFILLINCLUDED 3405b261ecSmrg#define SCANFILLINCLUDED 3505b261ecSmrg/* 3605b261ecSmrg * scanfill.h 3705b261ecSmrg * 3805b261ecSmrg * Written by Brian Kelleher; Jan 1985 3905b261ecSmrg * 4005b261ecSmrg * This file contains a few macros to help track 4105b261ecSmrg * the edge of a filled object. The object is assumed 4205b261ecSmrg * to be filled in scanline order, and thus the 4305b261ecSmrg * algorithm used is an extension of Bresenham's line 4405b261ecSmrg * drawing algorithm which assumes that y is always the 4505b261ecSmrg * major axis. 4605b261ecSmrg * Since these pieces of code are the same for any filled shape, 4705b261ecSmrg * it is more convenient to gather the library in one 4805b261ecSmrg * place, but since these pieces of code are also in 4905b261ecSmrg * the inner loops of output primitives, procedure call 5005b261ecSmrg * overhead is out of the question. 5105b261ecSmrg * See the author for a derivation if needed. 5205b261ecSmrg */ 5305b261ecSmrg 5405b261ecSmrg/* 5505b261ecSmrg * In scan converting polygons, we want to choose those pixels 5605b261ecSmrg * which are inside the polygon. Thus, we add .5 to the starting 5705b261ecSmrg * x coordinate for both left and right edges. Now we choose the 5805b261ecSmrg * first pixel which is inside the pgon for the left edge and the 5905b261ecSmrg * first pixel which is outside the pgon for the right edge. 6005b261ecSmrg * Draw the left pixel, but not the right. 6105b261ecSmrg * 6205b261ecSmrg * How to add .5 to the starting x coordinate: 6305b261ecSmrg * If the edge is moving to the right, then subtract dy from the 6405b261ecSmrg * error term from the general form of the algorithm. 6505b261ecSmrg * If the edge is moving to the left, then add dy to the error term. 6605b261ecSmrg * 6705b261ecSmrg * The reason for the difference between edges moving to the left 6805b261ecSmrg * and edges moving to the right is simple: If an edge is moving 6905b261ecSmrg * to the right, then we want the algorithm to flip immediately. 7005b261ecSmrg * If it is moving to the left, then we don't want it to flip until 7105b261ecSmrg * we traverse an entire pixel. 7205b261ecSmrg */ 7305b261ecSmrg#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \ 7405b261ecSmrg int dx; /* local storage */ \ 7505b261ecSmrg\ 7605b261ecSmrg /* \ 7705b261ecSmrg * if the edge is horizontal, then it is ignored \ 7805b261ecSmrg * and assumed not to be processed. Otherwise, do this stuff. \ 7905b261ecSmrg */ \ 8005b261ecSmrg if ((dy) != 0) { \ 8105b261ecSmrg xStart = (x1); \ 8205b261ecSmrg dx = (x2) - xStart; \ 8305b261ecSmrg if (dx < 0) { \ 8405b261ecSmrg m = dx / (dy); \ 8505b261ecSmrg m1 = m - 1; \ 8605b261ecSmrg incr1 = -2 * dx + 2 * (dy) * m1; \ 8705b261ecSmrg incr2 = -2 * dx + 2 * (dy) * m; \ 8805b261ecSmrg d = 2 * m * (dy) - 2 * dx - 2 * (dy); \ 8905b261ecSmrg } else { \ 9005b261ecSmrg m = dx / (dy); \ 9105b261ecSmrg m1 = m + 1; \ 9205b261ecSmrg incr1 = 2 * dx - 2 * (dy) * m1; \ 9305b261ecSmrg incr2 = 2 * dx - 2 * (dy) * m; \ 9405b261ecSmrg d = -2 * m * (dy) + 2 * dx; \ 9505b261ecSmrg } \ 9605b261ecSmrg } \ 9705b261ecSmrg} 9805b261ecSmrg 9905b261ecSmrg#define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \ 10005b261ecSmrg if (m1 > 0) { \ 10105b261ecSmrg if (d > 0) { \ 10205b261ecSmrg minval += m1; \ 10305b261ecSmrg d += incr1; \ 10405b261ecSmrg } \ 10505b261ecSmrg else { \ 10605b261ecSmrg minval += m; \ 10705b261ecSmrg d += incr2; \ 10805b261ecSmrg } \ 10905b261ecSmrg } else {\ 11005b261ecSmrg if (d >= 0) { \ 11105b261ecSmrg minval += m1; \ 11205b261ecSmrg d += incr1; \ 11305b261ecSmrg } \ 11405b261ecSmrg else { \ 11505b261ecSmrg minval += m; \ 11605b261ecSmrg d += incr2; \ 11705b261ecSmrg } \ 11805b261ecSmrg } \ 11905b261ecSmrg} 12005b261ecSmrg 12105b261ecSmrg/* 12205b261ecSmrg * This structure contains all of the information needed 12305b261ecSmrg * to run the bresenham algorithm. 12405b261ecSmrg * The variables may be hardcoded into the declarations 12505b261ecSmrg * instead of using this structure to make use of 12605b261ecSmrg * register declarations. 12705b261ecSmrg */ 12805b261ecSmrgtypedef struct { 12935c4bbdfSmrg int minor; /* minor axis */ 13035c4bbdfSmrg int d; /* decision variable */ 13135c4bbdfSmrg int m, m1; /* slope and slope+1 */ 13235c4bbdfSmrg int incr1, incr2; /* error increments */ 13305b261ecSmrg} BRESINFO; 13405b261ecSmrg 13505b261ecSmrg#define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \ 13605b261ecSmrg BRESINITPGON(dmaj, min1, min2, bres.minor, bres.d, \ 13705b261ecSmrg bres.m, bres.m1, bres.incr1, bres.incr2) 13805b261ecSmrg 13905b261ecSmrg#define BRESINCRPGONSTRUCT(bres) \ 14005b261ecSmrg BRESINCRPGON(bres.d, bres.minor, bres.m, bres.m1, bres.incr1, bres.incr2) 14105b261ecSmrg 14205b261ecSmrg#endif 143