OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2011 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 |
11 #include <stdlib.h> | 11 #include <stdlib.h> |
12 #include <time.h> | 12 #include <time.h> |
13 | 13 |
14 #include "libyuv/compare.h" | 14 #include "libyuv/compare.h" |
15 #include "libyuv/convert.h" | 15 #include "libyuv/convert.h" |
16 #include "libyuv/convert_argb.h" | 16 #include "libyuv/convert_argb.h" |
17 #include "libyuv/convert_from.h" | 17 #include "libyuv/convert_from.h" |
18 #include "libyuv/convert_from_argb.h" | 18 #include "libyuv/convert_from_argb.h" |
19 #include "libyuv/cpu_id.h" | 19 #include "libyuv/cpu_id.h" |
20 #include "libyuv/planar_functions.h" | 20 #include "libyuv/planar_functions.h" |
21 #include "libyuv/rotate.h" | 21 #include "libyuv/rotate.h" |
22 #include "libyuv/row.h" // For Sobel | |
23 #include "../unit_test/unit_test.h" | 22 #include "../unit_test/unit_test.h" |
24 | 23 |
25 namespace libyuv { | 24 namespace libyuv { |
26 | 25 |
27 TEST_F(LibYUVPlanarTest, TestAttenuate) { | 26 TEST_F(LibYUVPlanarTest, TestAttenuate) { |
28 const int kSize = 1280 * 4; | 27 const int kSize = 1280 * 4; |
29 align_buffer_64(orig_pixels, kSize); | 28 align_buffer_page_end(orig_pixels, kSize); |
30 align_buffer_64(atten_pixels, kSize); | 29 align_buffer_page_end(atten_pixels, kSize); |
31 align_buffer_64(unatten_pixels, kSize); | 30 align_buffer_page_end(unatten_pixels, kSize); |
32 align_buffer_64(atten2_pixels, kSize); | 31 align_buffer_page_end(atten2_pixels, kSize); |
33 | 32 |
34 // Test unattenuation clamps | 33 // Test unattenuation clamps |
35 orig_pixels[0 * 4 + 0] = 200u; | 34 orig_pixels[0 * 4 + 0] = 200u; |
36 orig_pixels[0 * 4 + 1] = 129u; | 35 orig_pixels[0 * 4 + 1] = 129u; |
37 orig_pixels[0 * 4 + 2] = 127u; | 36 orig_pixels[0 * 4 + 2] = 127u; |
38 orig_pixels[0 * 4 + 3] = 128u; | 37 orig_pixels[0 * 4 + 3] = 128u; |
39 // Test unattenuation transparent and opaque are unaffected | 38 // Test unattenuation transparent and opaque are unaffected |
40 orig_pixels[1 * 4 + 0] = 16u; | 39 orig_pixels[1 * 4 + 0] = 16u; |
41 orig_pixels[1 * 4 + 1] = 64u; | 40 orig_pixels[1 * 4 + 1] = 64u; |
42 orig_pixels[1 * 4 + 2] = 192u; | 41 orig_pixels[1 * 4 + 2] = 192u; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 EXPECT_EQ(0, atten_pixels[0 * 4 + 3]); | 90 EXPECT_EQ(0, atten_pixels[0 * 4 + 3]); |
92 EXPECT_EQ(64, atten_pixels[128 * 4 + 0]); | 91 EXPECT_EQ(64, atten_pixels[128 * 4 + 0]); |
93 EXPECT_EQ(32, atten_pixels[128 * 4 + 1]); | 92 EXPECT_EQ(32, atten_pixels[128 * 4 + 1]); |
94 EXPECT_EQ(21, atten_pixels[128 * 4 + 2]); | 93 EXPECT_EQ(21, atten_pixels[128 * 4 + 2]); |
95 EXPECT_EQ(128, atten_pixels[128 * 4 + 3]); | 94 EXPECT_EQ(128, atten_pixels[128 * 4 + 3]); |
96 EXPECT_NEAR(255, atten_pixels[255 * 4 + 0], 1); | 95 EXPECT_NEAR(255, atten_pixels[255 * 4 + 0], 1); |
97 EXPECT_NEAR(127, atten_pixels[255 * 4 + 1], 1); | 96 EXPECT_NEAR(127, atten_pixels[255 * 4 + 1], 1); |
98 EXPECT_NEAR(85, atten_pixels[255 * 4 + 2], 1); | 97 EXPECT_NEAR(85, atten_pixels[255 * 4 + 2], 1); |
99 EXPECT_EQ(255, atten_pixels[255 * 4 + 3]); | 98 EXPECT_EQ(255, atten_pixels[255 * 4 + 3]); |
100 | 99 |
101 free_aligned_buffer_64(atten2_pixels); | 100 free_aligned_buffer_page_end(atten2_pixels); |
102 free_aligned_buffer_64(unatten_pixels); | 101 free_aligned_buffer_page_end(unatten_pixels); |
103 free_aligned_buffer_64(atten_pixels); | 102 free_aligned_buffer_page_end(atten_pixels); |
104 free_aligned_buffer_64(orig_pixels); | 103 free_aligned_buffer_page_end(orig_pixels); |
105 } | 104 } |
106 | 105 |
107 static int TestAttenuateI(int width, int height, int benchmark_iterations, | 106 static int TestAttenuateI(int width, int height, int benchmark_iterations, |
108 int disable_cpu_flags, int benchmark_cpu_info, | 107 int disable_cpu_flags, int benchmark_cpu_info, |
109 int invert, int off) { | 108 int invert, int off) { |
110 if (width < 1) { | 109 if (width < 1) { |
111 width = 1; | 110 width = 1; |
112 } | 111 } |
113 const int kBpp = 4; | 112 const int kBpp = 4; |
114 const int kStride = width * kBpp; | 113 const int kStride = width * kBpp; |
115 align_buffer_64(src_argb, kStride * height + off); | 114 align_buffer_page_end(src_argb, kStride * height + off); |
116 align_buffer_64(dst_argb_c, kStride * height); | 115 align_buffer_page_end(dst_argb_c, kStride * height); |
117 align_buffer_64(dst_argb_opt, kStride * height); | 116 align_buffer_page_end(dst_argb_opt, kStride * height); |
118 for (int i = 0; i < kStride * height; ++i) { | 117 for (int i = 0; i < kStride * height; ++i) { |
119 src_argb[i + off] = (fastrand() & 0xff); | 118 src_argb[i + off] = (fastrand() & 0xff); |
120 } | 119 } |
121 memset(dst_argb_c, 0, kStride * height); | 120 memset(dst_argb_c, 0, kStride * height); |
122 memset(dst_argb_opt, 0, kStride * height); | 121 memset(dst_argb_opt, 0, kStride * height); |
123 | 122 |
124 MaskCpuFlags(disable_cpu_flags); | 123 MaskCpuFlags(disable_cpu_flags); |
125 ARGBAttenuate(src_argb + off, kStride, | 124 ARGBAttenuate(src_argb + off, kStride, |
126 dst_argb_c, kStride, | 125 dst_argb_c, kStride, |
127 width, invert * height); | 126 width, invert * height); |
128 MaskCpuFlags(benchmark_cpu_info); | 127 MaskCpuFlags(benchmark_cpu_info); |
129 for (int i = 0; i < benchmark_iterations; ++i) { | 128 for (int i = 0; i < benchmark_iterations; ++i) { |
130 ARGBAttenuate(src_argb + off, kStride, | 129 ARGBAttenuate(src_argb + off, kStride, |
131 dst_argb_opt, kStride, | 130 dst_argb_opt, kStride, |
132 width, invert * height); | 131 width, invert * height); |
133 } | 132 } |
134 int max_diff = 0; | 133 int max_diff = 0; |
135 for (int i = 0; i < kStride * height; ++i) { | 134 for (int i = 0; i < kStride * height; ++i) { |
136 int abs_diff = | 135 int abs_diff = |
137 abs(static_cast<int>(dst_argb_c[i]) - | 136 abs(static_cast<int>(dst_argb_c[i]) - |
138 static_cast<int>(dst_argb_opt[i])); | 137 static_cast<int>(dst_argb_opt[i])); |
139 if (abs_diff > max_diff) { | 138 if (abs_diff > max_diff) { |
140 max_diff = abs_diff; | 139 max_diff = abs_diff; |
141 } | 140 } |
142 } | 141 } |
143 free_aligned_buffer_64(src_argb); | 142 free_aligned_buffer_page_end(src_argb); |
144 free_aligned_buffer_64(dst_argb_c); | 143 free_aligned_buffer_page_end(dst_argb_c); |
145 free_aligned_buffer_64(dst_argb_opt); | 144 free_aligned_buffer_page_end(dst_argb_opt); |
146 return max_diff; | 145 return max_diff; |
147 } | 146 } |
148 | 147 |
149 TEST_F(LibYUVPlanarTest, ARGBAttenuate_Any) { | 148 TEST_F(LibYUVPlanarTest, ARGBAttenuate_Any) { |
150 int max_diff = TestAttenuateI(benchmark_width_ - 1, benchmark_height_, | 149 int max_diff = TestAttenuateI(benchmark_width_ - 1, benchmark_height_, |
151 benchmark_iterations_, | 150 benchmark_iterations_, |
152 disable_cpu_flags_, benchmark_cpu_info_, | 151 disable_cpu_flags_, benchmark_cpu_info_, |
153 +1, 0); | 152 +1, 0); |
154 EXPECT_LE(max_diff, 2); | 153 EXPECT_LE(max_diff, 2); |
155 } | 154 } |
(...skipping 23 matching lines...) Expand all Loading... |
179 } | 178 } |
180 | 179 |
181 static int TestUnattenuateI(int width, int height, int benchmark_iterations, | 180 static int TestUnattenuateI(int width, int height, int benchmark_iterations, |
182 int disable_cpu_flags, int benchmark_cpu_info, | 181 int disable_cpu_flags, int benchmark_cpu_info, |
183 int invert, int off) { | 182 int invert, int off) { |
184 if (width < 1) { | 183 if (width < 1) { |
185 width = 1; | 184 width = 1; |
186 } | 185 } |
187 const int kBpp = 4; | 186 const int kBpp = 4; |
188 const int kStride = width * kBpp; | 187 const int kStride = width * kBpp; |
189 align_buffer_64(src_argb, kStride * height + off); | 188 align_buffer_page_end(src_argb, kStride * height + off); |
190 align_buffer_64(dst_argb_c, kStride * height); | 189 align_buffer_page_end(dst_argb_c, kStride * height); |
191 align_buffer_64(dst_argb_opt, kStride * height); | 190 align_buffer_page_end(dst_argb_opt, kStride * height); |
192 for (int i = 0; i < kStride * height; ++i) { | 191 for (int i = 0; i < kStride * height; ++i) { |
193 src_argb[i + off] = (fastrand() & 0xff); | 192 src_argb[i + off] = (fastrand() & 0xff); |
194 } | 193 } |
195 ARGBAttenuate(src_argb + off, kStride, | 194 ARGBAttenuate(src_argb + off, kStride, |
196 src_argb + off, kStride, | 195 src_argb + off, kStride, |
197 width, height); | 196 width, height); |
198 memset(dst_argb_c, 0, kStride * height); | 197 memset(dst_argb_c, 0, kStride * height); |
199 memset(dst_argb_opt, 0, kStride * height); | 198 memset(dst_argb_opt, 0, kStride * height); |
200 | 199 |
201 MaskCpuFlags(disable_cpu_flags); | 200 MaskCpuFlags(disable_cpu_flags); |
202 ARGBUnattenuate(src_argb + off, kStride, | 201 ARGBUnattenuate(src_argb + off, kStride, |
203 dst_argb_c, kStride, | 202 dst_argb_c, kStride, |
204 width, invert * height); | 203 width, invert * height); |
205 MaskCpuFlags(benchmark_cpu_info); | 204 MaskCpuFlags(benchmark_cpu_info); |
206 for (int i = 0; i < benchmark_iterations; ++i) { | 205 for (int i = 0; i < benchmark_iterations; ++i) { |
207 ARGBUnattenuate(src_argb + off, kStride, | 206 ARGBUnattenuate(src_argb + off, kStride, |
208 dst_argb_opt, kStride, | 207 dst_argb_opt, kStride, |
209 width, invert * height); | 208 width, invert * height); |
210 } | 209 } |
211 int max_diff = 0; | 210 int max_diff = 0; |
212 for (int i = 0; i < kStride * height; ++i) { | 211 for (int i = 0; i < kStride * height; ++i) { |
213 int abs_diff = | 212 int abs_diff = |
214 abs(static_cast<int>(dst_argb_c[i]) - | 213 abs(static_cast<int>(dst_argb_c[i]) - |
215 static_cast<int>(dst_argb_opt[i])); | 214 static_cast<int>(dst_argb_opt[i])); |
216 if (abs_diff > max_diff) { | 215 if (abs_diff > max_diff) { |
217 max_diff = abs_diff; | 216 max_diff = abs_diff; |
218 } | 217 } |
219 } | 218 } |
220 free_aligned_buffer_64(src_argb); | 219 free_aligned_buffer_page_end(src_argb); |
221 free_aligned_buffer_64(dst_argb_c); | 220 free_aligned_buffer_page_end(dst_argb_c); |
222 free_aligned_buffer_64(dst_argb_opt); | 221 free_aligned_buffer_page_end(dst_argb_opt); |
223 return max_diff; | 222 return max_diff; |
224 } | 223 } |
225 | 224 |
226 TEST_F(LibYUVPlanarTest, ARGBUnattenuate_Any) { | 225 TEST_F(LibYUVPlanarTest, ARGBUnattenuate_Any) { |
227 int max_diff = TestUnattenuateI(benchmark_width_ - 1, benchmark_height_, | 226 int max_diff = TestUnattenuateI(benchmark_width_ - 1, benchmark_height_, |
228 benchmark_iterations_, | 227 benchmark_iterations_, |
229 disable_cpu_flags_, benchmark_cpu_info_, | 228 disable_cpu_flags_, benchmark_cpu_info_, |
230 +1, 0); | 229 +1, 0); |
231 EXPECT_LE(max_diff, 2); | 230 EXPECT_LE(max_diff, 2); |
232 } | 231 } |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 EXPECT_EQ(32u, interpolate_pixels[3]); | 1015 EXPECT_EQ(32u, interpolate_pixels[3]); |
1017 | 1016 |
1018 for (int i = 0; i < benchmark_pixels_div1280_; ++i) { | 1017 for (int i = 0; i < benchmark_pixels_div1280_; ++i) { |
1019 InterpolatePlane(&orig_pixels_0[0], 0, &orig_pixels_1[0], 0, | 1018 InterpolatePlane(&orig_pixels_0[0], 0, &orig_pixels_1[0], 0, |
1020 &interpolate_pixels[0], 0, 1280, 1, 123); | 1019 &interpolate_pixels[0], 0, 1280, 1, 123); |
1021 } | 1020 } |
1022 } | 1021 } |
1023 | 1022 |
1024 #define TESTTERP(FMT_A, BPP_A, STRIDE_A, \ | 1023 #define TESTTERP(FMT_A, BPP_A, STRIDE_A, \ |
1025 FMT_B, BPP_B, STRIDE_B, \ | 1024 FMT_B, BPP_B, STRIDE_B, \ |
1026 W1280, TERP, N, NEG, OFF) \ | 1025 W1280, TERP, N, NEG, OFF) \ |
1027 TEST_F(LibYUVPlanarTest, ARGBInterpolate##TERP##N) { \ | 1026 TEST_F(LibYUVPlanarTest, ARGBInterpolate##TERP##N) { \ |
1028 const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ | 1027 const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ |
1029 const int kHeight = benchmark_height_; \ | 1028 const int kHeight = benchmark_height_; \ |
1030 const int kStrideA = (kWidth * BPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ | 1029 const int kStrideA = (kWidth * BPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ |
1031 const int kStrideB = (kWidth * BPP_B + STRIDE_B - 1) / STRIDE_B * STRIDE_B; \ | 1030 const int kStrideB = (kWidth * BPP_B + STRIDE_B - 1) / STRIDE_B * STRIDE_B; \ |
1032 align_buffer_64(src_argb_a, kStrideA * kHeight + OFF); \ | 1031 align_buffer_page_end(src_argb_a, kStrideA * kHeight + OFF); \ |
1033 align_buffer_64(src_argb_b, kStrideA * kHeight + OFF); \ | 1032 align_buffer_page_end(src_argb_b, kStrideA * kHeight + OFF); \ |
1034 align_buffer_64(dst_argb_c, kStrideB * kHeight); \ | 1033 align_buffer_page_end(dst_argb_c, kStrideB * kHeight); \ |
1035 align_buffer_64(dst_argb_opt, kStrideB * kHeight); \ | 1034 align_buffer_page_end(dst_argb_opt, kStrideB * kHeight); \ |
1036 for (int i = 0; i < kStrideA * kHeight; ++i) { \ | 1035 for (int i = 0; i < kStrideA * kHeight; ++i) { \ |
1037 src_argb_a[i + OFF] = (fastrand() & 0xff); \ | 1036 src_argb_a[i + OFF] = (fastrand() & 0xff); \ |
1038 src_argb_b[i + OFF] = (fastrand() & 0xff); \ | 1037 src_argb_b[i + OFF] = (fastrand() & 0xff); \ |
1039 } \ | 1038 } \ |
1040 MaskCpuFlags(disable_cpu_flags_); \ | 1039 MaskCpuFlags(disable_cpu_flags_); \ |
1041 ARGBInterpolate(src_argb_a + OFF, kStrideA, \ | 1040 ARGBInterpolate(src_argb_a + OFF, kStrideA, \ |
1042 src_argb_b + OFF, kStrideA, \ | 1041 src_argb_b + OFF, kStrideA, \ |
1043 dst_argb_c, kStrideB, \ | 1042 dst_argb_c, kStrideB, \ |
1044 kWidth, NEG kHeight, TERP); \ | 1043 kWidth, NEG kHeight, TERP); \ |
1045 MaskCpuFlags(benchmark_cpu_info_); \ | 1044 MaskCpuFlags(benchmark_cpu_info_); \ |
1046 for (int i = 0; i < benchmark_iterations_; ++i) { \ | 1045 for (int i = 0; i < benchmark_iterations_; ++i) { \ |
1047 ARGBInterpolate(src_argb_a + OFF, kStrideA, \ | 1046 ARGBInterpolate(src_argb_a + OFF, kStrideA, \ |
1048 src_argb_b + OFF, kStrideA, \ | 1047 src_argb_b + OFF, kStrideA, \ |
1049 dst_argb_opt, kStrideB, \ | 1048 dst_argb_opt, kStrideB, \ |
1050 kWidth, NEG kHeight, TERP); \ | 1049 kWidth, NEG kHeight, TERP); \ |
1051 } \ | 1050 } \ |
1052 for (int i = 0; i < kStrideB * kHeight; ++i) { \ | 1051 for (int i = 0; i < kStrideB * kHeight; ++i) { \ |
1053 EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]); \ | 1052 EXPECT_EQ(dst_argb_c[i], dst_argb_opt[i]); \ |
1054 } \ | 1053 } \ |
1055 free_aligned_buffer_64(src_argb_a); \ | 1054 free_aligned_buffer_page_end(src_argb_a); \ |
1056 free_aligned_buffer_64(src_argb_b); \ | 1055 free_aligned_buffer_page_end(src_argb_b); \ |
1057 free_aligned_buffer_64(dst_argb_c); \ | 1056 free_aligned_buffer_page_end(dst_argb_c); \ |
1058 free_aligned_buffer_64(dst_argb_opt); \ | 1057 free_aligned_buffer_page_end(dst_argb_opt); \ |
1059 } | 1058 } |
1060 | 1059 |
1061 #define TESTINTERPOLATE(TERP) \ | 1060 #define TESTINTERPOLATE(TERP) \ |
1062 TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_ - 1, TERP, _Any, +, 0) \ | 1061 TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_ - 1, TERP, _Any, +, 0) \ |
1063 TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_, TERP, _Unaligned, +, 1) \ | 1062 TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_, TERP, _Unaligned, +, 1) \ |
1064 TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_, TERP, _Invert, -, 0) \ | 1063 TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_, TERP, _Invert, -, 0) \ |
1065 TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_, TERP, _Opt, +, 0) | 1064 TESTTERP(ARGB, 4, 1, ARGB, 4, 1, benchmark_width_, TERP, _Opt, +, 0) |
1066 | 1065 |
1067 TESTINTERPOLATE(0) | 1066 TESTINTERPOLATE(0) |
1068 TESTINTERPOLATE(64) | 1067 TESTINTERPOLATE(64) |
1069 TESTINTERPOLATE(128) | 1068 TESTINTERPOLATE(128) |
1070 TESTINTERPOLATE(192) | 1069 TESTINTERPOLATE(192) |
1071 TESTINTERPOLATE(255) | 1070 TESTINTERPOLATE(255) |
1072 | 1071 |
1073 static int TestBlend(int width, int height, int benchmark_iterations, | 1072 static int TestBlend(int width, int height, int benchmark_iterations, |
1074 int disable_cpu_flags, int benchmark_cpu_info, | 1073 int disable_cpu_flags, int benchmark_cpu_info, |
1075 int invert, int off) { | 1074 int invert, int off) { |
1076 if (width < 1) { | 1075 if (width < 1) { |
1077 width = 1; | 1076 width = 1; |
1078 } | 1077 } |
1079 const int kBpp = 4; | 1078 const int kBpp = 4; |
1080 const int kStride = width * kBpp; | 1079 const int kStride = width * kBpp; |
1081 align_buffer_64(src_argb_a, kStride * height + off); | 1080 align_buffer_page_end(src_argb_a, kStride * height + off); |
1082 align_buffer_64(src_argb_b, kStride * height + off); | 1081 align_buffer_page_end(src_argb_b, kStride * height + off); |
1083 align_buffer_64(dst_argb_c, kStride * height); | 1082 align_buffer_page_end(dst_argb_c, kStride * height); |
1084 align_buffer_64(dst_argb_opt, kStride * height); | 1083 align_buffer_page_end(dst_argb_opt, kStride * height); |
1085 for (int i = 0; i < kStride * height; ++i) { | 1084 for (int i = 0; i < kStride * height; ++i) { |
1086 src_argb_a[i + off] = (fastrand() & 0xff); | 1085 src_argb_a[i + off] = (fastrand() & 0xff); |
1087 src_argb_b[i + off] = (fastrand() & 0xff); | 1086 src_argb_b[i + off] = (fastrand() & 0xff); |
1088 } | 1087 } |
1089 ARGBAttenuate(src_argb_a + off, kStride, src_argb_a + off, kStride, width, | 1088 ARGBAttenuate(src_argb_a + off, kStride, src_argb_a + off, kStride, width, |
1090 height); | 1089 height); |
1091 ARGBAttenuate(src_argb_b + off, kStride, src_argb_b + off, kStride, width, | 1090 ARGBAttenuate(src_argb_b + off, kStride, src_argb_b + off, kStride, width, |
1092 height); | 1091 height); |
1093 memset(dst_argb_c, 255, kStride * height); | 1092 memset(dst_argb_c, 255, kStride * height); |
1094 memset(dst_argb_opt, 255, kStride * height); | 1093 memset(dst_argb_opt, 255, kStride * height); |
(...skipping 12 matching lines...) Expand all Loading... |
1107 } | 1106 } |
1108 int max_diff = 0; | 1107 int max_diff = 0; |
1109 for (int i = 0; i < kStride * height; ++i) { | 1108 for (int i = 0; i < kStride * height; ++i) { |
1110 int abs_diff = | 1109 int abs_diff = |
1111 abs(static_cast<int>(dst_argb_c[i]) - | 1110 abs(static_cast<int>(dst_argb_c[i]) - |
1112 static_cast<int>(dst_argb_opt[i])); | 1111 static_cast<int>(dst_argb_opt[i])); |
1113 if (abs_diff > max_diff) { | 1112 if (abs_diff > max_diff) { |
1114 max_diff = abs_diff; | 1113 max_diff = abs_diff; |
1115 } | 1114 } |
1116 } | 1115 } |
1117 free_aligned_buffer_64(src_argb_a); | 1116 free_aligned_buffer_page_end(src_argb_a); |
1118 free_aligned_buffer_64(src_argb_b); | 1117 free_aligned_buffer_page_end(src_argb_b); |
1119 free_aligned_buffer_64(dst_argb_c); | 1118 free_aligned_buffer_page_end(dst_argb_c); |
1120 free_aligned_buffer_64(dst_argb_opt); | 1119 free_aligned_buffer_page_end(dst_argb_opt); |
1121 return max_diff; | 1120 return max_diff; |
1122 } | 1121 } |
1123 | 1122 |
1124 TEST_F(LibYUVPlanarTest, ARGBBlend_Any) { | 1123 TEST_F(LibYUVPlanarTest, ARGBBlend_Any) { |
1125 int max_diff = TestBlend(benchmark_width_ - 4, benchmark_height_, | 1124 int max_diff = TestBlend(benchmark_width_ - 4, benchmark_height_, |
1126 benchmark_iterations_, | 1125 benchmark_iterations_, |
1127 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); | 1126 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); |
1128 EXPECT_LE(max_diff, 1); | 1127 EXPECT_LE(max_diff, 1); |
1129 } | 1128 } |
1130 | 1129 |
(...skipping 19 matching lines...) Expand all Loading... |
1150 } | 1149 } |
1151 | 1150 |
1152 static void TestBlendPlane(int width, int height, int benchmark_iterations, | 1151 static void TestBlendPlane(int width, int height, int benchmark_iterations, |
1153 int disable_cpu_flags, int benchmark_cpu_info, | 1152 int disable_cpu_flags, int benchmark_cpu_info, |
1154 int invert, int off) { | 1153 int invert, int off) { |
1155 if (width < 1) { | 1154 if (width < 1) { |
1156 width = 1; | 1155 width = 1; |
1157 } | 1156 } |
1158 const int kBpp = 1; | 1157 const int kBpp = 1; |
1159 const int kStride = width * kBpp; | 1158 const int kStride = width * kBpp; |
1160 align_buffer_64(src_argb_a, kStride * height + off); | 1159 align_buffer_page_end(src_argb_a, kStride * height + off); |
1161 align_buffer_64(src_argb_b, kStride * height + off); | 1160 align_buffer_page_end(src_argb_b, kStride * height + off); |
1162 align_buffer_64(src_argb_alpha, kStride * height + off); | 1161 align_buffer_page_end(src_argb_alpha, kStride * height + off); |
1163 align_buffer_64(dst_argb_c, kStride * height + off); | 1162 align_buffer_page_end(dst_argb_c, kStride * height + off); |
1164 align_buffer_64(dst_argb_opt, kStride * height + off); | 1163 align_buffer_page_end(dst_argb_opt, kStride * height + off); |
1165 memset(dst_argb_c, 255, kStride * height + off); | 1164 memset(dst_argb_c, 255, kStride * height + off); |
1166 memset(dst_argb_opt, 255, kStride * height + off); | 1165 memset(dst_argb_opt, 255, kStride * height + off); |
1167 | 1166 |
1168 // Test source is maintained exactly if alpha is 255. | 1167 // Test source is maintained exactly if alpha is 255. |
1169 for (int i = 0; i < width; ++i) { | 1168 for (int i = 0; i < width; ++i) { |
1170 src_argb_a[i + off] = i & 255; | 1169 src_argb_a[i + off] = i & 255; |
1171 src_argb_b[i + off] = 255 - (i & 255); | 1170 src_argb_b[i + off] = 255 - (i & 255); |
1172 } | 1171 } |
1173 memset(src_argb_alpha + off, 255, width); | 1172 memset(src_argb_alpha + off, 255, width); |
1174 BlendPlane(src_argb_a + off, width, | 1173 BlendPlane(src_argb_a + off, width, |
(...skipping 30 matching lines...) Expand all Loading... |
1205 for (int i = 0; i < benchmark_iterations; ++i) { | 1204 for (int i = 0; i < benchmark_iterations; ++i) { |
1206 BlendPlane(src_argb_a + off, width, | 1205 BlendPlane(src_argb_a + off, width, |
1207 src_argb_b + off, width, | 1206 src_argb_b + off, width, |
1208 src_argb_alpha + off, width, | 1207 src_argb_alpha + off, width, |
1209 dst_argb_opt + off, width, | 1208 dst_argb_opt + off, width, |
1210 width, height); | 1209 width, height); |
1211 } | 1210 } |
1212 for (int i = 0; i < kStride * height; ++i) { | 1211 for (int i = 0; i < kStride * height; ++i) { |
1213 EXPECT_EQ(dst_argb_c[i + off], dst_argb_opt[i + off]); | 1212 EXPECT_EQ(dst_argb_c[i + off], dst_argb_opt[i + off]); |
1214 } | 1213 } |
1215 free_aligned_buffer_64(src_argb_a); | 1214 free_aligned_buffer_page_end(src_argb_a); |
1216 free_aligned_buffer_64(src_argb_b); | 1215 free_aligned_buffer_page_end(src_argb_b); |
1217 free_aligned_buffer_64(src_argb_alpha); | 1216 free_aligned_buffer_page_end(src_argb_alpha); |
1218 free_aligned_buffer_64(dst_argb_c); | 1217 free_aligned_buffer_page_end(dst_argb_c); |
1219 free_aligned_buffer_64(dst_argb_opt); | 1218 free_aligned_buffer_page_end(dst_argb_opt); |
1220 return; | 1219 return; |
1221 } | 1220 } |
1222 | 1221 |
1223 TEST_F(LibYUVPlanarTest, BlendPlane_Opt) { | 1222 TEST_F(LibYUVPlanarTest, BlendPlane_Opt) { |
1224 TestBlendPlane(benchmark_width_, benchmark_height_, benchmark_iterations_, | 1223 TestBlendPlane(benchmark_width_, benchmark_height_, benchmark_iterations_, |
1225 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); | 1224 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); |
1226 } | 1225 } |
1227 TEST_F(LibYUVPlanarTest, BlendPlane_Unaligned) { | 1226 TEST_F(LibYUVPlanarTest, BlendPlane_Unaligned) { |
1228 TestBlendPlane(benchmark_width_, benchmark_height_, benchmark_iterations_, | 1227 TestBlendPlane(benchmark_width_, benchmark_height_, benchmark_iterations_, |
1229 disable_cpu_flags_, benchmark_cpu_info_, +1, 1); | 1228 disable_cpu_flags_, benchmark_cpu_info_, +1, 1); |
1230 } | 1229 } |
1231 TEST_F(LibYUVPlanarTest, BlendPlane_Any) { | 1230 TEST_F(LibYUVPlanarTest, BlendPlane_Any) { |
1232 TestBlendPlane(benchmark_width_ - 4, benchmark_height_, benchmark_iterations_, | 1231 TestBlendPlane(benchmark_width_ - 4, benchmark_height_, benchmark_iterations_, |
1233 disable_cpu_flags_, benchmark_cpu_info_, +1, 1); | 1232 disable_cpu_flags_, benchmark_cpu_info_, +1, 1); |
1234 } | 1233 } |
1235 TEST_F(LibYUVPlanarTest, BlendPlane_Invert) { | 1234 TEST_F(LibYUVPlanarTest, BlendPlane_Invert) { |
1236 TestBlendPlane(benchmark_width_, benchmark_height_, benchmark_iterations_, | 1235 TestBlendPlane(benchmark_width_, benchmark_height_, benchmark_iterations_, |
1237 disable_cpu_flags_, benchmark_cpu_info_, -1, 1); | 1236 disable_cpu_flags_, benchmark_cpu_info_, -1, 1); |
1238 } | 1237 } |
1239 | 1238 |
1240 #define SUBSAMPLE(v, a) ((((v) + (a) - 1)) / (a)) | 1239 #define SUBSAMPLE(v, a) ((((v) + (a) - 1)) / (a)) |
1241 | 1240 |
1242 static void TestI420Blend(int width, int height, int benchmark_iterations, | 1241 static void TestI420Blend(int width, int height, int benchmark_iterations, |
1243 int disable_cpu_flags, int benchmark_cpu_info, | 1242 int disable_cpu_flags, int benchmark_cpu_info, |
1244 int invert, int off) { | 1243 int invert, int off) { |
1245 width = ((width) > 0) ? (width) : 1; | 1244 width = ((width) > 0) ? (width) : 1; |
1246 const int kStrideUV = SUBSAMPLE(width, 2); | 1245 const int kStrideUV = SUBSAMPLE(width, 2); |
1247 const int kSizeUV = kStrideUV * SUBSAMPLE(height, 2); | 1246 const int kSizeUV = kStrideUV * SUBSAMPLE(height, 2); |
1248 align_buffer_64(src_y0, width * height + off); | 1247 align_buffer_page_end(src_y0, width * height + off); |
1249 align_buffer_64(src_u0, kSizeUV + off); | 1248 align_buffer_page_end(src_u0, kSizeUV + off); |
1250 align_buffer_64(src_v0, kSizeUV + off); | 1249 align_buffer_page_end(src_v0, kSizeUV + off); |
1251 align_buffer_64(src_y1, width * height + off); | 1250 align_buffer_page_end(src_y1, width * height + off); |
1252 align_buffer_64(src_u1, kSizeUV + off); | 1251 align_buffer_page_end(src_u1, kSizeUV + off); |
1253 align_buffer_64(src_v1, kSizeUV + off); | 1252 align_buffer_page_end(src_v1, kSizeUV + off); |
1254 align_buffer_64(src_a, width * height + off); | 1253 align_buffer_page_end(src_a, width * height + off); |
1255 align_buffer_64(dst_y_c, width * height + off); | 1254 align_buffer_page_end(dst_y_c, width * height + off); |
1256 align_buffer_64(dst_u_c, kSizeUV + off); | 1255 align_buffer_page_end(dst_u_c, kSizeUV + off); |
1257 align_buffer_64(dst_v_c, kSizeUV + off); | 1256 align_buffer_page_end(dst_v_c, kSizeUV + off); |
1258 align_buffer_64(dst_y_opt, width * height + off); | 1257 align_buffer_page_end(dst_y_opt, width * height + off); |
1259 align_buffer_64(dst_u_opt, kSizeUV + off); | 1258 align_buffer_page_end(dst_u_opt, kSizeUV + off); |
1260 align_buffer_64(dst_v_opt, kSizeUV + off); | 1259 align_buffer_page_end(dst_v_opt, kSizeUV + off); |
1261 | 1260 |
1262 MemRandomize(src_y0, width * height + off); | 1261 MemRandomize(src_y0, width * height + off); |
1263 MemRandomize(src_u0, kSizeUV + off); | 1262 MemRandomize(src_u0, kSizeUV + off); |
1264 MemRandomize(src_v0, kSizeUV + off); | 1263 MemRandomize(src_v0, kSizeUV + off); |
1265 MemRandomize(src_y1, width * height + off); | 1264 MemRandomize(src_y1, width * height + off); |
1266 MemRandomize(src_u1, kSizeUV + off); | 1265 MemRandomize(src_u1, kSizeUV + off); |
1267 MemRandomize(src_v1, kSizeUV + off); | 1266 MemRandomize(src_v1, kSizeUV + off); |
1268 MemRandomize(src_a, width * height + off); | 1267 MemRandomize(src_a, width * height + off); |
1269 memset(dst_y_c, 255, width * height + off); | 1268 memset(dst_y_c, 255, width * height + off); |
1270 memset(dst_u_c, 255, kSizeUV + off); | 1269 memset(dst_u_c, 255, kSizeUV + off); |
(...skipping 28 matching lines...) Expand all Loading... |
1299 dst_v_opt + off, kStrideUV, | 1298 dst_v_opt + off, kStrideUV, |
1300 width, height); | 1299 width, height); |
1301 } | 1300 } |
1302 for (int i = 0; i < width * height; ++i) { | 1301 for (int i = 0; i < width * height; ++i) { |
1303 EXPECT_EQ(dst_y_c[i + off], dst_y_opt[i + off]); | 1302 EXPECT_EQ(dst_y_c[i + off], dst_y_opt[i + off]); |
1304 } | 1303 } |
1305 for (int i = 0; i < kSizeUV; ++i) { | 1304 for (int i = 0; i < kSizeUV; ++i) { |
1306 EXPECT_EQ(dst_u_c[i + off], dst_u_opt[i + off]); | 1305 EXPECT_EQ(dst_u_c[i + off], dst_u_opt[i + off]); |
1307 EXPECT_EQ(dst_v_c[i + off], dst_v_opt[i + off]); | 1306 EXPECT_EQ(dst_v_c[i + off], dst_v_opt[i + off]); |
1308 } | 1307 } |
1309 free_aligned_buffer_64(src_y0); | 1308 free_aligned_buffer_page_end(src_y0); |
1310 free_aligned_buffer_64(src_u0); | 1309 free_aligned_buffer_page_end(src_u0); |
1311 free_aligned_buffer_64(src_v0); | 1310 free_aligned_buffer_page_end(src_v0); |
1312 free_aligned_buffer_64(src_y1); | 1311 free_aligned_buffer_page_end(src_y1); |
1313 free_aligned_buffer_64(src_u1); | 1312 free_aligned_buffer_page_end(src_u1); |
1314 free_aligned_buffer_64(src_v1); | 1313 free_aligned_buffer_page_end(src_v1); |
1315 free_aligned_buffer_64(src_a); | 1314 free_aligned_buffer_page_end(src_a); |
1316 free_aligned_buffer_64(dst_y_c); | 1315 free_aligned_buffer_page_end(dst_y_c); |
1317 free_aligned_buffer_64(dst_u_c); | 1316 free_aligned_buffer_page_end(dst_u_c); |
1318 free_aligned_buffer_64(dst_v_c); | 1317 free_aligned_buffer_page_end(dst_v_c); |
1319 free_aligned_buffer_64(dst_y_opt); | 1318 free_aligned_buffer_page_end(dst_y_opt); |
1320 free_aligned_buffer_64(dst_u_opt); | 1319 free_aligned_buffer_page_end(dst_u_opt); |
1321 free_aligned_buffer_64(dst_v_opt); | 1320 free_aligned_buffer_page_end(dst_v_opt); |
1322 return; | 1321 return; |
1323 } | 1322 } |
1324 | 1323 |
1325 TEST_F(LibYUVPlanarTest, I420Blend_Opt) { | 1324 TEST_F(LibYUVPlanarTest, I420Blend_Opt) { |
1326 TestI420Blend(benchmark_width_, benchmark_height_, benchmark_iterations_, | 1325 TestI420Blend(benchmark_width_, benchmark_height_, benchmark_iterations_, |
1327 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); | 1326 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); |
1328 } | 1327 } |
1329 TEST_F(LibYUVPlanarTest, I420Blend_Unaligned) { | 1328 TEST_F(LibYUVPlanarTest, I420Blend_Unaligned) { |
1330 TestI420Blend(benchmark_width_, benchmark_height_, benchmark_iterations_, | 1329 TestI420Blend(benchmark_width_, benchmark_height_, benchmark_iterations_, |
1331 disable_cpu_flags_, benchmark_cpu_info_, +1, 1); | 1330 disable_cpu_flags_, benchmark_cpu_info_, +1, 1); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 int has_sse2 = TestCpuFlag(kCpuHasSSE2); | 1367 int has_sse2 = TestCpuFlag(kCpuHasSSE2); |
1369 if (has_sse2) { | 1368 if (has_sse2) { |
1370 for (int i = 0; i < benchmark_pixels_div1280_; ++i) { | 1369 for (int i = 0; i < benchmark_pixels_div1280_; ++i) { |
1371 ARGBAffineRow_SSE2(&orig_pixels_0[0][0], 0, &interpolate_pixels_Opt[0][0], | 1370 ARGBAffineRow_SSE2(&orig_pixels_0[0][0], 0, &interpolate_pixels_Opt[0][0], |
1372 uv_step, 1280); | 1371 uv_step, 1280); |
1373 } | 1372 } |
1374 } | 1373 } |
1375 #endif | 1374 #endif |
1376 } | 1375 } |
1377 | 1376 |
1378 TEST_F(LibYUVPlanarTest, TestSobelX) { | |
1379 SIMD_ALIGNED(uint8 orig_pixels_0[1280 + 2]); | |
1380 SIMD_ALIGNED(uint8 orig_pixels_1[1280 + 2]); | |
1381 SIMD_ALIGNED(uint8 orig_pixels_2[1280 + 2]); | |
1382 SIMD_ALIGNED(uint8 sobel_pixels_c[1280]); | |
1383 SIMD_ALIGNED(uint8 sobel_pixels_opt[1280]); | |
1384 | |
1385 for (int i = 0; i < 1280 + 2; ++i) { | |
1386 orig_pixels_0[i] = i; | |
1387 orig_pixels_1[i] = i * 2; | |
1388 orig_pixels_2[i] = i * 3; | |
1389 } | |
1390 | |
1391 SobelXRow_C(orig_pixels_0, orig_pixels_1, orig_pixels_2, | |
1392 sobel_pixels_c, 1280); | |
1393 | |
1394 EXPECT_EQ(16u, sobel_pixels_c[0]); | |
1395 EXPECT_EQ(16u, sobel_pixels_c[100]); | |
1396 EXPECT_EQ(255u, sobel_pixels_c[255]); | |
1397 | |
1398 void (*SobelXRow)(const uint8* src_y0, const uint8* src_y1, | |
1399 const uint8* src_y2, uint8* dst_sobely, int width) = | |
1400 SobelXRow_C; | |
1401 #if defined(HAS_SOBELXROW_SSE2) | |
1402 if (TestCpuFlag(kCpuHasSSE2)) { | |
1403 SobelXRow = SobelXRow_SSE2; | |
1404 } | |
1405 #endif | |
1406 #if defined(HAS_SOBELXROW_NEON) | |
1407 if (TestCpuFlag(kCpuHasNEON)) { | |
1408 SobelXRow = SobelXRow_NEON; | |
1409 } | |
1410 #endif | |
1411 for (int i = 0; i < benchmark_pixels_div1280_; ++i) { | |
1412 SobelXRow(orig_pixels_0, orig_pixels_1, orig_pixels_2, | |
1413 sobel_pixels_opt, 1280); | |
1414 } | |
1415 for (int i = 0; i < 1280; ++i) { | |
1416 EXPECT_EQ(sobel_pixels_c[i], sobel_pixels_opt[i]); | |
1417 } | |
1418 } | |
1419 | |
1420 TEST_F(LibYUVPlanarTest, TestSobelY) { | |
1421 SIMD_ALIGNED(uint8 orig_pixels_0[1280 + 2]); | |
1422 SIMD_ALIGNED(uint8 orig_pixels_1[1280 + 2]); | |
1423 SIMD_ALIGNED(uint8 sobel_pixels_c[1280]); | |
1424 SIMD_ALIGNED(uint8 sobel_pixels_opt[1280]); | |
1425 | |
1426 for (int i = 0; i < 1280 + 2; ++i) { | |
1427 orig_pixels_0[i] = i; | |
1428 orig_pixels_1[i] = i * 2; | |
1429 } | |
1430 | |
1431 SobelYRow_C(orig_pixels_0, orig_pixels_1, sobel_pixels_c, 1280); | |
1432 | |
1433 EXPECT_EQ(4u, sobel_pixels_c[0]); | |
1434 EXPECT_EQ(255u, sobel_pixels_c[100]); | |
1435 EXPECT_EQ(0u, sobel_pixels_c[255]); | |
1436 void (*SobelYRow)(const uint8* src_y0, const uint8* src_y1, | |
1437 uint8* dst_sobely, int width) = SobelYRow_C; | |
1438 #if defined(HAS_SOBELYROW_SSE2) | |
1439 if (TestCpuFlag(kCpuHasSSE2)) { | |
1440 SobelYRow = SobelYRow_SSE2; | |
1441 } | |
1442 #endif | |
1443 #if defined(HAS_SOBELYROW_NEON) | |
1444 if (TestCpuFlag(kCpuHasNEON)) { | |
1445 SobelYRow = SobelYRow_NEON; | |
1446 } | |
1447 #endif | |
1448 for (int i = 0; i < benchmark_pixels_div1280_; ++i) { | |
1449 SobelYRow(orig_pixels_0, orig_pixels_1, sobel_pixels_opt, 1280); | |
1450 } | |
1451 for (int i = 0; i < 1280; ++i) { | |
1452 EXPECT_EQ(sobel_pixels_c[i], sobel_pixels_opt[i]); | |
1453 } | |
1454 } | |
1455 | |
1456 TEST_F(LibYUVPlanarTest, TestSobel) { | |
1457 SIMD_ALIGNED(uint8 orig_sobelx[1280]); | |
1458 SIMD_ALIGNED(uint8 orig_sobely[1280]); | |
1459 SIMD_ALIGNED(uint8 sobel_pixels_c[1280 * 4]); | |
1460 SIMD_ALIGNED(uint8 sobel_pixels_opt[1280 * 4]); | |
1461 | |
1462 for (int i = 0; i < 1280; ++i) { | |
1463 orig_sobelx[i] = i; | |
1464 orig_sobely[i] = i * 2; | |
1465 } | |
1466 | |
1467 SobelRow_C(orig_sobelx, orig_sobely, sobel_pixels_c, 1280); | |
1468 | |
1469 EXPECT_EQ(0u, sobel_pixels_c[0]); | |
1470 EXPECT_EQ(3u, sobel_pixels_c[4]); | |
1471 EXPECT_EQ(3u, sobel_pixels_c[5]); | |
1472 EXPECT_EQ(3u, sobel_pixels_c[6]); | |
1473 EXPECT_EQ(255u, sobel_pixels_c[7]); | |
1474 EXPECT_EQ(6u, sobel_pixels_c[8]); | |
1475 EXPECT_EQ(6u, sobel_pixels_c[9]); | |
1476 EXPECT_EQ(6u, sobel_pixels_c[10]); | |
1477 EXPECT_EQ(255u, sobel_pixels_c[7]); | |
1478 EXPECT_EQ(255u, sobel_pixels_c[100 * 4 + 1]); | |
1479 EXPECT_EQ(255u, sobel_pixels_c[255 * 4 + 1]); | |
1480 void (*SobelRow)(const uint8* src_sobelx, const uint8* src_sobely, | |
1481 uint8* dst_argb, int width) = SobelRow_C; | |
1482 #if defined(HAS_SOBELROW_SSE2) | |
1483 if (TestCpuFlag(kCpuHasSSE2)) { | |
1484 SobelRow = SobelRow_SSE2; | |
1485 } | |
1486 #endif | |
1487 #if defined(HAS_SOBELROW_NEON) | |
1488 if (TestCpuFlag(kCpuHasNEON)) { | |
1489 SobelRow = SobelRow_NEON; | |
1490 } | |
1491 #endif | |
1492 for (int i = 0; i < benchmark_pixels_div1280_; ++i) { | |
1493 SobelRow(orig_sobelx, orig_sobely, sobel_pixels_opt, 1280); | |
1494 } | |
1495 for (int i = 0; i < 1280 * 4; ++i) { | |
1496 EXPECT_EQ(sobel_pixels_c[i], sobel_pixels_opt[i]); | |
1497 } | |
1498 } | |
1499 | |
1500 TEST_F(LibYUVPlanarTest, TestSobelToPlane) { | |
1501 SIMD_ALIGNED(uint8 orig_sobelx[1280]); | |
1502 SIMD_ALIGNED(uint8 orig_sobely[1280]); | |
1503 SIMD_ALIGNED(uint8 sobel_pixels_c[1280]); | |
1504 SIMD_ALIGNED(uint8 sobel_pixels_opt[1280]); | |
1505 | |
1506 for (int i = 0; i < 1280; ++i) { | |
1507 orig_sobelx[i] = i; | |
1508 orig_sobely[i] = i * 2; | |
1509 } | |
1510 | |
1511 SobelToPlaneRow_C(orig_sobelx, orig_sobely, sobel_pixels_c, 1280); | |
1512 | |
1513 EXPECT_EQ(0u, sobel_pixels_c[0]); | |
1514 EXPECT_EQ(3u, sobel_pixels_c[1]); | |
1515 EXPECT_EQ(6u, sobel_pixels_c[2]); | |
1516 EXPECT_EQ(99u, sobel_pixels_c[33]); | |
1517 EXPECT_EQ(255u, sobel_pixels_c[100]); | |
1518 void (*SobelToPlaneRow)(const uint8* src_sobelx, const uint8* src_sobely, | |
1519 uint8* dst_y, int width) = SobelToPlaneRow_C; | |
1520 #if defined(HAS_SOBELTOPLANEROW_SSE2) | |
1521 if (TestCpuFlag(kCpuHasSSE2)) { | |
1522 SobelToPlaneRow = SobelToPlaneRow_SSE2; | |
1523 } | |
1524 #endif | |
1525 #if defined(HAS_SOBELTOPLANEROW_NEON) | |
1526 if (TestCpuFlag(kCpuHasNEON)) { | |
1527 SobelToPlaneRow = SobelToPlaneRow_NEON; | |
1528 } | |
1529 #endif | |
1530 for (int i = 0; i < benchmark_pixels_div1280_; ++i) { | |
1531 SobelToPlaneRow(orig_sobelx, orig_sobely, sobel_pixels_opt, 1280); | |
1532 } | |
1533 for (int i = 0; i < 1280; ++i) { | |
1534 EXPECT_EQ(sobel_pixels_c[i], sobel_pixels_opt[i]); | |
1535 } | |
1536 } | |
1537 | |
1538 TEST_F(LibYUVPlanarTest, TestSobelXY) { | |
1539 SIMD_ALIGNED(uint8 orig_sobelx[1280]); | |
1540 SIMD_ALIGNED(uint8 orig_sobely[1280]); | |
1541 SIMD_ALIGNED(uint8 sobel_pixels_c[1280 * 4]); | |
1542 SIMD_ALIGNED(uint8 sobel_pixels_opt[1280 * 4]); | |
1543 | |
1544 for (int i = 0; i < 1280; ++i) { | |
1545 orig_sobelx[i] = i; | |
1546 orig_sobely[i] = i * 2; | |
1547 } | |
1548 | |
1549 SobelXYRow_C(orig_sobelx, orig_sobely, sobel_pixels_c, 1280); | |
1550 | |
1551 EXPECT_EQ(0u, sobel_pixels_c[0]); | |
1552 EXPECT_EQ(2u, sobel_pixels_c[4]); | |
1553 EXPECT_EQ(3u, sobel_pixels_c[5]); | |
1554 EXPECT_EQ(1u, sobel_pixels_c[6]); | |
1555 EXPECT_EQ(255u, sobel_pixels_c[7]); | |
1556 EXPECT_EQ(255u, sobel_pixels_c[100 * 4 + 1]); | |
1557 EXPECT_EQ(255u, sobel_pixels_c[255 * 4 + 1]); | |
1558 void (*SobelXYRow)(const uint8* src_sobelx, const uint8* src_sobely, | |
1559 uint8* dst_argb, int width) = SobelXYRow_C; | |
1560 #if defined(HAS_SOBELXYROW_SSE2) | |
1561 if (TestCpuFlag(kCpuHasSSE2)) { | |
1562 SobelXYRow = SobelXYRow_SSE2; | |
1563 } | |
1564 #endif | |
1565 #if defined(HAS_SOBELXYROW_NEON) | |
1566 if (TestCpuFlag(kCpuHasNEON)) { | |
1567 SobelXYRow = SobelXYRow_NEON; | |
1568 } | |
1569 #endif | |
1570 for (int i = 0; i < benchmark_pixels_div1280_; ++i) { | |
1571 SobelXYRow(orig_sobelx, orig_sobely, sobel_pixels_opt, 1280); | |
1572 } | |
1573 for (int i = 0; i < 1280 * 4; ++i) { | |
1574 EXPECT_EQ(sobel_pixels_c[i], sobel_pixels_opt[i]); | |
1575 } | |
1576 } | |
1577 | |
1578 TEST_F(LibYUVPlanarTest, TestCopyPlane) { | 1377 TEST_F(LibYUVPlanarTest, TestCopyPlane) { |
1579 int err = 0; | 1378 int err = 0; |
1580 int yw = benchmark_width_; | 1379 int yw = benchmark_width_; |
1581 int yh = benchmark_height_; | 1380 int yh = benchmark_height_; |
1582 int b = 12; | 1381 int b = 12; |
1583 int i, j; | 1382 int i, j; |
1584 | 1383 |
1585 int y_plane_size = (yw + b * 2) * (yh + b * 2); | 1384 int y_plane_size = (yw + b * 2) * (yh + b * 2); |
1586 align_buffer_64(orig_y, y_plane_size); | 1385 align_buffer_page_end(orig_y, y_plane_size); |
1587 align_buffer_64(dst_c, y_plane_size); | 1386 align_buffer_page_end(dst_c, y_plane_size); |
1588 align_buffer_64(dst_opt, y_plane_size); | 1387 align_buffer_page_end(dst_opt, y_plane_size); |
1589 | 1388 |
1590 memset(orig_y, 0, y_plane_size); | 1389 memset(orig_y, 0, y_plane_size); |
1591 memset(dst_c, 0, y_plane_size); | 1390 memset(dst_c, 0, y_plane_size); |
1592 memset(dst_opt, 0, y_plane_size); | 1391 memset(dst_opt, 0, y_plane_size); |
1593 | 1392 |
1594 // Fill image buffers with random data. | 1393 // Fill image buffers with random data. |
1595 for (i = b; i < (yh + b); ++i) { | 1394 for (i = b; i < (yh + b); ++i) { |
1596 for (j = b; j < (yw + b); ++j) { | 1395 for (j = b; j < (yw + b); ++j) { |
1597 orig_y[i * (yw + b * 2) + j] = fastrand() & 0xff; | 1396 orig_y[i * (yw + b * 2) + j] = fastrand() & 0xff; |
1598 } | 1397 } |
(...skipping 25 matching lines...) Expand all Loading... |
1624 for (j = 0; j < benchmark_iterations_; j++) { | 1423 for (j = 0; j < benchmark_iterations_; j++) { |
1625 CopyPlane(orig_y + y_off, y_st, dst_opt + y_off, stride, yw, yh); | 1424 CopyPlane(orig_y + y_off, y_st, dst_opt + y_off, stride, yw, yh); |
1626 } | 1425 } |
1627 opt_time = (get_time() - opt_time) / benchmark_iterations_; | 1426 opt_time = (get_time() - opt_time) / benchmark_iterations_; |
1628 | 1427 |
1629 for (i = 0; i < y_plane_size; ++i) { | 1428 for (i = 0; i < y_plane_size; ++i) { |
1630 if (dst_c[i] != dst_opt[i]) | 1429 if (dst_c[i] != dst_opt[i]) |
1631 ++err; | 1430 ++err; |
1632 } | 1431 } |
1633 | 1432 |
1634 free_aligned_buffer_64(orig_y); | 1433 free_aligned_buffer_page_end(orig_y); |
1635 free_aligned_buffer_64(dst_c); | 1434 free_aligned_buffer_page_end(dst_c); |
1636 free_aligned_buffer_64(dst_opt); | 1435 free_aligned_buffer_page_end(dst_opt); |
1637 | 1436 |
1638 EXPECT_EQ(0, err); | 1437 EXPECT_EQ(0, err); |
1639 } | 1438 } |
1640 | 1439 |
1641 static int TestMultiply(int width, int height, int benchmark_iterations, | 1440 static int TestMultiply(int width, int height, int benchmark_iterations, |
1642 int disable_cpu_flags, int benchmark_cpu_info, | 1441 int disable_cpu_flags, int benchmark_cpu_info, |
1643 int invert, int off) { | 1442 int invert, int off) { |
1644 if (width < 1) { | 1443 if (width < 1) { |
1645 width = 1; | 1444 width = 1; |
1646 } | 1445 } |
1647 const int kBpp = 4; | 1446 const int kBpp = 4; |
1648 const int kStride = width * kBpp; | 1447 const int kStride = width * kBpp; |
1649 align_buffer_64(src_argb_a, kStride * height + off); | 1448 align_buffer_page_end(src_argb_a, kStride * height + off); |
1650 align_buffer_64(src_argb_b, kStride * height + off); | 1449 align_buffer_page_end(src_argb_b, kStride * height + off); |
1651 align_buffer_64(dst_argb_c, kStride * height); | 1450 align_buffer_page_end(dst_argb_c, kStride * height); |
1652 align_buffer_64(dst_argb_opt, kStride * height); | 1451 align_buffer_page_end(dst_argb_opt, kStride * height); |
1653 for (int i = 0; i < kStride * height; ++i) { | 1452 for (int i = 0; i < kStride * height; ++i) { |
1654 src_argb_a[i + off] = (fastrand() & 0xff); | 1453 src_argb_a[i + off] = (fastrand() & 0xff); |
1655 src_argb_b[i + off] = (fastrand() & 0xff); | 1454 src_argb_b[i + off] = (fastrand() & 0xff); |
1656 } | 1455 } |
1657 memset(dst_argb_c, 0, kStride * height); | 1456 memset(dst_argb_c, 0, kStride * height); |
1658 memset(dst_argb_opt, 0, kStride * height); | 1457 memset(dst_argb_opt, 0, kStride * height); |
1659 | 1458 |
1660 MaskCpuFlags(disable_cpu_flags); | 1459 MaskCpuFlags(disable_cpu_flags); |
1661 ARGBMultiply(src_argb_a + off, kStride, | 1460 ARGBMultiply(src_argb_a + off, kStride, |
1662 src_argb_b + off, kStride, | 1461 src_argb_b + off, kStride, |
1663 dst_argb_c, kStride, | 1462 dst_argb_c, kStride, |
1664 width, invert * height); | 1463 width, invert * height); |
1665 MaskCpuFlags(benchmark_cpu_info); | 1464 MaskCpuFlags(benchmark_cpu_info); |
1666 for (int i = 0; i < benchmark_iterations; ++i) { | 1465 for (int i = 0; i < benchmark_iterations; ++i) { |
1667 ARGBMultiply(src_argb_a + off, kStride, | 1466 ARGBMultiply(src_argb_a + off, kStride, |
1668 src_argb_b + off, kStride, | 1467 src_argb_b + off, kStride, |
1669 dst_argb_opt, kStride, | 1468 dst_argb_opt, kStride, |
1670 width, invert * height); | 1469 width, invert * height); |
1671 } | 1470 } |
1672 int max_diff = 0; | 1471 int max_diff = 0; |
1673 for (int i = 0; i < kStride * height; ++i) { | 1472 for (int i = 0; i < kStride * height; ++i) { |
1674 int abs_diff = | 1473 int abs_diff = |
1675 abs(static_cast<int>(dst_argb_c[i]) - | 1474 abs(static_cast<int>(dst_argb_c[i]) - |
1676 static_cast<int>(dst_argb_opt[i])); | 1475 static_cast<int>(dst_argb_opt[i])); |
1677 if (abs_diff > max_diff) { | 1476 if (abs_diff > max_diff) { |
1678 max_diff = abs_diff; | 1477 max_diff = abs_diff; |
1679 } | 1478 } |
1680 } | 1479 } |
1681 free_aligned_buffer_64(src_argb_a); | 1480 free_aligned_buffer_page_end(src_argb_a); |
1682 free_aligned_buffer_64(src_argb_b); | 1481 free_aligned_buffer_page_end(src_argb_b); |
1683 free_aligned_buffer_64(dst_argb_c); | 1482 free_aligned_buffer_page_end(dst_argb_c); |
1684 free_aligned_buffer_64(dst_argb_opt); | 1483 free_aligned_buffer_page_end(dst_argb_opt); |
1685 return max_diff; | 1484 return max_diff; |
1686 } | 1485 } |
1687 | 1486 |
1688 TEST_F(LibYUVPlanarTest, ARGBMultiply_Any) { | 1487 TEST_F(LibYUVPlanarTest, ARGBMultiply_Any) { |
1689 int max_diff = TestMultiply(benchmark_width_ - 1, benchmark_height_, | 1488 int max_diff = TestMultiply(benchmark_width_ - 1, benchmark_height_, |
1690 benchmark_iterations_, | 1489 benchmark_iterations_, |
1691 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); | 1490 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); |
1692 EXPECT_LE(max_diff, 1); | 1491 EXPECT_LE(max_diff, 1); |
1693 } | 1492 } |
1694 | 1493 |
(...skipping 19 matching lines...) Expand all Loading... |
1714 } | 1513 } |
1715 | 1514 |
1716 static int TestAdd(int width, int height, int benchmark_iterations, | 1515 static int TestAdd(int width, int height, int benchmark_iterations, |
1717 int disable_cpu_flags, int benchmark_cpu_info, | 1516 int disable_cpu_flags, int benchmark_cpu_info, |
1718 int invert, int off) { | 1517 int invert, int off) { |
1719 if (width < 1) { | 1518 if (width < 1) { |
1720 width = 1; | 1519 width = 1; |
1721 } | 1520 } |
1722 const int kBpp = 4; | 1521 const int kBpp = 4; |
1723 const int kStride = width * kBpp; | 1522 const int kStride = width * kBpp; |
1724 align_buffer_64(src_argb_a, kStride * height + off); | 1523 align_buffer_page_end(src_argb_a, kStride * height + off); |
1725 align_buffer_64(src_argb_b, kStride * height + off); | 1524 align_buffer_page_end(src_argb_b, kStride * height + off); |
1726 align_buffer_64(dst_argb_c, kStride * height); | 1525 align_buffer_page_end(dst_argb_c, kStride * height); |
1727 align_buffer_64(dst_argb_opt, kStride * height); | 1526 align_buffer_page_end(dst_argb_opt, kStride * height); |
1728 for (int i = 0; i < kStride * height; ++i) { | 1527 for (int i = 0; i < kStride * height; ++i) { |
1729 src_argb_a[i + off] = (fastrand() & 0xff); | 1528 src_argb_a[i + off] = (fastrand() & 0xff); |
1730 src_argb_b[i + off] = (fastrand() & 0xff); | 1529 src_argb_b[i + off] = (fastrand() & 0xff); |
1731 } | 1530 } |
1732 memset(dst_argb_c, 0, kStride * height); | 1531 memset(dst_argb_c, 0, kStride * height); |
1733 memset(dst_argb_opt, 0, kStride * height); | 1532 memset(dst_argb_opt, 0, kStride * height); |
1734 | 1533 |
1735 MaskCpuFlags(disable_cpu_flags); | 1534 MaskCpuFlags(disable_cpu_flags); |
1736 ARGBAdd(src_argb_a + off, kStride, | 1535 ARGBAdd(src_argb_a + off, kStride, |
1737 src_argb_b + off, kStride, | 1536 src_argb_b + off, kStride, |
1738 dst_argb_c, kStride, | 1537 dst_argb_c, kStride, |
1739 width, invert * height); | 1538 width, invert * height); |
1740 MaskCpuFlags(benchmark_cpu_info); | 1539 MaskCpuFlags(benchmark_cpu_info); |
1741 for (int i = 0; i < benchmark_iterations; ++i) { | 1540 for (int i = 0; i < benchmark_iterations; ++i) { |
1742 ARGBAdd(src_argb_a + off, kStride, | 1541 ARGBAdd(src_argb_a + off, kStride, |
1743 src_argb_b + off, kStride, | 1542 src_argb_b + off, kStride, |
1744 dst_argb_opt, kStride, | 1543 dst_argb_opt, kStride, |
1745 width, invert * height); | 1544 width, invert * height); |
1746 } | 1545 } |
1747 int max_diff = 0; | 1546 int max_diff = 0; |
1748 for (int i = 0; i < kStride * height; ++i) { | 1547 for (int i = 0; i < kStride * height; ++i) { |
1749 int abs_diff = | 1548 int abs_diff = |
1750 abs(static_cast<int>(dst_argb_c[i]) - | 1549 abs(static_cast<int>(dst_argb_c[i]) - |
1751 static_cast<int>(dst_argb_opt[i])); | 1550 static_cast<int>(dst_argb_opt[i])); |
1752 if (abs_diff > max_diff) { | 1551 if (abs_diff > max_diff) { |
1753 max_diff = abs_diff; | 1552 max_diff = abs_diff; |
1754 } | 1553 } |
1755 } | 1554 } |
1756 free_aligned_buffer_64(src_argb_a); | 1555 free_aligned_buffer_page_end(src_argb_a); |
1757 free_aligned_buffer_64(src_argb_b); | 1556 free_aligned_buffer_page_end(src_argb_b); |
1758 free_aligned_buffer_64(dst_argb_c); | 1557 free_aligned_buffer_page_end(dst_argb_c); |
1759 free_aligned_buffer_64(dst_argb_opt); | 1558 free_aligned_buffer_page_end(dst_argb_opt); |
1760 return max_diff; | 1559 return max_diff; |
1761 } | 1560 } |
1762 | 1561 |
1763 TEST_F(LibYUVPlanarTest, ARGBAdd_Any) { | 1562 TEST_F(LibYUVPlanarTest, ARGBAdd_Any) { |
1764 int max_diff = TestAdd(benchmark_width_ - 1, benchmark_height_, | 1563 int max_diff = TestAdd(benchmark_width_ - 1, benchmark_height_, |
1765 benchmark_iterations_, | 1564 benchmark_iterations_, |
1766 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); | 1565 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); |
1767 EXPECT_LE(max_diff, 1); | 1566 EXPECT_LE(max_diff, 1); |
1768 } | 1567 } |
1769 | 1568 |
(...skipping 19 matching lines...) Expand all Loading... |
1789 } | 1588 } |
1790 | 1589 |
1791 static int TestSubtract(int width, int height, int benchmark_iterations, | 1590 static int TestSubtract(int width, int height, int benchmark_iterations, |
1792 int disable_cpu_flags, int benchmark_cpu_info, | 1591 int disable_cpu_flags, int benchmark_cpu_info, |
1793 int invert, int off) { | 1592 int invert, int off) { |
1794 if (width < 1) { | 1593 if (width < 1) { |
1795 width = 1; | 1594 width = 1; |
1796 } | 1595 } |
1797 const int kBpp = 4; | 1596 const int kBpp = 4; |
1798 const int kStride = width * kBpp; | 1597 const int kStride = width * kBpp; |
1799 align_buffer_64(src_argb_a, kStride * height + off); | 1598 align_buffer_page_end(src_argb_a, kStride * height + off); |
1800 align_buffer_64(src_argb_b, kStride * height + off); | 1599 align_buffer_page_end(src_argb_b, kStride * height + off); |
1801 align_buffer_64(dst_argb_c, kStride * height); | 1600 align_buffer_page_end(dst_argb_c, kStride * height); |
1802 align_buffer_64(dst_argb_opt, kStride * height); | 1601 align_buffer_page_end(dst_argb_opt, kStride * height); |
1803 for (int i = 0; i < kStride * height; ++i) { | 1602 for (int i = 0; i < kStride * height; ++i) { |
1804 src_argb_a[i + off] = (fastrand() & 0xff); | 1603 src_argb_a[i + off] = (fastrand() & 0xff); |
1805 src_argb_b[i + off] = (fastrand() & 0xff); | 1604 src_argb_b[i + off] = (fastrand() & 0xff); |
1806 } | 1605 } |
1807 memset(dst_argb_c, 0, kStride * height); | 1606 memset(dst_argb_c, 0, kStride * height); |
1808 memset(dst_argb_opt, 0, kStride * height); | 1607 memset(dst_argb_opt, 0, kStride * height); |
1809 | 1608 |
1810 MaskCpuFlags(disable_cpu_flags); | 1609 MaskCpuFlags(disable_cpu_flags); |
1811 ARGBSubtract(src_argb_a + off, kStride, | 1610 ARGBSubtract(src_argb_a + off, kStride, |
1812 src_argb_b + off, kStride, | 1611 src_argb_b + off, kStride, |
1813 dst_argb_c, kStride, | 1612 dst_argb_c, kStride, |
1814 width, invert * height); | 1613 width, invert * height); |
1815 MaskCpuFlags(benchmark_cpu_info); | 1614 MaskCpuFlags(benchmark_cpu_info); |
1816 for (int i = 0; i < benchmark_iterations; ++i) { | 1615 for (int i = 0; i < benchmark_iterations; ++i) { |
1817 ARGBSubtract(src_argb_a + off, kStride, | 1616 ARGBSubtract(src_argb_a + off, kStride, |
1818 src_argb_b + off, kStride, | 1617 src_argb_b + off, kStride, |
1819 dst_argb_opt, kStride, | 1618 dst_argb_opt, kStride, |
1820 width, invert * height); | 1619 width, invert * height); |
1821 } | 1620 } |
1822 int max_diff = 0; | 1621 int max_diff = 0; |
1823 for (int i = 0; i < kStride * height; ++i) { | 1622 for (int i = 0; i < kStride * height; ++i) { |
1824 int abs_diff = | 1623 int abs_diff = |
1825 abs(static_cast<int>(dst_argb_c[i]) - | 1624 abs(static_cast<int>(dst_argb_c[i]) - |
1826 static_cast<int>(dst_argb_opt[i])); | 1625 static_cast<int>(dst_argb_opt[i])); |
1827 if (abs_diff > max_diff) { | 1626 if (abs_diff > max_diff) { |
1828 max_diff = abs_diff; | 1627 max_diff = abs_diff; |
1829 } | 1628 } |
1830 } | 1629 } |
1831 free_aligned_buffer_64(src_argb_a); | 1630 free_aligned_buffer_page_end(src_argb_a); |
1832 free_aligned_buffer_64(src_argb_b); | 1631 free_aligned_buffer_page_end(src_argb_b); |
1833 free_aligned_buffer_64(dst_argb_c); | 1632 free_aligned_buffer_page_end(dst_argb_c); |
1834 free_aligned_buffer_64(dst_argb_opt); | 1633 free_aligned_buffer_page_end(dst_argb_opt); |
1835 return max_diff; | 1634 return max_diff; |
1836 } | 1635 } |
1837 | 1636 |
1838 TEST_F(LibYUVPlanarTest, ARGBSubtract_Any) { | 1637 TEST_F(LibYUVPlanarTest, ARGBSubtract_Any) { |
1839 int max_diff = TestSubtract(benchmark_width_ - 1, benchmark_height_, | 1638 int max_diff = TestSubtract(benchmark_width_ - 1, benchmark_height_, |
1840 benchmark_iterations_, | 1639 benchmark_iterations_, |
1841 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); | 1640 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); |
1842 EXPECT_LE(max_diff, 1); | 1641 EXPECT_LE(max_diff, 1); |
1843 } | 1642 } |
1844 | 1643 |
(...skipping 19 matching lines...) Expand all Loading... |
1864 } | 1663 } |
1865 | 1664 |
1866 static int TestSobel(int width, int height, int benchmark_iterations, | 1665 static int TestSobel(int width, int height, int benchmark_iterations, |
1867 int disable_cpu_flags, int benchmark_cpu_info, | 1666 int disable_cpu_flags, int benchmark_cpu_info, |
1868 int invert, int off) { | 1667 int invert, int off) { |
1869 if (width < 1) { | 1668 if (width < 1) { |
1870 width = 1; | 1669 width = 1; |
1871 } | 1670 } |
1872 const int kBpp = 4; | 1671 const int kBpp = 4; |
1873 const int kStride = width * kBpp; | 1672 const int kStride = width * kBpp; |
1874 align_buffer_64(src_argb_a, kStride * height + off); | 1673 align_buffer_page_end(src_argb_a, kStride * height + off); |
1875 align_buffer_64(dst_argb_c, kStride * height); | 1674 align_buffer_page_end(dst_argb_c, kStride * height); |
1876 align_buffer_64(dst_argb_opt, kStride * height); | 1675 align_buffer_page_end(dst_argb_opt, kStride * height); |
1877 memset(src_argb_a, 0, kStride * height + off); | 1676 memset(src_argb_a, 0, kStride * height + off); |
1878 for (int i = 0; i < kStride * height; ++i) { | 1677 for (int i = 0; i < kStride * height; ++i) { |
1879 src_argb_a[i + off] = (fastrand() & 0xff); | 1678 src_argb_a[i + off] = (fastrand() & 0xff); |
1880 } | 1679 } |
1881 memset(dst_argb_c, 0, kStride * height); | 1680 memset(dst_argb_c, 0, kStride * height); |
1882 memset(dst_argb_opt, 0, kStride * height); | 1681 memset(dst_argb_opt, 0, kStride * height); |
1883 | 1682 |
1884 MaskCpuFlags(disable_cpu_flags); | 1683 MaskCpuFlags(disable_cpu_flags); |
1885 ARGBSobel(src_argb_a + off, kStride, | 1684 ARGBSobel(src_argb_a + off, kStride, |
1886 dst_argb_c, kStride, | 1685 dst_argb_c, kStride, |
1887 width, invert * height); | 1686 width, invert * height); |
1888 MaskCpuFlags(benchmark_cpu_info); | 1687 MaskCpuFlags(benchmark_cpu_info); |
1889 for (int i = 0; i < benchmark_iterations; ++i) { | 1688 for (int i = 0; i < benchmark_iterations; ++i) { |
1890 ARGBSobel(src_argb_a + off, kStride, | 1689 ARGBSobel(src_argb_a + off, kStride, |
1891 dst_argb_opt, kStride, | 1690 dst_argb_opt, kStride, |
1892 width, invert * height); | 1691 width, invert * height); |
1893 } | 1692 } |
1894 int max_diff = 0; | 1693 int max_diff = 0; |
1895 for (int i = 0; i < kStride * height; ++i) { | 1694 for (int i = 0; i < kStride * height; ++i) { |
1896 int abs_diff = | 1695 int abs_diff = |
1897 abs(static_cast<int>(dst_argb_c[i]) - | 1696 abs(static_cast<int>(dst_argb_c[i]) - |
1898 static_cast<int>(dst_argb_opt[i])); | 1697 static_cast<int>(dst_argb_opt[i])); |
1899 if (abs_diff > max_diff) { | 1698 if (abs_diff > max_diff) { |
1900 max_diff = abs_diff; | 1699 max_diff = abs_diff; |
1901 } | 1700 } |
1902 } | 1701 } |
1903 free_aligned_buffer_64(src_argb_a); | 1702 free_aligned_buffer_page_end(src_argb_a); |
1904 free_aligned_buffer_64(dst_argb_c); | 1703 free_aligned_buffer_page_end(dst_argb_c); |
1905 free_aligned_buffer_64(dst_argb_opt); | 1704 free_aligned_buffer_page_end(dst_argb_opt); |
1906 return max_diff; | 1705 return max_diff; |
1907 } | 1706 } |
1908 | 1707 |
1909 TEST_F(LibYUVPlanarTest, ARGBSobel_Any) { | 1708 TEST_F(LibYUVPlanarTest, ARGBSobel_Any) { |
1910 int max_diff = TestSobel(benchmark_width_ - 1, benchmark_height_, | 1709 int max_diff = TestSobel(benchmark_width_ - 1, benchmark_height_, |
1911 benchmark_iterations_, | 1710 benchmark_iterations_, |
1912 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); | 1711 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); |
1913 EXPECT_EQ(0, max_diff); | 1712 EXPECT_EQ(0, max_diff); |
1914 } | 1713 } |
1915 | 1714 |
(...skipping 21 matching lines...) Expand all Loading... |
1937 static int TestSobelToPlane(int width, int height, int benchmark_iterations, | 1736 static int TestSobelToPlane(int width, int height, int benchmark_iterations, |
1938 int disable_cpu_flags, int benchmark_cpu_info, | 1737 int disable_cpu_flags, int benchmark_cpu_info, |
1939 int invert, int off) { | 1738 int invert, int off) { |
1940 if (width < 1) { | 1739 if (width < 1) { |
1941 width = 1; | 1740 width = 1; |
1942 } | 1741 } |
1943 const int kSrcBpp = 4; | 1742 const int kSrcBpp = 4; |
1944 const int kDstBpp = 1; | 1743 const int kDstBpp = 1; |
1945 const int kSrcStride = (width * kSrcBpp + 15) & ~15; | 1744 const int kSrcStride = (width * kSrcBpp + 15) & ~15; |
1946 const int kDstStride = (width * kDstBpp + 15) & ~15; | 1745 const int kDstStride = (width * kDstBpp + 15) & ~15; |
1947 align_buffer_64(src_argb_a, kSrcStride * height + off); | 1746 align_buffer_page_end(src_argb_a, kSrcStride * height + off); |
1948 align_buffer_64(dst_argb_c, kDstStride * height); | 1747 align_buffer_page_end(dst_argb_c, kDstStride * height); |
1949 align_buffer_64(dst_argb_opt, kDstStride * height); | 1748 align_buffer_page_end(dst_argb_opt, kDstStride * height); |
1950 memset(src_argb_a, 0, kSrcStride * height + off); | 1749 memset(src_argb_a, 0, kSrcStride * height + off); |
1951 for (int i = 0; i < kSrcStride * height; ++i) { | 1750 for (int i = 0; i < kSrcStride * height; ++i) { |
1952 src_argb_a[i + off] = (fastrand() & 0xff); | 1751 src_argb_a[i + off] = (fastrand() & 0xff); |
1953 } | 1752 } |
1954 memset(dst_argb_c, 0, kDstStride * height); | 1753 memset(dst_argb_c, 0, kDstStride * height); |
1955 memset(dst_argb_opt, 0, kDstStride * height); | 1754 memset(dst_argb_opt, 0, kDstStride * height); |
1956 | 1755 |
1957 MaskCpuFlags(disable_cpu_flags); | 1756 MaskCpuFlags(disable_cpu_flags); |
1958 ARGBSobelToPlane(src_argb_a + off, kSrcStride, | 1757 ARGBSobelToPlane(src_argb_a + off, kSrcStride, |
1959 dst_argb_c, kDstStride, | 1758 dst_argb_c, kDstStride, |
1960 width, invert * height); | 1759 width, invert * height); |
1961 MaskCpuFlags(benchmark_cpu_info); | 1760 MaskCpuFlags(benchmark_cpu_info); |
1962 for (int i = 0; i < benchmark_iterations; ++i) { | 1761 for (int i = 0; i < benchmark_iterations; ++i) { |
1963 ARGBSobelToPlane(src_argb_a + off, kSrcStride, | 1762 ARGBSobelToPlane(src_argb_a + off, kSrcStride, |
1964 dst_argb_opt, kDstStride, | 1763 dst_argb_opt, kDstStride, |
1965 width, invert * height); | 1764 width, invert * height); |
1966 } | 1765 } |
1967 int max_diff = 0; | 1766 int max_diff = 0; |
1968 for (int i = 0; i < kDstStride * height; ++i) { | 1767 for (int i = 0; i < kDstStride * height; ++i) { |
1969 int abs_diff = | 1768 int abs_diff = |
1970 abs(static_cast<int>(dst_argb_c[i]) - | 1769 abs(static_cast<int>(dst_argb_c[i]) - |
1971 static_cast<int>(dst_argb_opt[i])); | 1770 static_cast<int>(dst_argb_opt[i])); |
1972 if (abs_diff > max_diff) { | 1771 if (abs_diff > max_diff) { |
1973 max_diff = abs_diff; | 1772 max_diff = abs_diff; |
1974 } | 1773 } |
1975 } | 1774 } |
1976 free_aligned_buffer_64(src_argb_a); | 1775 free_aligned_buffer_page_end(src_argb_a); |
1977 free_aligned_buffer_64(dst_argb_c); | 1776 free_aligned_buffer_page_end(dst_argb_c); |
1978 free_aligned_buffer_64(dst_argb_opt); | 1777 free_aligned_buffer_page_end(dst_argb_opt); |
1979 return max_diff; | 1778 return max_diff; |
1980 } | 1779 } |
1981 | 1780 |
1982 TEST_F(LibYUVPlanarTest, ARGBSobelToPlane_Any) { | 1781 TEST_F(LibYUVPlanarTest, ARGBSobelToPlane_Any) { |
1983 int max_diff = TestSobelToPlane(benchmark_width_ - 1, benchmark_height_, | 1782 int max_diff = TestSobelToPlane(benchmark_width_ - 1, benchmark_height_, |
1984 benchmark_iterations_, | 1783 benchmark_iterations_, |
1985 disable_cpu_flags_, benchmark_cpu_info_, | 1784 disable_cpu_flags_, benchmark_cpu_info_, |
1986 +1, 0); | 1785 +1, 0); |
1987 EXPECT_EQ(0, max_diff); | 1786 EXPECT_EQ(0, max_diff); |
1988 } | 1787 } |
(...skipping 23 matching lines...) Expand all Loading... |
2012 } | 1811 } |
2013 | 1812 |
2014 static int TestSobelXY(int width, int height, int benchmark_iterations, | 1813 static int TestSobelXY(int width, int height, int benchmark_iterations, |
2015 int disable_cpu_flags, int benchmark_cpu_info, | 1814 int disable_cpu_flags, int benchmark_cpu_info, |
2016 int invert, int off) { | 1815 int invert, int off) { |
2017 if (width < 1) { | 1816 if (width < 1) { |
2018 width = 1; | 1817 width = 1; |
2019 } | 1818 } |
2020 const int kBpp = 4; | 1819 const int kBpp = 4; |
2021 const int kStride = width * kBpp; | 1820 const int kStride = width * kBpp; |
2022 align_buffer_64(src_argb_a, kStride * height + off); | 1821 align_buffer_page_end(src_argb_a, kStride * height + off); |
2023 align_buffer_64(dst_argb_c, kStride * height); | 1822 align_buffer_page_end(dst_argb_c, kStride * height); |
2024 align_buffer_64(dst_argb_opt, kStride * height); | 1823 align_buffer_page_end(dst_argb_opt, kStride * height); |
2025 memset(src_argb_a, 0, kStride * height + off); | 1824 memset(src_argb_a, 0, kStride * height + off); |
2026 for (int i = 0; i < kStride * height; ++i) { | 1825 for (int i = 0; i < kStride * height; ++i) { |
2027 src_argb_a[i + off] = (fastrand() & 0xff); | 1826 src_argb_a[i + off] = (fastrand() & 0xff); |
2028 } | 1827 } |
2029 memset(dst_argb_c, 0, kStride * height); | 1828 memset(dst_argb_c, 0, kStride * height); |
2030 memset(dst_argb_opt, 0, kStride * height); | 1829 memset(dst_argb_opt, 0, kStride * height); |
2031 | 1830 |
2032 MaskCpuFlags(disable_cpu_flags); | 1831 MaskCpuFlags(disable_cpu_flags); |
2033 ARGBSobelXY(src_argb_a + off, kStride, | 1832 ARGBSobelXY(src_argb_a + off, kStride, |
2034 dst_argb_c, kStride, | 1833 dst_argb_c, kStride, |
2035 width, invert * height); | 1834 width, invert * height); |
2036 MaskCpuFlags(benchmark_cpu_info); | 1835 MaskCpuFlags(benchmark_cpu_info); |
2037 for (int i = 0; i < benchmark_iterations; ++i) { | 1836 for (int i = 0; i < benchmark_iterations; ++i) { |
2038 ARGBSobelXY(src_argb_a + off, kStride, | 1837 ARGBSobelXY(src_argb_a + off, kStride, |
2039 dst_argb_opt, kStride, | 1838 dst_argb_opt, kStride, |
2040 width, invert * height); | 1839 width, invert * height); |
2041 } | 1840 } |
2042 int max_diff = 0; | 1841 int max_diff = 0; |
2043 for (int i = 0; i < kStride * height; ++i) { | 1842 for (int i = 0; i < kStride * height; ++i) { |
2044 int abs_diff = | 1843 int abs_diff = |
2045 abs(static_cast<int>(dst_argb_c[i]) - | 1844 abs(static_cast<int>(dst_argb_c[i]) - |
2046 static_cast<int>(dst_argb_opt[i])); | 1845 static_cast<int>(dst_argb_opt[i])); |
2047 if (abs_diff > max_diff) { | 1846 if (abs_diff > max_diff) { |
2048 max_diff = abs_diff; | 1847 max_diff = abs_diff; |
2049 } | 1848 } |
2050 } | 1849 } |
2051 free_aligned_buffer_64(src_argb_a); | 1850 free_aligned_buffer_page_end(src_argb_a); |
2052 free_aligned_buffer_64(dst_argb_c); | 1851 free_aligned_buffer_page_end(dst_argb_c); |
2053 free_aligned_buffer_64(dst_argb_opt); | 1852 free_aligned_buffer_page_end(dst_argb_opt); |
2054 return max_diff; | 1853 return max_diff; |
2055 } | 1854 } |
2056 | 1855 |
2057 TEST_F(LibYUVPlanarTest, ARGBSobelXY_Any) { | 1856 TEST_F(LibYUVPlanarTest, ARGBSobelXY_Any) { |
2058 int max_diff = TestSobelXY(benchmark_width_ - 1, benchmark_height_, | 1857 int max_diff = TestSobelXY(benchmark_width_ - 1, benchmark_height_, |
2059 benchmark_iterations_, | 1858 benchmark_iterations_, |
2060 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); | 1859 disable_cpu_flags_, benchmark_cpu_info_, +1, 0); |
2061 EXPECT_EQ(0, max_diff); | 1860 EXPECT_EQ(0, max_diff); |
2062 } | 1861 } |
2063 | 1862 |
(...skipping 19 matching lines...) Expand all Loading... |
2083 } | 1882 } |
2084 | 1883 |
2085 static int TestBlur(int width, int height, int benchmark_iterations, | 1884 static int TestBlur(int width, int height, int benchmark_iterations, |
2086 int disable_cpu_flags, int benchmark_cpu_info, | 1885 int disable_cpu_flags, int benchmark_cpu_info, |
2087 int invert, int off, int radius) { | 1886 int invert, int off, int radius) { |
2088 if (width < 1) { | 1887 if (width < 1) { |
2089 width = 1; | 1888 width = 1; |
2090 } | 1889 } |
2091 const int kBpp = 4; | 1890 const int kBpp = 4; |
2092 const int kStride = width * kBpp; | 1891 const int kStride = width * kBpp; |
2093 align_buffer_64(src_argb_a, kStride * height + off); | 1892 align_buffer_page_end(src_argb_a, kStride * height + off); |
2094 align_buffer_64(dst_cumsum, width * height * 16); | 1893 align_buffer_page_end(dst_cumsum, width * height * 16); |
2095 align_buffer_64(dst_argb_c, kStride * height); | 1894 align_buffer_page_end(dst_argb_c, kStride * height); |
2096 align_buffer_64(dst_argb_opt, kStride * height); | 1895 align_buffer_page_end(dst_argb_opt, kStride * height); |
2097 for (int i = 0; i < kStride * height; ++i) { | 1896 for (int i = 0; i < kStride * height; ++i) { |
2098 src_argb_a[i + off] = (fastrand() & 0xff); | 1897 src_argb_a[i + off] = (fastrand() & 0xff); |
2099 } | 1898 } |
2100 memset(dst_cumsum, 0, width * height * 16); | 1899 memset(dst_cumsum, 0, width * height * 16); |
2101 memset(dst_argb_c, 0, kStride * height); | 1900 memset(dst_argb_c, 0, kStride * height); |
2102 memset(dst_argb_opt, 0, kStride * height); | 1901 memset(dst_argb_opt, 0, kStride * height); |
2103 | 1902 |
2104 MaskCpuFlags(disable_cpu_flags); | 1903 MaskCpuFlags(disable_cpu_flags); |
2105 ARGBBlur(src_argb_a + off, kStride, | 1904 ARGBBlur(src_argb_a + off, kStride, |
2106 dst_argb_c, kStride, | 1905 dst_argb_c, kStride, |
2107 reinterpret_cast<int32*>(dst_cumsum), width * 4, | 1906 reinterpret_cast<int32*>(dst_cumsum), width * 4, |
2108 width, invert * height, radius); | 1907 width, invert * height, radius); |
2109 MaskCpuFlags(benchmark_cpu_info); | 1908 MaskCpuFlags(benchmark_cpu_info); |
2110 for (int i = 0; i < benchmark_iterations; ++i) { | 1909 for (int i = 0; i < benchmark_iterations; ++i) { |
2111 ARGBBlur(src_argb_a + off, kStride, | 1910 ARGBBlur(src_argb_a + off, kStride, |
2112 dst_argb_opt, kStride, | 1911 dst_argb_opt, kStride, |
2113 reinterpret_cast<int32*>(dst_cumsum), width * 4, | 1912 reinterpret_cast<int32*>(dst_cumsum), width * 4, |
2114 width, invert * height, radius); | 1913 width, invert * height, radius); |
2115 } | 1914 } |
2116 int max_diff = 0; | 1915 int max_diff = 0; |
2117 for (int i = 0; i < kStride * height; ++i) { | 1916 for (int i = 0; i < kStride * height; ++i) { |
2118 int abs_diff = | 1917 int abs_diff = |
2119 abs(static_cast<int>(dst_argb_c[i]) - | 1918 abs(static_cast<int>(dst_argb_c[i]) - |
2120 static_cast<int>(dst_argb_opt[i])); | 1919 static_cast<int>(dst_argb_opt[i])); |
2121 if (abs_diff > max_diff) { | 1920 if (abs_diff > max_diff) { |
2122 max_diff = abs_diff; | 1921 max_diff = abs_diff; |
2123 } | 1922 } |
2124 } | 1923 } |
2125 free_aligned_buffer_64(src_argb_a); | 1924 free_aligned_buffer_page_end(src_argb_a); |
2126 free_aligned_buffer_64(dst_cumsum); | 1925 free_aligned_buffer_page_end(dst_cumsum); |
2127 free_aligned_buffer_64(dst_argb_c); | 1926 free_aligned_buffer_page_end(dst_argb_c); |
2128 free_aligned_buffer_64(dst_argb_opt); | 1927 free_aligned_buffer_page_end(dst_argb_opt); |
2129 return max_diff; | 1928 return max_diff; |
2130 } | 1929 } |
2131 | 1930 |
2132 static const int kBlurSize = 55; | 1931 static const int kBlurSize = 55; |
2133 TEST_F(LibYUVPlanarTest, ARGBBlur_Any) { | 1932 TEST_F(LibYUVPlanarTest, DISABLED_ARGBBlur_Any) { |
2134 int max_diff = TestBlur(benchmark_width_ - 1, benchmark_height_, | 1933 int max_diff = TestBlur(benchmark_width_ - 1, benchmark_height_, |
2135 benchmark_iterations_, | 1934 benchmark_iterations_, |
2136 disable_cpu_flags_, benchmark_cpu_info_, | 1935 disable_cpu_flags_, benchmark_cpu_info_, |
2137 +1, 0, kBlurSize); | 1936 +1, 0, kBlurSize); |
2138 EXPECT_LE(max_diff, 1); | 1937 EXPECT_LE(max_diff, 1); |
2139 } | 1938 } |
2140 | 1939 |
2141 TEST_F(LibYUVPlanarTest, ARGBBlur_Unaligned) { | 1940 TEST_F(LibYUVPlanarTest, ARGBBlur_Unaligned) { |
2142 int max_diff = TestBlur(benchmark_width_, benchmark_height_, | 1941 int max_diff = TestBlur(benchmark_width_, benchmark_height_, |
2143 benchmark_iterations_, | 1942 benchmark_iterations_, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2281 EXPECT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]); | 2080 EXPECT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]); |
2282 } | 2081 } |
2283 } | 2082 } |
2284 | 2083 |
2285 TEST_F(LibYUVPlanarTest, TestARGBLumaColorTable) { | 2084 TEST_F(LibYUVPlanarTest, TestARGBLumaColorTable) { |
2286 SIMD_ALIGNED(uint8 orig_pixels[1280][4]); | 2085 SIMD_ALIGNED(uint8 orig_pixels[1280][4]); |
2287 SIMD_ALIGNED(uint8 dst_pixels_opt[1280][4]); | 2086 SIMD_ALIGNED(uint8 dst_pixels_opt[1280][4]); |
2288 SIMD_ALIGNED(uint8 dst_pixels_c[1280][4]); | 2087 SIMD_ALIGNED(uint8 dst_pixels_c[1280][4]); |
2289 memset(orig_pixels, 0, sizeof(orig_pixels)); | 2088 memset(orig_pixels, 0, sizeof(orig_pixels)); |
2290 | 2089 |
2291 align_buffer_64(lumacolortable, 32768); | 2090 align_buffer_page_end(lumacolortable, 32768); |
2292 int v = 0; | 2091 int v = 0; |
2293 for (int i = 0; i < 32768; ++i) { | 2092 for (int i = 0; i < 32768; ++i) { |
2294 lumacolortable[i] = v; | 2093 lumacolortable[i] = v; |
2295 v += 3; | 2094 v += 3; |
2296 } | 2095 } |
2297 // Test blue | 2096 // Test blue |
2298 orig_pixels[0][0] = 255u; | 2097 orig_pixels[0][0] = 255u; |
2299 orig_pixels[0][1] = 0u; | 2098 orig_pixels[0][1] = 0u; |
2300 orig_pixels[0][2] = 0u; | 2099 orig_pixels[0][2] = 0u; |
2301 orig_pixels[0][3] = 128u; | 2100 orig_pixels[0][3] = 128u; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2350 ARGBLumaColorTable(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0, | 2149 ARGBLumaColorTable(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0, |
2351 lumacolortable, 1280, 1); | 2150 lumacolortable, 1280, 1); |
2352 } | 2151 } |
2353 for (int i = 0; i < 1280; ++i) { | 2152 for (int i = 0; i < 1280; ++i) { |
2354 EXPECT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]); | 2153 EXPECT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]); |
2355 EXPECT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]); | 2154 EXPECT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]); |
2356 EXPECT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]); | 2155 EXPECT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]); |
2357 EXPECT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]); | 2156 EXPECT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]); |
2358 } | 2157 } |
2359 | 2158 |
2360 free_aligned_buffer_64(lumacolortable); | 2159 free_aligned_buffer_page_end(lumacolortable); |
2361 } | 2160 } |
2362 | 2161 |
2363 TEST_F(LibYUVPlanarTest, TestARGBCopyAlpha) { | 2162 TEST_F(LibYUVPlanarTest, TestARGBCopyAlpha) { |
2364 const int kSize = benchmark_width_ * benchmark_height_ * 4; | 2163 const int kSize = benchmark_width_ * benchmark_height_ * 4; |
2365 align_buffer_64(orig_pixels, kSize); | 2164 align_buffer_page_end(orig_pixels, kSize); |
2366 align_buffer_64(dst_pixels_opt, kSize); | 2165 align_buffer_page_end(dst_pixels_opt, kSize); |
2367 align_buffer_64(dst_pixels_c, kSize); | 2166 align_buffer_page_end(dst_pixels_c, kSize); |
2368 | 2167 |
2369 MemRandomize(orig_pixels, kSize); | 2168 MemRandomize(orig_pixels, kSize); |
2370 MemRandomize(dst_pixels_opt, kSize); | 2169 MemRandomize(dst_pixels_opt, kSize); |
2371 memcpy(dst_pixels_c, dst_pixels_opt, kSize); | 2170 memcpy(dst_pixels_c, dst_pixels_opt, kSize); |
2372 | 2171 |
2373 MaskCpuFlags(disable_cpu_flags_); | 2172 MaskCpuFlags(disable_cpu_flags_); |
2374 ARGBCopyAlpha(orig_pixels, benchmark_width_ * 4, | 2173 ARGBCopyAlpha(orig_pixels, benchmark_width_ * 4, |
2375 dst_pixels_c, benchmark_width_ * 4, | 2174 dst_pixels_c, benchmark_width_ * 4, |
2376 benchmark_width_, benchmark_height_); | 2175 benchmark_width_, benchmark_height_); |
2377 MaskCpuFlags(benchmark_cpu_info_); | 2176 MaskCpuFlags(benchmark_cpu_info_); |
2378 | 2177 |
2379 for (int i = 0; i < benchmark_iterations_; ++i) { | 2178 for (int i = 0; i < benchmark_iterations_; ++i) { |
2380 ARGBCopyAlpha(orig_pixels, benchmark_width_ * 4, | 2179 ARGBCopyAlpha(orig_pixels, benchmark_width_ * 4, |
2381 dst_pixels_opt, benchmark_width_ * 4, | 2180 dst_pixels_opt, benchmark_width_ * 4, |
2382 benchmark_width_, benchmark_height_); | 2181 benchmark_width_, benchmark_height_); |
2383 } | 2182 } |
2384 for (int i = 0; i < kSize; ++i) { | 2183 for (int i = 0; i < kSize; ++i) { |
2385 EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); | 2184 EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); |
2386 } | 2185 } |
2387 | 2186 |
2388 free_aligned_buffer_64(dst_pixels_c); | 2187 free_aligned_buffer_page_end(dst_pixels_c); |
2389 free_aligned_buffer_64(dst_pixels_opt); | 2188 free_aligned_buffer_page_end(dst_pixels_opt); |
2390 free_aligned_buffer_64(orig_pixels); | 2189 free_aligned_buffer_page_end(orig_pixels); |
2391 } | 2190 } |
2392 | 2191 |
2393 TEST_F(LibYUVPlanarTest, TestARGBExtractAlpha) { | 2192 TEST_F(LibYUVPlanarTest, TestARGBExtractAlpha) { |
2394 const int kPixels = benchmark_width_ * benchmark_height_; | 2193 const int kPixels = benchmark_width_ * benchmark_height_; |
2395 align_buffer_64(src_pixels, kPixels * 4); | 2194 align_buffer_page_end(src_pixels, kPixels * 4); |
2396 align_buffer_64(dst_pixels_opt, kPixels); | 2195 align_buffer_page_end(dst_pixels_opt, kPixels); |
2397 align_buffer_64(dst_pixels_c, kPixels); | 2196 align_buffer_page_end(dst_pixels_c, kPixels); |
2398 | 2197 |
2399 MemRandomize(src_pixels, kPixels * 4); | 2198 MemRandomize(src_pixels, kPixels * 4); |
2400 MemRandomize(dst_pixels_opt, kPixels); | 2199 MemRandomize(dst_pixels_opt, kPixels); |
2401 memcpy(dst_pixels_c, dst_pixels_opt, kPixels); | 2200 memcpy(dst_pixels_c, dst_pixels_opt, kPixels); |
2402 | 2201 |
2403 MaskCpuFlags(disable_cpu_flags_); | 2202 MaskCpuFlags(disable_cpu_flags_); |
2404 ARGBExtractAlpha(src_pixels, benchmark_width_ * 4, | 2203 ARGBExtractAlpha(src_pixels, benchmark_width_ * 4, |
2405 dst_pixels_c, benchmark_width_, | 2204 dst_pixels_c, benchmark_width_, |
2406 benchmark_width_, benchmark_height_); | 2205 benchmark_width_, benchmark_height_); |
2407 MaskCpuFlags(benchmark_cpu_info_); | 2206 MaskCpuFlags(benchmark_cpu_info_); |
2408 | 2207 |
2409 for (int i = 0; i < benchmark_iterations_; ++i) { | 2208 for (int i = 0; i < benchmark_iterations_; ++i) { |
2410 ARGBExtractAlpha(src_pixels, benchmark_width_ * 4, | 2209 ARGBExtractAlpha(src_pixels, benchmark_width_ * 4, |
2411 dst_pixels_opt, benchmark_width_, | 2210 dst_pixels_opt, benchmark_width_, |
2412 benchmark_width_, benchmark_height_); | 2211 benchmark_width_, benchmark_height_); |
2413 } | 2212 } |
2414 for (int i = 0; i < kPixels; ++i) { | 2213 for (int i = 0; i < kPixels; ++i) { |
2415 EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); | 2214 EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); |
2416 } | 2215 } |
2417 | 2216 |
2418 free_aligned_buffer_64(dst_pixels_c); | 2217 free_aligned_buffer_page_end(dst_pixels_c); |
2419 free_aligned_buffer_64(dst_pixels_opt); | 2218 free_aligned_buffer_page_end(dst_pixels_opt); |
2420 free_aligned_buffer_64(src_pixels); | 2219 free_aligned_buffer_page_end(src_pixels); |
2421 } | 2220 } |
2422 | 2221 |
2423 TEST_F(LibYUVPlanarTest, TestARGBCopyYToAlpha) { | 2222 TEST_F(LibYUVPlanarTest, TestARGBCopyYToAlpha) { |
2424 const int kPixels = benchmark_width_ * benchmark_height_; | 2223 const int kPixels = benchmark_width_ * benchmark_height_; |
2425 align_buffer_64(orig_pixels, kPixels); | 2224 align_buffer_page_end(orig_pixels, kPixels); |
2426 align_buffer_64(dst_pixels_opt, kPixels * 4); | 2225 align_buffer_page_end(dst_pixels_opt, kPixels * 4); |
2427 align_buffer_64(dst_pixels_c, kPixels * 4); | 2226 align_buffer_page_end(dst_pixels_c, kPixels * 4); |
2428 | 2227 |
2429 MemRandomize(orig_pixels, kPixels); | 2228 MemRandomize(orig_pixels, kPixels); |
2430 MemRandomize(dst_pixels_opt, kPixels * 4); | 2229 MemRandomize(dst_pixels_opt, kPixels * 4); |
2431 memcpy(dst_pixels_c, dst_pixels_opt, kPixels * 4); | 2230 memcpy(dst_pixels_c, dst_pixels_opt, kPixels * 4); |
2432 | 2231 |
2433 MaskCpuFlags(disable_cpu_flags_); | 2232 MaskCpuFlags(disable_cpu_flags_); |
2434 ARGBCopyYToAlpha(orig_pixels, benchmark_width_, | 2233 ARGBCopyYToAlpha(orig_pixels, benchmark_width_, |
2435 dst_pixels_c, benchmark_width_ * 4, | 2234 dst_pixels_c, benchmark_width_ * 4, |
2436 benchmark_width_, benchmark_height_); | 2235 benchmark_width_, benchmark_height_); |
2437 MaskCpuFlags(benchmark_cpu_info_); | 2236 MaskCpuFlags(benchmark_cpu_info_); |
2438 | 2237 |
2439 for (int i = 0; i < benchmark_iterations_; ++i) { | 2238 for (int i = 0; i < benchmark_iterations_; ++i) { |
2440 ARGBCopyYToAlpha(orig_pixels, benchmark_width_, | 2239 ARGBCopyYToAlpha(orig_pixels, benchmark_width_, |
2441 dst_pixels_opt, benchmark_width_ * 4, | 2240 dst_pixels_opt, benchmark_width_ * 4, |
2442 benchmark_width_, benchmark_height_); | 2241 benchmark_width_, benchmark_height_); |
2443 } | 2242 } |
2444 for (int i = 0; i < kPixels * 4; ++i) { | 2243 for (int i = 0; i < kPixels * 4; ++i) { |
2445 EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); | 2244 EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); |
2446 } | 2245 } |
2447 | 2246 |
2448 free_aligned_buffer_64(dst_pixels_c); | 2247 free_aligned_buffer_page_end(dst_pixels_c); |
2449 free_aligned_buffer_64(dst_pixels_opt); | 2248 free_aligned_buffer_page_end(dst_pixels_opt); |
2450 free_aligned_buffer_64(orig_pixels); | 2249 free_aligned_buffer_page_end(orig_pixels); |
2451 } | 2250 } |
2452 | 2251 |
2453 static int TestARGBRect(int width, int height, int benchmark_iterations, | 2252 static int TestARGBRect(int width, int height, int benchmark_iterations, |
2454 int disable_cpu_flags, int benchmark_cpu_info, | 2253 int disable_cpu_flags, int benchmark_cpu_info, |
2455 int invert, int off, int bpp) { | 2254 int invert, int off, int bpp) { |
2456 if (width < 1) { | 2255 if (width < 1) { |
2457 width = 1; | 2256 width = 1; |
2458 } | 2257 } |
2459 const int kStride = width * bpp; | 2258 const int kStride = width * bpp; |
2460 const int kSize = kStride * height; | 2259 const int kSize = kStride * height; |
2461 const uint32 v32 = fastrand() & (bpp == 4 ? 0xffffffff : 0xff); | 2260 const uint32 v32 = fastrand() & (bpp == 4 ? 0xffffffff : 0xff); |
2462 | 2261 |
2463 align_buffer_64(dst_argb_c, kSize + off); | 2262 align_buffer_page_end(dst_argb_c, kSize + off); |
2464 align_buffer_64(dst_argb_opt, kSize + off); | 2263 align_buffer_page_end(dst_argb_opt, kSize + off); |
2465 | 2264 |
2466 MemRandomize(dst_argb_c + off, kSize); | 2265 MemRandomize(dst_argb_c + off, kSize); |
2467 memcpy(dst_argb_opt + off, dst_argb_c + off, kSize); | 2266 memcpy(dst_argb_opt + off, dst_argb_c + off, kSize); |
2468 | 2267 |
2469 MaskCpuFlags(disable_cpu_flags); | 2268 MaskCpuFlags(disable_cpu_flags); |
2470 if (bpp == 4) { | 2269 if (bpp == 4) { |
2471 ARGBRect(dst_argb_c + off, kStride, 0, 0, width, invert * height, v32); | 2270 ARGBRect(dst_argb_c + off, kStride, 0, 0, width, invert * height, v32); |
2472 } else { | 2271 } else { |
2473 SetPlane(dst_argb_c + off, kStride, width, invert * height, v32); | 2272 SetPlane(dst_argb_c + off, kStride, width, invert * height, v32); |
2474 } | 2273 } |
2475 | 2274 |
2476 MaskCpuFlags(benchmark_cpu_info); | 2275 MaskCpuFlags(benchmark_cpu_info); |
2477 for (int i = 0; i < benchmark_iterations; ++i) { | 2276 for (int i = 0; i < benchmark_iterations; ++i) { |
2478 if (bpp == 4) { | 2277 if (bpp == 4) { |
2479 ARGBRect(dst_argb_opt + off, kStride, 0, 0, width, invert * height, v32); | 2278 ARGBRect(dst_argb_opt + off, kStride, 0, 0, width, invert * height, v32); |
2480 } else { | 2279 } else { |
2481 SetPlane(dst_argb_opt + off, kStride, width, invert * height, v32); | 2280 SetPlane(dst_argb_opt + off, kStride, width, invert * height, v32); |
2482 } | 2281 } |
2483 } | 2282 } |
2484 int max_diff = 0; | 2283 int max_diff = 0; |
2485 for (int i = 0; i < kStride * height; ++i) { | 2284 for (int i = 0; i < kStride * height; ++i) { |
2486 int abs_diff = | 2285 int abs_diff = |
2487 abs(static_cast<int>(dst_argb_c[i + off]) - | 2286 abs(static_cast<int>(dst_argb_c[i + off]) - |
2488 static_cast<int>(dst_argb_opt[i + off])); | 2287 static_cast<int>(dst_argb_opt[i + off])); |
2489 if (abs_diff > max_diff) { | 2288 if (abs_diff > max_diff) { |
2490 max_diff = abs_diff; | 2289 max_diff = abs_diff; |
2491 } | 2290 } |
2492 } | 2291 } |
2493 free_aligned_buffer_64(dst_argb_c); | 2292 free_aligned_buffer_page_end(dst_argb_c); |
2494 free_aligned_buffer_64(dst_argb_opt); | 2293 free_aligned_buffer_page_end(dst_argb_opt); |
2495 return max_diff; | 2294 return max_diff; |
2496 } | 2295 } |
2497 | 2296 |
2498 TEST_F(LibYUVPlanarTest, ARGBRect_Any) { | 2297 TEST_F(LibYUVPlanarTest, ARGBRect_Any) { |
2499 int max_diff = TestARGBRect(benchmark_width_ - 1, benchmark_height_, | 2298 int max_diff = TestARGBRect(benchmark_width_ - 1, benchmark_height_, |
2500 benchmark_iterations_, | 2299 benchmark_iterations_, |
2501 disable_cpu_flags_, benchmark_cpu_info_, | 2300 disable_cpu_flags_, benchmark_cpu_info_, |
2502 +1, 0, 4); | 2301 +1, 0, 4); |
2503 EXPECT_EQ(0, max_diff); | 2302 EXPECT_EQ(0, max_diff); |
2504 } | 2303 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2553 | 2352 |
2554 TEST_F(LibYUVPlanarTest, SetPlane_Opt) { | 2353 TEST_F(LibYUVPlanarTest, SetPlane_Opt) { |
2555 int max_diff = TestARGBRect(benchmark_width_, benchmark_height_, | 2354 int max_diff = TestARGBRect(benchmark_width_, benchmark_height_, |
2556 benchmark_iterations_, | 2355 benchmark_iterations_, |
2557 disable_cpu_flags_, benchmark_cpu_info_, | 2356 disable_cpu_flags_, benchmark_cpu_info_, |
2558 +1, 0, 1); | 2357 +1, 0, 1); |
2559 EXPECT_EQ(0, max_diff); | 2358 EXPECT_EQ(0, max_diff); |
2560 } | 2359 } |
2561 | 2360 |
2562 } // namespace libyuv | 2361 } // namespace libyuv |
OLD | NEW |