mifillarc.c revision 05b261ec
105b261ecSmrg/************************************************************ 205b261ecSmrg 305b261ecSmrgCopyright 1989, 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 in 1205b261ecSmrgall copies or substantial portions of the Software. 1305b261ecSmrg 1405b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1505b261ecSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1605b261ecSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1705b261ecSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1805b261ecSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1905b261ecSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2005b261ecSmrg 2105b261ecSmrgExcept as contained in this notice, the name of The Open Group shall not be 2205b261ecSmrgused in advertising or otherwise to promote the sale, use or other dealings 2305b261ecSmrgin this Software without prior written authorization from The Open Group. 2405b261ecSmrg 2505b261ecSmrgAuthor: Bob Scheifler, MIT X Consortium 2605b261ecSmrg 2705b261ecSmrg********************************************************/ 2805b261ecSmrg 2905b261ecSmrg 3005b261ecSmrg#ifdef HAVE_DIX_CONFIG_H 3105b261ecSmrg#include <dix-config.h> 3205b261ecSmrg#endif 3305b261ecSmrg 3405b261ecSmrg#include <math.h> 3505b261ecSmrg#include <X11/X.h> 3605b261ecSmrg#include <X11/Xprotostr.h> 3705b261ecSmrg#include "regionstr.h" 3805b261ecSmrg#include "gcstruct.h" 3905b261ecSmrg#include "pixmapstr.h" 4005b261ecSmrg#include "mifpoly.h" 4105b261ecSmrg#include "mi.h" 4205b261ecSmrg#include "mifillarc.h" 4305b261ecSmrg 4405b261ecSmrg#define QUADRANT (90 * 64) 4505b261ecSmrg#define HALFCIRCLE (180 * 64) 4605b261ecSmrg#define QUADRANT3 (270 * 64) 4705b261ecSmrg 4805b261ecSmrg#ifndef M_PI 4905b261ecSmrg#define M_PI 3.14159265358979323846 5005b261ecSmrg#endif 5105b261ecSmrg 5205b261ecSmrg#define Dsin(d) sin((double)d*(M_PI/11520.0)) 5305b261ecSmrg#define Dcos(d) cos((double)d*(M_PI/11520.0)) 5405b261ecSmrg 5505b261ecSmrg_X_EXPORT void 5605b261ecSmrgmiFillArcSetup(arc, info) 5705b261ecSmrg xArc *arc; 5805b261ecSmrg miFillArcRec *info; 5905b261ecSmrg{ 6005b261ecSmrg info->y = arc->height >> 1; 6105b261ecSmrg info->dy = arc->height & 1; 6205b261ecSmrg info->yorg = arc->y + info->y; 6305b261ecSmrg info->dx = arc->width & 1; 6405b261ecSmrg info->xorg = arc->x + (arc->width >> 1) + info->dx; 6505b261ecSmrg info->dx = 1 - info->dx; 6605b261ecSmrg if (arc->width == arc->height) 6705b261ecSmrg { 6805b261ecSmrg /* (2x - 2xorg)^2 = d^2 - (2y - 2yorg)^2 */ 6905b261ecSmrg /* even: xorg = yorg = 0 odd: xorg = .5, yorg = -.5 */ 7005b261ecSmrg info->ym = 8; 7105b261ecSmrg info->xm = 8; 7205b261ecSmrg info->yk = info->y << 3; 7305b261ecSmrg if (!info->dx) 7405b261ecSmrg { 7505b261ecSmrg info->xk = 0; 7605b261ecSmrg info->e = -1; 7705b261ecSmrg } 7805b261ecSmrg else 7905b261ecSmrg { 8005b261ecSmrg info->y++; 8105b261ecSmrg info->yk += 4; 8205b261ecSmrg info->xk = -4; 8305b261ecSmrg info->e = - (info->y << 3); 8405b261ecSmrg } 8505b261ecSmrg } 8605b261ecSmrg else 8705b261ecSmrg { 8805b261ecSmrg /* h^2 * (2x - 2xorg)^2 = w^2 * h^2 - w^2 * (2y - 2yorg)^2 */ 8905b261ecSmrg /* even: xorg = yorg = 0 odd: xorg = .5, yorg = -.5 */ 9005b261ecSmrg info->ym = (arc->width * arc->width) << 3; 9105b261ecSmrg info->xm = (arc->height * arc->height) << 3; 9205b261ecSmrg info->yk = info->y * info->ym; 9305b261ecSmrg if (!info->dy) 9405b261ecSmrg info->yk -= info->ym >> 1; 9505b261ecSmrg if (!info->dx) 9605b261ecSmrg { 9705b261ecSmrg info->xk = 0; 9805b261ecSmrg info->e = - (info->xm >> 3); 9905b261ecSmrg } 10005b261ecSmrg else 10105b261ecSmrg { 10205b261ecSmrg info->y++; 10305b261ecSmrg info->yk += info->ym; 10405b261ecSmrg info->xk = -(info->xm >> 1); 10505b261ecSmrg info->e = info->xk - info->yk; 10605b261ecSmrg } 10705b261ecSmrg } 10805b261ecSmrg} 10905b261ecSmrg 11005b261ecSmrgstatic void 11105b261ecSmrgmiFillArcDSetup(xArc *arc, miFillArcDRec *info) 11205b261ecSmrg{ 11305b261ecSmrg /* h^2 * (2x - 2xorg)^2 = w^2 * h^2 - w^2 * (2y - 2yorg)^2 */ 11405b261ecSmrg /* even: xorg = yorg = 0 odd: xorg = .5, yorg = -.5 */ 11505b261ecSmrg info->y = arc->height >> 1; 11605b261ecSmrg info->dy = arc->height & 1; 11705b261ecSmrg info->yorg = arc->y + info->y; 11805b261ecSmrg info->dx = arc->width & 1; 11905b261ecSmrg info->xorg = arc->x + (arc->width >> 1) + info->dx; 12005b261ecSmrg info->dx = 1 - info->dx; 12105b261ecSmrg info->ym = ((double)arc->width) * (arc->width * 8); 12205b261ecSmrg info->xm = ((double)arc->height) * (arc->height * 8); 12305b261ecSmrg info->yk = info->y * info->ym; 12405b261ecSmrg if (!info->dy) 12505b261ecSmrg info->yk -= info->ym / 2.0; 12605b261ecSmrg if (!info->dx) 12705b261ecSmrg { 12805b261ecSmrg info->xk = 0; 12905b261ecSmrg info->e = - (info->xm / 8.0); 13005b261ecSmrg } 13105b261ecSmrg else 13205b261ecSmrg { 13305b261ecSmrg info->y++; 13405b261ecSmrg info->yk += info->ym; 13505b261ecSmrg info->xk = -info->xm / 2.0; 13605b261ecSmrg info->e = info->xk - info->yk; 13705b261ecSmrg } 13805b261ecSmrg} 13905b261ecSmrg 14005b261ecSmrgstatic void 14105b261ecSmrgmiGetArcEdge( 14205b261ecSmrg xArc *arc, 14305b261ecSmrg miSliceEdgePtr edge, 14405b261ecSmrg int k, 14505b261ecSmrg Bool top, 14605b261ecSmrg Bool left ) 14705b261ecSmrg{ 14805b261ecSmrg int xady, y; 14905b261ecSmrg 15005b261ecSmrg y = arc->height >> 1; 15105b261ecSmrg if (!(arc->width & 1)) 15205b261ecSmrg y++; 15305b261ecSmrg if (!top) 15405b261ecSmrg { 15505b261ecSmrg y = -y; 15605b261ecSmrg if (arc->height & 1) 15705b261ecSmrg y--; 15805b261ecSmrg } 15905b261ecSmrg xady = k + y * edge->dx; 16005b261ecSmrg if (xady <= 0) 16105b261ecSmrg edge->x = - ((-xady) / edge->dy + 1); 16205b261ecSmrg else 16305b261ecSmrg edge->x = (xady - 1) / edge->dy; 16405b261ecSmrg edge->e = xady - edge->x * edge->dy; 16505b261ecSmrg if ((top && (edge->dx < 0)) || (!top && (edge->dx > 0))) 16605b261ecSmrg edge->e = edge->dy - edge->e + 1; 16705b261ecSmrg if (left) 16805b261ecSmrg edge->x++; 16905b261ecSmrg edge->x += arc->x + (arc->width >> 1); 17005b261ecSmrg if (edge->dx > 0) 17105b261ecSmrg { 17205b261ecSmrg edge->deltax = 1; 17305b261ecSmrg edge->stepx = edge->dx / edge->dy; 17405b261ecSmrg edge->dx = edge->dx % edge->dy; 17505b261ecSmrg } 17605b261ecSmrg else 17705b261ecSmrg { 17805b261ecSmrg edge->deltax = -1; 17905b261ecSmrg edge->stepx = - ((-edge->dx) / edge->dy); 18005b261ecSmrg edge->dx = (-edge->dx) % edge->dy; 18105b261ecSmrg } 18205b261ecSmrg if (!top) 18305b261ecSmrg { 18405b261ecSmrg edge->deltax = -edge->deltax; 18505b261ecSmrg edge->stepx = -edge->stepx; 18605b261ecSmrg } 18705b261ecSmrg} 18805b261ecSmrg 18905b261ecSmrgstatic void 19005b261ecSmrgmiEllipseAngleToSlope (int angle, int width, int height, int *dxp, int *dyp, 19105b261ecSmrg double *d_dxp, double *d_dyp) 19205b261ecSmrg{ 19305b261ecSmrg int dx, dy; 19405b261ecSmrg double d_dx, d_dy, scale; 19505b261ecSmrg Bool negative_dx, negative_dy; 19605b261ecSmrg 19705b261ecSmrg switch (angle) { 19805b261ecSmrg case 0: 19905b261ecSmrg *dxp = -1; 20005b261ecSmrg *dyp = 0; 20105b261ecSmrg if (d_dxp) { 20205b261ecSmrg *d_dxp = width / 2.0; 20305b261ecSmrg *d_dyp = 0; 20405b261ecSmrg } 20505b261ecSmrg break; 20605b261ecSmrg case QUADRANT: 20705b261ecSmrg *dxp = 0; 20805b261ecSmrg *dyp = 1; 20905b261ecSmrg if (d_dxp) { 21005b261ecSmrg *d_dxp = 0; 21105b261ecSmrg *d_dyp = - height / 2.0; 21205b261ecSmrg } 21305b261ecSmrg break; 21405b261ecSmrg case HALFCIRCLE: 21505b261ecSmrg *dxp = 1; 21605b261ecSmrg *dyp = 0; 21705b261ecSmrg if (d_dxp) { 21805b261ecSmrg *d_dxp = - width / 2.0; 21905b261ecSmrg *d_dyp = 0; 22005b261ecSmrg } 22105b261ecSmrg break; 22205b261ecSmrg case QUADRANT3: 22305b261ecSmrg *dxp = 0; 22405b261ecSmrg *dyp = -1; 22505b261ecSmrg if (d_dxp) { 22605b261ecSmrg *d_dxp = 0; 22705b261ecSmrg *d_dyp = height / 2.0; 22805b261ecSmrg } 22905b261ecSmrg break; 23005b261ecSmrg default: 23105b261ecSmrg d_dx = Dcos(angle) * width; 23205b261ecSmrg d_dy = Dsin(angle) * height; 23305b261ecSmrg if (d_dxp) { 23405b261ecSmrg *d_dxp = d_dx / 2.0; 23505b261ecSmrg *d_dyp = - d_dy / 2.0; 23605b261ecSmrg } 23705b261ecSmrg negative_dx = FALSE; 23805b261ecSmrg if (d_dx < 0.0) 23905b261ecSmrg { 24005b261ecSmrg d_dx = -d_dx; 24105b261ecSmrg negative_dx = TRUE; 24205b261ecSmrg } 24305b261ecSmrg negative_dy = FALSE; 24405b261ecSmrg if (d_dy < 0.0) 24505b261ecSmrg { 24605b261ecSmrg d_dy = -d_dy; 24705b261ecSmrg negative_dy = TRUE; 24805b261ecSmrg } 24905b261ecSmrg scale = d_dx; 25005b261ecSmrg if (d_dy > d_dx) 25105b261ecSmrg scale = d_dy; 25205b261ecSmrg dx = floor ((d_dx * 32768) / scale + 0.5); 25305b261ecSmrg if (negative_dx) 25405b261ecSmrg dx = -dx; 25505b261ecSmrg *dxp = dx; 25605b261ecSmrg dy = floor ((d_dy * 32768) / scale + 0.5); 25705b261ecSmrg if (negative_dy) 25805b261ecSmrg dy = -dy; 25905b261ecSmrg *dyp = dy; 26005b261ecSmrg break; 26105b261ecSmrg } 26205b261ecSmrg} 26305b261ecSmrg 26405b261ecSmrgstatic void 26505b261ecSmrgmiGetPieEdge( 26605b261ecSmrg xArc *arc, 26705b261ecSmrg int angle, 26805b261ecSmrg miSliceEdgePtr edge, 26905b261ecSmrg Bool top, 27005b261ecSmrg Bool left ) 27105b261ecSmrg{ 27205b261ecSmrg int k; 27305b261ecSmrg int dx, dy; 27405b261ecSmrg 27505b261ecSmrg miEllipseAngleToSlope (angle, arc->width, arc->height, &dx, &dy, 0, 0); 27605b261ecSmrg 27705b261ecSmrg if (dy == 0) 27805b261ecSmrg { 27905b261ecSmrg edge->x = left ? -65536 : 65536; 28005b261ecSmrg edge->stepx = 0; 28105b261ecSmrg edge->e = 0; 28205b261ecSmrg edge->dx = -1; 28305b261ecSmrg return; 28405b261ecSmrg } 28505b261ecSmrg if (dx == 0) 28605b261ecSmrg { 28705b261ecSmrg edge->x = arc->x + (arc->width >> 1); 28805b261ecSmrg if (left && (arc->width & 1)) 28905b261ecSmrg edge->x++; 29005b261ecSmrg else if (!left && !(arc->width & 1)) 29105b261ecSmrg edge->x--; 29205b261ecSmrg edge->stepx = 0; 29305b261ecSmrg edge->e = 0; 29405b261ecSmrg edge->dx = -1; 29505b261ecSmrg return; 29605b261ecSmrg } 29705b261ecSmrg if (dy < 0) { 29805b261ecSmrg dx = -dx; 29905b261ecSmrg dy = -dy; 30005b261ecSmrg } 30105b261ecSmrg k = (arc->height & 1) ? dx : 0; 30205b261ecSmrg if (arc->width & 1) 30305b261ecSmrg k += dy; 30405b261ecSmrg edge->dx = dx << 1; 30505b261ecSmrg edge->dy = dy << 1; 30605b261ecSmrg miGetArcEdge(arc, edge, k, top, left); 30705b261ecSmrg} 30805b261ecSmrg 30905b261ecSmrg_X_EXPORT void 31005b261ecSmrgmiFillArcSliceSetup(arc, slice, pGC) 31105b261ecSmrg xArc *arc; 31205b261ecSmrg miArcSliceRec *slice; 31305b261ecSmrg GCPtr pGC; 31405b261ecSmrg{ 31505b261ecSmrg int angle1, angle2; 31605b261ecSmrg 31705b261ecSmrg angle1 = arc->angle1; 31805b261ecSmrg if (arc->angle2 < 0) 31905b261ecSmrg { 32005b261ecSmrg angle2 = angle1; 32105b261ecSmrg angle1 += arc->angle2; 32205b261ecSmrg } 32305b261ecSmrg else 32405b261ecSmrg angle2 = angle1 + arc->angle2; 32505b261ecSmrg while (angle1 < 0) 32605b261ecSmrg angle1 += FULLCIRCLE; 32705b261ecSmrg while (angle1 >= FULLCIRCLE) 32805b261ecSmrg angle1 -= FULLCIRCLE; 32905b261ecSmrg while (angle2 < 0) 33005b261ecSmrg angle2 += FULLCIRCLE; 33105b261ecSmrg while (angle2 >= FULLCIRCLE) 33205b261ecSmrg angle2 -= FULLCIRCLE; 33305b261ecSmrg slice->min_top_y = 0; 33405b261ecSmrg slice->max_top_y = arc->height >> 1; 33505b261ecSmrg slice->min_bot_y = 1 - (arc->height & 1); 33605b261ecSmrg slice->max_bot_y = slice->max_top_y - 1; 33705b261ecSmrg slice->flip_top = FALSE; 33805b261ecSmrg slice->flip_bot = FALSE; 33905b261ecSmrg if (pGC->arcMode == ArcPieSlice) 34005b261ecSmrg { 34105b261ecSmrg slice->edge1_top = (angle1 < HALFCIRCLE); 34205b261ecSmrg slice->edge2_top = (angle2 <= HALFCIRCLE); 34305b261ecSmrg if ((angle2 == 0) || (angle1 == HALFCIRCLE)) 34405b261ecSmrg { 34505b261ecSmrg if (angle2 ? slice->edge2_top : slice->edge1_top) 34605b261ecSmrg slice->min_top_y = slice->min_bot_y; 34705b261ecSmrg else 34805b261ecSmrg slice->min_top_y = arc->height; 34905b261ecSmrg slice->min_bot_y = 0; 35005b261ecSmrg } 35105b261ecSmrg else if ((angle1 == 0) || (angle2 == HALFCIRCLE)) 35205b261ecSmrg { 35305b261ecSmrg slice->min_top_y = slice->min_bot_y; 35405b261ecSmrg if (angle1 ? slice->edge1_top : slice->edge2_top) 35505b261ecSmrg slice->min_bot_y = arc->height; 35605b261ecSmrg else 35705b261ecSmrg slice->min_bot_y = 0; 35805b261ecSmrg } 35905b261ecSmrg else if (slice->edge1_top == slice->edge2_top) 36005b261ecSmrg { 36105b261ecSmrg if (angle2 < angle1) 36205b261ecSmrg { 36305b261ecSmrg slice->flip_top = slice->edge1_top; 36405b261ecSmrg slice->flip_bot = !slice->edge1_top; 36505b261ecSmrg } 36605b261ecSmrg else if (slice->edge1_top) 36705b261ecSmrg { 36805b261ecSmrg slice->min_top_y = 1; 36905b261ecSmrg slice->min_bot_y = arc->height; 37005b261ecSmrg } 37105b261ecSmrg else 37205b261ecSmrg { 37305b261ecSmrg slice->min_bot_y = 0; 37405b261ecSmrg slice->min_top_y = arc->height; 37505b261ecSmrg } 37605b261ecSmrg } 37705b261ecSmrg miGetPieEdge(arc, angle1, &slice->edge1, 37805b261ecSmrg slice->edge1_top, !slice->edge1_top); 37905b261ecSmrg miGetPieEdge(arc, angle2, &slice->edge2, 38005b261ecSmrg slice->edge2_top, slice->edge2_top); 38105b261ecSmrg } 38205b261ecSmrg else 38305b261ecSmrg { 38405b261ecSmrg double w2, h2, x1, y1, x2, y2, dx, dy, scale; 38505b261ecSmrg int signdx, signdy, y, k; 38605b261ecSmrg Bool isInt1 = TRUE, isInt2 = TRUE; 38705b261ecSmrg 38805b261ecSmrg w2 = (double)arc->width / 2.0; 38905b261ecSmrg h2 = (double)arc->height / 2.0; 39005b261ecSmrg if ((angle1 == 0) || (angle1 == HALFCIRCLE)) 39105b261ecSmrg { 39205b261ecSmrg x1 = angle1 ? -w2 : w2; 39305b261ecSmrg y1 = 0.0; 39405b261ecSmrg } 39505b261ecSmrg else if ((angle1 == QUADRANT) || (angle1 == QUADRANT3)) 39605b261ecSmrg { 39705b261ecSmrg x1 = 0.0; 39805b261ecSmrg y1 = (angle1 == QUADRANT) ? h2 : -h2; 39905b261ecSmrg } 40005b261ecSmrg else 40105b261ecSmrg { 40205b261ecSmrg isInt1 = FALSE; 40305b261ecSmrg x1 = Dcos(angle1) * w2; 40405b261ecSmrg y1 = Dsin(angle1) * h2; 40505b261ecSmrg } 40605b261ecSmrg if ((angle2 == 0) || (angle2 == HALFCIRCLE)) 40705b261ecSmrg { 40805b261ecSmrg x2 = angle2 ? -w2 : w2; 40905b261ecSmrg y2 = 0.0; 41005b261ecSmrg } 41105b261ecSmrg else if ((angle2 == QUADRANT) || (angle2 == QUADRANT3)) 41205b261ecSmrg { 41305b261ecSmrg x2 = 0.0; 41405b261ecSmrg y2 = (angle2 == QUADRANT) ? h2 : -h2; 41505b261ecSmrg } 41605b261ecSmrg else 41705b261ecSmrg { 41805b261ecSmrg isInt2 = FALSE; 41905b261ecSmrg x2 = Dcos(angle2) * w2; 42005b261ecSmrg y2 = Dsin(angle2) * h2; 42105b261ecSmrg } 42205b261ecSmrg dx = x2 - x1; 42305b261ecSmrg dy = y2 - y1; 42405b261ecSmrg if (arc->height & 1) 42505b261ecSmrg { 42605b261ecSmrg y1 -= 0.5; 42705b261ecSmrg y2 -= 0.5; 42805b261ecSmrg } 42905b261ecSmrg if (arc->width & 1) 43005b261ecSmrg { 43105b261ecSmrg x1 += 0.5; 43205b261ecSmrg x2 += 0.5; 43305b261ecSmrg } 43405b261ecSmrg if (dy < 0.0) 43505b261ecSmrg { 43605b261ecSmrg dy = -dy; 43705b261ecSmrg signdy = -1; 43805b261ecSmrg } 43905b261ecSmrg else 44005b261ecSmrg signdy = 1; 44105b261ecSmrg if (dx < 0.0) 44205b261ecSmrg { 44305b261ecSmrg dx = -dx; 44405b261ecSmrg signdx = -1; 44505b261ecSmrg } 44605b261ecSmrg else 44705b261ecSmrg signdx = 1; 44805b261ecSmrg if (isInt1 && isInt2) 44905b261ecSmrg { 45005b261ecSmrg slice->edge1.dx = dx * 2; 45105b261ecSmrg slice->edge1.dy = dy * 2; 45205b261ecSmrg } 45305b261ecSmrg else 45405b261ecSmrg { 45505b261ecSmrg scale = (dx > dy) ? dx : dy; 45605b261ecSmrg slice->edge1.dx = floor((dx * 32768) / scale + .5); 45705b261ecSmrg slice->edge1.dy = floor((dy * 32768) / scale + .5); 45805b261ecSmrg } 45905b261ecSmrg if (!slice->edge1.dy) 46005b261ecSmrg { 46105b261ecSmrg if (signdx < 0) 46205b261ecSmrg { 46305b261ecSmrg y = floor(y1 + 1.0); 46405b261ecSmrg if (y >= 0) 46505b261ecSmrg { 46605b261ecSmrg slice->min_top_y = y; 46705b261ecSmrg slice->min_bot_y = arc->height; 46805b261ecSmrg } 46905b261ecSmrg else 47005b261ecSmrg { 47105b261ecSmrg slice->max_bot_y = -y - (arc->height & 1); 47205b261ecSmrg } 47305b261ecSmrg } 47405b261ecSmrg else 47505b261ecSmrg { 47605b261ecSmrg y = floor(y1); 47705b261ecSmrg if (y >= 0) 47805b261ecSmrg slice->max_top_y = y; 47905b261ecSmrg else 48005b261ecSmrg { 48105b261ecSmrg slice->min_top_y = arc->height; 48205b261ecSmrg slice->min_bot_y = -y - (arc->height & 1); 48305b261ecSmrg } 48405b261ecSmrg } 48505b261ecSmrg slice->edge1_top = TRUE; 48605b261ecSmrg slice->edge1.x = 65536; 48705b261ecSmrg slice->edge1.stepx = 0; 48805b261ecSmrg slice->edge1.e = 0; 48905b261ecSmrg slice->edge1.dx = -1; 49005b261ecSmrg slice->edge2 = slice->edge1; 49105b261ecSmrg slice->edge2_top = FALSE; 49205b261ecSmrg } 49305b261ecSmrg else if (!slice->edge1.dx) 49405b261ecSmrg { 49505b261ecSmrg if (signdy < 0) 49605b261ecSmrg x1 -= 1.0; 49705b261ecSmrg slice->edge1.x = ceil(x1); 49805b261ecSmrg slice->edge1_top = signdy < 0; 49905b261ecSmrg slice->edge1.x += arc->x + (arc->width >> 1); 50005b261ecSmrg slice->edge1.stepx = 0; 50105b261ecSmrg slice->edge1.e = 0; 50205b261ecSmrg slice->edge1.dx = -1; 50305b261ecSmrg slice->edge2_top = !slice->edge1_top; 50405b261ecSmrg slice->edge2 = slice->edge1; 50505b261ecSmrg } 50605b261ecSmrg else 50705b261ecSmrg { 50805b261ecSmrg if (signdx < 0) 50905b261ecSmrg slice->edge1.dx = -slice->edge1.dx; 51005b261ecSmrg if (signdy < 0) 51105b261ecSmrg slice->edge1.dx = -slice->edge1.dx; 51205b261ecSmrg k = ceil(((x1 + x2) * slice->edge1.dy - (y1 + y2) * slice->edge1.dx) / 2.0); 51305b261ecSmrg slice->edge2.dx = slice->edge1.dx; 51405b261ecSmrg slice->edge2.dy = slice->edge1.dy; 51505b261ecSmrg slice->edge1_top = signdy < 0; 51605b261ecSmrg slice->edge2_top = !slice->edge1_top; 51705b261ecSmrg miGetArcEdge(arc, &slice->edge1, k, 51805b261ecSmrg slice->edge1_top, !slice->edge1_top); 51905b261ecSmrg miGetArcEdge(arc, &slice->edge2, k, 52005b261ecSmrg slice->edge2_top, slice->edge2_top); 52105b261ecSmrg } 52205b261ecSmrg } 52305b261ecSmrg} 52405b261ecSmrg 52505b261ecSmrg#define ADDSPANS() \ 52605b261ecSmrg pts->x = xorg - x; \ 52705b261ecSmrg pts->y = yorg - y; \ 52805b261ecSmrg *wids = slw; \ 52905b261ecSmrg pts++; \ 53005b261ecSmrg wids++; \ 53105b261ecSmrg if (miFillArcLower(slw)) \ 53205b261ecSmrg { \ 53305b261ecSmrg pts->x = xorg - x; \ 53405b261ecSmrg pts->y = yorg + y + dy; \ 53505b261ecSmrg pts++; \ 53605b261ecSmrg *wids++ = slw; \ 53705b261ecSmrg } 53805b261ecSmrg 53905b261ecSmrgstatic void 54005b261ecSmrgmiFillEllipseI( 54105b261ecSmrg DrawablePtr pDraw, 54205b261ecSmrg GCPtr pGC, 54305b261ecSmrg xArc *arc ) 54405b261ecSmrg{ 54505b261ecSmrg int x, y, e; 54605b261ecSmrg int yk, xk, ym, xm, dx, dy, xorg, yorg; 54705b261ecSmrg int slw; 54805b261ecSmrg miFillArcRec info; 54905b261ecSmrg DDXPointPtr points; 55005b261ecSmrg DDXPointPtr pts; 55105b261ecSmrg int *widths; 55205b261ecSmrg int *wids; 55305b261ecSmrg 55405b261ecSmrg points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * arc->height); 55505b261ecSmrg if (!points) 55605b261ecSmrg return; 55705b261ecSmrg widths = (int *)ALLOCATE_LOCAL(sizeof(int) * arc->height); 55805b261ecSmrg if (!widths) 55905b261ecSmrg { 56005b261ecSmrg DEALLOCATE_LOCAL(points); 56105b261ecSmrg return; 56205b261ecSmrg } 56305b261ecSmrg miFillArcSetup(arc, &info); 56405b261ecSmrg MIFILLARCSETUP(); 56505b261ecSmrg if (pGC->miTranslate) 56605b261ecSmrg { 56705b261ecSmrg xorg += pDraw->x; 56805b261ecSmrg yorg += pDraw->y; 56905b261ecSmrg } 57005b261ecSmrg pts = points; 57105b261ecSmrg wids = widths; 57205b261ecSmrg while (y > 0) 57305b261ecSmrg { 57405b261ecSmrg MIFILLARCSTEP(slw); 57505b261ecSmrg ADDSPANS(); 57605b261ecSmrg } 57705b261ecSmrg (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE); 57805b261ecSmrg DEALLOCATE_LOCAL(widths); 57905b261ecSmrg DEALLOCATE_LOCAL(points); 58005b261ecSmrg} 58105b261ecSmrg 58205b261ecSmrgstatic void 58305b261ecSmrgmiFillEllipseD( 58405b261ecSmrg DrawablePtr pDraw, 58505b261ecSmrg GCPtr pGC, 58605b261ecSmrg xArc *arc ) 58705b261ecSmrg{ 58805b261ecSmrg int x, y; 58905b261ecSmrg int xorg, yorg, dx, dy, slw; 59005b261ecSmrg double e, yk, xk, ym, xm; 59105b261ecSmrg miFillArcDRec info; 59205b261ecSmrg DDXPointPtr points; 59305b261ecSmrg DDXPointPtr pts; 59405b261ecSmrg int *widths; 59505b261ecSmrg int *wids; 59605b261ecSmrg 59705b261ecSmrg points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * arc->height); 59805b261ecSmrg if (!points) 59905b261ecSmrg return; 60005b261ecSmrg widths = (int *)ALLOCATE_LOCAL(sizeof(int) * arc->height); 60105b261ecSmrg if (!widths) 60205b261ecSmrg { 60305b261ecSmrg DEALLOCATE_LOCAL(points); 60405b261ecSmrg return; 60505b261ecSmrg } 60605b261ecSmrg miFillArcDSetup(arc, &info); 60705b261ecSmrg MIFILLARCSETUP(); 60805b261ecSmrg if (pGC->miTranslate) 60905b261ecSmrg { 61005b261ecSmrg xorg += pDraw->x; 61105b261ecSmrg yorg += pDraw->y; 61205b261ecSmrg } 61305b261ecSmrg pts = points; 61405b261ecSmrg wids = widths; 61505b261ecSmrg while (y > 0) 61605b261ecSmrg { 61705b261ecSmrg MIFILLARCSTEP(slw); 61805b261ecSmrg ADDSPANS(); 61905b261ecSmrg } 62005b261ecSmrg (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE); 62105b261ecSmrg DEALLOCATE_LOCAL(widths); 62205b261ecSmrg DEALLOCATE_LOCAL(points); 62305b261ecSmrg} 62405b261ecSmrg 62505b261ecSmrg#define ADDSPAN(l,r) \ 62605b261ecSmrg if (r >= l) \ 62705b261ecSmrg { \ 62805b261ecSmrg pts->x = l; \ 62905b261ecSmrg pts->y = ya; \ 63005b261ecSmrg pts++; \ 63105b261ecSmrg *wids++ = r - l + 1; \ 63205b261ecSmrg } 63305b261ecSmrg 63405b261ecSmrg#define ADDSLICESPANS(flip) \ 63505b261ecSmrg if (!flip) \ 63605b261ecSmrg { \ 63705b261ecSmrg ADDSPAN(xl, xr); \ 63805b261ecSmrg } \ 63905b261ecSmrg else \ 64005b261ecSmrg { \ 64105b261ecSmrg xc = xorg - x; \ 64205b261ecSmrg ADDSPAN(xc, xr); \ 64305b261ecSmrg xc += slw - 1; \ 64405b261ecSmrg ADDSPAN(xl, xc); \ 64505b261ecSmrg } 64605b261ecSmrg 64705b261ecSmrgstatic void 64805b261ecSmrgmiFillArcSliceI( 64905b261ecSmrg DrawablePtr pDraw, 65005b261ecSmrg GCPtr pGC, 65105b261ecSmrg xArc *arc ) 65205b261ecSmrg{ 65305b261ecSmrg int yk, xk, ym, xm, dx, dy, xorg, yorg, slw; 65405b261ecSmrg int x, y, e; 65505b261ecSmrg miFillArcRec info; 65605b261ecSmrg miArcSliceRec slice; 65705b261ecSmrg int ya, xl, xr, xc; 65805b261ecSmrg DDXPointPtr points; 65905b261ecSmrg DDXPointPtr pts; 66005b261ecSmrg int *widths; 66105b261ecSmrg int *wids; 66205b261ecSmrg 66305b261ecSmrg miFillArcSetup(arc, &info); 66405b261ecSmrg miFillArcSliceSetup(arc, &slice, pGC); 66505b261ecSmrg MIFILLARCSETUP(); 66605b261ecSmrg slw = arc->height; 66705b261ecSmrg if (slice.flip_top || slice.flip_bot) 66805b261ecSmrg slw += (arc->height >> 1) + 1; 66905b261ecSmrg points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * slw); 67005b261ecSmrg if (!points) 67105b261ecSmrg return; 67205b261ecSmrg widths = (int *)ALLOCATE_LOCAL(sizeof(int) * slw); 67305b261ecSmrg if (!widths) 67405b261ecSmrg { 67505b261ecSmrg DEALLOCATE_LOCAL(points); 67605b261ecSmrg return; 67705b261ecSmrg } 67805b261ecSmrg if (pGC->miTranslate) 67905b261ecSmrg { 68005b261ecSmrg xorg += pDraw->x; 68105b261ecSmrg yorg += pDraw->y; 68205b261ecSmrg slice.edge1.x += pDraw->x; 68305b261ecSmrg slice.edge2.x += pDraw->x; 68405b261ecSmrg } 68505b261ecSmrg pts = points; 68605b261ecSmrg wids = widths; 68705b261ecSmrg while (y > 0) 68805b261ecSmrg { 68905b261ecSmrg MIFILLARCSTEP(slw); 69005b261ecSmrg MIARCSLICESTEP(slice.edge1); 69105b261ecSmrg MIARCSLICESTEP(slice.edge2); 69205b261ecSmrg if (miFillSliceUpper(slice)) 69305b261ecSmrg { 69405b261ecSmrg ya = yorg - y; 69505b261ecSmrg MIARCSLICEUPPER(xl, xr, slice, slw); 69605b261ecSmrg ADDSLICESPANS(slice.flip_top); 69705b261ecSmrg } 69805b261ecSmrg if (miFillSliceLower(slice)) 69905b261ecSmrg { 70005b261ecSmrg ya = yorg + y + dy; 70105b261ecSmrg MIARCSLICELOWER(xl, xr, slice, slw); 70205b261ecSmrg ADDSLICESPANS(slice.flip_bot); 70305b261ecSmrg } 70405b261ecSmrg } 70505b261ecSmrg (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE); 70605b261ecSmrg DEALLOCATE_LOCAL(widths); 70705b261ecSmrg DEALLOCATE_LOCAL(points); 70805b261ecSmrg} 70905b261ecSmrg 71005b261ecSmrgstatic void 71105b261ecSmrgmiFillArcSliceD( 71205b261ecSmrg DrawablePtr pDraw, 71305b261ecSmrg GCPtr pGC, 71405b261ecSmrg xArc *arc ) 71505b261ecSmrg{ 71605b261ecSmrg int x, y; 71705b261ecSmrg int dx, dy, xorg, yorg, slw; 71805b261ecSmrg double e, yk, xk, ym, xm; 71905b261ecSmrg miFillArcDRec info; 72005b261ecSmrg miArcSliceRec slice; 72105b261ecSmrg int ya, xl, xr, xc; 72205b261ecSmrg DDXPointPtr points; 72305b261ecSmrg DDXPointPtr pts; 72405b261ecSmrg int *widths; 72505b261ecSmrg int *wids; 72605b261ecSmrg 72705b261ecSmrg miFillArcDSetup(arc, &info); 72805b261ecSmrg miFillArcSliceSetup(arc, &slice, pGC); 72905b261ecSmrg MIFILLARCSETUP(); 73005b261ecSmrg slw = arc->height; 73105b261ecSmrg if (slice.flip_top || slice.flip_bot) 73205b261ecSmrg slw += (arc->height >> 1) + 1; 73305b261ecSmrg points = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * slw); 73405b261ecSmrg if (!points) 73505b261ecSmrg return; 73605b261ecSmrg widths = (int *)ALLOCATE_LOCAL(sizeof(int) * slw); 73705b261ecSmrg if (!widths) 73805b261ecSmrg { 73905b261ecSmrg DEALLOCATE_LOCAL(points); 74005b261ecSmrg return; 74105b261ecSmrg } 74205b261ecSmrg if (pGC->miTranslate) 74305b261ecSmrg { 74405b261ecSmrg xorg += pDraw->x; 74505b261ecSmrg yorg += pDraw->y; 74605b261ecSmrg slice.edge1.x += pDraw->x; 74705b261ecSmrg slice.edge2.x += pDraw->x; 74805b261ecSmrg } 74905b261ecSmrg pts = points; 75005b261ecSmrg wids = widths; 75105b261ecSmrg while (y > 0) 75205b261ecSmrg { 75305b261ecSmrg MIFILLARCSTEP(slw); 75405b261ecSmrg MIARCSLICESTEP(slice.edge1); 75505b261ecSmrg MIARCSLICESTEP(slice.edge2); 75605b261ecSmrg if (miFillSliceUpper(slice)) 75705b261ecSmrg { 75805b261ecSmrg ya = yorg - y; 75905b261ecSmrg MIARCSLICEUPPER(xl, xr, slice, slw); 76005b261ecSmrg ADDSLICESPANS(slice.flip_top); 76105b261ecSmrg } 76205b261ecSmrg if (miFillSliceLower(slice)) 76305b261ecSmrg { 76405b261ecSmrg ya = yorg + y + dy; 76505b261ecSmrg MIARCSLICELOWER(xl, xr, slice, slw); 76605b261ecSmrg ADDSLICESPANS(slice.flip_bot); 76705b261ecSmrg } 76805b261ecSmrg } 76905b261ecSmrg (*pGC->ops->FillSpans)(pDraw, pGC, pts - points, points, widths, FALSE); 77005b261ecSmrg DEALLOCATE_LOCAL(widths); 77105b261ecSmrg DEALLOCATE_LOCAL(points); 77205b261ecSmrg} 77305b261ecSmrg 77405b261ecSmrg/* MIPOLYFILLARC -- The public entry for the PolyFillArc request. 77505b261ecSmrg * Since we don't have to worry about overlapping segments, we can just 77605b261ecSmrg * fill each arc as it comes. 77705b261ecSmrg */ 77805b261ecSmrg_X_EXPORT void 77905b261ecSmrgmiPolyFillArc(pDraw, pGC, narcs, parcs) 78005b261ecSmrg DrawablePtr pDraw; 78105b261ecSmrg GCPtr pGC; 78205b261ecSmrg int narcs; 78305b261ecSmrg xArc *parcs; 78405b261ecSmrg{ 78505b261ecSmrg int i; 78605b261ecSmrg xArc *arc; 78705b261ecSmrg 78805b261ecSmrg for(i = narcs, arc = parcs; --i >= 0; arc++) 78905b261ecSmrg { 79005b261ecSmrg if (miFillArcEmpty(arc)) 79105b261ecSmrg continue;; 79205b261ecSmrg if ((arc->angle2 >= FULLCIRCLE) || (arc->angle2 <= -FULLCIRCLE)) 79305b261ecSmrg { 79405b261ecSmrg if (miCanFillArc(arc)) 79505b261ecSmrg miFillEllipseI(pDraw, pGC, arc); 79605b261ecSmrg else 79705b261ecSmrg miFillEllipseD(pDraw, pGC, arc); 79805b261ecSmrg } 79905b261ecSmrg else 80005b261ecSmrg { 80105b261ecSmrg if (miCanFillArc(arc)) 80205b261ecSmrg miFillArcSliceI(pDraw, pGC, arc); 80305b261ecSmrg else 80405b261ecSmrg miFillArcSliceD(pDraw, pGC, arc); 80505b261ecSmrg } 80605b261ecSmrg } 80705b261ecSmrg} 808