blob: ad452088e605001a7def22ec857836d78497450e [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2000-2006 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 ByteIndexed_h_Included
27#define ByteIndexed_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 "ByteIndexed".
34 */
35
36typedef jubyte ByteIndexedPixelType;
37typedef jubyte ByteIndexedDataType;
38
39#define ByteIndexedPixelStride 1
40#define ByteIndexedBitsPerPixel 8
41
42#define DeclareByteIndexedLoadVars(PREFIX) \
43 jint *PREFIX ## Lut;
44
45#define DeclareByteIndexedStoreVars(PREFIX) \
46 int PREFIX ## XDither, PREFIX ## YDither; \
47 char *PREFIX ## rerr, *PREFIX ## gerr, *PREFIX ## berr; \
48 unsigned char *PREFIX ## InvLut;
49
50#define SetByteIndexedStoreVarsYPos(PREFIX, pRasInfo, LOC) \
51 do { \
52 PREFIX ## YDither = ((LOC & 7) << 3); \
53 } while (0)
54
55#define SetByteIndexedStoreVarsXPos(PREFIX, pRasInfo, LOC) \
56 do { \
57 PREFIX ## rerr = (pRasInfo)->redErrTable + PREFIX ## YDither; \
58 PREFIX ## gerr = (pRasInfo)->grnErrTable + PREFIX ## YDither; \
59 PREFIX ## berr = (pRasInfo)->bluErrTable + PREFIX ## YDither; \
60 PREFIX ## XDither = (LOC & 7); \
61 } while (0)
62
63#define InitByteIndexedLoadVars(PREFIX, pRasInfo) \
64 PREFIX ## Lut = (pRasInfo)->lutBase
65
66/* REMIND Could collapse Init..Store..X and Init..Store..Y into one Init
67 * and factor out the Set.. macros.
68 */
69#define InitByteIndexedStoreVarsY(PREFIX, pRasInfo) \
70 do { \
71 SetByteIndexedStoreVarsYPos(PREFIX, pRasInfo, (pRasInfo)->bounds.y1); \
72 PREFIX ## InvLut = (pRasInfo)->invColorTable; \
73 } while (0)
74
75#define InitByteIndexedStoreVarsX(PREFIX, pRasInfo) \
76 SetByteIndexedStoreVarsXPos(PREFIX, pRasInfo, (pRasInfo)->bounds.x1);
77
78
79#define NextByteIndexedStoreVarsX(PREFIX) \
80 PREFIX ## XDither = (PREFIX ## XDither + 1) & 7
81
82#define NextByteIndexedStoreVarsY(PREFIX) \
83 PREFIX ## YDither = (PREFIX ## YDither + (1 << 3)) & (7 << 3)
84
85typedef jubyte ByteIndexedBmPixelType;
86typedef jubyte ByteIndexedBmDataType;
87
88#define ByteIndexedBmPixelStride 1
89#define ByteIndexedBmBitsPerPixel 8
90
91#define DeclareByteIndexedBmLoadVars DeclareByteIndexedLoadVars
92#define DeclareByteIndexedBmStoreVars DeclareByteIndexedStoreVars
93#define InitByteIndexedBmLoadVars InitByteIndexedLoadVars
94#define InitByteIndexedBmStoreVarsY InitByteIndexedStoreVarsY
95#define InitByteIndexedBmStoreVarsX InitByteIndexedStoreVarsX
96#define NextByteIndexedBmStoreVarsX NextByteIndexedStoreVarsX
97#define NextByteIndexedBmStoreVarsY NextByteIndexedStoreVarsY
98
99#define LoadByteIndexedBmTo1IntArgb LoadByteIndexedTo1IntArgb
100
101#define CopyByteIndexedBmToIntArgbPre(pRGB, i, PREFIX, pRow, x) \
102 do { \
103 jint argb = PREFIX ## Lut[pRow[x]]; \
104 (pRGB)[i] = argb & (argb >> 24); \
105 } while (0)
106
107
108#define ByteIndexedXparLutEntry -1
109#define ByteIndexedIsXparLutEntry(pix) (pix < 0)
110#define StoreByteIndexedNonXparFromArgb StoreByteIndexedFrom1IntArgb
111
112#define StoreByteIndexedPixel(pRas, x, pixel) \
113 ((pRas)[x] = (jubyte) (pixel))
114
115#define DeclareByteIndexedPixelData(PREFIX)
116#define ExtractByteIndexedPixelData(PIXEL, PREFIX)
117
118#define StoreByteIndexedPixelData(pPix, x, pixel, PREFIX) \
119 (pPix)[x] = (jubyte) (pixel)
120
121#define ByteIndexedPixelFromArgb(pixel, rgb, pRasInfo) \
122 do { \
123 jint r, g, b; \
124 ExtractIntDcmComponentsX123(rgb, r, g, b); \
125 (pixel) = SurfaceData_InvColorMap((pRasInfo)->invColorTable, \
126 r, g, b); \
127 } while (0)
128
129#define LoadByteIndexedTo1IntRgb(pRas, PREFIX, x, rgb) \
130 (rgb) = PREFIX ## Lut[pRas[x]]
131
132#define LoadByteIndexedTo1IntArgb(pRas, PREFIX, x, argb) \
133 (argb) = PREFIX ## Lut[pRas[x]]
134
135#define LoadByteIndexedTo3ByteRgb(pRas, PREFIX, x, r, g, b) \
136 do { \
137 jint rgb = PREFIX ## Lut[pRas[x]]; \
138 ExtractIntDcmComponentsX123(rgb, r, g, b); \
139 } while (0)
140
141#define LoadByteIndexedTo4ByteArgb(pRas, PREFIX, x, a, r, g, b) \
142 do { \
143 jint argb = PREFIX ## Lut[pRas[x]]; \
144 ExtractIntDcmComponents1234(argb, a, r, g, b); \
145 } while (0)
146
147#define ByteClamp1Component(X) \
148 do { if (((X) >> 8) != 0) {X = (~(X >> 31)) & 255; } } while (0)
149
150#define ByteClamp3Components(R, G, B) \
151 do { \
152 if (((R|G|B) >> 8) != 0) { \
153 ByteClamp1Component(R); \
154 ByteClamp1Component(G); \
155 ByteClamp1Component(B); \
156 } \
157 } while (0)
158
159#define StoreByteIndexedFrom1IntRgb(pRas, PREFIX, x, rgb) \
160 do { \
161 int r, g, b; \
162 ExtractIntDcmComponentsX123(rgb, r, g, b); \
163 StoreByteIndexedFrom3ByteRgb(pRas, PREFIX, x, r, g, b); \
164 } while (0)
165
166#define StoreByteIndexedFrom1IntArgb(pRas, PREFIX, x, argb) \
167 StoreByteIndexedFrom1IntRgb(pRas, PREFIX, x, argb)
168
169#define StoreByteIndexedFrom3ByteRgb(pRas, PREFIX, x, r, g, b) \
170 do { \
171 r += PREFIX ## rerr[PREFIX ## XDither]; \
172 g += PREFIX ## gerr[PREFIX ## XDither]; \
173 b += PREFIX ## berr[PREFIX ## XDither]; \
174 ByteClamp3Components(r, g, b); \
175 (pRas)[x] = SurfaceData_InvColorMap(PREFIX ## InvLut, r, g, b); \
176 } while (0)
177
178#define StoreByteIndexedFrom4ByteArgb(pRas, PREFIX, x, a, r, g, b) \
179 StoreByteIndexedFrom3ByteRgb(pRas, PREFIX, x, r, g, b)
180
181#define CopyByteIndexedToIntArgbPre(pRGB, i, PREFIX, pRow, x) \
182 do { \
183 jint argb = PREFIX ## Lut[pRow[x]]; \
184 jint a = URShift(argb, 24); \
185 if (a == 0) { \
186 argb = 0; \
187 } else if (a < 0xff) { \
188 jint r = (argb >> 16) & 0xff; \
189 jint g = (argb >> 8) & 0xff; \
190 jint b = (argb ) & 0xff; \
191 r = MUL8(a, r); \
192 g = MUL8(a, g); \
193 b = MUL8(a, b); \
194 argb = ComposeIntDcmComponents1234(a, r, g, b); \
195 } \
196 (pRGB)[i] = argb; \
197 } while (0)
198
199
200#define DeclareByteIndexedAlphaLoadData(PREFIX) \
201 jint *PREFIX ## Lut; \
202 jint PREFIX ## rgb;
203
204#define InitByteIndexedAlphaLoadData(PREFIX, pRasInfo) \
205 PREFIX ## Lut = (pRasInfo)->lutBase
206
207#define LoadAlphaFromByteIndexedFor4ByteArgb(pRas, PREFIX, COMP_PREFIX) \
208 do { \
209 PREFIX ## rgb = PREFIX ## Lut[(pRas)[0]]; \
210 COMP_PREFIX ## A = ((juint) PREFIX ## rgb) >> 24; \
211 } while (0)
212
213#define Postload4ByteArgbFromByteIndexed(pRas, PREFIX, COMP_PREFIX) \
214 do { \
215 COMP_PREFIX ## R = (PREFIX ## rgb >> 16) & 0xff; \
216 COMP_PREFIX ## G = (PREFIX ## rgb >> 8) & 0xff; \
217 COMP_PREFIX ## B = (PREFIX ## rgb >> 0) & 0xff; \
218 } while (0)
219
220
221#define ByteIndexedIsPremultiplied 0
222
223#define StoreByteIndexedFrom4ByteArgbComps(pRas, PREFIX, x, COMP_PREFIX) \
224 StoreByteIndexedFrom4ByteArgb(pRas, PREFIX, x, \
225 COMP_PREFIX ## A, COMP_PREFIX ## R, \
226 COMP_PREFIX ## G, COMP_PREFIX ## B)
227
228#endif /* ByteIndexed_h_Included */