1/*
2 * Copyright (c) 2003, 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#if !defined(JAVA2D_NO_MLIB) || defined(MLIB_ADD_SUFF)
27
28#include <vis_proto.h>
29#include <mlib_image.h>
30
31#include "java2d_Mlib.h"
32#include "AlphaMacros.h"
33
34/***************************************************************/
35
36extern const mlib_u32 vis_mul8s_tbl[];
37extern const mlib_u64 vis_div8_tbl[];
38extern const mlib_u64 vis_div8pre_tbl[];
39
40/***************************************************************/
41
42void IntArgbToIntAbgrConvert_line(mlib_s32 *srcBase,
43                                  mlib_s32 *dstBase,
44                                  mlib_s32 width);
45
46/***************************************************************/
47
48#define BUFF_SIZE  256
49
50/***************************************************************/
51
52#define COPY_NA(src, dst, _size) {                             \
53    mlib_s32 cci, size = _size;                                \
54    if (size <= 16) {                                          \
55        for (cci = 0; cci < size; cci++) {                     \
56            ((mlib_u8*)dst)[cci] = ((mlib_u8*)src)[cci];       \
57        }                                                      \
58    } else {                                                   \
59        mlib_ImageCopy_na(src, dst, size);                     \
60    }                                                          \
61}
62
63/***************************************************************/
64
65#define MUL8_INT(x, y) mul8_tbl[256*(y) + (x)]
66
67#define FMUL_16x16(x, y)       \
68    vis_fpadd16(vis_fmul8sux16(x, y), vis_fmul8ulx16(x, y))
69
70/***************************************************************/
71
72#define MUL8_VIS(rr, alp)      \
73    vis_fmul8x16al(rr, ((mlib_f32 *)vis_mul8s_tbl)[alp])
74
75#define DIV_ALPHA(rr, alp) {                           \
76    mlib_d64 d_div = ((mlib_d64*)vis_div8_tbl)[alp];   \
77    rr = FMUL_16x16(rr, d_div);                        \
78}
79
80#define DIV_ALPHA_RGB(rr, alp)         \
81    DIV_ALPHA(rr, alp)
82
83/***************************************************************/
84
85#define BLEND_VIS(rr, dstARGB, srcARGB, dstA, srcA)    \
86{                                                      \
87    mlib_d64 t0, t1;                                   \
88                                                       \
89    t0 = MUL8_VIS(srcARGB, srcA);                      \
90    t1 = MUL8_VIS(dstARGB, dstA);                      \
91    rr = vis_fpadd16(t0, t1);                          \
92                                                       \
93    dstA += srcA;                                      \
94    DIV_ALPHA(rr, dstA);                               \
95}
96
97#define BLEND_VIS_RGB(rr, dstARGB, srcARGB, dstA, srcA)        \
98    BLEND_VIS(rr, dstARGB, srcARGB, dstA, srcA)
99
100/***************************************************************/
101
102#if 0
103extern const mlib_u16 vis_div8_16_tbl[];
104
105#undef  BLEND_VIS
106#define BLEND_VIS(rr, dstARGB, srcARGB, dstA, srcA)                    \
107{                                                                      \
108    mlib_d64 done = vis_to_double_dup(0x00FFFFFF);                     \
109    mlib_d64 t0, t1;                                                   \
110    mlib_f32 s0, s1;                                                   \
111    mlib_s32 resA;                                                     \
112                                                                       \
113    resA = dstA + srcA;                                                \
114    t0 = vis_ld_u16((mlib_u16*)vis_div8_16_tbl + 256*srcA + resA);     \
115    t1 = vis_ld_u16((mlib_u16*)vis_div8_16_tbl + 256*dstA + resA);     \
116    dstA = resA;                                                       \
117                                                                       \
118    t0 = vis_fmul8x16al(srcARGB, vis_read_lo(t0));                     \
119    t1 = vis_fmul8x16al(dstARGB, vis_read_lo(t1));                     \
120    rr = vis_fpadd16(t0, t1);                                          \
121}
122
123#define BLEND_VIS_RGB(rr, dstARGB, srcARGB, dstA, srcA)        \
124{                                                              \
125    mlib_d64 maskRGB = vis_to_double_dup(0x00FFFFFF);          \
126                                                               \
127    BLEND_VIS(rr, dstARGB, srcARGB, dstA, srcA)                \
128                                                               \
129    rr = vis_fand(rr, maskRGB);                                \
130}
131
132#endif
133
134/***************************************************************/
135
136#define F32_FROM_U8x4(x0, x1, x2, x3)          \
137    vis_to_float(((x0) << 24) | ((x1) << 16) | ((x2)<< 8) | ((x3)))
138
139/***************************************************************/
140
141#define D64_FROM_U8x8(dd, val)         \
142    val &= 0xFF;                       \
143    val |= (val << 8);                 \
144    val |= (val << 16);                \
145    dd = vis_to_double_dup(val)
146
147/***************************************************************/
148
149#define D64_FROM_U16x4(dd, val)        \
150    val &= 0xFFFF;                     \
151    val |= (val << 16);                \
152    dd = vis_to_double_dup(val)
153
154/***************************************************************/
155
156#define D64_FROM_F32x2(ff)     \
157    vis_freg_pair(ff, ff)
158
159/***************************************************************/
160
161#if VIS >= 0x200
162
163#define ARGB2ABGR_FL(src)      \
164    src = vis_read_hi(vis_bshuffle(vis_freg_pair(src, vis_fzeros()), 0));
165
166#define ARGB2ABGR_FL2(dst, src0, src1)         \
167    dst = vis_freg_pair(src0, src1);           \
168    dst = vis_bshuffle(dst, 0)
169
170#define ARGB2ABGR_DB(src)      \
171    src = vis_bshuffle(src, 0);
172
173#else
174
175#define ARGB2ABGR_FL(src) {                                    \
176    mlib_d64 t0, t1, t2, t3;                                   \
177    t0 = vis_fpmerge(src, src);                                \
178    t1 = vis_fpmerge(vis_read_lo(t0), vis_read_hi(t0));        \
179    t2 = vis_fpmerge(vis_read_hi(t0), vis_read_lo(t0));        \
180    t3 = vis_fpmerge(vis_read_hi(t2), vis_read_lo(t1));        \
181    src = vis_read_hi(t3);                                     \
182}
183
184#define ARGB2ABGR_FL2(dst, src0, src1) {                       \
185    mlib_d64 t0, t1, t2;                                       \
186    t0 = vis_fpmerge(src0, src1);                              \
187    t1 = vis_fpmerge(vis_read_lo(t0), vis_read_hi(t0));        \
188    t2 = vis_fpmerge(vis_read_hi(t0), vis_read_lo(t0));        \
189    dst = vis_fpmerge(vis_read_hi(t2), vis_read_lo(t1));       \
190}
191
192#define ARGB2ABGR_DB(src)      \
193    ARGB2ABGR_FL2(src, vis_read_hi(src), vis_read_lo(src))
194
195#endif
196
197/***************************************************************/
198
199#endif /* JAVA2D_NO_MLIB */
200