1/*
2 * Copyright (c) 2000, 2004, Oracle and/or its affiliates. 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26#include <string.h>
27
28#include "AnyByte.h"
29#include "ByteIndexed.h"
30#include "AlphaMacros.h"
31
32#include "IntArgb.h"
33#include "IntArgbBm.h"
34#include "IntArgbPre.h"
35#include "IntRgb.h"
36#include "ThreeByteBgr.h"
37#include "ByteGray.h"
38#include "Index12Gray.h"
39
40/*
41 * This file declares, registers, and defines the various graphics
42 * primitive loops to manipulate surfaces of type "ByteIndexed".
43 *
44 * See also LoopMacros.h
45 */
46
47RegisterFunc RegisterByteIndexed;
48
49DECLARE_CONVERT_BLIT(IntArgb, ByteIndexed);
50DECLARE_CONVERT_BLIT(ThreeByteBgr, ByteIndexed);
51DECLARE_CONVERT_BLIT(ByteGray, ByteIndexed);
52DECLARE_CONVERT_BLIT(ByteIndexed, ByteIndexed);
53DECLARE_CONVERT_BLIT(Index12Gray, ByteIndexed);
54DECLARE_SCALE_BLIT(IntArgb, ByteIndexed);
55DECLARE_SCALE_BLIT(ThreeByteBgr, ByteIndexed);
56DECLARE_SCALE_BLIT(ByteGray, ByteIndexed);
57DECLARE_SCALE_BLIT(Index12Gray, ByteIndexed);
58DECLARE_SCALE_BLIT(ByteIndexed, ByteIndexed);
59DECLARE_XPAR_CONVERT_BLIT(ByteIndexedBm, ByteIndexed);
60DECLARE_XPAR_SCALE_BLIT(ByteIndexedBm, ByteIndexed);
61DECLARE_XPAR_SCALE_BLIT(IntArgbBm, ByteIndexed);
62DECLARE_XPAR_BLITBG(ByteIndexedBm, ByteIndexed);
63DECLARE_XPAR_CONVERT_BLIT(IntArgbBm, ByteIndexed);
64DECLARE_XPAR_BLITBG(IntArgbBm, ByteIndexed);
65
66DECLARE_XOR_BLIT(IntArgb, ByteIndexed);
67DECLARE_ALPHA_MASKFILL(ByteIndexed);
68DECLARE_ALPHA_MASKBLIT(IntArgb, ByteIndexed);
69DECLARE_ALPHA_MASKBLIT(IntArgbPre, ByteIndexed);
70DECLARE_ALPHA_MASKBLIT(IntRgb, ByteIndexed);
71DECLARE_SOLID_DRAWGLYPHLISTAA(ByteIndexed);
72
73DECLARE_TRANSFORMHELPER_FUNCS(ByteIndexed);
74DECLARE_TRANSFORMHELPER_FUNCS(ByteIndexedBm);
75
76NativePrimitive ByteIndexedPrimitives[] = {
77 REGISTER_CONVERT_BLIT(IntArgb, ByteIndexed),
78 REGISTER_CONVERT_BLIT_EQUIV(IntRgb, ByteIndexed,
79 NAME_CONVERT_BLIT(IntArgb, ByteIndexed)),
80 REGISTER_CONVERT_BLIT_EQUIV(IntArgbBm, ByteIndexed,
81 NAME_CONVERT_BLIT(IntArgb, ByteIndexed)),
82 REGISTER_CONVERT_BLIT(ThreeByteBgr, ByteIndexed),
83 REGISTER_CONVERT_BLIT(ByteGray, ByteIndexed),
84 REGISTER_CONVERT_BLIT(Index12Gray, ByteIndexed),
85 REGISTER_CONVERT_BLIT_FLAGS(ByteIndexed, ByteIndexed, 0, SD_LOCK_LUT),
86 REGISTER_SCALE_BLIT(IntArgb, ByteIndexed),
87 REGISTER_SCALE_BLIT_EQUIV(IntRgb, ByteIndexed,
88 NAME_SCALE_BLIT(IntArgb, ByteIndexed)),
89 REGISTER_SCALE_BLIT_EQUIV(IntArgbBm, ByteIndexed,
90 NAME_SCALE_BLIT(IntArgb, ByteIndexed)),
91 REGISTER_SCALE_BLIT(ThreeByteBgr, ByteIndexed),
92 REGISTER_SCALE_BLIT(ByteGray, ByteIndexed),
93 REGISTER_SCALE_BLIT(Index12Gray, ByteIndexed),
94 REGISTER_SCALE_BLIT_FLAGS(ByteIndexed, ByteIndexed, 0, SD_LOCK_LUT),
95 REGISTER_XPAR_CONVERT_BLIT(ByteIndexedBm, ByteIndexed),
96 REGISTER_XPAR_SCALE_BLIT(ByteIndexedBm, ByteIndexed),
97 REGISTER_XPAR_SCALE_BLIT(IntArgbBm, ByteIndexed),
98 REGISTER_XPAR_BLITBG(ByteIndexedBm, ByteIndexed),
99 REGISTER_XPAR_CONVERT_BLIT(IntArgbBm, ByteIndexed),
100 REGISTER_XPAR_BLITBG(IntArgbBm, ByteIndexed),
101
102 REGISTER_XOR_BLIT(IntArgb, ByteIndexed),
103 REGISTER_ALPHA_MASKFILL(ByteIndexed),
104 REGISTER_ALPHA_MASKBLIT(IntArgb, ByteIndexed),
105 REGISTER_ALPHA_MASKBLIT(IntArgbPre, ByteIndexed),
106 REGISTER_ALPHA_MASKBLIT(IntRgb, ByteIndexed),
107 REGISTER_SOLID_DRAWGLYPHLISTAA(ByteIndexed),
108
109 REGISTER_TRANSFORMHELPER_FUNCS(ByteIndexed),
110 REGISTER_TRANSFORMHELPER_FUNCS(ByteIndexedBm),
111};
112
113jboolean RegisterByteIndexed(JNIEnv *env)
114{
115 return RegisterPrimitives(env, ByteIndexedPrimitives,
116 ArraySize(ByteIndexedPrimitives));
117}
118
119jint PixelForByteIndexed(SurfaceDataRasInfo *pRasInfo, jint rgb)
120{
121 jint r, g, b;
122 ExtractIntDcmComponentsX123(rgb, r, g, b);
123 return SurfaceData_InvColorMap(pRasInfo->invColorTable, r, g, b);
124}
125
126jboolean checkSameLut(jint *SrcReadLut, jint *DstReadLut,
127 SurfaceDataRasInfo *pSrcInfo,
128 SurfaceDataRasInfo *pDstInfo)
129{
130 if (SrcReadLut != DstReadLut) {
131 juint lutSize = pSrcInfo->lutSize;
132 if (lutSize > pDstInfo->lutSize) {
133 return JNI_FALSE;
134 } else {
135 juint i;
136 for (i = 0; i < lutSize; i++) {
137 if (SrcReadLut[i] != DstReadLut[i]) {
138 return JNI_FALSE;
139 }
140 }
141 }
142 }
143 return JNI_TRUE;
144}
145
146DEFINE_CONVERT_BLIT(IntArgb, ByteIndexed, 3ByteRgb)
147
148DEFINE_CONVERT_BLIT(ThreeByteBgr, ByteIndexed, 3ByteRgb)
149
150DEFINE_CONVERT_BLIT(ByteGray, ByteIndexed, 3ByteRgb)
151
152DEFINE_CONVERT_BLIT(Index12Gray, ByteIndexed, 3ByteRgb)
153
154void NAME_CONVERT_BLIT(ByteIndexed, ByteIndexed)
155 (void *srcBase, void *dstBase,
156 juint width, juint height,
157 SurfaceDataRasInfo *pSrcInfo,
158 SurfaceDataRasInfo *pDstInfo,
159 NativePrimitive *pPrim,
160 CompositeInfo *pCompInfo)
161{
162 DeclareByteIndexedLoadVars(SrcRead)
163 DeclareByteIndexedLoadVars(DstRead)
164 jint srcScan = pSrcInfo->scanStride;
165 jint dstScan = pDstInfo->scanStride;
166
167 InitByteIndexedLoadVars(SrcRead, pSrcInfo);
168 InitByteIndexedLoadVars(DstRead, pDstInfo);
169
170 if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) {
171 do {
172 memcpy(dstBase, srcBase, width);
173 srcBase = PtrAddBytes(srcBase, srcScan);
174 dstBase = PtrAddBytes(dstBase, dstScan);
175 } while (--height > 0);
176 } else {
177 DeclareByteIndexedStoreVars(DstWrite);
178
179 BlitLoopWidthHeight(ByteIndexed, pSrc, srcBase, pSrcInfo,
180 ByteIndexed, pDst, dstBase, pDstInfo, DstWrite,
181 width, height,
182 ConvertVia3ByteRgb
183 (pSrc, ByteIndexed, SrcRead,
184 pDst, ByteIndexed, DstWrite, 0, 0));
185 }
186}
187
188DEFINE_SCALE_BLIT(IntArgb, ByteIndexed, 3ByteRgb)
189
190DEFINE_SCALE_BLIT(ThreeByteBgr, ByteIndexed, 3ByteRgb)
191
192DEFINE_SCALE_BLIT(ByteGray, ByteIndexed, 3ByteRgb)
193
194DEFINE_SCALE_BLIT(Index12Gray, ByteIndexed, 3ByteRgb)
195
196void NAME_SCALE_BLIT(ByteIndexed, ByteIndexed)
197 (void *srcBase, void *dstBase,
198 juint width, juint height,
199 jint sxloc, jint syloc,
200 jint sxinc, jint syinc, jint shift,
201 SurfaceDataRasInfo *pSrcInfo,
202 SurfaceDataRasInfo *pDstInfo,
203 NativePrimitive *pPrim,
204 CompositeInfo *pCompInfo)
205{
206 DeclareByteIndexedLoadVars(SrcRead)
207 DeclareByteIndexedLoadVars(DstRead)
208 jint srcScan = pSrcInfo->scanStride;
209 jint dstScan = pDstInfo->scanStride;
210 DeclareByteIndexedStoreVars(DstWrite)
211
212 InitByteIndexedLoadVars(SrcRead, pSrcInfo);
213 InitByteIndexedLoadVars(DstRead, pDstInfo);
214
215 if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) {
216 BlitLoopScaleWidthHeight(ByteIndexed, pSrc, srcBase, pSrcInfo,
217 ByteIndexed, pDst, dstBase, pDstInfo, DstWrite,
218 x, width, height,
219 sxloc, syloc, sxinc, syinc, shift,
220 pDst[0] = pSrc[x]);
221 } else {
222 BlitLoopScaleWidthHeight(ByteIndexed, pSrc, srcBase, pSrcInfo,
223 ByteIndexed, pDst, dstBase, pDstInfo, DstWrite,
224 x, width, height,
225 sxloc, syloc, sxinc, syinc, shift,
226 ConvertVia3ByteRgb(pSrc, ByteIndexed, SrcRead,
227 pDst, ByteIndexed, DstWrite,
228 x, 0));
229 }
230}
231
232DEFINE_XPAR_CONVERT_BLIT_LUT8(ByteIndexedBm, ByteIndexed, ConvertOnTheFly)
233
234DEFINE_XPAR_SCALE_BLIT_LUT8(ByteIndexedBm, ByteIndexed, ConvertOnTheFly)
235
236DEFINE_XPAR_SCALE_BLIT(IntArgbBm, ByteIndexed, 1IntRgb)
237
238DEFINE_XPAR_BLITBG_LUT8(ByteIndexedBm, ByteIndexed, ConvertOnTheFly)
239
240DEFINE_XPAR_CONVERT_BLIT(IntArgbBm, ByteIndexed, 1IntRgb)
241
242DEFINE_XPAR_BLITBG(IntArgbBm, ByteIndexed, 1IntRgb)
243
244DEFINE_XOR_BLIT(IntArgb, ByteIndexed, AnyByte)
245
246DEFINE_ALPHA_MASKFILL(ByteIndexed, 4ByteArgb)
247
248DEFINE_ALPHA_MASKBLIT(IntArgb, ByteIndexed, 4ByteArgb)
249
250DEFINE_ALPHA_MASKBLIT(IntArgbPre, ByteIndexed, 4ByteArgb)
251
252DEFINE_ALPHA_MASKBLIT(IntRgb, ByteIndexed, 4ByteArgb)
253
254DEFINE_SOLID_DRAWGLYPHLISTAA(ByteIndexed, 3ByteRgb)
255
256DEFINE_TRANSFORMHELPERS(ByteIndexed)
257
258DEFINE_TRANSFORMHELPERS(ByteIndexedBm)
259