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