1/* 2 * Copyright (c) 1998, 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#include "vis_proto.h" 29#include "mlib_image.h" 30#include "mlib_v_ImageLookUpFunc.h" 31 32/***************************************************************/ 33static void mlib_v_ImageLookUp_U8_S32_124_D1(const mlib_u8 *src, 34 mlib_f32 *dst, 35 mlib_s32 xsize, 36 const mlib_f32 *table0, 37 const mlib_f32 *table1, 38 const mlib_f32 *table2, 39 const mlib_f32 *table3); 40 41static void mlib_v_ImageLookUp_U8_S32_3_D1(const mlib_u8 *src, 42 mlib_f32 *dst, 43 mlib_s32 xsize, 44 const mlib_f32 *table0, 45 const mlib_f32 *table1, 46 const mlib_f32 *table2); 47 48/***************************************************************/ 49void mlib_v_ImageLookUp_U8_S32_124_D1(const mlib_u8 *src, 50 mlib_f32 *dst, 51 mlib_s32 xsize, 52 const mlib_f32 *table0, 53 const mlib_f32 *table1, 54 const mlib_f32 *table2, 55 const mlib_f32 *table3) 56{ 57 mlib_u32 *sa; /* aligned pointer to source data */ 58 mlib_u8 *sp; /* pointer to source data */ 59 mlib_u32 s0; /* source data */ 60 mlib_f32 *dp; /* aligned pointer to destination */ 61 mlib_f32 acc0, acc1; /* destination data */ 62 mlib_f32 acc2, acc3; /* destination data */ 63 mlib_s32 i; /* loop variable */ 64 mlib_u32 s00, s01, s02, s03; 65 66 sa = (mlib_u32 *) src; 67 dp = dst; 68 69 i = 0; 70 71 if (xsize >= 4) { 72 73 s0 = *sa++; 74 s00 = (s0 >> 22) & 0x3FC; 75 s01 = (s0 >> 14) & 0x3FC; 76 77#pragma pipeloop(0) 78 for (i = 0; i <= xsize - 8; i += 4, dp += 4) { 79 s02 = (s0 >> 6) & 0x3FC; 80 s03 = (s0 << 2) & 0x3FC; 81 acc0 = *(mlib_f32 *) ((mlib_u8 *) table0 + s00); 82 acc1 = *(mlib_f32 *) ((mlib_u8 *) table1 + s01); 83 acc2 = *(mlib_f32 *) ((mlib_u8 *) table2 + s02); 84 acc3 = *(mlib_f32 *) ((mlib_u8 *) table3 + s03); 85 s0 = *sa++; 86 s00 = (s0 >> 22) & 0x3FC; 87 s01 = (s0 >> 14) & 0x3FC; 88 dp[0] = acc0; 89 dp[1] = acc1; 90 dp[2] = acc2; 91 dp[3] = acc3; 92 } 93 94 s02 = (s0 >> 6) & 0x3FC; 95 s03 = (s0 << 2) & 0x3FC; 96 acc0 = *(mlib_f32 *) ((mlib_u8 *) table0 + s00); 97 acc1 = *(mlib_f32 *) ((mlib_u8 *) table1 + s01); 98 acc2 = *(mlib_f32 *) ((mlib_u8 *) table2 + s02); 99 acc3 = *(mlib_f32 *) ((mlib_u8 *) table3 + s03); 100 dp[0] = acc0; 101 dp[1] = acc1; 102 dp[2] = acc2; 103 dp[3] = acc3; 104 dp += 4; 105 i += 4; 106 } 107 108 sp = (mlib_u8 *) sa; 109 110 if (i < xsize) { 111 *dp++ = table0[sp[0]]; 112 i++; 113 sp++; 114 } 115 116 if (i < xsize) { 117 *dp++ = table1[sp[0]]; 118 i++; 119 sp++; 120 } 121 122 if (i < xsize) { 123 *dp++ = table2[sp[0]]; 124 } 125} 126 127/***************************************************************/ 128void mlib_v_ImageLookUp_U8_S32_1(const mlib_u8 *src, 129 mlib_s32 slb, 130 mlib_s32 *dst, 131 mlib_s32 dlb, 132 mlib_s32 xsize, 133 mlib_s32 ysize, 134 const mlib_s32 **table) 135{ 136 mlib_u8 *sl; 137 mlib_s32 *dl; 138 mlib_f32 *tab = (mlib_f32 *) table[0]; 139 mlib_s32 j, i; 140 141 sl = (void *)src; 142 dl = dst; 143 144 /* row loop */ 145 for (j = 0; j < ysize; j++) { 146 mlib_u8 *sp = sl; 147 mlib_f32 *dp = (mlib_f32 *) dl; 148 mlib_s32 off, size = xsize; 149 150 off = (mlib_s32) ((4 - ((mlib_addr) sp & 3)) & 3); 151 152 off = (off < size) ? off : size; 153 154 for (i = 0; i < off; i++) { 155 *dp++ = tab[(*sp++)]; 156 size--; 157 } 158 159 if (size > 0) { 160 mlib_v_ImageLookUp_U8_S32_124_D1(sp, dp, size, tab, tab, tab, tab); 161 } 162 163 sl = (mlib_u8 *) ((mlib_u8 *) sl + slb); 164 dl = (mlib_s32 *) ((mlib_u8 *) dl + dlb); 165 } 166} 167 168/***************************************************************/ 169void mlib_v_ImageLookUp_U8_S32_2(const mlib_u8 *src, 170 mlib_s32 slb, 171 mlib_s32 *dst, 172 mlib_s32 dlb, 173 mlib_s32 xsize, 174 mlib_s32 ysize, 175 const mlib_s32 **table) 176{ 177 mlib_u8 *sl; 178 mlib_s32 *dl; 179 mlib_f32 *tab; 180 mlib_s32 j, i; 181 182 sl = (void *)src; 183 dl = dst; 184 185 /* row loop */ 186 for (j = 0; j < ysize; j++) { 187 mlib_u8 *sp = sl; 188 mlib_f32 *dp = (mlib_f32 *) dl; 189 mlib_s32 off, size = xsize * 2; 190 mlib_f32 *tab0 = (mlib_f32 *) table[0]; 191 mlib_f32 *tab1 = (mlib_f32 *) table[1]; 192 193 off = (mlib_s32) ((4 - ((mlib_addr) sp & 3)) & 3); 194 195 off = (off < size) ? off : size; 196 197 for (i = 0; i < off - 1; i += 2) { 198 *dp++ = tab0[(*sp++)]; 199 *dp++ = tab1[(*sp++)]; 200 size -= 2; 201 } 202 203 if ((off & 1) != 0) { 204 *dp++ = tab0[(*sp++)]; 205 size--; 206 tab = tab0; 207 tab0 = tab1; 208 tab1 = tab; 209 } 210 211 if (size > 0) { 212 mlib_v_ImageLookUp_U8_S32_124_D1(sp, dp, size, tab0, tab1, tab0, tab1); 213 } 214 215 sl = (mlib_u8 *) ((mlib_u8 *) sl + slb); 216 dl = (mlib_s32 *) ((mlib_u8 *) dl + dlb); 217 } 218} 219 220/***************************************************************/ 221void mlib_v_ImageLookUp_U8_S32_4(const mlib_u8 *src, 222 mlib_s32 slb, 223 mlib_s32 *dst, 224 mlib_s32 dlb, 225 mlib_s32 xsize, 226 mlib_s32 ysize, 227 const mlib_s32 **table) 228{ 229 mlib_u8 *sl; 230 mlib_s32 *dl; 231 mlib_f32 *tab; 232 mlib_s32 j; 233 234 sl = (void *)src; 235 dl = dst; 236 237 /* row loop */ 238 for (j = 0; j < ysize; j++) { 239 mlib_u8 *sp = sl; 240 mlib_f32 *dp = (mlib_f32 *) dl; 241 mlib_f32 *tab0 = (mlib_f32 *) table[0]; 242 mlib_f32 *tab1 = (mlib_f32 *) table[1]; 243 mlib_f32 *tab2 = (mlib_f32 *) table[2]; 244 mlib_f32 *tab3 = (mlib_f32 *) table[3]; 245 mlib_s32 off, size = xsize * 4; 246 247 off = (mlib_s32) ((4 - ((mlib_addr) sp & 3)) & 3); 248 249 off = (off < size) ? off : size; 250 251 if (off == 1) { 252 *dp++ = tab0[(*sp++)]; 253 tab = tab0; 254 tab0 = tab1; 255 tab1 = tab2; 256 tab2 = tab3; 257 tab3 = tab; 258 size--; 259 } 260 else if (off == 2) { 261 *dp++ = tab0[(*sp++)]; 262 *dp++ = tab1[(*sp++)]; 263 tab = tab0; 264 tab0 = tab2; 265 tab2 = tab; 266 tab = tab1; 267 tab1 = tab3; 268 tab3 = tab; 269 size -= 2; 270 } 271 else if (off == 3) { 272 *dp++ = tab0[(*sp++)]; 273 *dp++ = tab1[(*sp++)]; 274 *dp++ = tab2[(*sp++)]; 275 tab = tab3; 276 tab3 = tab2; 277 tab2 = tab1; 278 tab1 = tab0; 279 tab0 = tab; 280 size -= 3; 281 } 282 283 if (size > 0) { 284 mlib_v_ImageLookUp_U8_S32_124_D1(sp, dp, size, tab0, tab1, tab2, tab3); 285 } 286 287 sl = (mlib_u8 *) ((mlib_u8 *) sl + slb); 288 dl = (mlib_s32 *) ((mlib_u8 *) dl + dlb); 289 } 290} 291 292/***************************************************************/ 293void mlib_v_ImageLookUp_U8_S32_3_D1(const mlib_u8 *src, 294 mlib_f32 *dst, 295 mlib_s32 xsize, 296 const mlib_f32 *table0, 297 const mlib_f32 *table1, 298 const mlib_f32 *table2) 299{ 300 mlib_u32 *sa; /* aligned pointer to source data */ 301 mlib_u8 *sp; /* pointer to source data */ 302 mlib_u32 s0; /* source data */ 303 mlib_f32 *dp; /* aligned pointer to destination */ 304 mlib_f32 acc0, acc1; /* destination data */ 305 mlib_f32 acc2, acc3; /* destination data */ 306 mlib_s32 i; /* loop variable */ 307 const mlib_f32 *table; 308 mlib_u32 s00, s01, s02, s03; 309 310 sa = (mlib_u32 *) src; 311 dp = dst; 312 313 i = 0; 314 315 if (xsize >= 4) { 316 317 s0 = *sa++; 318 s00 = (s0 >> 22) & 0x3FC; 319 s01 = (s0 >> 14) & 0x3FC; 320 321#pragma pipeloop(0) 322 for (i = 0; i <= xsize - 8; i += 4, dp += 4) { 323 s02 = (s0 >> 6) & 0x3FC; 324 s03 = (s0 << 2) & 0x3FC; 325 acc0 = *(mlib_f32 *) ((mlib_u8 *) table0 + s00); 326 acc1 = *(mlib_f32 *) ((mlib_u8 *) table1 + s01); 327 acc2 = *(mlib_f32 *) ((mlib_u8 *) table2 + s02); 328 acc3 = *(mlib_f32 *) ((mlib_u8 *) table0 + s03); 329 s0 = *sa++; 330 s00 = (s0 >> 22) & 0x3FC; 331 s01 = (s0 >> 14) & 0x3FC; 332 table = table0; 333 table0 = table1; 334 table1 = table2; 335 table2 = table; 336 dp[0] = acc0; 337 dp[1] = acc1; 338 dp[2] = acc2; 339 dp[3] = acc3; 340 } 341 342 s02 = (s0 >> 6) & 0x3FC; 343 s03 = (s0 << 2) & 0x3FC; 344 acc0 = *(mlib_f32 *) ((mlib_u8 *) table0 + s00); 345 acc1 = *(mlib_f32 *) ((mlib_u8 *) table1 + s01); 346 acc2 = *(mlib_f32 *) ((mlib_u8 *) table2 + s02); 347 acc3 = *(mlib_f32 *) ((mlib_u8 *) table0 + s03); 348 dp[0] = acc0; 349 dp[1] = acc1; 350 dp[2] = acc2; 351 dp[3] = acc3; 352 table = table0; 353 table0 = table1; 354 table1 = table2; 355 table2 = table; 356 dp += 4; 357 i += 4; 358 } 359 360 sp = (mlib_u8 *) sa; 361 362 if (i < xsize) { 363 *dp++ = table0[sp[0]]; 364 i++; 365 sp++; 366 } 367 368 if (i < xsize) { 369 *dp++ = table1[sp[0]]; 370 i++; 371 sp++; 372 } 373 374 if (i < xsize) { 375 *dp++ = table2[sp[0]]; 376 } 377} 378 379/***************************************************************/ 380void mlib_v_ImageLookUp_U8_S32_3(const mlib_u8 *src, 381 mlib_s32 slb, 382 mlib_s32 *dst, 383 mlib_s32 dlb, 384 mlib_s32 xsize, 385 mlib_s32 ysize, 386 const mlib_s32 **table) 387{ 388 mlib_u8 *sl; 389 mlib_s32 *dl; 390 mlib_f32 *tab; 391 mlib_s32 j; 392 393 sl = (void *)src; 394 dl = dst; 395 396 /* row loop */ 397 for (j = 0; j < ysize; j++) { 398 mlib_u8 *sp = sl; 399 mlib_f32 *dp = (mlib_f32 *) dl; 400 mlib_f32 *tab0 = (mlib_f32 *) table[0]; 401 mlib_f32 *tab1 = (mlib_f32 *) table[1]; 402 mlib_f32 *tab2 = (mlib_f32 *) table[2]; 403 mlib_s32 off, size = xsize * 3; 404 405 off = (mlib_s32) ((4 - ((mlib_addr) sp & 3)) & 3); 406 407 off = (off < size) ? off : size; 408 409 if (off == 1) { 410 *dp++ = tab0[(*sp++)]; 411 tab = tab0; 412 tab0 = tab1; 413 tab1 = tab2; 414 tab2 = tab; 415 size--; 416 } 417 else if (off == 2) { 418 *dp++ = tab0[(*sp++)]; 419 *dp++ = tab1[(*sp++)]; 420 tab = tab2; 421 tab2 = tab1; 422 tab1 = tab0; 423 tab0 = tab; 424 size -= 2; 425 } 426 else if (off == 3) { 427 *dp++ = tab0[(*sp++)]; 428 *dp++ = tab1[(*sp++)]; 429 *dp++ = tab2[(*sp++)]; 430 size -= 3; 431 } 432 433 if (size > 0) { 434 mlib_v_ImageLookUp_U8_S32_3_D1(sp, dp, size, tab0, tab1, tab2); 435 } 436 437 sl = (mlib_u8 *) ((mlib_u8 *) sl + slb); 438 dl = (mlib_s32 *) ((mlib_u8 *) dl + dlb); 439 } 440} 441 442/***************************************************************/ 443