1/*
2 * Copyright (c) 2003, 2012, 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
27#ifndef __MLIB_IMAGEAFFINE_H
28#define __MLIB_IMAGEAFFINE_H
29
30#include "mlib_image.h"
31#include "mlib_ImageDivTables.h"
32#include "mlib_ImageFilters.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif /* __cplusplus */
37
38/*
39 * DESCRIPTION
40 * Internal macro for mlib_ImageAffine.
41 *
42 * DTYPE define must be set to data type of image.
43 * FTYPE define must be set to type of floating-point operations.
44 */
45
46/***************************************************************/
47typedef struct {
48 mlib_image *src;
49 mlib_image *dst;
50 mlib_u8 *buff_malloc;
51 mlib_u8 **lineAddr;
52 mlib_u8 *dstData;
53 mlib_s32 *leftEdges;
54 mlib_s32 *rightEdges;
55 mlib_s32 *xStarts;
56 mlib_s32 *yStarts;
57 mlib_s32 yStart;
58 mlib_s32 yFinish;
59 mlib_s32 dX;
60 mlib_s32 dY;
61 mlib_s32 max_xsize;
62 mlib_s32 srcYStride;
63 mlib_s32 dstYStride;
64 mlib_s32 *warp_tbl;
65 mlib_filter filter;
66} mlib_affine_param;
67
68/***************************************************************/
69
70#define LOAD_PARAM(param, x) x = param->x
71#define STORE_PARAM(param, x) param->x=x
72
73/***************************************************************/
74mlib_status mlib_AffineEdges(mlib_affine_param *param,
75 const mlib_image *dst,
76 const mlib_image *src,
77 void *buff_lcl,
78 mlib_s32 buff_size,
79 mlib_s32 kw,
80 mlib_s32 kh,
81 mlib_s32 kw1,
82 mlib_s32 kh1,
83 mlib_edge edge,
84 const mlib_d64 *mtx,
85 mlib_s32 shiftx,
86 mlib_s32 shifty);
87
88/***************************************************************/
89typedef mlib_status (*type_affine_fun)(mlib_affine_param *param);
90
91/***************************************************************/
92void mlib_ImageAffine_bit_1ch_nn(mlib_affine_param *param,
93 mlib_s32 s_bitoff,
94 mlib_s32 d_bitoff);
95
96mlib_status mlib_ImageAffine_u8_1ch_nn(mlib_affine_param *param);
97mlib_status mlib_ImageAffine_u8_2ch_nn(mlib_affine_param *param);
98mlib_status mlib_ImageAffine_u8_3ch_nn(mlib_affine_param *param);
99mlib_status mlib_ImageAffine_u8_4ch_nn(mlib_affine_param *param);
100mlib_status mlib_ImageAffine_s16_1ch_nn(mlib_affine_param *param);
101mlib_status mlib_ImageAffine_s16_2ch_nn(mlib_affine_param *param);
102mlib_status mlib_ImageAffine_s16_3ch_nn(mlib_affine_param *param);
103mlib_status mlib_ImageAffine_s16_4ch_nn(mlib_affine_param *param);
104mlib_status mlib_ImageAffine_s32_1ch_nn(mlib_affine_param *param);
105mlib_status mlib_ImageAffine_s32_2ch_nn(mlib_affine_param *param);
106mlib_status mlib_ImageAffine_s32_3ch_nn(mlib_affine_param *param);
107mlib_status mlib_ImageAffine_s32_4ch_nn(mlib_affine_param *param);
108mlib_status mlib_ImageAffine_d64_1ch_nn(mlib_affine_param *param);
109mlib_status mlib_ImageAffine_d64_2ch_nn(mlib_affine_param *param);
110mlib_status mlib_ImageAffine_d64_3ch_nn(mlib_affine_param *param);
111mlib_status mlib_ImageAffine_d64_4ch_nn(mlib_affine_param *param);
112
113mlib_status mlib_ImageAffine_u8_1ch_bl(mlib_affine_param *param);
114mlib_status mlib_ImageAffine_u8_2ch_bl(mlib_affine_param *param);
115mlib_status mlib_ImageAffine_u8_3ch_bl(mlib_affine_param *param);
116mlib_status mlib_ImageAffine_u8_4ch_bl(mlib_affine_param *param);
117mlib_status mlib_ImageAffine_s16_1ch_bl(mlib_affine_param *param);
118mlib_status mlib_ImageAffine_s16_2ch_bl(mlib_affine_param *param);
119mlib_status mlib_ImageAffine_s16_3ch_bl(mlib_affine_param *param);
120mlib_status mlib_ImageAffine_s16_4ch_bl(mlib_affine_param *param);
121mlib_status mlib_ImageAffine_u16_1ch_bl(mlib_affine_param *param);
122mlib_status mlib_ImageAffine_u16_2ch_bl(mlib_affine_param *param);
123mlib_status mlib_ImageAffine_u16_3ch_bl(mlib_affine_param *param);
124mlib_status mlib_ImageAffine_u16_4ch_bl(mlib_affine_param *param);
125mlib_status mlib_ImageAffine_s32_1ch_bl(mlib_affine_param *param);
126mlib_status mlib_ImageAffine_s32_2ch_bl(mlib_affine_param *param);
127mlib_status mlib_ImageAffine_s32_3ch_bl(mlib_affine_param *param);
128mlib_status mlib_ImageAffine_s32_4ch_bl(mlib_affine_param *param);
129mlib_status mlib_ImageAffine_f32_1ch_bl(mlib_affine_param *param);
130mlib_status mlib_ImageAffine_f32_2ch_bl(mlib_affine_param *param);
131mlib_status mlib_ImageAffine_f32_3ch_bl(mlib_affine_param *param);
132mlib_status mlib_ImageAffine_f32_4ch_bl(mlib_affine_param *param);
133mlib_status mlib_ImageAffine_d64_1ch_bl(mlib_affine_param *param);
134mlib_status mlib_ImageAffine_d64_2ch_bl(mlib_affine_param *param);
135mlib_status mlib_ImageAffine_d64_3ch_bl(mlib_affine_param *param);
136mlib_status mlib_ImageAffine_d64_4ch_bl(mlib_affine_param *param);
137
138mlib_status mlib_ImageAffine_u8_1ch_bc(mlib_affine_param *param);
139mlib_status mlib_ImageAffine_u8_2ch_bc(mlib_affine_param *param);
140mlib_status mlib_ImageAffine_u8_3ch_bc(mlib_affine_param *param);
141mlib_status mlib_ImageAffine_u8_4ch_bc(mlib_affine_param *param);
142mlib_status mlib_ImageAffine_s16_1ch_bc(mlib_affine_param *param);
143mlib_status mlib_ImageAffine_s16_2ch_bc(mlib_affine_param *param);
144mlib_status mlib_ImageAffine_s16_3ch_bc(mlib_affine_param *param);
145mlib_status mlib_ImageAffine_s16_4ch_bc(mlib_affine_param *param);
146mlib_status mlib_ImageAffine_u16_1ch_bc(mlib_affine_param *param);
147mlib_status mlib_ImageAffine_u16_2ch_bc(mlib_affine_param *param);
148mlib_status mlib_ImageAffine_u16_3ch_bc(mlib_affine_param *param);
149mlib_status mlib_ImageAffine_u16_4ch_bc(mlib_affine_param *param);
150mlib_status mlib_ImageAffine_s32_1ch_bc(mlib_affine_param *param);
151mlib_status mlib_ImageAffine_s32_2ch_bc(mlib_affine_param *param);
152mlib_status mlib_ImageAffine_s32_3ch_bc(mlib_affine_param *param);
153mlib_status mlib_ImageAffine_s32_4ch_bc(mlib_affine_param *param);
154mlib_status mlib_ImageAffine_f32_1ch_bc(mlib_affine_param *param);
155mlib_status mlib_ImageAffine_f32_2ch_bc(mlib_affine_param *param);
156mlib_status mlib_ImageAffine_f32_3ch_bc(mlib_affine_param *param);
157mlib_status mlib_ImageAffine_f32_4ch_bc(mlib_affine_param *param);
158mlib_status mlib_ImageAffine_d64_1ch_bc(mlib_affine_param *param);
159mlib_status mlib_ImageAffine_d64_2ch_bc(mlib_affine_param *param);
160mlib_status mlib_ImageAffine_d64_3ch_bc(mlib_affine_param *param);
161mlib_status mlib_ImageAffine_d64_4ch_bc(mlib_affine_param *param);
162
163/***************************************************************/
164void mlib_ImageAffineEdgeZero(mlib_affine_param *param,
165 mlib_affine_param *param_e);
166
167void mlib_ImageAffineEdgeNearest(mlib_affine_param *param,
168 mlib_affine_param *param_e);
169
170mlib_status mlib_ImageAffineEdgeExtend_BL(mlib_affine_param *param,
171 mlib_affine_param *param_e);
172
173mlib_status mlib_ImageAffineEdgeExtend_BC(mlib_affine_param *param,
174 mlib_affine_param *param_e);
175
176/***************************************************************/
177mlib_status mlib_ImageAffine_alltypes(mlib_image *dst,
178 const mlib_image *src,
179 const mlib_d64 *mtx,
180 mlib_filter filter,
181 mlib_edge edge);
182
183/***************************************************************/
184extern const type_affine_fun mlib_AffineFunArr_nn[];
185extern const type_affine_fun mlib_AffineFunArr_bl[];
186extern const type_affine_fun mlib_AffineFunArr_bc[];
187
188/***************************************************************/
189typedef union {
190 mlib_d64 d64;
191 struct {
192 mlib_f32 f0;
193 mlib_f32 f1;
194 } f32s;
195} d64_2x32;
196
197/***************************************************************/
198#define MLIB_SHIFT 16
199#define MLIB_PREC (1 << MLIB_SHIFT)
200#define MLIB_MASK (MLIB_PREC - 1)
201
202/***************************************************************/
203#define ONE (FTYPE)1.0
204
205/***************************************************************/
206#ifdef MLIB_USE_FTOI_CLAMPING
207
208#define SAT_32(DST, SRC) \
209 DST = (mlib_s32) SRC
210
211#else
212
213#define SAT_32(DST, SRC) \
214 if (SRC >= MLIB_S32_MAX) \
215 SRC = MLIB_S32_MAX; \
216 if (SRC <= MLIB_S32_MIN) \
217 SRC = MLIB_S32_MIN; \
218 DST = (mlib_s32) SRC
219
220#endif /* MLIB_USE_FTOI_CLAMPING */
221
222//we still need this for mlib_ImageAffine_BC_S32.c
223#define SAT32(DST) SAT_32(DST, val0)
224
225/***************************************************************/
226#if defined(MLIB_OS64BIT) || (defined(MACOSX) && defined(_LP64))
227#define PBITS 3
228#define MLIB_POINTER_SHIFT(P) (((P) >> (MLIB_SHIFT - 3)) &~ 7)
229#define MLIB_POINTER_GET(A, P) (*(DTYPE**)((mlib_u8*)(A) + (P)))
230#else
231#define PBITS 2
232#define MLIB_POINTER_SHIFT(P) (((P) >> (MLIB_SHIFT - 2)) &~ 3)
233#define MLIB_POINTER_GET(A, P) (*(DTYPE**)((mlib_addr)(A) + (P)))
234#endif /* MLIB_OS64BIT */
235
236#define PTR_SHIFT MLIB_POINTER_SHIFT
237
238/***************************************************************/
239#define SHIFT(X, SH, LO_BITS) \
240 (((X) >> (SH - LO_BITS)) & ((1 << (15 + LO_BITS)) - (1 << LO_BITS)))
241
242/***************************************************************/
243#define S_PTRl(Y, SH) \
244 (*(DTYPE**)((mlib_u8*)lineAddr + SHIFT(Y, SH, PBITS)))
245
246#define S_PTR(Y) S_PTRl(Y, 16)
247
248/***************************************************************/
249#define AL_ADDR(sp, ind) (mlib_d64*)((mlib_addr)(sp + ind) &~ 7)
250
251/***************************************************************/
252#define FILTER_ELEM_BITS 3
253
254/***************************************************************/
255#define FILTER_SHIFT (MLIB_SHIFT - FILTER_BITS - FILTER_ELEM_BITS)
256#define FILTER_SIZE (1 << FILTER_BITS)
257#define FILTER_MASK ((FILTER_SIZE - 1) << FILTER_ELEM_BITS)
258
259/***************************************************************/
260#define DECLAREVAR0() \
261 mlib_s32 *leftEdges = param -> leftEdges; \
262 mlib_s32 *rightEdges = param -> rightEdges; \
263 mlib_s32 *xStarts = param -> xStarts; \
264 mlib_s32 *yStarts = param -> yStarts; \
265 mlib_u8 *dstData = param -> dstData; \
266 mlib_u8 **lineAddr = param -> lineAddr; \
267 mlib_s32 dstYStride = param -> dstYStride; \
268 mlib_s32 xLeft, xRight, X, Y; \
269 mlib_s32 yStart = param -> yStart; \
270 mlib_s32 yFinish = param -> yFinish; \
271 mlib_s32 dX = param -> dX; \
272 mlib_s32 dY = param -> dY; \
273 mlib_s32 j
274
275/***************************************************************/
276#define DECLAREVAR() \
277 DECLAREVAR0(); \
278 mlib_s32 *warp_tbl = param -> warp_tbl; \
279 DTYPE *dstPixelPtr
280
281/***************************************************************/
282#define DECLAREVAR_NN() \
283 DECLAREVAR(); \
284 DTYPE *srcPixelPtr; \
285 mlib_s32 xSrc, ySrc
286
287/***************************************************************/
288#define DECLAREVAR_BL() \
289 DECLAREVAR_NN(); \
290 mlib_s32 srcYStride = param -> srcYStride
291
292/***************************************************************/
293#define DECLAREVAR_BC() \
294 DECLAREVAR_BL(); \
295 mlib_filter filter = param -> filter
296
297/***************************************************************/
298#define PREPARE_DELTAS \
299 if (warp_tbl != NULL) { \
300 dX = warp_tbl[2*j]; \
301 dY = warp_tbl[2*j + 1]; \
302 }
303
304/***************************************************************/
305#define CLIP(N) \
306 dstData += dstYStride; \
307 xLeft = leftEdges[j]; \
308 xRight = rightEdges[j]; \
309 X = xStarts[j]; \
310 Y = yStarts[j]; \
311 PREPARE_DELTAS; \
312 if (xLeft > xRight) continue; \
313 dstPixelPtr = (DTYPE*)dstData + N * xLeft
314
315/***************************************************************/
316#define NEW_LINE(NCHAN) \
317 dstData += dstYStride; \
318 xLeft = leftEdges[j]; \
319 xRight = rightEdges[j]; \
320 X = xStarts[j]; \
321 Y = yStarts[j]; \
322 PREPARE_DELTAS \
323 dl = (void*)((DTYPE*)dstData + NCHAN*xLeft); \
324 size = xRight - xLeft + 1; \
325 if (size <= 0) continue
326
327/***************************************************************/
328
329#ifdef __cplusplus
330}
331#endif /* __cplusplus */
332#endif /* __MLIB_IMAGEAFFINE_H */
333