2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
#ifndef LineUtils_h_Included
|
|
27 |
#define LineUtils_h_Included
|
|
28 |
|
|
29 |
#define SIGNED(d, v) (((d) < 0) ? (-((jint) (v))) : ((jint) (v)))
|
|
30 |
#define SWAP(a, b, t) do { jint t = a; a = b; b = t; } while (0)
|
|
31 |
#define SETORDERED(a,b,min,max, shorten) \
|
|
32 |
do { \
|
|
33 |
if (a < b) { \
|
|
34 |
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 |
|
|
48 |
extern 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 */
|