src/java.desktop/share/native/libawt/java2d/loops/LineUtils.h
author ihse
Mon, 11 Jun 2018 11:23:20 +0200
branchihse-remove-mapfiles-branch
changeset 56721 01b558efd286
parent 47216 71c04702a3d5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#ifndef LineUtils_h_Included
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#define LineUtils_h_Included
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#define SIGNED(d, v)    (((d) < 0) ? (-((jint) (v))) : ((jint) (v)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#define SWAP(a, b, t)   do { jint t = a; a = b; b = t; } while (0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#define SETORDERED(a,b,min,max, shorten) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    do { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
        if (a < b) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
            min = a; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
            max = b - shorten; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
        } else { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
            min = b + shorten; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
            max = a; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    } while (0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#define BUMP_NOOP         0x0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#define BUMP_POS_PIXEL    0x1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#define BUMP_NEG_PIXEL    0x2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#define BUMP_POS_SCAN     0x4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#define BUMP_NEG_SCAN     0x8
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
extern jboolean LineUtils_SetupBresenham(jint x1, jint y1, jint x2, jint y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                                         jint shorten,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                                         SurfaceDataBounds *pBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                                         jint *pStartX, jint *pStartY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                                         jint *pSteps, jint *pError,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                                         jint *pErrMajor, jint *pBumpMajorMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                                         jint *pErrMinor, jint *pBumpMinorMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#define LineUtils_ProcessLine(pRasInfo, pixel, pLine, pPrim, pCompInfo, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                              X1, Y1, X2, Y2, shorten) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    do { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        jint tx1, ty1, tx2, ty2; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        if (Y1 == Y2) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            if (Y1 >= (pRasInfo)->bounds.y1 && Y1 < (pRasInfo)->bounds.y2) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                SETORDERED(X1, X2, tx1, tx2, shorten); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                if (++tx2 < tx1) --tx2; /* integer overflow */ \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                if (tx1 < (pRasInfo)->bounds.x1) tx1 = (pRasInfo)->bounds.x1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                if (tx2 > (pRasInfo)->bounds.x2) tx2 = (pRasInfo)->bounds.x2; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                if (tx1 < tx2) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                    (*pLine)((pRasInfo), tx1, Y1, pixel, tx2 - tx1, 0, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                             BUMP_POS_PIXEL, 0, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                             BUMP_NOOP, 0, pPrim, pCompInfo); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        } else if (X1 == X2) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            if (X1 >= (pRasInfo)->bounds.x1 && X1 < (pRasInfo)->bounds.x2) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                SETORDERED(Y1, Y2, ty1, ty2, shorten); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                if (++ty2 < ty1) --ty2; /* integer overflow */ \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                if (ty1 < (pRasInfo)->bounds.y1) ty1 = (pRasInfo)->bounds.y1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                if (ty2 > (pRasInfo)->bounds.y2) ty2 = (pRasInfo)->bounds.y2; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                if (ty1 < ty2) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                    (*pLine)((pRasInfo), X1, ty1, pixel, ty2 - ty1, 0, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                             BUMP_POS_SCAN, 0, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                             BUMP_NOOP, 0, pPrim, pCompInfo); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        } else { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            jint steps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            jint error; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            jint errmajor, errminor; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            jint bumpmajormask, bumpminormask; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            if (LineUtils_SetupBresenham(X1, Y1, X2, Y2, shorten, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                         &(pRasInfo)->bounds, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                         &tx1, &ty1, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                         &steps, &error, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                         &errmajor, &bumpmajormask, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                         &errminor, &bumpminormask)) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                (*pLine)((pRasInfo), tx1, ty1, pixel, steps, error, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                         bumpmajormask, errmajor, bumpminormask, errminor, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                         pPrim, pCompInfo); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    } while (0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
#endif /* LineUtils_h_Included */