1706f2543Smrg/* 2706f2543Smrg 3706f2543SmrgCopyright 1987, 1998 The Open Group 4706f2543Smrg 5706f2543SmrgPermission to use, copy, modify, distribute, and sell this software and its 6706f2543Smrgdocumentation for any purpose is hereby granted without fee, provided that 7706f2543Smrgthe above copyright notice appear in all copies and that both that 8706f2543Smrgcopyright notice and this permission notice appear in supporting 9706f2543Smrgdocumentation. 10706f2543Smrg 11706f2543SmrgThe above copyright notice and this permission notice shall be included 12706f2543Smrgin all copies or substantial portions of the Software. 13706f2543Smrg 14706f2543SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15706f2543SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16706f2543SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17706f2543SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18706f2543SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19706f2543SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20706f2543SmrgOTHER DEALINGS IN THE SOFTWARE. 21706f2543Smrg 22706f2543SmrgExcept as contained in this notice, the name of The Open Group shall 23706f2543Smrgnot be used in advertising or otherwise to promote the sale, use or 24706f2543Smrgother dealings in this Software without prior written authorization 25706f2543Smrgfrom The Open Group. 26706f2543Smrg 27706f2543Smrg*/ 28706f2543Smrg 29706f2543Smrg 30706f2543Smrg#ifdef HAVE_DIX_CONFIG_H 31706f2543Smrg#include <dix-config.h> 32706f2543Smrg#endif 33706f2543Smrg 34706f2543Smrg#ifndef SCANFILLINCLUDED 35706f2543Smrg#define SCANFILLINCLUDED 36706f2543Smrg/* 37706f2543Smrg * scanfill.h 38706f2543Smrg * 39706f2543Smrg * Written by Brian Kelleher; Jan 1985 40706f2543Smrg * 41706f2543Smrg * This file contains a few macros to help track 42706f2543Smrg * the edge of a filled object. The object is assumed 43706f2543Smrg * to be filled in scanline order, and thus the 44706f2543Smrg * algorithm used is an extension of Bresenham's line 45706f2543Smrg * drawing algorithm which assumes that y is always the 46706f2543Smrg * major axis. 47706f2543Smrg * Since these pieces of code are the same for any filled shape, 48706f2543Smrg * it is more convenient to gather the library in one 49706f2543Smrg * place, but since these pieces of code are also in 50706f2543Smrg * the inner loops of output primitives, procedure call 51706f2543Smrg * overhead is out of the question. 52706f2543Smrg * See the author for a derivation if needed. 53706f2543Smrg */ 54706f2543Smrg 55706f2543Smrg 56706f2543Smrg/* 57706f2543Smrg * In scan converting polygons, we want to choose those pixels 58706f2543Smrg * which are inside the polygon. Thus, we add .5 to the starting 59706f2543Smrg * x coordinate for both left and right edges. Now we choose the 60706f2543Smrg * first pixel which is inside the pgon for the left edge and the 61706f2543Smrg * first pixel which is outside the pgon for the right edge. 62706f2543Smrg * Draw the left pixel, but not the right. 63706f2543Smrg * 64706f2543Smrg * How to add .5 to the starting x coordinate: 65706f2543Smrg * If the edge is moving to the right, then subtract dy from the 66706f2543Smrg * error term from the general form of the algorithm. 67706f2543Smrg * If the edge is moving to the left, then add dy to the error term. 68706f2543Smrg * 69706f2543Smrg * The reason for the difference between edges moving to the left 70706f2543Smrg * and edges moving to the right is simple: If an edge is moving 71706f2543Smrg * to the right, then we want the algorithm to flip immediately. 72706f2543Smrg * If it is moving to the left, then we don't want it to flip until 73706f2543Smrg * we traverse an entire pixel. 74706f2543Smrg */ 75706f2543Smrg#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \ 76706f2543Smrg int dx; /* local storage */ \ 77706f2543Smrg\ 78706f2543Smrg /* \ 79706f2543Smrg * if the edge is horizontal, then it is ignored \ 80706f2543Smrg * and assumed not to be processed. Otherwise, do this stuff. \ 81706f2543Smrg */ \ 82706f2543Smrg if ((dy) != 0) { \ 83706f2543Smrg xStart = (x1); \ 84706f2543Smrg dx = (x2) - xStart; \ 85706f2543Smrg if (dx < 0) { \ 86706f2543Smrg m = dx / (dy); \ 87706f2543Smrg m1 = m - 1; \ 88706f2543Smrg incr1 = -2 * dx + 2 * (dy) * m1; \ 89706f2543Smrg incr2 = -2 * dx + 2 * (dy) * m; \ 90706f2543Smrg d = 2 * m * (dy) - 2 * dx - 2 * (dy); \ 91706f2543Smrg } else { \ 92706f2543Smrg m = dx / (dy); \ 93706f2543Smrg m1 = m + 1; \ 94706f2543Smrg incr1 = 2 * dx - 2 * (dy) * m1; \ 95706f2543Smrg incr2 = 2 * dx - 2 * (dy) * m; \ 96706f2543Smrg d = -2 * m * (dy) + 2 * dx; \ 97706f2543Smrg } \ 98706f2543Smrg } \ 99706f2543Smrg} 100706f2543Smrg 101706f2543Smrg#define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \ 102706f2543Smrg if (m1 > 0) { \ 103706f2543Smrg if (d > 0) { \ 104706f2543Smrg minval += m1; \ 105706f2543Smrg d += incr1; \ 106706f2543Smrg } \ 107706f2543Smrg else { \ 108706f2543Smrg minval += m; \ 109706f2543Smrg d += incr2; \ 110706f2543Smrg } \ 111706f2543Smrg } else {\ 112706f2543Smrg if (d >= 0) { \ 113706f2543Smrg minval += m1; \ 114706f2543Smrg d += incr1; \ 115706f2543Smrg } \ 116706f2543Smrg else { \ 117706f2543Smrg minval += m; \ 118706f2543Smrg d += incr2; \ 119706f2543Smrg } \ 120706f2543Smrg } \ 121706f2543Smrg} 122706f2543Smrg 123706f2543Smrg 124706f2543Smrg/* 125706f2543Smrg * This structure contains all of the information needed 126706f2543Smrg * to run the bresenham algorithm. 127706f2543Smrg * The variables may be hardcoded into the declarations 128706f2543Smrg * instead of using this structure to make use of 129706f2543Smrg * register declarations. 130706f2543Smrg */ 131706f2543Smrgtypedef struct { 132706f2543Smrg int minor; /* minor axis */ 133706f2543Smrg int d; /* decision variable */ 134706f2543Smrg int m, m1; /* slope and slope+1 */ 135706f2543Smrg int incr1, incr2; /* error increments */ 136706f2543Smrg} BRESINFO; 137706f2543Smrg 138706f2543Smrg 139706f2543Smrg#define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \ 140706f2543Smrg BRESINITPGON(dmaj, min1, min2, bres.minor, bres.d, \ 141706f2543Smrg bres.m, bres.m1, bres.incr1, bres.incr2) 142706f2543Smrg 143706f2543Smrg#define BRESINCRPGONSTRUCT(bres) \ 144706f2543Smrg BRESINCRPGON(bres.d, bres.minor, bres.m, bres.m1, bres.incr1, bres.incr2) 145706f2543Smrg 146706f2543Smrg 147706f2543Smrg#endif 148