1 | /* |
2 | * Copyright (c) 2001, 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 | #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 | |
47 | RegisterFunc RegisterIndex8Gray; |
48 | |
49 | DECLARE_CONVERT_BLIT(IntArgb, Index8Gray); |
50 | DECLARE_CONVERT_BLIT(ThreeByteBgr, Index8Gray); |
51 | DECLARE_CONVERT_BLIT(ByteGray, Index8Gray); |
52 | DECLARE_CONVERT_BLIT(Index12Gray, Index8Gray); |
53 | DECLARE_CONVERT_BLIT(ByteIndexed, Index8Gray); |
54 | DECLARE_CONVERT_BLIT(Index8Gray, Index8Gray); |
55 | |
56 | DECLARE_SCALE_BLIT(Index8Gray, Index8Gray); |
57 | DECLARE_SCALE_BLIT(IntArgb, Index8Gray); |
58 | DECLARE_SCALE_BLIT(ThreeByteBgr, Index8Gray); |
59 | DECLARE_SCALE_BLIT(UshortGray, Index8Gray); |
60 | DECLARE_SCALE_BLIT(ByteIndexed, Index8Gray); |
61 | DECLARE_SCALE_BLIT(ByteGray, Index8Gray); |
62 | DECLARE_SCALE_BLIT(Index12Gray, Index8Gray); |
63 | |
64 | DECLARE_XPAR_CONVERT_BLIT(ByteIndexedBm, Index8Gray); |
65 | DECLARE_XPAR_BLITBG(ByteIndexedBm, Index8Gray); |
66 | |
67 | DECLARE_XOR_BLIT(IntArgb, Index8Gray); |
68 | DECLARE_ALPHA_MASKFILL(Index8Gray); |
69 | DECLARE_ALPHA_MASKBLIT(IntArgb, Index8Gray); |
70 | DECLARE_ALPHA_MASKBLIT(IntArgbPre, Index8Gray); |
71 | DECLARE_ALPHA_MASKBLIT(IntRgb, Index8Gray); |
72 | DECLARE_SRCOVER_MASKFILL(Index8Gray); |
73 | DECLARE_SRCOVER_MASKBLIT(IntArgb, Index8Gray); |
74 | DECLARE_SRCOVER_MASKBLIT(IntArgbPre, Index8Gray); |
75 | DECLARE_SOLID_DRAWGLYPHLISTAA(Index8Gray); |
76 | |
77 | DECLARE_TRANSFORMHELPER_FUNCS(Index8Gray); |
78 | |
79 | NativePrimitive 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 | |
118 | extern jboolean checkSameLut(jint *SrcReadLut, jint *DstReadLut, |
119 | SurfaceDataRasInfo *pSrcInfo, |
120 | SurfaceDataRasInfo *pDstInfo); |
121 | |
122 | jboolean RegisterIndex8Gray(JNIEnv *env) |
123 | { |
124 | return RegisterPrimitives(env, Index8GrayPrimitives, |
125 | ArraySize(Index8GrayPrimitives)); |
126 | } |
127 | |
128 | jint 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 | |
136 | DEFINE_CONVERT_BLIT(IntArgb, Index8Gray, 3ByteRgb) |
137 | |
138 | DEFINE_CONVERT_BLIT(ThreeByteBgr, Index8Gray, 3ByteRgb) |
139 | |
140 | DEFINE_CONVERT_BLIT(ByteGray, Index8Gray, 1ByteGray) |
141 | |
142 | DEFINE_CONVERT_BLIT(Index12Gray, Index8Gray, 1ByteGray) |
143 | |
144 | DEFINE_CONVERT_BLIT_LUT8(ByteIndexed, Index8Gray, PreProcessLut) |
145 | |
146 | void 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 | |
181 | void 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 | |
219 | DEFINE_SCALE_BLIT(IntArgb, Index8Gray, 3ByteRgb) |
220 | |
221 | DEFINE_SCALE_BLIT(ThreeByteBgr, Index8Gray, 3ByteRgb) |
222 | |
223 | DEFINE_SCALE_BLIT(UshortGray, Index8Gray, 1ByteGray) |
224 | |
225 | DEFINE_SCALE_BLIT_LUT8(ByteIndexed, Index8Gray, PreProcessLut) |
226 | |
227 | DEFINE_SCALE_BLIT(ByteGray, Index8Gray, 1ByteGray) |
228 | |
229 | DEFINE_SCALE_BLIT(Index12Gray, Index8Gray, 1ByteGray) |
230 | |
231 | DEFINE_XPAR_CONVERT_BLIT_LUT8(ByteIndexedBm, Index8Gray, PreProcessLut) |
232 | |
233 | DEFINE_XPAR_BLITBG_LUT8(ByteIndexedBm, Index8Gray, PreProcessLut) |
234 | |
235 | DEFINE_XOR_BLIT(IntArgb, Index8Gray, AnyByte) |
236 | |
237 | DEFINE_ALPHA_MASKFILL(Index8Gray, 1ByteGray) |
238 | |
239 | DEFINE_ALPHA_MASKBLIT(IntArgb, Index8Gray, 1ByteGray) |
240 | |
241 | DEFINE_ALPHA_MASKBLIT(IntArgbPre, Index8Gray, 1ByteGray) |
242 | |
243 | DEFINE_ALPHA_MASKBLIT(IntRgb, Index8Gray, 1ByteGray) |
244 | |
245 | DEFINE_SRCOVER_MASKFILL(Index8Gray, 1ByteGray) |
246 | |
247 | DEFINE_SRCOVER_MASKBLIT(IntArgb, Index8Gray, 1ByteGray) |
248 | |
249 | DEFINE_SRCOVER_MASKBLIT(IntArgbPre, Index8Gray, 1ByteGray) |
250 | |
251 | DEFINE_SOLID_DRAWGLYPHLISTAA(Index8Gray, 1ByteGray) |
252 | |
253 | DEFINE_TRANSFORMHELPERS(Index8Gray) |
254 | |