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