2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
|
2
|
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
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
|
|
27 |
#include "mlib_image.h"
|
|
28 |
#include "mlib_ImageAffine.h"
|
|
29 |
#include "mlib_ImageColormap.h"
|
|
30 |
|
|
31 |
/***************************************************************/
|
|
32 |
#define MLIB_LIMIT 512
|
|
33 |
|
|
34 |
/***************************************************************/
|
|
35 |
#define DTYPE MLIB_TYPE
|
|
36 |
|
|
37 |
/***************************************************************/
|
|
38 |
#define DECLAREVAR_IND() \
|
|
39 |
DECLAREVAR0(); \
|
|
40 |
mlib_s32 *warp_tbl = param -> warp_tbl; \
|
|
41 |
mlib_s32 xSrc, ySrc; \
|
|
42 |
mlib_s32 srcYStride = param -> srcYStride; \
|
|
43 |
mlib_s32 max_xsize = param -> max_xsize; \
|
|
44 |
MLIB_TYPE *sp0, *sp1; \
|
|
45 |
MLIB_TYPE *dl; \
|
|
46 |
mlib_d64 scale = 1.0 / 65536.0; \
|
|
47 |
mlib_s32 i, size
|
|
48 |
|
|
49 |
/***************************************************************/
|
|
50 |
#define DECLARE_INTERNAL_VAR_3CH() \
|
|
51 |
mlib_d64 fdx, fdy; \
|
|
52 |
mlib_d64 a00_0, a01_0, a10_0, a11_0; \
|
|
53 |
mlib_d64 a00_1, a01_1, a10_1, a11_1; \
|
|
54 |
mlib_d64 a00_2, a01_2, a10_2, a11_2; \
|
|
55 |
mlib_d64 pix0_0, pix1_0, res0; \
|
|
56 |
mlib_d64 pix0_1, pix1_1, res1; \
|
|
57 |
mlib_d64 pix0_2, pix1_2, res2
|
|
58 |
|
|
59 |
/***************************************************************/
|
|
60 |
#define DECLARE_INTERNAL_VAR_4CH() \
|
|
61 |
mlib_d64 fdx, fdy; \
|
|
62 |
mlib_d64 a00_0, a01_0, a10_0, a11_0; \
|
|
63 |
mlib_d64 a00_1, a01_1, a10_1, a11_1; \
|
|
64 |
mlib_d64 a00_2, a01_2, a10_2, a11_2; \
|
|
65 |
mlib_d64 a00_3, a01_3, a10_3, a11_3; \
|
|
66 |
mlib_d64 pix0_0, pix1_0, res0; \
|
|
67 |
mlib_d64 pix0_1, pix1_1, res1; \
|
|
68 |
mlib_d64 pix0_2, pix1_2, res2; \
|
|
69 |
mlib_d64 pix0_3, pix1_3, res3
|
|
70 |
|
|
71 |
/***************************************************************/
|
|
72 |
#define GET_PIXELS_POINTERS() \
|
|
73 |
fdx = (X & MLIB_MASK) * scale; \
|
|
74 |
fdy = (Y & MLIB_MASK) * scale; \
|
|
75 |
ySrc = MLIB_POINTER_SHIFT(Y); Y += dY; \
|
|
76 |
xSrc = X >> MLIB_SHIFT; X += dX; \
|
|
77 |
sp0 = MLIB_POINTER_GET(lineAddr, ySrc) + xSrc; \
|
|
78 |
sp1 = (MLIB_TYPE *)((mlib_u8 *)sp0 + srcYStride)
|
|
79 |
|
|
80 |
/***************************************************************/
|
|
81 |
#define GET_COLOR_POINTERS(ind) \
|
|
82 |
pcolor00 = (lut + sp0[0]*ind); \
|
|
83 |
pcolor10 = (lut + sp1[0]*ind); \
|
|
84 |
pcolor01 = (lut + sp0[1]*ind); \
|
|
85 |
pcolor11 = (lut + sp1[1]*ind)
|
|
86 |
|
|
87 |
/***************************************************************/
|
|
88 |
#define COUNT_BL_U8(ind) \
|
|
89 |
pix0_##ind = a00_##ind + fdy * (a10_##ind - a00_##ind); \
|
|
90 |
pix1_##ind = a01_##ind + fdy * (a11_##ind - a01_##ind); \
|
|
91 |
res##ind = pix0_##ind + fdx * (pix1_##ind - pix0_##ind) + 0.5
|
|
92 |
|
|
93 |
/***************************************************************/
|
|
94 |
#define COUNT_BL_U8_3CH() \
|
|
95 |
COUNT_BL_U8(0); \
|
|
96 |
COUNT_BL_U8(1); \
|
|
97 |
COUNT_BL_U8(2);
|
|
98 |
|
|
99 |
/***************************************************************/
|
|
100 |
#define COUNT_BL_U8_4CH() \
|
|
101 |
COUNT_BL_U8_3CH(); \
|
|
102 |
COUNT_BL_U8(3);
|
|
103 |
|
|
104 |
/***************************************************************/
|
|
105 |
#define COUNT_BL_S16(ind) \
|
|
106 |
pix0_##ind = a00_##ind + fdy * (a10_##ind - a00_##ind); \
|
|
107 |
pix1_##ind = a01_##ind + fdy * (a11_##ind - a01_##ind); \
|
|
108 |
res##ind = pix0_##ind + fdx * (pix1_##ind - pix0_##ind)
|
|
109 |
|
|
110 |
/***************************************************************/
|
|
111 |
#define COUNT_BL_S16_3CH() \
|
|
112 |
COUNT_BL_S16(0); \
|
|
113 |
COUNT_BL_S16(1); \
|
|
114 |
COUNT_BL_S16(2);
|
|
115 |
|
|
116 |
/***************************************************************/
|
|
117 |
#define COUNT_BL_S16_4CH() \
|
|
118 |
COUNT_BL_S16_3CH(); \
|
|
119 |
COUNT_BL_S16(3);
|
|
120 |
|
|
121 |
/***************************************************************/
|
|
122 |
#define LOAD(ind) \
|
|
123 |
a00_##ind = pcolor00[ind]; \
|
|
124 |
a01_##ind = pcolor01[ind]; \
|
|
125 |
a10_##ind = pcolor10[ind]; \
|
|
126 |
a11_##ind = pcolor11[ind]
|
|
127 |
|
|
128 |
/***************************************************************/
|
|
129 |
#define LOAD_3CH() \
|
|
130 |
LOAD(0); \
|
|
131 |
LOAD(1); \
|
|
132 |
LOAD(2);
|
|
133 |
|
|
134 |
/***************************************************************/
|
|
135 |
#define LOAD_4CH() \
|
|
136 |
LOAD_3CH(); \
|
|
137 |
LOAD(3);
|
|
138 |
|
|
139 |
/***************************************************************/
|
|
140 |
#define STORE_INTO_INTERM_BUF_3CH(LTYPE) \
|
|
141 |
dp[0] = (mlib_##LTYPE)res0; \
|
|
142 |
dp[1] = (mlib_##LTYPE)res1; \
|
|
143 |
dp[2] = (mlib_##LTYPE)res2
|
|
144 |
|
|
145 |
/***************************************************************/
|
|
146 |
#define STORE_INTO_INTERM_BUF_4CH(LTYPE) \
|
|
147 |
dp[0] = (mlib_##LTYPE)res0; \
|
|
148 |
dp[1] = (mlib_##LTYPE)res1; \
|
|
149 |
dp[2] = (mlib_##LTYPE)res2; \
|
|
150 |
dp[3] = (mlib_##LTYPE)res3
|
|
151 |
|
|
152 |
/***************************************************************/
|
|
153 |
#undef MLIB_TYPE
|
|
154 |
#define MLIB_TYPE mlib_u8
|
|
155 |
|
|
156 |
/***************************************************************/
|
|
157 |
#define mlib_U8 mlib_u8
|
|
158 |
#define mlib_S16 mlib_s16
|
|
159 |
|
|
160 |
/***************************************************************/
|
|
161 |
#define FUNC_AFFINEINDEX_BL_0(ITYPE, LTYPE, NCHAN) \
|
|
162 |
mlib_status mlib_ImageAffineIndex_##ITYPE##_##LTYPE##_##NCHAN##CH_BL(mlib_affine_param *param, \
|
|
163 |
const void *colormap) \
|
|
164 |
{ \
|
|
165 |
DECLAREVAR_IND(); \
|
|
166 |
mlib_##LTYPE *dp, buff_lcl[NCHAN*MLIB_LIMIT], *pbuff = buff_lcl; \
|
|
167 |
mlib_d64 *pcolor00, *pcolor10, *pcolor01, *pcolor11; \
|
|
168 |
mlib_d64 *lut = mlib_ImageGetLutDoubleData(colormap); \
|
|
169 |
\
|
|
170 |
lut -= NCHAN*mlib_ImageGetLutOffset(colormap); \
|
|
171 |
\
|
|
172 |
if (max_xsize > MLIB_LIMIT) { \
|
|
173 |
pbuff = mlib_malloc(NCHAN * sizeof(mlib_##LTYPE) * max_xsize); \
|
|
174 |
if (pbuff == NULL) return MLIB_FAILURE; \
|
|
175 |
} \
|
|
176 |
\
|
|
177 |
for (j = yStart; j <= yFinish; j++) { \
|
|
178 |
DECLARE_INTERNAL_VAR_##NCHAN##CH(); \
|
|
179 |
\
|
|
180 |
NEW_LINE(1); \
|
|
181 |
dp = pbuff; \
|
|
182 |
\
|
|
183 |
GET_PIXELS_POINTERS(); \
|
|
184 |
GET_COLOR_POINTERS(NCHAN); \
|
|
185 |
LOAD_##NCHAN##CH();
|
|
186 |
|
|
187 |
/* pragma pipeloop(0) must be here */
|
|
188 |
|
|
189 |
/***************************************************************/
|
|
190 |
#define FUNC_AFFINEINDEX_BL_1(ITYPE, LTYPE, NCHAN) \
|
|
191 |
for (i = 0; i < (xRight - xLeft); i++, dp += NCHAN) { \
|
|
192 |
COUNT_BL_##LTYPE##_##NCHAN##CH(); \
|
|
193 |
\
|
|
194 |
GET_PIXELS_POINTERS(); \
|
|
195 |
GET_COLOR_POINTERS(NCHAN); \
|
|
196 |
LOAD_##NCHAN##CH(); \
|
|
197 |
\
|
|
198 |
STORE_INTO_INTERM_BUF_##NCHAN##CH(LTYPE); \
|
|
199 |
} \
|
|
200 |
\
|
|
201 |
COUNT_BL_##LTYPE##_##NCHAN##CH(); \
|
|
202 |
STORE_INTO_INTERM_BUF_##NCHAN##CH(LTYPE); \
|
|
203 |
\
|
|
204 |
mlib_ImageColorTrue2IndexLine_##LTYPE##_##ITYPE##_##NCHAN \
|
|
205 |
(pbuff, dl, xRight - xLeft + 1, colormap); \
|
|
206 |
} \
|
|
207 |
\
|
|
208 |
if (pbuff != buff_lcl) mlib_free(pbuff); \
|
|
209 |
\
|
|
210 |
return MLIB_SUCCESS; \
|
|
211 |
}
|
|
212 |
|
|
213 |
/***************************************************************/
|
|
214 |
#undef MLIB_TYPE
|
|
215 |
#define MLIB_TYPE mlib_u8
|
|
216 |
|
|
217 |
FUNC_AFFINEINDEX_BL_0(U8, U8, 3)
|
|
218 |
#ifdef __SUNPRO_C
|
|
219 |
#pragma pipeloop(0)
|
|
220 |
#endif /* __SUNPRO_C */
|
|
221 |
FUNC_AFFINEINDEX_BL_1(U8, U8, 3)
|
|
222 |
|
|
223 |
FUNC_AFFINEINDEX_BL_0(U8, S16, 3)
|
|
224 |
#ifdef __SUNPRO_C
|
|
225 |
#pragma pipeloop(0)
|
|
226 |
#endif /* __SUNPRO_C */
|
|
227 |
FUNC_AFFINEINDEX_BL_1(U8, S16, 3)
|
|
228 |
|
|
229 |
FUNC_AFFINEINDEX_BL_0(U8, U8, 4)
|
|
230 |
#ifdef __SUNPRO_C
|
|
231 |
#pragma pipeloop(0)
|
|
232 |
#endif /* __SUNPRO_C */
|
|
233 |
FUNC_AFFINEINDEX_BL_1(U8, U8, 4)
|
|
234 |
|
|
235 |
FUNC_AFFINEINDEX_BL_0(U8, S16, 4)
|
|
236 |
#ifdef __SUNPRO_C
|
|
237 |
#pragma pipeloop(0)
|
|
238 |
#endif /* __SUNPRO_C */
|
|
239 |
FUNC_AFFINEINDEX_BL_1(U8, S16, 4)
|
|
240 |
|
|
241 |
/***************************************************************/
|
|
242 |
#undef MLIB_TYPE
|
|
243 |
#define MLIB_TYPE mlib_s16
|
|
244 |
|
|
245 |
FUNC_AFFINEINDEX_BL_0(S16, U8, 3)
|
|
246 |
#ifdef __SUNPRO_C
|
|
247 |
#pragma pipeloop(0)
|
|
248 |
#endif /* __SUNPRO_C */
|
|
249 |
FUNC_AFFINEINDEX_BL_1(S16, U8, 3)
|
|
250 |
|
|
251 |
FUNC_AFFINEINDEX_BL_0(S16, S16, 3)
|
|
252 |
#ifdef __SUNPRO_C
|
|
253 |
#pragma pipeloop(0)
|
|
254 |
#endif /* __SUNPRO_C */
|
|
255 |
FUNC_AFFINEINDEX_BL_1(S16, S16, 3)
|
|
256 |
|
|
257 |
FUNC_AFFINEINDEX_BL_0(S16, U8, 4)
|
|
258 |
#ifdef __SUNPRO_C
|
|
259 |
#pragma pipeloop(0)
|
|
260 |
#endif /* __SUNPRO_C */
|
|
261 |
FUNC_AFFINEINDEX_BL_1(S16, U8, 4)
|
|
262 |
|
|
263 |
FUNC_AFFINEINDEX_BL_0(S16, S16, 4)
|
|
264 |
#ifdef __SUNPRO_C
|
|
265 |
#pragma pipeloop(0)
|
|
266 |
#endif /* __SUNPRO_C */
|
|
267 |
FUNC_AFFINEINDEX_BL_1(S16, S16, 4)
|
|
268 |
|
|
269 |
/***************************************************************/
|
|
270 |
const type_affine_i_fun mlib_AffineFunArr_bl_i[] = {
|
|
271 |
mlib_ImageAffineIndex_U8_U8_3CH_BL,
|
|
272 |
mlib_ImageAffineIndex_U8_U8_4CH_BL,
|
|
273 |
mlib_ImageAffineIndex_S16_U8_3CH_BL,
|
|
274 |
mlib_ImageAffineIndex_S16_U8_4CH_BL,
|
|
275 |
mlib_ImageAffineIndex_U8_S16_3CH_BL,
|
|
276 |
mlib_ImageAffineIndex_U8_S16_4CH_BL,
|
|
277 |
mlib_ImageAffineIndex_S16_S16_3CH_BL,
|
|
278 |
mlib_ImageAffineIndex_S16_S16_4CH_BL
|
|
279 |
};
|
|
280 |
/***************************************************************/
|