miscanfill.h revision 05b261ec
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 3005b261ecSmrg#ifdef HAVE_DIX_CONFIG_H 3105b261ecSmrg#include <dix-config.h> 3205b261ecSmrg#endif 3305b261ecSmrg 3405b261ecSmrg#ifndef SCANFILLINCLUDED 3505b261ecSmrg#define SCANFILLINCLUDED 3605b261ecSmrg/* 3705b261ecSmrg * scanfill.h 3805b261ecSmrg * 3905b261ecSmrg * Written by Brian Kelleher; Jan 1985 4005b261ecSmrg * 4105b261ecSmrg * This file contains a few macros to help track 4205b261ecSmrg * the edge of a filled object. The object is assumed 4305b261ecSmrg * to be filled in scanline order, and thus the 4405b261ecSmrg * algorithm used is an extension of Bresenham's line 4505b261ecSmrg * drawing algorithm which assumes that y is always the 4605b261ecSmrg * major axis. 4705b261ecSmrg * Since these pieces of code are the same for any filled shape, 4805b261ecSmrg * it is more convenient to gather the library in one 4905b261ecSmrg * place, but since these pieces of code are also in 5005b261ecSmrg * the inner loops of output primitives, procedure call 5105b261ecSmrg * overhead is out of the question. 5205b261ecSmrg * See the author for a derivation if needed. 5305b261ecSmrg */ 5405b261ecSmrg 5505b261ecSmrg 5605b261ecSmrg/* 5705b261ecSmrg * In scan converting polygons, we want to choose those pixels 5805b261ecSmrg * which are inside the polygon. Thus, we add .5 to the starting 5905b261ecSmrg * x coordinate for both left and right edges. Now we choose the 6005b261ecSmrg * first pixel which is inside the pgon for the left edge and the 6105b261ecSmrg * first pixel which is outside the pgon for the right edge. 6205b261ecSmrg * Draw the left pixel, but not the right. 6305b261ecSmrg * 6405b261ecSmrg * How to add .5 to the starting x coordinate: 6505b261ecSmrg * If the edge is moving to the right, then subtract dy from the 6605b261ecSmrg * error term from the general form of the algorithm. 6705b261ecSmrg * If the edge is moving to the left, then add dy to the error term. 6805b261ecSmrg * 6905b261ecSmrg * The reason for the difference between edges moving to the left 7005b261ecSmrg * and edges moving to the right is simple: If an edge is moving 7105b261ecSmrg * to the right, then we want the algorithm to flip immediately. 7205b261ecSmrg * If it is moving to the left, then we don't want it to flip until 7305b261ecSmrg * we traverse an entire pixel. 7405b261ecSmrg */ 7505b261ecSmrg#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \ 7605b261ecSmrg int dx; /* local storage */ \ 7705b261ecSmrg\ 7805b261ecSmrg /* \ 7905b261ecSmrg * if the edge is horizontal, then it is ignored \ 8005b261ecSmrg * and assumed not to be processed. Otherwise, do this stuff. \ 8105b261ecSmrg */ \ 8205b261ecSmrg if ((dy) != 0) { \ 8305b261ecSmrg xStart = (x1); \ 8405b261ecSmrg dx = (x2) - xStart; \ 8505b261ecSmrg if (dx < 0) { \ 8605b261ecSmrg m = dx / (dy); \ 8705b261ecSmrg m1 = m - 1; \ 8805b261ecSmrg incr1 = -2 * dx + 2 * (dy) * m1; \ 8905b261ecSmrg incr2 = -2 * dx + 2 * (dy) * m; \ 9005b261ecSmrg d = 2 * m * (dy) - 2 * dx - 2 * (dy); \ 9105b261ecSmrg } else { \ 9205b261ecSmrg m = dx / (dy); \ 9305b261ecSmrg m1 = m + 1; \ 9405b261ecSmrg incr1 = 2 * dx - 2 * (dy) * m1; \ 9505b261ecSmrg incr2 = 2 * dx - 2 * (dy) * m; \ 9605b261ecSmrg d = -2 * m * (dy) + 2 * dx; \ 9705b261ecSmrg } \ 9805b261ecSmrg } \ 9905b261ecSmrg} 10005b261ecSmrg 10105b261ecSmrg#define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \ 10205b261ecSmrg if (m1 > 0) { \ 10305b261ecSmrg if (d > 0) { \ 10405b261ecSmrg minval += m1; \ 10505b261ecSmrg d += incr1; \ 10605b261ecSmrg } \ 10705b261ecSmrg else { \ 10805b261ecSmrg minval += m; \ 10905b261ecSmrg d += incr2; \ 11005b261ecSmrg } \ 11105b261ecSmrg } else {\ 11205b261ecSmrg if (d >= 0) { \ 11305b261ecSmrg minval += m1; \ 11405b261ecSmrg d += incr1; \ 11505b261ecSmrg } \ 11605b261ecSmrg else { \ 11705b261ecSmrg minval += m; \ 11805b261ecSmrg d += incr2; \ 11905b261ecSmrg } \ 12005b261ecSmrg } \ 12105b261ecSmrg} 12205b261ecSmrg 12305b261ecSmrg 12405b261ecSmrg/* 12505b261ecSmrg * This structure contains all of the information needed 12605b261ecSmrg * to run the bresenham algorithm. 12705b261ecSmrg * The variables may be hardcoded into the declarations 12805b261ecSmrg * instead of using this structure to make use of 12905b261ecSmrg * register declarations. 13005b261ecSmrg */ 13105b261ecSmrgtypedef struct { 13205b261ecSmrg int minor; /* minor axis */ 13305b261ecSmrg int d; /* decision variable */ 13405b261ecSmrg int m, m1; /* slope and slope+1 */ 13505b261ecSmrg int incr1, incr2; /* error increments */ 13605b261ecSmrg} BRESINFO; 13705b261ecSmrg 13805b261ecSmrg 13905b261ecSmrg#define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \ 14005b261ecSmrg BRESINITPGON(dmaj, min1, min2, bres.minor, bres.d, \ 14105b261ecSmrg bres.m, bres.m1, bres.incr1, bres.incr2) 14205b261ecSmrg 14305b261ecSmrg#define BRESINCRPGONSTRUCT(bres) \ 14405b261ecSmrg BRESINCRPGON(bres.d, bres.minor, bres.m, bres.m1, bres.incr1, bres.incr2) 14505b261ecSmrg 14605b261ecSmrg 14705b261ecSmrg#endif 148