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 27 /* 28 * FUNCTION 29 * mlib_ImageAffine_s16_1ch_bl 30 * mlib_ImageAffine_s16_2ch_bl 31 * mlib_ImageAffine_s16_3ch_bl 32 * mlib_ImageAffine_s16_4ch_bl 33 * - image affine transformation with Bilinear filtering 34 * SYNOPSIS 35 * mlib_status mlib_ImageAffine_s16_?ch_bl(mlib_s32 *leftEdges, 36 * mlib_s32 *rightEdges, 37 * mlib_s32 *xStarts, 38 * mlib_s32 *yStarts, 39 * mlib_s32 *sides, 40 * mlib_u8 *dstData, 41 * mlib_u8 **lineAddr, 42 * mlib_s32 dstYStride, 43 * mlib_s32 is_affine, 44 * mlib_s32 srcYStride) 45 * 46 * ARGUMENTS 47 * leftEdges array[dstHeight] of xLeft coordinates 48 * RightEdges array[dstHeight] of xRight coordinates 49 * xStarts array[dstHeight] of xStart * 65536 coordinates 50 * yStarts array[dstHeight] of yStart * 65536 coordinates 51 * sides output array[4]. sides[0] is yStart, sides[1] is yFinish, 52 * sides[2] is dx * 65536, sides[3] is dy * 65536 53 * dstData pointer to the first pixel on (yStart - 1) line 54 * lineAddr array[srcHeight] of pointers to the first pixel on 55 * the corresponding lines 56 * dstYStride stride of destination image 57 * is_affine indicator (Affine - GridWarp) 58 * srcYStride stride of source image 59 * 60 * DESCRIPTION 61 * The functions step along the lines from xLeft to xRight and apply 62 * the bilinear filtering. 63 * 64 */ 65 66 #include "mlib_ImageAffine.h" 67 68 /***************************************************************/ 69 #define DTYPE mlib_s16 70 #define FTYPE mlib_d64 71 72 /***************************************************************/ 73 #define TTYPE mlib_s32 74 #define I2F(x) (x) 75 #define ROUND(x) (x) 76 77 #define FUN_NAME(CHAN) mlib_ImageAffine_s16_##CHAN##_bl 78 79 /***************************************************************/ 80 /* for x86, using integer multiplies is faster */ 81 82 /***************************************************************/ 83 /* for SHORT/USHORT decrease MLIB_SHIFT due to 84 * overflow in multiplies like fdy * (a10 - a00) 85 */ 86 #undef MLIB_SHIFT 87 #define MLIB_SHIFT 15 88 89 #define MLIB_ROUND (1 << (MLIB_SHIFT - 1)) 90 91 /***************************************************************/ 92 #define GET_POINTERS(ind) \ 93 fdx = X & MLIB_MASK; \ 94 fdy = Y & MLIB_MASK; \ 95 ySrc = MLIB_POINTER_SHIFT(Y); \ 96 xSrc = X >> MLIB_SHIFT; \ 97 srcPixelPtr = MLIB_POINTER_GET(lineAddr, ySrc) + ind * xSrc; \ 98 srcPixelPtr2 = (DTYPE *)((mlib_u8 *)srcPixelPtr + srcYStride); \ 99 X += dX; \ 100 Y += dY 101 102 /***************************************************************/ 103 #define COUNT(ind) \ 104 pix0_##ind = a00_##ind + ((fdy * (a10_##ind - a00_##ind) + MLIB_ROUND) >> MLIB_SHIFT); \ 105 pix1_##ind = a01_##ind + ((fdy * (a11_##ind - a01_##ind) + MLIB_ROUND) >> MLIB_SHIFT); \ 106 res##ind = pix0_##ind + ((fdx * (pix1_##ind - pix0_##ind) + MLIB_ROUND) >> MLIB_SHIFT) 107 108 /***************************************************************/ 109 #define LOAD(ind, ind1, ind2) \ 110 a00_##ind = srcPixelPtr[ind1]; \ 111 a01_##ind = srcPixelPtr[ind2]; \ 112 a10_##ind = srcPixelPtr2[ind1]; \ 113 a11_##ind = srcPixelPtr2[ind2] 114 115 /***************************************************************/ 116 mlib_status FUN_NAME(1ch)(mlib_affine_param *param) 117 { 118 DECLAREVAR_BL(); 119 DTYPE *dstLineEnd; 120 DTYPE *srcPixelPtr2; 121 122 #if MLIB_SHIFT == 15 123 dX = (dX + 1) >> 1; 124 dY = (dY + 1) >> 1; 125 #endif /* MLIB_SHIFT == 15 */ 126 127 for (j = yStart; j <= yFinish; j++) { 128 mlib_s32 fdx, fdy; 129 mlib_s32 a00_0, a01_0, a10_0, a11_0; 130 mlib_s32 pix0_0, pix1_0, res0; 131 132 CLIP(1); 133 dstLineEnd = (DTYPE *) dstData + xRight; 134 #if MLIB_SHIFT == 15 135 X = X >> 1; 136 Y = Y >> 1; 137 138 if (warp_tbl != NULL) { 139 dX = (dX + 1) >> 1; 140 dY = (dY + 1) >> 1; 141 } 142 143 #endif /* MLIB_SHIFT == 15 */ 144 145 GET_POINTERS(1); 146 LOAD(0, 0, 1); 147 #ifdef __SUNPRO_C 148 #pragma pipeloop(0) 149 #endif /* __SUNPRO_C */ 150 for (; dstPixelPtr < dstLineEnd; dstPixelPtr++) { 151 COUNT(0); 152 GET_POINTERS(1); 153 LOAD(0, 0, 1); 154 dstPixelPtr[0] = (DTYPE) res0; 155 } 156 157 COUNT(0); 158 dstPixelPtr[0] = (DTYPE) res0; 159 } 160 161 return MLIB_SUCCESS; 162 } 163 164 /***************************************************************/ 165 mlib_status FUN_NAME(2ch)(mlib_affine_param *param) 166 { 167 DECLAREVAR_BL(); 168 DTYPE *dstLineEnd; 169 DTYPE *srcPixelPtr2; 170 171 #if MLIB_SHIFT == 15 172 dX = (dX + 1) >> 1; 173 dY = (dY + 1) >> 1; 174 #endif /* MLIB_SHIFT == 15 */ 175 176 for (j = yStart; j <= yFinish; j++) { 177 mlib_s32 fdx, fdy; 178 mlib_s32 a00_0, a01_0, a10_0, a11_0; 179 mlib_s32 a00_1, a01_1, a10_1, a11_1; 180 mlib_s32 pix0_0, pix1_0, res0; 181 mlib_s32 pix0_1, pix1_1, res1; 182 183 CLIP(2); 184 dstLineEnd = (DTYPE *) dstData + 2 * xRight; 185 #if MLIB_SHIFT == 15 186 X = X >> 1; 187 Y = Y >> 1; 188 189 if (warp_tbl != NULL) { 190 dX = (dX + 1) >> 1; 191 dY = (dY + 1) >> 1; 192 } 193 194 #endif /* MLIB_SHIFT == 15 */ 195 196 GET_POINTERS(2); 197 LOAD(0, 0, 2); 198 LOAD(1, 1, 3); 199 #ifdef __SUNPRO_C 200 #pragma pipeloop(0) 201 #endif /* __SUNPRO_C */ 202 for (; dstPixelPtr < dstLineEnd; dstPixelPtr += 2) { 203 COUNT(0); 204 COUNT(1); 205 GET_POINTERS(2); 206 LOAD(0, 0, 2); 207 LOAD(1, 1, 3); 208 dstPixelPtr[0] = (DTYPE) res0; 209 dstPixelPtr[1] = (DTYPE) res1; 210 } 211 212 COUNT(0); 213 COUNT(1); 214 dstPixelPtr[0] = (DTYPE) res0; 215 dstPixelPtr[1] = (DTYPE) res1; 216 } 217 218 return MLIB_SUCCESS; 219 } 220 221 /***************************************************************/ 222 mlib_status FUN_NAME(3ch)(mlib_affine_param *param) 223 { 224 DECLAREVAR_BL(); 225 DTYPE *dstLineEnd; 226 DTYPE *srcPixelPtr2; 227 228 #if MLIB_SHIFT == 15 229 dX = (dX + 1) >> 1; 230 dY = (dY + 1) >> 1; 231 #endif /* MLIB_SHIFT == 15 */ 232 233 for (j = yStart; j <= yFinish; j++) { 234 mlib_s32 fdx, fdy; 235 mlib_s32 a00_0, a01_0, a10_0, a11_0; 236 mlib_s32 a00_1, a01_1, a10_1, a11_1; 237 mlib_s32 a00_2, a01_2, a10_2, a11_2; 238 mlib_s32 pix0_0, pix1_0, res0; 239 mlib_s32 pix0_1, pix1_1, res1; 240 mlib_s32 pix0_2, pix1_2, res2; 241 242 CLIP(3); 243 dstLineEnd = (DTYPE *) dstData + 3 * xRight; 244 #if MLIB_SHIFT == 15 245 X = X >> 1; 246 Y = Y >> 1; 247 248 if (warp_tbl != NULL) { 249 dX = (dX + 1) >> 1; 250 dY = (dY + 1) >> 1; 251 } 252 253 #endif /* MLIB_SHIFT == 15 */ 254 255 GET_POINTERS(3); 256 LOAD(0, 0, 3); 257 LOAD(1, 1, 4); 258 LOAD(2, 2, 5); 259 #ifdef __SUNPRO_C 260 #pragma pipeloop(0) 261 #endif /* __SUNPRO_C */ 262 for (; dstPixelPtr < dstLineEnd; dstPixelPtr += 3) { 263 COUNT(0); 264 COUNT(1); 265 COUNT(2); 266 GET_POINTERS(3); 267 LOAD(0, 0, 3); 268 LOAD(1, 1, 4); 269 LOAD(2, 2, 5); 270 dstPixelPtr[0] = (DTYPE) res0; 271 dstPixelPtr[1] = (DTYPE) res1; 272 dstPixelPtr[2] = (DTYPE) res2; 273 } 274 275 COUNT(0); 276 COUNT(1); 277 COUNT(2); 278 dstPixelPtr[0] = (DTYPE) res0; 279 dstPixelPtr[1] = (DTYPE) res1; 280 dstPixelPtr[2] = (DTYPE) res2; 281 } 282 283 return MLIB_SUCCESS; 284 } 285 286 /***************************************************************/ 287 mlib_status FUN_NAME(4ch)(mlib_affine_param *param) 288 { 289 DECLAREVAR_BL(); 290 DTYPE *dstLineEnd; 291 DTYPE *srcPixelPtr2; 292 293 #if MLIB_SHIFT == 15 294 dX = (dX + 1) >> 1; 295 dY = (dY + 1) >> 1; 296 #endif /* MLIB_SHIFT == 15 */ 297 298 for (j = yStart; j <= yFinish; j++) { 299 mlib_s32 fdx, fdy; 300 mlib_s32 a00_0, a01_0, a10_0, a11_0; 301 mlib_s32 a00_1, a01_1, a10_1, a11_1; 302 mlib_s32 a00_2, a01_2, a10_2, a11_2; 303 mlib_s32 a00_3, a01_3, a10_3, a11_3; 304 mlib_s32 pix0_0, pix1_0, res0; 305 mlib_s32 pix0_1, pix1_1, res1; 306 mlib_s32 pix0_2, pix1_2, res2; 307 mlib_s32 pix0_3, pix1_3, res3; 308 309 CLIP(4); 310 dstLineEnd = (DTYPE *) dstData + 4 * xRight; 311 #if MLIB_SHIFT == 15 312 X = X >> 1; 313 Y = Y >> 1; 314 315 if (warp_tbl != NULL) { 316 dX = (dX + 1) >> 1; 317 dY = (dY + 1) >> 1; 318 } 319 320 #endif /* MLIB_SHIFT == 15 */ 321 322 GET_POINTERS(4); 323 LOAD(0, 0, 4); 324 LOAD(1, 1, 5); 325 LOAD(2, 2, 6); 326 LOAD(3, 3, 7); 327 #ifdef __SUNPRO_C 328 #pragma pipeloop(0) 329 #endif /* __SUNPRO_C */ 330 for (; dstPixelPtr < dstLineEnd; dstPixelPtr += 4) { 331 COUNT(0); 332 COUNT(1); 333 COUNT(2); 334 COUNT(3); 335 GET_POINTERS(4); 336 LOAD(0, 0, 4); 337 LOAD(1, 1, 5); 338 LOAD(2, 2, 6); 339 LOAD(3, 3, 7); 340 dstPixelPtr[0] = (DTYPE) res0; 341 dstPixelPtr[1] = (DTYPE) res1; 342 dstPixelPtr[2] = (DTYPE) res2; 343 dstPixelPtr[3] = (DTYPE) res3; 344 } 345 346 COUNT(0); 347 COUNT(1); 348 COUNT(2); 349 COUNT(3); 350 dstPixelPtr[0] = (DTYPE) res0; 351 dstPixelPtr[1] = (DTYPE) res1; 352 dstPixelPtr[2] = (DTYPE) res2; 353 dstPixelPtr[3] = (DTYPE) res3; 354 } 355 356 return MLIB_SUCCESS; 357 } 358 359 /***************************************************************/