0N/A/*
2362N/A * Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A#ifndef LineUtils_h_Included
0N/A#define LineUtils_h_Included
0N/A
0N/A#define SIGNED(d, v) (((d) < 0) ? (-((jint) (v))) : ((jint) (v)))
0N/A#define SWAP(a, b, t) do { jint t = a; a = b; b = t; } while (0)
0N/A#define SETORDERED(a,b,min,max, shorten) \
0N/A do { \
0N/A if (a < b) { \
0N/A min = a; \
0N/A max = b - shorten; \
0N/A } else { \
0N/A min = b + shorten; \
0N/A max = a; \
0N/A } \
0N/A } while (0)
0N/A
0N/A#define BUMP_NOOP 0x0
0N/A#define BUMP_POS_PIXEL 0x1
0N/A#define BUMP_NEG_PIXEL 0x2
0N/A#define BUMP_POS_SCAN 0x4
0N/A#define BUMP_NEG_SCAN 0x8
0N/A
0N/Aextern jboolean LineUtils_SetupBresenham(jint x1, jint y1, jint x2, jint y2,
0N/A jint shorten,
0N/A SurfaceDataBounds *pBounds,
0N/A jint *pStartX, jint *pStartY,
0N/A jint *pSteps, jint *pError,
0N/A jint *pErrMajor, jint *pBumpMajorMask,
0N/A jint *pErrMinor, jint *pBumpMinorMask);
0N/A
0N/A#define LineUtils_ProcessLine(pRasInfo, pixel, pLine, pPrim, pCompInfo, \
0N/A X1, Y1, X2, Y2, shorten) \
0N/A do { \
0N/A jint tx1, ty1, tx2, ty2; \
0N/A if (Y1 == Y2) { \
0N/A if (Y1 >= (pRasInfo)->bounds.y1 && Y1 < (pRasInfo)->bounds.y2) { \
0N/A SETORDERED(X1, X2, tx1, tx2, shorten); \
0N/A if (++tx2 < tx1) --tx2; /* integer overflow */ \
0N/A if (tx1 < (pRasInfo)->bounds.x1) tx1 = (pRasInfo)->bounds.x1; \
0N/A if (tx2 > (pRasInfo)->bounds.x2) tx2 = (pRasInfo)->bounds.x2; \
0N/A if (tx1 < tx2) { \
0N/A (*pLine)((pRasInfo), tx1, Y1, pixel, tx2 - tx1, 0, \
0N/A BUMP_POS_PIXEL, 0, \
0N/A BUMP_NOOP, 0, pPrim, pCompInfo); \
0N/A } \
0N/A } \
0N/A } else if (X1 == X2) { \
0N/A if (X1 >= (pRasInfo)->bounds.x1 && X1 < (pRasInfo)->bounds.x2) { \
0N/A SETORDERED(Y1, Y2, ty1, ty2, shorten); \
0N/A if (++ty2 < ty1) --ty2; /* integer overflow */ \
0N/A if (ty1 < (pRasInfo)->bounds.y1) ty1 = (pRasInfo)->bounds.y1; \
0N/A if (ty2 > (pRasInfo)->bounds.y2) ty2 = (pRasInfo)->bounds.y2; \
0N/A if (ty1 < ty2) { \
0N/A (*pLine)((pRasInfo), X1, ty1, pixel, ty2 - ty1, 0, \
0N/A BUMP_POS_SCAN, 0, \
0N/A BUMP_NOOP, 0, pPrim, pCompInfo); \
0N/A } \
0N/A } \
0N/A } else { \
0N/A jint steps; \
0N/A jint error; \
0N/A jint errmajor, errminor; \
0N/A jint bumpmajormask, bumpminormask; \
0N/A if (LineUtils_SetupBresenham(X1, Y1, X2, Y2, shorten, \
0N/A &(pRasInfo)->bounds, \
0N/A &tx1, &ty1, \
0N/A &steps, &error, \
0N/A &errmajor, &bumpmajormask, \
0N/A &errminor, &bumpminormask)) \
0N/A { \
0N/A (*pLine)((pRasInfo), tx1, ty1, pixel, steps, error, \
0N/A bumpmajormask, errmajor, bumpminormask, errminor, \
0N/A pPrim, pCompInfo); \
0N/A } \
0N/A } \
0N/A } while (0)
0N/A
0N/A#endif /* LineUtils_h_Included */