jdk/src/share/native/sun/java2d/loops/UshortGray.h
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 549 4273b1234967
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 549
diff changeset
     2
 * Copyright 2000-2008 Sun Microsystems, Inc.  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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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 UshortGray_h_Included
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#define UshortGray_h_Included
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "IntDcm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * This file contains macro and type definitions used by the macros in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * LoopMacros.h to manipulate a surface of type "UshortGray".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
typedef jushort UshortGrayPixelType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
typedef jushort UshortGrayDataType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
549
4273b1234967 6679308: Poor text rendering on translucent image.
prr
parents: 2
diff changeset
    39
#define UshortGrayIsOpaque 1
4273b1234967 6679308: Poor text rendering on translucent image.
prr
parents: 2
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#define UshortGrayPixelStride           2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#define UshortGrayBitsPerPixel         16
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#define DeclareUshortGrayLoadVars(PREFIX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#define DeclareUshortGrayStoreVars(PREFIX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#define SetUshortGrayStoreVarsYPos(PREFIX, pRasInfo, y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#define SetUshortGrayStoreVarsXPos(PREFIX, pRasInfo, x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#define InitUshortGrayLoadVars(PREFIX, pRasInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#define InitUshortGrayStoreVarsY(PREFIX, pRasInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#define InitUshortGrayStoreVarsX(PREFIX, pRasInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#define NextUshortGrayStoreVarsX(PREFIX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#define NextUshortGrayStoreVarsY(PREFIX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#define DeclareUshortGrayPixelData(PREFIX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#define ExtractUshortGrayPixelData(PIXEL, PREFIX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#define UshortGrayXparLutEntry                  -1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#define UshortGrayIsXparLutEntry(pix)           (pix < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#define StoreUshortGrayNonXparFromArgb          StoreUshortGrayFrom1IntArgb
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Note: The following (original) equation was incorrect:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *   gray = (((19595*r) + (38470*g) + (7471*b) + 32768) / 65536);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * The new component coefficients were derived from the following equation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *   k*rf*255 + k*gf*255 + k*bf*255 = 2^24 - 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * The new calculated coefficients are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *   rf = 19672
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *   gf = 38620
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *   bf = 7500
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * Thus the new equation would be:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *   gray = (((19672*r) + (38620*g) + (7500*b) + 128) / 255)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * but it has been tweaked so the faster "divide by 256" can be performed and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * the "add 128" can be removed.  Therefore, the resultant formula is optimal:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *   gray = (((19672*r) + (38621*g) + (7500*b)) / 256)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
#define ComposeUshortGrayFrom3ByteRgb(r, g, b) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    (UshortGrayPixelType)(((19672*(r)) + (38621*(g)) + (7500*(b))) / 256)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#define UshortGrayPixelFromArgb(pixel, rgb, pRasInfo) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    do { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        int r, g, b; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        ExtractIntDcmComponentsX123(rgb, r, g, b); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        (pixel) = ComposeUshortGrayFrom3ByteRgb(r, g, b); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    } while (0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
#define StoreUshortGrayPixel(pRas, x, pixel) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    ((pRas)[x] = (jushort) (pixel))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
#define StoreUshortGrayPixelData(pPix, x, pixel, PREFIX) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    StoreUshortGrayPixel(pPix, x, pixel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
#define LoadUshortGrayTo1IntRgb(pRas, PREFIX, x, rgb) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    do { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        int gray = (pRas)[x] >> 8; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        (rgb) = (((gray << 8) | gray) << 8) | gray; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    } while (0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
#define LoadUshortGrayTo1IntArgb(pRas, PREFIX, x, argb) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    do { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        int gray = (pRas)[x] >> 8; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        (argb) = (((((0xff << 8) | gray) << 8) | gray) << 8) | gray; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    } while (0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
#define LoadUshortGrayTo3ByteRgb(pRas, PREFIX, x, r, g, b) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    ((r) = (g) = (b) = ((pRas)[x] >> 8))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
#define LoadUshortGrayTo4ByteArgb(pRas, PREFIX, x, a, r, g, b) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    do { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        LoadUshortGrayTo3ByteRgb(pRas, PREFIX, x, r, g, b); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        (a) = 0xff; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    } while (0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
#define LoadUshortGrayTo1ByteGray(pRas, PREFIX, x, gray) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    (gray) = ((pRas)[x] >> 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
#define LoadUshortGrayTo1ShortGray(pRas, PREFIX, x, gray) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    (gray) = (pRas)[x]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
#define StoreUshortGrayFrom1IntRgb(pRas, PREFIX, x, rgb) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    do { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        int r, g, b; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        ExtractIntDcmComponentsX123(rgb, r, g, b); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        StoreUshortGrayFrom3ByteRgb(pRas, PREFIX, x, r, g, b); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    } while (0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
#define StoreUshortGrayFrom1IntArgb(pRas, PREFIX, x, argb) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    StoreUshortGrayFrom1IntRgb(pRas, PREFIX, x, argb)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
#define StoreUshortGrayFrom3ByteRgb(pRas, PREFIX, x, r, g, b) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    (pRas)[x] = ComposeUshortGrayFrom3ByteRgb(r, g, b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
#define StoreUshortGrayFrom4ByteArgb(pRas, PREFIX, x, a, r, g, b) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    StoreUshortGrayFrom3ByteRgb(pRas, PREFIX, x, r, g, b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
#define StoreUshortGrayFrom1ByteGray(pRas, PREFIX, x, gray) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    (pRas)[x] = (jushort) (((gray) << 8) + (gray))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
#define StoreUshortGrayFrom1ShortGray(pRas, PREFIX, x, gray) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    StoreUshortGrayPixel(pRas, x, gray)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
#define DeclareUshortGrayAlphaLoadData(PREFIX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
#define InitUshortGrayAlphaLoadData(PREFIX, pRasInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
#define LoadAlphaFromUshortGrayFor1ShortGray(pRas, PREFIX, COMP_PREFIX) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    COMP_PREFIX ## A = 0xffff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
#define Postload1ShortGrayFromUshortGray(pRas, PREFIX, COMP_PREFIX) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    COMP_PREFIX ## G = (pRas)[0]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
#define UshortGrayIsPremultiplied       0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
#define DeclareUshortGrayBlendFillVars(PREFIX) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    jushort PREFIX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
#define ClearUshortGrayBlendFillVars(PREFIX, argb) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    PREFIX = 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
#define InitUshortGrayBlendFillVarsNonPre(PREFIX, argb, COMP_PREFIX) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    PREFIX = (jushort) COMP_PREFIX ## G
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
#define InitUshortGrayBlendFillVarsPre(PREFIX, argb, COMP_PREFIX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
#define StoreUshortGrayBlendFill(pRas, PREFIX, x, argb, COMP_PREFIX) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    (pRas)[x] = PREFIX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
#define StoreUshortGrayFrom1ShortGrayComps(pRas, PREFIX, x, COMP_PREFIX) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    StoreUshortGrayPixel(pRas, x, COMP_PREFIX ## G)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
#endif /* UshortGray_h_Included */