📄 tclines.c
字号:
/*Copyright (c) 1986, 1987 by Hewlett-Packard CompanyCopyright (c) 1986, 1987 by the Massachusetts Institute of TechnologyPermission to use, copy, modify, and distribute thissoftware and its documentation for any purpose and withoutfee is hereby granted, provided that the above copyrightnotice appear in all copies and that both that copyrightnotice and this permission notice appear in supportingdocumentation, and that the name of M.I.T. not be used inadvertising or publicity pertaining to distribution of thesoftware without specific, written prior permission.HEWLETT-PACKARD MAKES NO WARRANTY OF ANY KIND WITH REGARDTO THIS SOFWARE, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Hewlett-Packard shall not be liable for errors contained herein or direct, indirect, special, incidental or consequential damages in connection with the furnishing, performance, or use of this material.This software is not subject to any license of the AmericanTelephone and Telegraph Company or of the Regents of theUniversity of California.*//***********************************************************Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,and the Massachusetts Institute of Technology, Cambridge, Massachusetts. All Rights ReservedPermission to use, copy, modify, and distribute this software and itsdocumentation for any purpose and without fee is hereby granted,provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear insupporting documentation, and that the names of Digital or MIT not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission.DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THISSOFTWARE.******************************************************************/#include <stdio.h>#include <sys/types.h>#include "X.h"#include "Xproto.h"#include "scrnintstr.h"#include "pixmapstr.h"#include "regionstr.h"#include "../cfb/cfb.h"#include "topcat.h"#include "gcstruct.h"#include "windowstr.h"#include "mi.h"extern u_char XHP_NewRule[16][6];#define OUTCODES(result, x, y, pbox) \ if (x < pbox->x1) \ result |= OUT_LEFT; \ if (y < pbox->y1) \ result |= OUT_ABOVE; \ if (x >= pbox->x2) \ result |= OUT_RIGHT; \ if (y >= pbox->y2) \ result |= OUT_BELOW;/******************************************************************** * Routine: topcatZeroLine - draws 0-width lines quickly * Most of this code was borrowed (really - I'll give it back!) from * mfbline.c */voidtopcatZeroLine(dst, pgc, mode, nptInit, pptInit) DrawablePtr dst; GCPtr pgc; int mode; int nptInit; /* number of points in polyline */ DDXPointRec *pptInit; /* points in the polyline */{ int nboxInit; register int nbox; BoxPtr pboxInit; register BoxPtr pbox; int nptTmp; int xorg, yorg; DDXPointPtr ppt; int npt; DDXPointRec pt1, pt2, pt1Orig, pt2Orig; int dx, dy; int adx, ady; int signdx, signdy; register int len; int du, dv; register int e, e1, e2; int axis; /* major axis of line */ int yinc; int err; unsigned int oc1, oc2; int clip1, clip2, clipdx, clipdy; int clipDone; int tmp; register int x,y; /* current point on the line */ int i; /* traditional name for loop counter */ CARD8 *pDstBase, *pPixel; unsigned int dstWidth; unsigned int fore = pgc->fgPixel; pboxInit = ((cfbPrivGC *)(pgc->devPriv))->pCompositeClip->rects; nboxInit = ((cfbPrivGC *)(pgc->devPriv))->pCompositeClip->numRects; if (dst->type == DRAWABLE_WINDOW) { xorg = ((WindowPtr)dst)->absCorner.x; yorg = ((WindowPtr)dst)->absCorner.y; pDstBase = (CARD8 *)((cfbPrivScreenPtr) (dst->pScreen->devPrivate))->bits; dstWidth = (unsigned int)((cfbPrivScreenPtr) (dst->pScreen->devPrivate))->stride; } else { cfbPrivPixmapPtr pPriv = (cfbPrivPixmapPtr)((PixmapPtr)dst)->devPrivate; if(((PixmapPtr)dst)->devKind == PIXMAP_FRAME_BUFFER) { xorg = ((hpChunk *)pPriv->pChunk)->x; yorg = ((hpChunk *)pPriv->pChunk)->y; pDstBase = (CARD8 *)((cfbPrivScreenPtr) (dst->pScreen->devPrivate))->bits; dstWidth = (unsigned int)((cfbPrivScreenPtr) (dst->pScreen->devPrivate))->stride; } else { /* XXX THIS DOESN"T WORK, AND WILL NEVER WORK */ xorg = 0; yorg = 0; pDstBase = (CARD8 *) pPriv->bits; dstWidth = (unsigned int) pPriv->stride; } } ppt = pptInit; npt = nptInit; if (mode == CoordModeOrigin) { if(xorg || yorg) { while(npt--) { ppt->x += xorg; ppt++->y += yorg; } } } else { ppt->x += xorg; ppt->y += yorg; npt--; while(npt--) { ppt++; ppt->x += (ppt-1)->x; ppt->y += (ppt-1)->y; } } ppt = pptInit; npt = nptInit; while (--npt) { DDXPointPtr pspan; DDXPointPtr pspanInit; int *pwidth; int *pwidthInit; int width; nbox = nboxInit; pbox = pboxInit; pt1 = *ppt++; pt2 = *ppt; dx = pt2.x - pt1.x; dy = pt2.y - pt1.y; adx = abs(dx); ady = abs(dy); /* * ~jra Hack to go to directly to the block mover */ if (dx == 0){ int starty; if(dy < 0) { starty = pt2.y + 1; } else { starty = pt1.y; } tcPaintBlockClipped(dst, pgc, pt1.x, /* x coor */ starty, /* y coor (topmost) */ 1, /* width */ ady /* height */ ); continue; } if (dy == 0) { int startx; if(dx < 0) { startx = pt2.x + 1; } else { startx = pt1.x; } tcPaintBlockClipped(dst, pgc, startx, /* x coor (leftmost) */ pt1.y, /* y coor */ adx, /* width */ 1 /* height */ ); continue; } topcatMaskConfig(dst->pScreen, pgc->planemask, pgc->alu); signdx = sign(dx); signdy = sign(dy); if (adx > ady) { axis = X_AXIS; e1 = ady * 2; e2 = e1 - 2 * adx; e = e1 - adx; } else { axis = Y_AXIS; e1 = adx*2; e2 = e1 - 2*ady; e = e1 - ady; } yinc = signdy * dstWidth; pt1Orig = pt1; pt2Orig = pt2; while(nbox--) { BoxRec box; pt1 = pt1Orig; pt2 = pt2Orig; clipDone = 0; box.x1 = pbox->x1; box.y1 = pbox->y1; box.x2 = pbox->x2-1; box.y2 = pbox->y2-1; clip1 = 0; clip2 = 0; oc1 = 0; oc2 = 0; OUTCODES(oc1, pt1.x, pt1.y, pbox); OUTCODES(oc2, pt2.x, pt2.y, pbox); if (oc1 & oc2) clipDone = -1; else if ((oc1 | oc2) == 0) clipDone = 1; else /* have to clip */ clipDone = mfbClipLine(pbox, box, &pt1Orig, &pt1, &pt2, adx, ady, signdx, signdy, axis, &clip1, &clip2); if(clipDone == -1) { /* * the line doesn't go through this box */ pbox++; continue; } if(axis == X_AXIS) len = abs(pt2.x - pt1.x); else len = abs(pt2.y - pt1.y); len += (clip2 != 0); /* if end clipped, draw the last point */ if(len) { if(clip1) { clipdx = abs(pt1.x - pt1Orig.x); clipdy = abs(pt1.y - pt1Orig.y); if (axis == X_AXIS) err = e+((clipdy*e2) + ((clipdx-clipdy)*e1)); else err = e+((clipdx*e2) + ((clipdy-clipdx)*e1)); } else err = e; pPixel = pDstBase + (pt1.y * dstWidth) + pt1.x; if(axis == X_AXIS) { if (signdx > 0) { while(len--) { *pPixel = fore; if (err < 0) err += e1; else { pPixel += yinc; err += e2; } pPixel++; } } else { while(len--) { *pPixel = fore; if (err <= 0) err += e1; else { pPixel += yinc; err += e2; } pPixel--; } } } /* if X_AXIS */ else { if (signdx > 0) { while(len--) { *pPixel = fore; if (err < 0) err += e1; else { pPixel++; err += e2; } pPixel += yinc; } } else { while(len--) { *pPixel = fore; if (err <= 0) err += e1; else { pPixel--; err += e2; } pPixel += yinc; } } } /* else Y_AXIS */ } /* if segment is unclipped, skip remaining rectangles */ if (!(clip1 || clip2)) break; else pbox++; } } /* while(--npt) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -