| 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 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 src_ptr[stride + 3] + src_ptr[stride + 4] + | 614 src_ptr[stride + 3] + src_ptr[stride + 4] + |
| 615 src_ptr[stride + 5]) * (65536 / 6) >> 16; | 615 src_ptr[stride + 5]) * (65536 / 6) >> 16; |
| 616 dst_ptr[2] = (src_ptr[6] + src_ptr[7] + | 616 dst_ptr[2] = (src_ptr[6] + src_ptr[7] + |
| 617 src_ptr[stride + 6] + src_ptr[stride + 7]) * | 617 src_ptr[stride + 6] + src_ptr[stride + 7]) * |
| 618 (65536 / 4) >> 16; | 618 (65536 / 4) >> 16; |
| 619 src_ptr += 8; | 619 src_ptr += 8; |
| 620 dst_ptr += 3; | 620 dst_ptr += 3; |
| 621 } | 621 } |
| 622 } | 622 } |
| 623 | 623 |
| 624 void ScaleAddRows_C(const uint8* src_ptr, ptrdiff_t src_stride, | 624 void ScaleAddRow_C(const uint8* src_ptr, uint16* dst_ptr, int src_width) { |
| 625 uint16* dst_ptr, int src_width, int src_height) { | |
| 626 int x; | 625 int x; |
| 627 assert(src_width > 0); | 626 assert(src_width > 0); |
| 628 assert(src_height > 0); | 627 for (x = 0; x < src_width - 1; x += 2) { |
| 629 for (x = 0; x < src_width; ++x) { | 628 dst_ptr[0] += src_ptr[0]; |
| 630 const uint8* s = src_ptr + x; | 629 dst_ptr[1] += src_ptr[1]; |
| 631 unsigned int sum = 0u; | 630 src_ptr += 2; |
| 632 int y; | 631 dst_ptr += 2; |
| 633 for (y = 0; y < src_height; ++y) { | 632 } |
| 634 sum += s[0]; | 633 if (src_width & 1) { |
| 635 s += src_stride; | 634 dst_ptr[0] += src_ptr[0]; |
| 636 } | |
| 637 // TODO(fbarchard): Consider limitting height to 256 to avoid overflow. | |
| 638 dst_ptr[x] = sum < 65535u ? sum : 65535u; | |
| 639 } | 635 } |
| 640 } | 636 } |
| 641 | 637 |
| 642 void ScaleAddRows_16_C(const uint16* src_ptr, ptrdiff_t src_stride, | 638 void ScaleAddRow_16_C(const uint16* src_ptr, uint32* dst_ptr, int src_width) { |
| 643 uint32* dst_ptr, int src_width, int src_height) { | |
| 644 int x; | 639 int x; |
| 645 assert(src_width > 0); | 640 assert(src_width > 0); |
| 646 assert(src_height > 0); | 641 for (x = 0; x < src_width - 1; x += 2) { |
| 647 for (x = 0; x < src_width; ++x) { | 642 dst_ptr[0] += src_ptr[0]; |
| 648 const uint16* s = src_ptr + x; | 643 dst_ptr[1] += src_ptr[1]; |
| 649 unsigned int sum = 0u; | 644 src_ptr += 2; |
| 650 int y; | 645 dst_ptr += 2; |
| 651 for (y = 0; y < src_height; ++y) { | 646 } |
| 652 sum += s[0]; | 647 if (src_width & 1) { |
| 653 s += src_stride; | 648 dst_ptr[0] += src_ptr[0]; |
| 654 } | |
| 655 // No risk of overflow here now | |
| 656 dst_ptr[x] = sum; | |
| 657 } | 649 } |
| 658 } | 650 } |
| 659 | 651 |
| 660 void ScaleARGBRowDown2_C(const uint8* src_argb, | 652 void ScaleARGBRowDown2_C(const uint8* src_argb, |
| 661 ptrdiff_t src_stride, | 653 ptrdiff_t src_stride, |
| 662 uint8* dst_argb, int dst_width) { | 654 uint8* dst_argb, int dst_width) { |
| 663 const uint32* src = (const uint32*)(src_argb); | 655 const uint32* src = (const uint32*)(src_argb); |
| 664 uint32* dst = (uint32*)(dst_argb); | 656 uint32* dst = (uint32*)(dst_argb); |
| 665 | 657 |
| 666 int x; | 658 int x; |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 src_width = -src_width; | 1015 src_width = -src_width; |
| 1024 } | 1016 } |
| 1025 if (src_height < 0) { | 1017 if (src_height < 0) { |
| 1026 src_height = -src_height; | 1018 src_height = -src_height; |
| 1027 } | 1019 } |
| 1028 if (filtering == kFilterBox) { | 1020 if (filtering == kFilterBox) { |
| 1029 // If scaling both axis to 0.5 or larger, switch from Box to Bilinear. | 1021 // If scaling both axis to 0.5 or larger, switch from Box to Bilinear. |
| 1030 if (dst_width * 2 >= src_width && dst_height * 2 >= src_height) { | 1022 if (dst_width * 2 >= src_width && dst_height * 2 >= src_height) { |
| 1031 filtering = kFilterBilinear; | 1023 filtering = kFilterBilinear; |
| 1032 } | 1024 } |
| 1033 // If scaling to larger, switch from Box to Bilinear. | |
| 1034 if (dst_width >= src_width || dst_height >= src_height) { | |
| 1035 filtering = kFilterBilinear; | |
| 1036 } | |
| 1037 } | 1025 } |
| 1038 if (filtering == kFilterBilinear) { | 1026 if (filtering == kFilterBilinear) { |
| 1039 if (src_height == 1) { | 1027 if (src_height == 1) { |
| 1040 filtering = kFilterLinear; | 1028 filtering = kFilterLinear; |
| 1041 } | 1029 } |
| 1042 // TODO(fbarchard): Detect any odd scale factor and reduce to Linear. | 1030 // TODO(fbarchard): Detect any odd scale factor and reduce to Linear. |
| 1043 if (dst_height == src_height || dst_height * 3 == src_height) { | 1031 if (dst_height == src_height || dst_height * 3 == src_height) { |
| 1044 filtering = kFilterLinear; | 1032 filtering = kFilterLinear; |
| 1045 } | 1033 } |
| 1046 // TODO(fbarchard): Remove 1 pixel wide filter restriction, which is to | 1034 // TODO(fbarchard): Remove 1 pixel wide filter restriction, which is to |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1140 *dx = -*dx; | 1128 *dx = -*dx; |
| 1141 // src_width = -src_width; // Caller must do this. | 1129 // src_width = -src_width; // Caller must do this. |
| 1142 } | 1130 } |
| 1143 } | 1131 } |
| 1144 #undef CENTERSTART | 1132 #undef CENTERSTART |
| 1145 | 1133 |
| 1146 #ifdef __cplusplus | 1134 #ifdef __cplusplus |
| 1147 } // extern "C" | 1135 } // extern "C" |
| 1148 } // namespace libyuv | 1136 } // namespace libyuv |
| 1149 #endif | 1137 #endif |
| OLD | NEW |