blob: 59a483da6a1beb9c432684b295da235e616ae0bd [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2001-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#include <string.h>
27
28#include "AnyShort.h"
29#include "Index12Gray.h"
30#include "AlphaMacros.h"
31
32#include "IntArgb.h"
33#include "IntArgbPre.h"
34#include "IntRgb.h"
35#include "ThreeByteBgr.h"
36#include "ByteGray.h"
37#include "ByteIndexed.h"
38#include "Index8Gray.h"
39
40/*
41 * This file declares, registers, and defines the various graphics
42 * primitive loops to manipulate surfaces of type "Index12Gray".
43 *
44 * See also LoopMacros.h
45 */
46
47RegisterFunc RegisterIndex12Gray;
48
49DECLARE_CONVERT_BLIT(Index12Gray, IntArgb);
50DECLARE_CONVERT_BLIT(IntArgb, Index12Gray);
51DECLARE_CONVERT_BLIT(ThreeByteBgr, Index12Gray);
52DECLARE_CONVERT_BLIT(ByteGray, Index12Gray);
53DECLARE_CONVERT_BLIT(Index8Gray, Index12Gray);
54DECLARE_CONVERT_BLIT(ByteIndexed, Index12Gray);
55DECLARE_CONVERT_BLIT(Index12Gray, Index12Gray);
56
57DECLARE_SCALE_BLIT(Index12Gray, Index12Gray);
58DECLARE_SCALE_BLIT(Index12Gray, IntArgb);
59DECLARE_SCALE_BLIT(IntArgb, Index12Gray);
60DECLARE_SCALE_BLIT(ThreeByteBgr, Index12Gray);
61DECLARE_SCALE_BLIT(UshortGray, Index12Gray);
62DECLARE_SCALE_BLIT(ByteIndexed, Index12Gray);
63DECLARE_SCALE_BLIT(ByteGray, Index12Gray);
64DECLARE_SCALE_BLIT(Index8Gray, Index12Gray);
65
66DECLARE_XPAR_CONVERT_BLIT(ByteIndexedBm, Index12Gray);
67DECLARE_XPAR_BLITBG(ByteIndexedBm, Index12Gray);
68
69DECLARE_XOR_BLIT(IntArgb, Index12Gray);
70DECLARE_ALPHA_MASKFILL(Index12Gray);
71DECLARE_ALPHA_MASKBLIT(IntArgb, Index12Gray);
72DECLARE_ALPHA_MASKBLIT(IntArgbPre, Index12Gray);
73DECLARE_ALPHA_MASKBLIT(IntRgb, Index12Gray);
74DECLARE_SRCOVER_MASKFILL(Index12Gray);
75DECLARE_SRCOVER_MASKBLIT(IntArgb, Index12Gray);
76DECLARE_SRCOVER_MASKBLIT(IntArgbPre, Index12Gray);
77DECLARE_SOLID_DRAWGLYPHLISTAA(Index12Gray);
78
79DECLARE_TRANSFORMHELPER_FUNCS(Index12Gray);
80
81NativePrimitive Index12GrayPrimitives[] = {
82 REGISTER_CONVERT_BLIT(IntArgb, Index12Gray),
83 REGISTER_CONVERT_BLIT_EQUIV(IntRgb, Index12Gray,
84 NAME_CONVERT_BLIT(IntArgb, Index12Gray)),
85 REGISTER_CONVERT_BLIT(ThreeByteBgr, Index12Gray),
86 REGISTER_CONVERT_BLIT(ByteGray, Index12Gray),
87 REGISTER_CONVERT_BLIT(Index8Gray, Index12Gray),
88 REGISTER_CONVERT_BLIT_FLAGS(Index12Gray, Index12Gray,
89 SD_LOCK_LUT,
90 SD_LOCK_LUT | SD_LOCK_INVGRAY),
91 REGISTER_CONVERT_BLIT(ByteIndexed, Index12Gray),
92
93 REGISTER_SCALE_BLIT(Index12Gray, IntArgb),
94 REGISTER_SCALE_BLIT(IntArgb, Index12Gray),
95 REGISTER_SCALE_BLIT_EQUIV(IntRgb, Index12Gray,
96 NAME_SCALE_BLIT(IntArgb, Index12Gray)),
97 REGISTER_SCALE_BLIT(ThreeByteBgr, Index12Gray),
98 REGISTER_SCALE_BLIT(UshortGray, Index12Gray),
99 REGISTER_SCALE_BLIT(ByteIndexed, Index12Gray),
100 REGISTER_SCALE_BLIT(ByteGray, Index12Gray),
101 REGISTER_SCALE_BLIT(Index8Gray, Index12Gray),
102 REGISTER_SCALE_BLIT_FLAGS(Index12Gray, Index12Gray, 0,
103 SD_LOCK_LUT | SD_LOCK_INVGRAY),
104
105 REGISTER_XPAR_CONVERT_BLIT(ByteIndexedBm, Index12Gray),
106 REGISTER_XPAR_BLITBG(ByteIndexedBm, Index12Gray),
107
108 REGISTER_XOR_BLIT(IntArgb, Index12Gray),
109 REGISTER_ALPHA_MASKFILL(Index12Gray),
110 REGISTER_ALPHA_MASKBLIT(IntArgb, Index12Gray),
111 REGISTER_ALPHA_MASKBLIT(IntArgbPre, Index12Gray),
112 REGISTER_ALPHA_MASKBLIT(IntRgb, Index12Gray),
113 REGISTER_SRCOVER_MASKFILL(Index12Gray),
114 REGISTER_SRCOVER_MASKBLIT(IntArgb, Index12Gray),
115 REGISTER_SRCOVER_MASKBLIT(IntArgbPre, Index12Gray),
116 REGISTER_SOLID_DRAWGLYPHLISTAA(Index12Gray),
117
118 REGISTER_TRANSFORMHELPER_FUNCS(Index12Gray),
119};
120
121extern jboolean checkSameLut(jint *SrcReadLut, jint *DstReadLut,
122 SurfaceDataRasInfo *pSrcInfo,
123 SurfaceDataRasInfo *pDstInfo);
124
125jboolean RegisterIndex12Gray(JNIEnv *env)
126{
127 return RegisterPrimitives(env, Index12GrayPrimitives,
128 ArraySize(Index12GrayPrimitives));
129}
130
131jint PixelForIndex12Gray(SurfaceDataRasInfo *pRasInfo, jint rgb)
132{
133 jint r, g, b, gray;
134 ExtractIntDcmComponentsX123(rgb, r, g, b);
135 gray = ComposeByteGrayFrom3ByteRgb(r, g, b);
136 return pRasInfo->invGrayTable[gray];
137}
138
139DEFINE_CONVERT_BLIT(IntArgb, Index12Gray, 3ByteRgb)
140
141DEFINE_CONVERT_BLIT(ThreeByteBgr, Index12Gray, 3ByteRgb)
142
143DEFINE_CONVERT_BLIT(ByteGray, Index12Gray, 1ByteGray)
144
145DEFINE_CONVERT_BLIT(Index8Gray, Index12Gray, 1ByteGray)
146
147DEFINE_CONVERT_BLIT(ByteIndexed, Index12Gray, 3ByteRgb)
148
149void NAME_CONVERT_BLIT(Index12Gray, Index12Gray)
150 (void *srcBase, void *dstBase,
151 juint width, juint height,
152 SurfaceDataRasInfo *pSrcInfo,
153 SurfaceDataRasInfo *pDstInfo,
154 NativePrimitive *pPrim,
155 CompositeInfo *pCompInfo)
156{
157 DeclareIndex12GrayLoadVars(SrcRead)
158 DeclareIndex12GrayLoadVars(DstRead)
159 jint srcScan = pSrcInfo->scanStride;
160 jint dstScan = pDstInfo->scanStride;
161
162 InitIndex12GrayLoadVars(SrcRead, pSrcInfo);
163 InitIndex12GrayLoadVars(DstRead, pDstInfo);
164
165 if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) {
166 do {
167 memcpy(dstBase, srcBase, width);
168 srcBase = PtrAddBytes(srcBase, srcScan);
169 dstBase = PtrAddBytes(dstBase, dstScan);
170 } while (--height > 0);
171 } else {
172 DeclareIndex12GrayStoreVars(DstWrite);
173 InitIndex12GrayStoreVarsY(DstWrite, pDstInfo);
174
175 BlitLoopWidthHeight(Index12Gray, pSrc, srcBase, pSrcInfo,
176 Index12Gray, pDst, dstBase, pDstInfo, DstWrite,
177 width, height,
178 ConvertVia1ByteGray
179 (pSrc, Index12Gray, SrcRead,
180 pDst, Index12Gray, DstWrite, 0, 0));
181 }
182}
183
184void NAME_SCALE_BLIT(Index12Gray, Index12Gray)
185 (void *srcBase, void *dstBase,
186 juint width, juint height,
187 jint sxloc, jint syloc,
188 jint sxinc, jint syinc, jint shift,
189 SurfaceDataRasInfo *pSrcInfo,
190 SurfaceDataRasInfo *pDstInfo,
191 NativePrimitive *pPrim,
192 CompositeInfo *pCompInfo)
193{
194 DeclareIndex8GrayLoadVars(SrcRead)
195 DeclareIndex8GrayLoadVars(DstRead)
196 jint srcScan = pSrcInfo->scanStride;
197 jint dstScan = pDstInfo->scanStride;
198 DeclareIndex8GrayStoreVars(DstWrite)
199
200 InitIndex8GrayLoadVars(SrcRead, pSrcInfo);
201 InitIndex8GrayLoadVars(DstRead, pDstInfo);
202
203 if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) {
204 BlitLoopScaleWidthHeight(Index8Gray, pSrc, srcBase, pSrcInfo,
205 Index8Gray, pDst, dstBase, pDstInfo, DstWrite,
206 x, width, height,
207 sxloc, syloc, sxinc, syinc, shift,
208 pDst[0] = pSrc[x]);
209 } else {
210 DeclareIndex8GrayStoreVars(DstWrite);
211 InitIndex8GrayStoreVarsY(DstWrite, pDstInfo);
212 BlitLoopScaleWidthHeight(Index8Gray, pSrc, srcBase, pSrcInfo,
213 Index8Gray, pDst, dstBase, pDstInfo, DstWrite,
214 x, width, height,
215 sxloc, syloc, sxinc, syinc, shift,
216 ConvertVia1ByteGray(pSrc, Index8Gray, SrcRead,
217 pDst, Index8Gray, DstWrite,
218 x, 0));
219 }
220}
221
222DEFINE_SCALE_BLIT(Index12Gray, IntArgb, 1IntArgb)
223
224DEFINE_SCALE_BLIT(IntArgb, Index12Gray, 3ByteRgb)
225
226DEFINE_SCALE_BLIT(ThreeByteBgr, Index12Gray, 3ByteRgb)
227
228DEFINE_SCALE_BLIT(UshortGray, Index12Gray, 1ByteGray)
229
230DEFINE_SCALE_BLIT_LUT8(ByteIndexed, Index12Gray, PreProcessLut)
231
232DEFINE_SCALE_BLIT(ByteGray, Index12Gray, 1ByteGray)
233
234DEFINE_SCALE_BLIT_LUT8(Index8Gray, Index12Gray, PreProcessLut)
235
236DEFINE_XPAR_CONVERT_BLIT_LUT8(ByteIndexedBm, Index12Gray, PreProcessLut)
237
238DEFINE_XPAR_BLITBG_LUT8(ByteIndexedBm, Index12Gray, PreProcessLut)
239
240DEFINE_XOR_BLIT(IntArgb, Index12Gray, AnyShort)
241
242DEFINE_ALPHA_MASKFILL(Index12Gray, 1ByteGray)
243
244DEFINE_ALPHA_MASKBLIT(IntArgb, Index12Gray, 1ByteGray)
245
246DEFINE_ALPHA_MASKBLIT(IntArgbPre, Index12Gray, 1ByteGray)
247
248DEFINE_ALPHA_MASKBLIT(IntRgb, Index12Gray, 1ByteGray)
249
250DEFINE_SRCOVER_MASKFILL(Index12Gray, 1ByteGray)
251
252DEFINE_SRCOVER_MASKBLIT(IntArgb, Index12Gray, 1ByteGray)
253
254DEFINE_SRCOVER_MASKBLIT(IntArgbPre, Index12Gray, 1ByteGray)
255
256DEFINE_SOLID_DRAWGLYPHLISTAA(Index12Gray, 1ByteGray)
257
258DEFINE_TRANSFORMHELPERS(Index12Gray)