| 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__) | 420 #if defined(__arm__) || defined(__aarch64__) |
| 421 // arm uses 16 bit math with truncation. | |
| 422 // TODO(fbarchard): add rounding. | |
| 423 #define BLENDER(a, b, f) (uint8)((int)(a) + \ | 421 #define BLENDER(a, b, f) (uint8)((int)(a) + \ |
| 424 (((int)((f)) * ((int)(b) - (int)(a))) >> 16)) | 422 ((((int)((f)) * ((int)(b) - (int)(a))) + 0x8000) >> 16)) |
| 425 #else | 423 #else |
| 426 // inteluses 7 bit math with rounding. | 424 // inteluses 7 bit math with rounding. |
| 427 #define BLENDER(a, b, f) (uint8)((int)(a) + \ | 425 #define BLENDER(a, b, f) (uint8)((int)(a) + \ |
| 428 (((int)((f) >> 9) * ((int)(b) - (int)(a)) + 0x40) >> 7)) | 426 (((int)((f) >> 9) * ((int)(b) - (int)(a)) + 0x40) >> 7)) |
| 429 #endif | 427 #endif |
| 430 | 428 |
| 431 void ScaleFilterCols_C(uint8* dst_ptr, const uint8* src_ptr, | 429 void ScaleFilterCols_C(uint8* dst_ptr, const uint8* src_ptr, |
| 432 int dst_width, int x, int dx) { | 430 int dst_width, int x, int dx) { |
| 433 int j; | 431 int j; |
| 434 for (j = 0; j < dst_width - 1; j += 2) { | 432 for (j = 0; j < dst_width - 1; j += 2) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 int64 xi = x >> 16; | 471 int64 xi = x >> 16; |
| 474 int a = src_ptr[xi]; | 472 int a = src_ptr[xi]; |
| 475 int b = src_ptr[xi + 1]; | 473 int b = src_ptr[xi + 1]; |
| 476 dst_ptr[0] = BLENDER(a, b, x & 0xffff); | 474 dst_ptr[0] = BLENDER(a, b, x & 0xffff); |
| 477 } | 475 } |
| 478 } | 476 } |
| 479 #undef BLENDER | 477 #undef BLENDER |
| 480 | 478 |
| 481 // Same as 8 bit arm blender but return is cast to uint16 | 479 // Same as 8 bit arm blender but return is cast to uint16 |
| 482 #define BLENDER(a, b, f) (uint16)((int)(a) + \ | 480 #define BLENDER(a, b, f) (uint16)((int)(a) + \ |
| 483 (((int)((f)) * ((int)(b) - (int)(a))) >> 16)) | 481 ((((int)((f)) * ((int)(b) - (int)(a))) + 0x8000) >> 16)) |
| 484 | 482 |
| 485 void ScaleFilterCols_16_C(uint16* dst_ptr, const uint16* src_ptr, | 483 void ScaleFilterCols_16_C(uint16* dst_ptr, const uint16* src_ptr, |
| 486 int dst_width, int x, int dx) { | 484 int dst_width, int x, int dx) { |
| 487 int j; | 485 int j; |
| 488 for (j = 0; j < dst_width - 1; j += 2) { | 486 for (j = 0; j < dst_width - 1; j += 2) { |
| 489 int xi = x >> 16; | 487 int xi = x >> 16; |
| 490 int a = src_ptr[xi]; | 488 int a = src_ptr[xi]; |
| 491 int b = src_ptr[xi + 1]; | 489 int b = src_ptr[xi + 1]; |
| 492 dst_ptr[0] = BLENDER(a, b, x & 0xffff); | 490 dst_ptr[0] = BLENDER(a, b, x & 0xffff); |
| 493 x += dx; | 491 x += dx; |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 for (j = 0; j < dst_width - 1; j += 2) { | 809 for (j = 0; j < dst_width - 1; j += 2) { |
| 812 dst[1] = dst[0] = src[0]; | 810 dst[1] = dst[0] = src[0]; |
| 813 src += 1; | 811 src += 1; |
| 814 dst += 2; | 812 dst += 2; |
| 815 } | 813 } |
| 816 if (dst_width & 1) { | 814 if (dst_width & 1) { |
| 817 dst[0] = src[0]; | 815 dst[0] = src[0]; |
| 818 } | 816 } |
| 819 } | 817 } |
| 820 | 818 |
| 821 // TODO(fbarchard): Replace 0x7f ^ f with 128-f. bug=605. | 819 // TODO(fbarchard): Replace 0x7f ^ f with 128-f. bug=607. |
| 822 // Mimics SSSE3 blender | 820 // Mimics SSSE3 blender |
| 823 #define BLENDER1(a, b, f) ((a) * (0x7f ^ f) + (b) * f) >> 7 | 821 #define BLENDER1(a, b, f) ((a) * (0x7f ^ f) + (b) * f) >> 7 |
| 824 #define BLENDERC(a, b, f, s) (uint32)( \ | 822 #define BLENDERC(a, b, f, s) (uint32)( \ |
| 825 BLENDER1(((a) >> s) & 255, ((b) >> s) & 255, f) << s) | 823 BLENDER1(((a) >> s) & 255, ((b) >> s) & 255, f) << s) |
| 826 #define BLENDER(a, b, f) \ | 824 #define BLENDER(a, b, f) \ |
| 827 BLENDERC(a, b, f, 24) | BLENDERC(a, b, f, 16) | \ | 825 BLENDERC(a, b, f, 24) | BLENDERC(a, b, f, 16) | \ |
| 828 BLENDERC(a, b, f, 8) | BLENDERC(a, b, f, 0) | 826 BLENDERC(a, b, f, 8) | BLENDERC(a, b, f, 0) |
| 829 | 827 |
| 830 void ScaleARGBFilterCols_C(uint8* dst_argb, const uint8* src_argb, | 828 void ScaleARGBFilterCols_C(uint8* dst_argb, const uint8* src_argb, |
| 831 int dst_width, int x, int dx) { | 829 int dst_width, int x, int dx) { |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 *dx = -*dx; | 1150 *dx = -*dx; |
| 1153 // src_width = -src_width; // Caller must do this. | 1151 // src_width = -src_width; // Caller must do this. |
| 1154 } | 1152 } |
| 1155 } | 1153 } |
| 1156 #undef CENTERSTART | 1154 #undef CENTERSTART |
| 1157 | 1155 |
| 1158 #ifdef __cplusplus | 1156 #ifdef __cplusplus |
| 1159 } // extern "C" | 1157 } // extern "C" |
| 1160 } // namespace libyuv | 1158 } // namespace libyuv |
| 1161 #endif | 1159 #endif |
| OLD | NEW |