1/*
2 * Copyright (c) 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 "UshortIndexed.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 "UshortIndexed".
43 *
44 * See also LoopMacros.h
45 */
46
47RegisterFunc RegisterUshortIndexed;
48
49DECLARE_CONVERT_BLIT(IntArgb, UshortIndexed);
50DECLARE_CONVERT_BLIT(ThreeByteBgr, UshortIndexed);
51DECLARE_CONVERT_BLIT(ByteGray, UshortIndexed);
52DECLARE_CONVERT_BLIT(UshortIndexed, UshortIndexed);
53DECLARE_CONVERT_BLIT(Index12Gray, UshortIndexed);
54DECLARE_CONVERT_BLIT(UshortIndexed, IntArgb);
55DECLARE_SCALE_BLIT(IntArgb, UshortIndexed);
56DECLARE_SCALE_BLIT(ThreeByteBgr, UshortIndexed);
57DECLARE_SCALE_BLIT(ByteGray, UshortIndexed);
58DECLARE_SCALE_BLIT(Index12Gray, UshortIndexed);
59DECLARE_SCALE_BLIT(UshortIndexed, UshortIndexed);
60DECLARE_SCALE_BLIT(UshortIndexed, IntArgb);
61DECLARE_XPAR_CONVERT_BLIT(ByteIndexedBm, UshortIndexed);
62DECLARE_XPAR_SCALE_BLIT(ByteIndexedBm, UshortIndexed);
63DECLARE_XPAR_SCALE_BLIT(IntArgbBm, UshortIndexed);
64DECLARE_XPAR_BLITBG(ByteIndexedBm, UshortIndexed);
65DECLARE_XPAR_CONVERT_BLIT(IntArgbBm, UshortIndexed);
66DECLARE_XPAR_BLITBG(IntArgbBm, UshortIndexed);
67
68DECLARE_XOR_BLIT(IntArgb, UshortIndexed);
69DECLARE_ALPHA_MASKFILL(UshortIndexed);
70DECLARE_ALPHA_MASKBLIT(IntArgb, UshortIndexed);
71DECLARE_ALPHA_MASKBLIT(IntArgbPre, UshortIndexed);
72DECLARE_ALPHA_MASKBLIT(IntRgb, UshortIndexed);
73DECLARE_SOLID_DRAWGLYPHLISTAA(UshortIndexed);
74
75NativePrimitive UshortIndexedPrimitives[] = {
76    REGISTER_CONVERT_BLIT(IntArgb, UshortIndexed),
77    REGISTER_CONVERT_BLIT_EQUIV(IntRgb, UshortIndexed,
78                                NAME_CONVERT_BLIT(IntArgb, UshortIndexed)),
79    REGISTER_CONVERT_BLIT_EQUIV(IntArgbBm, UshortIndexed,
80                                NAME_CONVERT_BLIT(IntArgb, UshortIndexed)),
81    REGISTER_CONVERT_BLIT(ThreeByteBgr, UshortIndexed),
82    REGISTER_CONVERT_BLIT(ByteGray, UshortIndexed),
83    REGISTER_CONVERT_BLIT(Index12Gray, UshortIndexed),
84    REGISTER_CONVERT_BLIT_FLAGS(UshortIndexed, UshortIndexed, 0, SD_LOCK_LUT),
85    REGISTER_CONVERT_BLIT(UshortIndexed, IntArgb),
86    REGISTER_CONVERT_BLIT_EQUIV(UshortIndexed, IntRgb,
87                                NAME_CONVERT_BLIT(UshortIndexed, IntArgb)),
88    REGISTER_SCALE_BLIT(IntArgb, UshortIndexed),
89    REGISTER_SCALE_BLIT_EQUIV(IntRgb, UshortIndexed,
90                              NAME_SCALE_BLIT(IntArgb, UshortIndexed)),
91    REGISTER_SCALE_BLIT_EQUIV(IntArgbBm, UshortIndexed,
92                              NAME_SCALE_BLIT(IntArgb, UshortIndexed)),
93    REGISTER_SCALE_BLIT(ThreeByteBgr, UshortIndexed),
94    REGISTER_SCALE_BLIT(ByteGray, UshortIndexed),
95    REGISTER_SCALE_BLIT(Index12Gray, UshortIndexed),
96    REGISTER_SCALE_BLIT_FLAGS(UshortIndexed, UshortIndexed, 0, SD_LOCK_LUT),
97    REGISTER_SCALE_BLIT(UshortIndexed, IntArgb),
98    REGISTER_SCALE_BLIT_EQUIV(UshortIndexed, IntRgb,
99                              NAME_SCALE_BLIT(UshortIndexed, IntArgb)),
100    REGISTER_XPAR_CONVERT_BLIT(ByteIndexedBm, UshortIndexed),
101    REGISTER_XPAR_SCALE_BLIT(ByteIndexedBm, UshortIndexed),
102    REGISTER_XPAR_SCALE_BLIT(IntArgbBm, UshortIndexed),
103    REGISTER_XPAR_BLITBG(ByteIndexedBm, UshortIndexed),
104    REGISTER_XPAR_CONVERT_BLIT(IntArgbBm, UshortIndexed),
105    REGISTER_XPAR_BLITBG(IntArgbBm, UshortIndexed),
106
107    REGISTER_XOR_BLIT(IntArgb, UshortIndexed),
108    REGISTER_ALPHA_MASKFILL(UshortIndexed),
109    REGISTER_ALPHA_MASKBLIT(IntArgb, UshortIndexed),
110    REGISTER_ALPHA_MASKBLIT(IntArgbPre, UshortIndexed),
111    REGISTER_ALPHA_MASKBLIT(IntRgb, UshortIndexed),
112    REGISTER_SOLID_DRAWGLYPHLISTAA(UshortIndexed),
113};
114
115extern jint PixelForByteIndexed(SurfaceDataRasInfo *pRasInfo, jint rgb);
116extern jboolean checkSameLut(jint *SrcReadLut, jint *DstReadLut,
117                             SurfaceDataRasInfo *pSrcInfo,
118                             SurfaceDataRasInfo *pDstInfo);
119
120jboolean RegisterUshortIndexed(JNIEnv *env)
121{
122    return RegisterPrimitives(env, UshortIndexedPrimitives,
123                              ArraySize(UshortIndexedPrimitives));
124}
125
126jint PixelForUshortIndexed(SurfaceDataRasInfo *pRasInfo, jint rgb)
127{
128    return PixelForByteIndexed(pRasInfo, rgb);
129}
130
131
132DEFINE_CONVERT_BLIT(IntArgb, UshortIndexed, 3ByteRgb)
133
134DEFINE_CONVERT_BLIT(ThreeByteBgr, UshortIndexed, 3ByteRgb)
135
136DEFINE_CONVERT_BLIT(ByteGray, UshortIndexed, 3ByteRgb)
137
138DEFINE_CONVERT_BLIT(Index12Gray, UshortIndexed, 3ByteRgb)
139
140DEFINE_CONVERT_BLIT_LUT(UshortIndexed, IntArgb, ConvertOnTheFly)
141
142DEFINE_SCALE_BLIT_LUT(UshortIndexed, IntArgb, ConvertOnTheFly)
143
144void NAME_CONVERT_BLIT(UshortIndexed, UshortIndexed)
145    (void *srcBase, void *dstBase,
146     juint width, juint height,
147     SurfaceDataRasInfo *pSrcInfo,
148     SurfaceDataRasInfo *pDstInfo,
149     NativePrimitive *pPrim,
150     CompositeInfo *pCompInfo)
151{
152    DeclareUshortIndexedLoadVars(SrcRead)
153    DeclareUshortIndexedLoadVars(DstRead)
154    jint srcScan = pSrcInfo->scanStride;
155    jint dstScan = pDstInfo->scanStride;
156    jint bytesToCopy = width * pDstInfo->pixelStride;
157
158    InitUshortIndexedLoadVars(SrcRead, pSrcInfo);
159    InitUshortIndexedLoadVars(DstRead, pDstInfo);
160
161    if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) {
162        do {
163            memcpy(dstBase, srcBase, bytesToCopy);
164            srcBase = PtrAddBytes(srcBase, srcScan);
165            dstBase = PtrAddBytes(dstBase, dstScan);
166        } while (--height > 0);
167    } else {
168        DeclareUshortIndexedStoreVars(DstWrite);
169
170        BlitLoopWidthHeight(UshortIndexed, pSrc, srcBase, pSrcInfo,
171                            UshortIndexed, pDst, dstBase, pDstInfo, DstWrite,
172                            width, height,
173                            ConvertVia3ByteRgb
174                                (pSrc, UshortIndexed, SrcRead,
175                                 pDst, UshortIndexed, DstWrite, 0, 0));
176    }
177}
178
179DEFINE_SCALE_BLIT(IntArgb, UshortIndexed, 3ByteRgb)
180
181DEFINE_SCALE_BLIT(ThreeByteBgr, UshortIndexed, 3ByteRgb)
182
183DEFINE_SCALE_BLIT(ByteGray, UshortIndexed, 3ByteRgb)
184
185DEFINE_SCALE_BLIT(Index12Gray, UshortIndexed, 3ByteRgb)
186
187void NAME_SCALE_BLIT(UshortIndexed, UshortIndexed)
188    (void *srcBase, void *dstBase,
189     juint width, juint height,
190     jint sxloc, jint syloc,
191     jint sxinc, jint syinc, jint shift,
192     SurfaceDataRasInfo *pSrcInfo,
193     SurfaceDataRasInfo *pDstInfo,
194     NativePrimitive *pPrim,
195     CompositeInfo *pCompInfo)
196{
197    DeclareUshortIndexedLoadVars(SrcRead)
198    DeclareUshortIndexedLoadVars(DstRead)
199    jint srcScan = pSrcInfo->scanStride;
200    jint dstScan = pDstInfo->scanStride;
201    DeclareUshortIndexedStoreVars(DstWrite)
202
203    InitUshortIndexedLoadVars(SrcRead, pSrcInfo);
204    InitUshortIndexedLoadVars(DstRead, pDstInfo);
205
206    if (checkSameLut(SrcReadLut, DstReadLut, pSrcInfo, pDstInfo)) {
207        BlitLoopScaleWidthHeight(UshortIndexed, pSrc, srcBase, pSrcInfo,
208                                 UshortIndexed, pDst, dstBase, pDstInfo, DstWrite,
209                                 x, width, height,
210                                 sxloc, syloc, sxinc, syinc, shift,
211                                 pDst[0] = pSrc[x]);
212    } else {
213        BlitLoopScaleWidthHeight(UshortIndexed, pSrc, srcBase, pSrcInfo,
214                                 UshortIndexed, pDst, dstBase, pDstInfo, DstWrite,
215                                 x, width, height,
216                                 sxloc, syloc, sxinc, syinc, shift,
217                                 ConvertVia3ByteRgb(pSrc, UshortIndexed, SrcRead,
218                                                    pDst, UshortIndexed, DstWrite,
219                                                    x, 0));
220    }
221}
222
223DEFINE_XPAR_CONVERT_BLIT_LUT(ByteIndexedBm, UshortIndexed, ConvertOnTheFly)
224
225DEFINE_XPAR_SCALE_BLIT_LUT(ByteIndexedBm, UshortIndexed, ConvertOnTheFly)
226
227DEFINE_XPAR_SCALE_BLIT(IntArgbBm, UshortIndexed, 1IntRgb)
228
229DEFINE_XPAR_BLITBG_LUT(ByteIndexedBm, UshortIndexed, ConvertOnTheFly)
230
231DEFINE_XPAR_CONVERT_BLIT(IntArgbBm, UshortIndexed, 1IntRgb)
232
233DEFINE_XPAR_BLITBG(IntArgbBm, UshortIndexed, 1IntRgb)
234
235DEFINE_XOR_BLIT(IntArgb, UshortIndexed, AnyByte)
236
237DEFINE_ALPHA_MASKFILL(UshortIndexed, 4ByteArgb)
238
239DEFINE_ALPHA_MASKBLIT(IntArgb, UshortIndexed, 4ByteArgb)
240
241DEFINE_ALPHA_MASKBLIT(IntArgbPre, UshortIndexed, 4ByteArgb)
242
243DEFINE_ALPHA_MASKBLIT(IntRgb, UshortIndexed, 4ByteArgb)
244
245DEFINE_SOLID_DRAWGLYPHLISTAA(UshortIndexed, 3ByteRgb)
246