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 
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 
47 RegisterFunc RegisterIndex12Gray;
48 
49 DECLARE_CONVERT_BLIT(Index12Gray, IntArgb);
50 DECLARE_CONVERT_BLIT(IntArgb, Index12Gray);
51 DECLARE_CONVERT_BLIT(ThreeByteBgr, Index12Gray);
52 DECLARE_CONVERT_BLIT(ByteGray, Index12Gray);
53 DECLARE_CONVERT_BLIT(Index8Gray, Index12Gray);
54 DECLARE_CONVERT_BLIT(ByteIndexed, Index12Gray);
55 DECLARE_CONVERT_BLIT(Index12Gray, Index12Gray);
56 
57 DECLARE_SCALE_BLIT(Index12Gray, Index12Gray);
58 DECLARE_SCALE_BLIT(Index12Gray, IntArgb);
59 DECLARE_SCALE_BLIT(IntArgb, Index12Gray);
60 DECLARE_SCALE_BLIT(ThreeByteBgr, Index12Gray);
61 DECLARE_SCALE_BLIT(UshortGray, Index12Gray);
62 DECLARE_SCALE_BLIT(ByteIndexed, Index12Gray);
63 DECLARE_SCALE_BLIT(ByteGray, Index12Gray);
64 DECLARE_SCALE_BLIT(Index8Gray, Index12Gray);
65 
66 DECLARE_XPAR_CONVERT_BLIT(ByteIndexedBm, Index12Gray);
67 DECLARE_XPAR_BLITBG(ByteIndexedBm, Index12Gray);
68 
69 DECLARE_XOR_BLIT(IntArgb, Index12Gray);
70 DECLARE_ALPHA_MASKFILL(Index12Gray);
71 DECLARE_ALPHA_MASKBLIT(IntArgb, Index12Gray);
72 DECLARE_ALPHA_MASKBLIT(IntArgbPre, Index12Gray);
73 DECLARE_ALPHA_MASKBLIT(IntRgb, Index12Gray);
74 DECLARE_SRCOVER_MASKFILL(Index12Gray);
75 DECLARE_SRCOVER_MASKBLIT(IntArgb, Index12Gray);
76 DECLARE_SRCOVER_MASKBLIT(IntArgbPre, Index12Gray);
77 DECLARE_SOLID_DRAWGLYPHLISTAA(Index12Gray);
78 
79 DECLARE_TRANSFORMHELPER_FUNCS(Index12Gray);
80 
81 NativePrimitive 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 
121 extern jboolean checkSameLut(jint *SrcReadLut, jint *DstReadLut,
122                              SurfaceDataRasInfo *pSrcInfo,
123                              SurfaceDataRasInfo *pDstInfo);
124 
RegisterIndex12Gray(JNIEnv * env)125 jboolean RegisterIndex12Gray(JNIEnv *env)
126 {
127     return RegisterPrimitives(env, Index12GrayPrimitives,
128                               ArraySize(Index12GrayPrimitives));
129 }
130 
PixelForIndex12Gray(SurfaceDataRasInfo * pRasInfo,jint rgb)131 jint 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 
139 DEFINE_CONVERT_BLIT(IntArgb, Index12Gray, 3ByteRgb)
140 
141 DEFINE_CONVERT_BLIT(ThreeByteBgr, Index12Gray, 3ByteRgb)
142 
143 DEFINE_CONVERT_BLIT(ByteGray, Index12Gray, 1ByteGray)
144 
145 DEFINE_CONVERT_BLIT(Index8Gray, Index12Gray, 1ByteGray)
146 
147 DEFINE_CONVERT_BLIT(ByteIndexed, Index12Gray, 3ByteRgb)
148 
NAME_CONVERT_BLIT(Index12Gray,Index12Gray)149 void 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 
NAME_SCALE_BLIT(Index12Gray,Index12Gray)184 void 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 
222 DEFINE_SCALE_BLIT(Index12Gray, IntArgb, 1IntArgb)
223 
224 DEFINE_SCALE_BLIT(IntArgb, Index12Gray, 3ByteRgb)
225 
226 DEFINE_SCALE_BLIT(ThreeByteBgr, Index12Gray, 3ByteRgb)
227 
228 DEFINE_SCALE_BLIT(UshortGray, Index12Gray, 1ByteGray)
229 
230 DEFINE_SCALE_BLIT_LUT8(ByteIndexed, Index12Gray, PreProcessLut)
231 
232 DEFINE_SCALE_BLIT(ByteGray, Index12Gray, 1ByteGray)
233 
234 DEFINE_SCALE_BLIT_LUT8(Index8Gray, Index12Gray, PreProcessLut)
235 
236 DEFINE_XPAR_CONVERT_BLIT_LUT8(ByteIndexedBm, Index12Gray, PreProcessLut)
237 
238 DEFINE_XPAR_BLITBG_LUT8(ByteIndexedBm, Index12Gray, PreProcessLut)
239 
240 DEFINE_XOR_BLIT(IntArgb, Index12Gray, AnyShort)
241 
242 DEFINE_ALPHA_MASKFILL(Index12Gray, 1ByteGray)
243 
244 DEFINE_ALPHA_MASKBLIT(IntArgb, Index12Gray, 1ByteGray)
245 
246 DEFINE_ALPHA_MASKBLIT(IntArgbPre, Index12Gray, 1ByteGray)
247 
248 DEFINE_ALPHA_MASKBLIT(IntRgb, Index12Gray, 1ByteGray)
249 
250 DEFINE_SRCOVER_MASKFILL(Index12Gray, 1ByteGray)
251 
252 DEFINE_SRCOVER_MASKBLIT(IntArgb, Index12Gray, 1ByteGray)
253 
254 DEFINE_SRCOVER_MASKBLIT(IntArgbPre, Index12Gray, 1ByteGray)
255 
256 DEFINE_SOLID_DRAWGLYPHLISTAA(Index12Gray, 1ByteGray)
257 
258 DEFINE_TRANSFORMHELPERS(Index12Gray)
259