LineUtils.h revision 10731:e66f69113b89
1237834Smm/* 2237834Smm * Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved. 3237834Smm * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4237834Smm * 5237834Smm * This code is free software; you can redistribute it and/or modify it 6237834Smm * under the terms of the GNU General Public License version 2 only, as 7237834Smm * published by the Free Software Foundation. Oracle designates this 8237834Smm * particular file as subject to the "Classpath" exception as provided 9237834Smm * by Oracle in the LICENSE file that accompanied this code. 10237834Smm * 11237834Smm * This code is distributed in the hope that it will be useful, but WITHOUT 12237834Smm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13237834Smm * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14237834Smm * version 2 for more details (a copy is included in the LICENSE file that 15237834Smm * accompanied this code). 16237834Smm * 17237834Smm * You should have received a copy of the GNU General Public License version 18237834Smm * 2 along with this work; if not, write to the Free Software Foundation, 19237834Smm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20237834Smm * 21237834Smm * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22237834Smm * or visit www.oracle.com if you need additional information or have any 23237834Smm * questions. 24237834Smm */ 25237834Smm 26237834Smm#ifndef LineUtils_h_Included 27237834Smm#define LineUtils_h_Included 28237834Smm 29237834Smm#define SIGNED(d, v) (((d) < 0) ? (-((jint) (v))) : ((jint) (v))) 30237834Smm#define SWAP(a, b, t) do { jint t = a; a = b; b = t; } while (0) 31237834Smm#define SETORDERED(a,b,min,max, shorten) \ 32237834Smm do { \ 33237834Smm if (a < b) { \ 34237834Smm min = a; \ 35 max = b - shorten; \ 36 } else { \ 37 min = b + shorten; \ 38 max = a; \ 39 } \ 40 } while (0) 41 42#define BUMP_NOOP 0x0 43#define BUMP_POS_PIXEL 0x1 44#define BUMP_NEG_PIXEL 0x2 45#define BUMP_POS_SCAN 0x4 46#define BUMP_NEG_SCAN 0x8 47 48extern jboolean LineUtils_SetupBresenham(jint x1, jint y1, jint x2, jint y2, 49 jint shorten, 50 SurfaceDataBounds *pBounds, 51 jint *pStartX, jint *pStartY, 52 jint *pSteps, jint *pError, 53 jint *pErrMajor, jint *pBumpMajorMask, 54 jint *pErrMinor, jint *pBumpMinorMask); 55 56#define LineUtils_ProcessLine(pRasInfo, pixel, pLine, pPrim, pCompInfo, \ 57 X1, Y1, X2, Y2, shorten) \ 58 do { \ 59 jint tx1, ty1, tx2, ty2; \ 60 if (Y1 == Y2) { \ 61 if (Y1 >= (pRasInfo)->bounds.y1 && Y1 < (pRasInfo)->bounds.y2) { \ 62 SETORDERED(X1, X2, tx1, tx2, shorten); \ 63 if (++tx2 < tx1) --tx2; /* integer overflow */ \ 64 if (tx1 < (pRasInfo)->bounds.x1) tx1 = (pRasInfo)->bounds.x1; \ 65 if (tx2 > (pRasInfo)->bounds.x2) tx2 = (pRasInfo)->bounds.x2; \ 66 if (tx1 < tx2) { \ 67 (*pLine)((pRasInfo), tx1, Y1, pixel, tx2 - tx1, 0, \ 68 BUMP_POS_PIXEL, 0, \ 69 BUMP_NOOP, 0, pPrim, pCompInfo); \ 70 } \ 71 } \ 72 } else if (X1 == X2) { \ 73 if (X1 >= (pRasInfo)->bounds.x1 && X1 < (pRasInfo)->bounds.x2) { \ 74 SETORDERED(Y1, Y2, ty1, ty2, shorten); \ 75 if (++ty2 < ty1) --ty2; /* integer overflow */ \ 76 if (ty1 < (pRasInfo)->bounds.y1) ty1 = (pRasInfo)->bounds.y1; \ 77 if (ty2 > (pRasInfo)->bounds.y2) ty2 = (pRasInfo)->bounds.y2; \ 78 if (ty1 < ty2) { \ 79 (*pLine)((pRasInfo), X1, ty1, pixel, ty2 - ty1, 0, \ 80 BUMP_POS_SCAN, 0, \ 81 BUMP_NOOP, 0, pPrim, pCompInfo); \ 82 } \ 83 } \ 84 } else { \ 85 jint steps; \ 86 jint error; \ 87 jint errmajor, errminor; \ 88 jint bumpmajormask, bumpminormask; \ 89 if (LineUtils_SetupBresenham(X1, Y1, X2, Y2, shorten, \ 90 &(pRasInfo)->bounds, \ 91 &tx1, &ty1, \ 92 &steps, &error, \ 93 &errmajor, &bumpmajormask, \ 94 &errminor, &bumpminormask)) \ 95 { \ 96 (*pLine)((pRasInfo), tx1, ty1, pixel, steps, error, \ 97 bumpmajormask, errmajor, bumpminormask, errminor, \ 98 pPrim, pCompInfo); \ 99 } \ 100 } \ 101 } while (0) 102 103#endif /* LineUtils_h_Included */ 104