OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2013 The LibYuv Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 dst_ptr[1] = dst_ptr[0] = src_ptr[0]; | 410 dst_ptr[1] = dst_ptr[0] = src_ptr[0]; |
411 src_ptr += 1; | 411 src_ptr += 1; |
412 dst_ptr += 2; | 412 dst_ptr += 2; |
413 } | 413 } |
414 if (dst_width & 1) { | 414 if (dst_width & 1) { |
415 dst_ptr[0] = src_ptr[0]; | 415 dst_ptr[0] = src_ptr[0]; |
416 } | 416 } |
417 } | 417 } |
418 | 418 |
419 // (1-f)a + fb can be replaced with a + f(b-a) | 419 // (1-f)a + fb can be replaced with a + f(b-a) |
| 420 #if defined(__arm__) |
| 421 // arm uses 16 bit math with truncation. |
| 422 // TODO(fbarchard): add rounding. |
420 #define BLENDER(a, b, f) (uint8)((int)(a) + \ | 423 #define BLENDER(a, b, f) (uint8)((int)(a) + \ |
421 ((int)(f) * ((int)(b) - (int)(a)) >> 16)) | 424 (((int)((f)) * ((int)(b) - (int)(a))) >> 16)) |
| 425 #else |
| 426 // inteluses 7 bit math with rounding. |
| 427 #define BLENDER(a, b, f) (uint8)((int)(a) + \ |
| 428 (((int)((f) >> 9) * ((int)(b) - (int)(a)) + 0x40) >> 7)) |
| 429 #endif |
422 | 430 |
423 void ScaleFilterCols_C(uint8* dst_ptr, const uint8* src_ptr, | 431 void ScaleFilterCols_C(uint8* dst_ptr, const uint8* src_ptr, |
424 int dst_width, int x, int dx) { | 432 int dst_width, int x, int dx) { |
425 int j; | 433 int j; |
426 for (j = 0; j < dst_width - 1; j += 2) { | 434 for (j = 0; j < dst_width - 1; j += 2) { |
427 int xi = x >> 16; | 435 int xi = x >> 16; |
428 int a = src_ptr[xi]; | 436 int a = src_ptr[xi]; |
429 int b = src_ptr[xi + 1]; | 437 int b = src_ptr[xi + 1]; |
430 dst_ptr[0] = BLENDER(a, b, x & 0xffff); | 438 dst_ptr[0] = BLENDER(a, b, x & 0xffff); |
431 x += dx; | 439 x += dx; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 } | 471 } |
464 if (dst_width & 1) { | 472 if (dst_width & 1) { |
465 int64 xi = x >> 16; | 473 int64 xi = x >> 16; |
466 int a = src_ptr[xi]; | 474 int a = src_ptr[xi]; |
467 int b = src_ptr[xi + 1]; | 475 int b = src_ptr[xi + 1]; |
468 dst_ptr[0] = BLENDER(a, b, x & 0xffff); | 476 dst_ptr[0] = BLENDER(a, b, x & 0xffff); |
469 } | 477 } |
470 } | 478 } |
471 #undef BLENDER | 479 #undef BLENDER |
472 | 480 |
| 481 // Same as 8 bit arm blender but return is cast to uint16 |
473 #define BLENDER(a, b, f) (uint16)((int)(a) + \ | 482 #define BLENDER(a, b, f) (uint16)((int)(a) + \ |
474 ((int)(f) * ((int)(b) - (int)(a)) >> 16)) | 483 (((int)((f)) * ((int)(b) - (int)(a))) >> 16)) |
475 | 484 |
476 void ScaleFilterCols_16_C(uint16* dst_ptr, const uint16* src_ptr, | 485 void ScaleFilterCols_16_C(uint16* dst_ptr, const uint16* src_ptr, |
477 int dst_width, int x, int dx) { | 486 int dst_width, int x, int dx) { |
478 int j; | 487 int j; |
479 for (j = 0; j < dst_width - 1; j += 2) { | 488 for (j = 0; j < dst_width - 1; j += 2) { |
480 int xi = x >> 16; | 489 int xi = x >> 16; |
481 int a = src_ptr[xi]; | 490 int a = src_ptr[xi]; |
482 int b = src_ptr[xi + 1]; | 491 int b = src_ptr[xi + 1]; |
483 dst_ptr[0] = BLENDER(a, b, x & 0xffff); | 492 dst_ptr[0] = BLENDER(a, b, x & 0xffff); |
484 x += dx; | 493 x += dx; |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 for (j = 0; j < dst_width - 1; j += 2) { | 811 for (j = 0; j < dst_width - 1; j += 2) { |
803 dst[1] = dst[0] = src[0]; | 812 dst[1] = dst[0] = src[0]; |
804 src += 1; | 813 src += 1; |
805 dst += 2; | 814 dst += 2; |
806 } | 815 } |
807 if (dst_width & 1) { | 816 if (dst_width & 1) { |
808 dst[0] = src[0]; | 817 dst[0] = src[0]; |
809 } | 818 } |
810 } | 819 } |
811 | 820 |
| 821 // TODO(fbarchard): Replace 0x7f ^ f with 128-f. bug=605. |
812 // Mimics SSSE3 blender | 822 // Mimics SSSE3 blender |
813 #define BLENDER1(a, b, f) ((a) * (0x7f ^ f) + (b) * f) >> 7 | 823 #define BLENDER1(a, b, f) ((a) * (0x7f ^ f) + (b) * f) >> 7 |
814 #define BLENDERC(a, b, f, s) (uint32)( \ | 824 #define BLENDERC(a, b, f, s) (uint32)( \ |
815 BLENDER1(((a) >> s) & 255, ((b) >> s) & 255, f) << s) | 825 BLENDER1(((a) >> s) & 255, ((b) >> s) & 255, f) << s) |
816 #define BLENDER(a, b, f) \ | 826 #define BLENDER(a, b, f) \ |
817 BLENDERC(a, b, f, 24) | BLENDERC(a, b, f, 16) | \ | 827 BLENDERC(a, b, f, 24) | BLENDERC(a, b, f, 16) | \ |
818 BLENDERC(a, b, f, 8) | BLENDERC(a, b, f, 0) | 828 BLENDERC(a, b, f, 8) | BLENDERC(a, b, f, 0) |
819 | 829 |
820 void ScaleARGBFilterCols_C(uint8* dst_argb, const uint8* src_argb, | 830 void ScaleARGBFilterCols_C(uint8* dst_argb, const uint8* src_argb, |
821 int dst_width, int x, int dx) { | 831 int dst_width, int x, int dx) { |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 *dx = -*dx; | 1152 *dx = -*dx; |
1143 // src_width = -src_width; // Caller must do this. | 1153 // src_width = -src_width; // Caller must do this. |
1144 } | 1154 } |
1145 } | 1155 } |
1146 #undef CENTERSTART | 1156 #undef CENTERSTART |
1147 | 1157 |
1148 #ifdef __cplusplus | 1158 #ifdef __cplusplus |
1149 } // extern "C" | 1159 } // extern "C" |
1150 } // namespace libyuv | 1160 } // namespace libyuv |
1151 #endif | 1161 #endif |
OLD | NEW |