1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libyuv/unit_test/planar_test.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,2108 @@ 1.4 +/* 1.5 + * Copyright 2011 The LibYuv Project Authors. All rights reserved. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license 1.8 + * that can be found in the LICENSE file in the root of the source 1.9 + * tree. An additional intellectual property rights grant can be found 1.10 + * in the file PATENTS. All contributing project authors may 1.11 + * be found in the AUTHORS file in the root of the source tree. 1.12 + */ 1.13 + 1.14 +#include <stdlib.h> 1.15 +#include <time.h> 1.16 + 1.17 +#include "libyuv/compare.h" 1.18 +#include "libyuv/convert.h" 1.19 +#include "libyuv/convert_argb.h" 1.20 +#include "libyuv/convert_from.h" 1.21 +#include "libyuv/convert_from_argb.h" 1.22 +#include "libyuv/cpu_id.h" 1.23 +#include "libyuv/format_conversion.h" 1.24 +#include "libyuv/planar_functions.h" 1.25 +#include "libyuv/rotate.h" 1.26 +#include "libyuv/row.h" // For Sobel 1.27 +#include "../unit_test/unit_test.h" 1.28 + 1.29 +#if defined(_MSC_VER) 1.30 +#define SIMD_ALIGNED(var) __declspec(align(16)) var 1.31 +#else // __GNUC__ 1.32 +#define SIMD_ALIGNED(var) var __attribute__((aligned(16))) 1.33 +#endif 1.34 + 1.35 +namespace libyuv { 1.36 + 1.37 +TEST_F(libyuvTest, TestAttenuate) { 1.38 + const int kSize = 1280 * 4; 1.39 + align_buffer_64(orig_pixels, kSize); 1.40 + align_buffer_64(atten_pixels, kSize); 1.41 + align_buffer_64(unatten_pixels, kSize); 1.42 + align_buffer_64(atten2_pixels, kSize); 1.43 + 1.44 + // Test unattenuation clamps 1.45 + orig_pixels[0 * 4 + 0] = 200u; 1.46 + orig_pixels[0 * 4 + 1] = 129u; 1.47 + orig_pixels[0 * 4 + 2] = 127u; 1.48 + orig_pixels[0 * 4 + 3] = 128u; 1.49 + // Test unattenuation transparent and opaque are unaffected 1.50 + orig_pixels[1 * 4 + 0] = 16u; 1.51 + orig_pixels[1 * 4 + 1] = 64u; 1.52 + orig_pixels[1 * 4 + 2] = 192u; 1.53 + orig_pixels[1 * 4 + 3] = 0u; 1.54 + orig_pixels[2 * 4 + 0] = 16u; 1.55 + orig_pixels[2 * 4 + 1] = 64u; 1.56 + orig_pixels[2 * 4 + 2] = 192u; 1.57 + orig_pixels[2 * 4 + 3] = 255u; 1.58 + orig_pixels[3 * 4 + 0] = 16u; 1.59 + orig_pixels[3 * 4 + 1] = 64u; 1.60 + orig_pixels[3 * 4 + 2] = 192u; 1.61 + orig_pixels[3 * 4 + 3] = 128u; 1.62 + ARGBUnattenuate(orig_pixels, 0, unatten_pixels, 0, 4, 1); 1.63 + EXPECT_EQ(255u, unatten_pixels[0 * 4 + 0]); 1.64 + EXPECT_EQ(255u, unatten_pixels[0 * 4 + 1]); 1.65 + EXPECT_EQ(254u, unatten_pixels[0 * 4 + 2]); 1.66 + EXPECT_EQ(128u, unatten_pixels[0 * 4 + 3]); 1.67 + EXPECT_EQ(0u, unatten_pixels[1 * 4 + 0]); 1.68 + EXPECT_EQ(0u, unatten_pixels[1 * 4 + 1]); 1.69 + EXPECT_EQ(0u, unatten_pixels[1 * 4 + 2]); 1.70 + EXPECT_EQ(0u, unatten_pixels[1 * 4 + 3]); 1.71 + EXPECT_EQ(16u, unatten_pixels[2 * 4 + 0]); 1.72 + EXPECT_EQ(64u, unatten_pixels[2 * 4 + 1]); 1.73 + EXPECT_EQ(192u, unatten_pixels[2 * 4 + 2]); 1.74 + EXPECT_EQ(255u, unatten_pixels[2 * 4 + 3]); 1.75 + EXPECT_EQ(32u, unatten_pixels[3 * 4 + 0]); 1.76 + EXPECT_EQ(128u, unatten_pixels[3 * 4 + 1]); 1.77 + EXPECT_EQ(255u, unatten_pixels[3 * 4 + 2]); 1.78 + EXPECT_EQ(128u, unatten_pixels[3 * 4 + 3]); 1.79 + 1.80 + for (int i = 0; i < 1280; ++i) { 1.81 + orig_pixels[i * 4 + 0] = i; 1.82 + orig_pixels[i * 4 + 1] = i / 2; 1.83 + orig_pixels[i * 4 + 2] = i / 3; 1.84 + orig_pixels[i * 4 + 3] = i; 1.85 + } 1.86 + ARGBAttenuate(orig_pixels, 0, atten_pixels, 0, 1280, 1); 1.87 + ARGBUnattenuate(atten_pixels, 0, unatten_pixels, 0, 1280, 1); 1.88 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.89 + ARGBAttenuate(unatten_pixels, 0, atten2_pixels, 0, 1280, 1); 1.90 + } 1.91 + for (int i = 0; i < 1280; ++i) { 1.92 + EXPECT_NEAR(atten_pixels[i * 4 + 0], atten2_pixels[i * 4 + 0], 2); 1.93 + EXPECT_NEAR(atten_pixels[i * 4 + 1], atten2_pixels[i * 4 + 1], 2); 1.94 + EXPECT_NEAR(atten_pixels[i * 4 + 2], atten2_pixels[i * 4 + 2], 2); 1.95 + EXPECT_NEAR(atten_pixels[i * 4 + 3], atten2_pixels[i * 4 + 3], 2); 1.96 + } 1.97 + // Make sure transparent, 50% and opaque are fully accurate. 1.98 + EXPECT_EQ(0, atten_pixels[0 * 4 + 0]); 1.99 + EXPECT_EQ(0, atten_pixels[0 * 4 + 1]); 1.100 + EXPECT_EQ(0, atten_pixels[0 * 4 + 2]); 1.101 + EXPECT_EQ(0, atten_pixels[0 * 4 + 3]); 1.102 + EXPECT_EQ(64, atten_pixels[128 * 4 + 0]); 1.103 + EXPECT_EQ(32, atten_pixels[128 * 4 + 1]); 1.104 + EXPECT_EQ(21, atten_pixels[128 * 4 + 2]); 1.105 + EXPECT_EQ(128, atten_pixels[128 * 4 + 3]); 1.106 + EXPECT_NEAR(255, atten_pixels[255 * 4 + 0], 1); 1.107 + EXPECT_NEAR(127, atten_pixels[255 * 4 + 1], 1); 1.108 + EXPECT_NEAR(85, atten_pixels[255 * 4 + 2], 1); 1.109 + EXPECT_EQ(255, atten_pixels[255 * 4 + 3]); 1.110 + 1.111 + free_aligned_buffer_64(atten2_pixels); 1.112 + free_aligned_buffer_64(unatten_pixels); 1.113 + free_aligned_buffer_64(atten_pixels); 1.114 + free_aligned_buffer_64(orig_pixels); 1.115 +} 1.116 + 1.117 +static int TestAttenuateI(int width, int height, int benchmark_iterations, 1.118 + int invert, int off) { 1.119 + if (width < 1) { 1.120 + width = 1; 1.121 + } 1.122 + const int kBpp = 4; 1.123 + const int kStride = (width * kBpp + 15) & ~15; 1.124 + align_buffer_64(src_argb, kStride * height + off); 1.125 + align_buffer_64(dst_argb_c, kStride * height); 1.126 + align_buffer_64(dst_argb_opt, kStride * height); 1.127 + srandom(time(NULL)); 1.128 + for (int i = 0; i < kStride * height; ++i) { 1.129 + src_argb[i + off] = (random() & 0xff); 1.130 + } 1.131 + memset(dst_argb_c, 0, kStride * height); 1.132 + memset(dst_argb_opt, 0, kStride * height); 1.133 + 1.134 + MaskCpuFlags(0); 1.135 + ARGBAttenuate(src_argb + off, kStride, 1.136 + dst_argb_c, kStride, 1.137 + width, invert * height); 1.138 + MaskCpuFlags(-1); 1.139 + for (int i = 0; i < benchmark_iterations; ++i) { 1.140 + ARGBAttenuate(src_argb + off, kStride, 1.141 + dst_argb_opt, kStride, 1.142 + width, invert * height); 1.143 + } 1.144 + int max_diff = 0; 1.145 + for (int i = 0; i < kStride * height; ++i) { 1.146 + int abs_diff = 1.147 + abs(static_cast<int>(dst_argb_c[i]) - 1.148 + static_cast<int>(dst_argb_opt[i])); 1.149 + if (abs_diff > max_diff) { 1.150 + max_diff = abs_diff; 1.151 + } 1.152 + } 1.153 + free_aligned_buffer_64(src_argb); 1.154 + free_aligned_buffer_64(dst_argb_c); 1.155 + free_aligned_buffer_64(dst_argb_opt); 1.156 + return max_diff; 1.157 +} 1.158 + 1.159 +TEST_F(libyuvTest, ARGBAttenuate_Any) { 1.160 + int max_diff = TestAttenuateI(benchmark_width_ - 1, benchmark_height_, 1.161 + benchmark_iterations_, +1, 0); 1.162 + EXPECT_LE(max_diff, 2); 1.163 +} 1.164 + 1.165 +TEST_F(libyuvTest, ARGBAttenuate_Unaligned) { 1.166 + int max_diff = TestAttenuateI(benchmark_width_, benchmark_height_, 1.167 + benchmark_iterations_, +1, 1); 1.168 + EXPECT_LE(max_diff, 2); 1.169 +} 1.170 + 1.171 +TEST_F(libyuvTest, ARGBAttenuate_Invert) { 1.172 + int max_diff = TestAttenuateI(benchmark_width_, benchmark_height_, 1.173 + benchmark_iterations_, -1, 0); 1.174 + EXPECT_LE(max_diff, 2); 1.175 +} 1.176 + 1.177 +TEST_F(libyuvTest, ARGBAttenuate_Opt) { 1.178 + int max_diff = TestAttenuateI(benchmark_width_, benchmark_height_, 1.179 + benchmark_iterations_, +1, 0); 1.180 + EXPECT_LE(max_diff, 2); 1.181 +} 1.182 + 1.183 +static int TestUnattenuateI(int width, int height, int benchmark_iterations, 1.184 + int invert, int off) { 1.185 + if (width < 1) { 1.186 + width = 1; 1.187 + } 1.188 + const int kBpp = 4; 1.189 + const int kStride = (width * kBpp + 15) & ~15; 1.190 + align_buffer_64(src_argb, kStride * height + off); 1.191 + align_buffer_64(dst_argb_c, kStride * height); 1.192 + align_buffer_64(dst_argb_opt, kStride * height); 1.193 + srandom(time(NULL)); 1.194 + for (int i = 0; i < kStride * height; ++i) { 1.195 + src_argb[i + off] = (random() & 0xff); 1.196 + } 1.197 + ARGBAttenuate(src_argb + off, kStride, 1.198 + src_argb + off, kStride, 1.199 + width, height); 1.200 + memset(dst_argb_c, 0, kStride * height); 1.201 + memset(dst_argb_opt, 0, kStride * height); 1.202 + 1.203 + MaskCpuFlags(0); 1.204 + ARGBUnattenuate(src_argb + off, kStride, 1.205 + dst_argb_c, kStride, 1.206 + width, invert * height); 1.207 + MaskCpuFlags(-1); 1.208 + for (int i = 0; i < benchmark_iterations; ++i) { 1.209 + ARGBUnattenuate(src_argb + off, kStride, 1.210 + dst_argb_opt, kStride, 1.211 + width, invert * height); 1.212 + } 1.213 + int max_diff = 0; 1.214 + for (int i = 0; i < kStride * height; ++i) { 1.215 + int abs_diff = 1.216 + abs(static_cast<int>(dst_argb_c[i]) - 1.217 + static_cast<int>(dst_argb_opt[i])); 1.218 + if (abs_diff > max_diff) { 1.219 + max_diff = abs_diff; 1.220 + } 1.221 + } 1.222 + free_aligned_buffer_64(src_argb); 1.223 + free_aligned_buffer_64(dst_argb_c); 1.224 + free_aligned_buffer_64(dst_argb_opt); 1.225 + return max_diff; 1.226 +} 1.227 + 1.228 +TEST_F(libyuvTest, ARGBUnattenuate_Any) { 1.229 + int max_diff = TestUnattenuateI(benchmark_width_ - 1, benchmark_height_, 1.230 + benchmark_iterations_, +1, 0); 1.231 + EXPECT_LE(max_diff, 2); 1.232 +} 1.233 + 1.234 +TEST_F(libyuvTest, ARGBUnattenuate_Unaligned) { 1.235 + int max_diff = TestUnattenuateI(benchmark_width_, benchmark_height_, 1.236 + benchmark_iterations_, +1, 1); 1.237 + EXPECT_LE(max_diff, 2); 1.238 +} 1.239 + 1.240 +TEST_F(libyuvTest, ARGBUnattenuate_Invert) { 1.241 + int max_diff = TestUnattenuateI(benchmark_width_, benchmark_height_, 1.242 + benchmark_iterations_, -1, 0); 1.243 + EXPECT_LE(max_diff, 2); 1.244 +} 1.245 + 1.246 +TEST_F(libyuvTest, ARGBUnattenuate_Opt) { 1.247 + int max_diff = TestUnattenuateI(benchmark_width_, benchmark_height_, 1.248 + benchmark_iterations_, +1, 0); 1.249 + EXPECT_LE(max_diff, 2); 1.250 +} 1.251 + 1.252 +TEST_F(libyuvTest, TestARGBComputeCumulativeSum) { 1.253 + SIMD_ALIGNED(uint8 orig_pixels[16][16][4]); 1.254 + SIMD_ALIGNED(int32 added_pixels[16][16][4]); 1.255 + 1.256 + for (int y = 0; y < 16; ++y) { 1.257 + for (int x = 0; x < 16; ++x) { 1.258 + orig_pixels[y][x][0] = 1u; 1.259 + orig_pixels[y][x][1] = 2u; 1.260 + orig_pixels[y][x][2] = 3u; 1.261 + orig_pixels[y][x][3] = 255u; 1.262 + } 1.263 + } 1.264 + 1.265 + ARGBComputeCumulativeSum(&orig_pixels[0][0][0], 16 * 4, 1.266 + &added_pixels[0][0][0], 16 * 4, 1.267 + 16, 16); 1.268 + 1.269 + for (int y = 0; y < 16; ++y) { 1.270 + for (int x = 0; x < 16; ++x) { 1.271 + EXPECT_EQ((x + 1) * (y + 1), added_pixels[y][x][0]); 1.272 + EXPECT_EQ((x + 1) * (y + 1) * 2, added_pixels[y][x][1]); 1.273 + EXPECT_EQ((x + 1) * (y + 1) * 3, added_pixels[y][x][2]); 1.274 + EXPECT_EQ((x + 1) * (y + 1) * 255, added_pixels[y][x][3]); 1.275 + } 1.276 + } 1.277 +} 1.278 + 1.279 +TEST_F(libyuvTest, TestARGBGray) { 1.280 + SIMD_ALIGNED(uint8 orig_pixels[1280][4]); 1.281 + memset(orig_pixels, 0, sizeof(orig_pixels)); 1.282 + 1.283 + // Test blue 1.284 + orig_pixels[0][0] = 255u; 1.285 + orig_pixels[0][1] = 0u; 1.286 + orig_pixels[0][2] = 0u; 1.287 + orig_pixels[0][3] = 128u; 1.288 + // Test green 1.289 + orig_pixels[1][0] = 0u; 1.290 + orig_pixels[1][1] = 255u; 1.291 + orig_pixels[1][2] = 0u; 1.292 + orig_pixels[1][3] = 0u; 1.293 + // Test red 1.294 + orig_pixels[2][0] = 0u; 1.295 + orig_pixels[2][1] = 0u; 1.296 + orig_pixels[2][2] = 255u; 1.297 + orig_pixels[2][3] = 255u; 1.298 + // Test black 1.299 + orig_pixels[3][0] = 0u; 1.300 + orig_pixels[3][1] = 0u; 1.301 + orig_pixels[3][2] = 0u; 1.302 + orig_pixels[3][3] = 255u; 1.303 + // Test white 1.304 + orig_pixels[4][0] = 255u; 1.305 + orig_pixels[4][1] = 255u; 1.306 + orig_pixels[4][2] = 255u; 1.307 + orig_pixels[4][3] = 255u; 1.308 + // Test color 1.309 + orig_pixels[5][0] = 16u; 1.310 + orig_pixels[5][1] = 64u; 1.311 + orig_pixels[5][2] = 192u; 1.312 + orig_pixels[5][3] = 224u; 1.313 + // Do 16 to test asm version. 1.314 + ARGBGray(&orig_pixels[0][0], 0, 0, 0, 16, 1); 1.315 + EXPECT_EQ(30u, orig_pixels[0][0]); 1.316 + EXPECT_EQ(30u, orig_pixels[0][1]); 1.317 + EXPECT_EQ(30u, orig_pixels[0][2]); 1.318 + EXPECT_EQ(128u, orig_pixels[0][3]); 1.319 + EXPECT_EQ(149u, orig_pixels[1][0]); 1.320 + EXPECT_EQ(149u, orig_pixels[1][1]); 1.321 + EXPECT_EQ(149u, orig_pixels[1][2]); 1.322 + EXPECT_EQ(0u, orig_pixels[1][3]); 1.323 + EXPECT_EQ(76u, orig_pixels[2][0]); 1.324 + EXPECT_EQ(76u, orig_pixels[2][1]); 1.325 + EXPECT_EQ(76u, orig_pixels[2][2]); 1.326 + EXPECT_EQ(255u, orig_pixels[2][3]); 1.327 + EXPECT_EQ(0u, orig_pixels[3][0]); 1.328 + EXPECT_EQ(0u, orig_pixels[3][1]); 1.329 + EXPECT_EQ(0u, orig_pixels[3][2]); 1.330 + EXPECT_EQ(255u, orig_pixels[3][3]); 1.331 + EXPECT_EQ(255u, orig_pixels[4][0]); 1.332 + EXPECT_EQ(255u, orig_pixels[4][1]); 1.333 + EXPECT_EQ(255u, orig_pixels[4][2]); 1.334 + EXPECT_EQ(255u, orig_pixels[4][3]); 1.335 + EXPECT_EQ(96u, orig_pixels[5][0]); 1.336 + EXPECT_EQ(96u, orig_pixels[5][1]); 1.337 + EXPECT_EQ(96u, orig_pixels[5][2]); 1.338 + EXPECT_EQ(224u, orig_pixels[5][3]); 1.339 + for (int i = 0; i < 1280; ++i) { 1.340 + orig_pixels[i][0] = i; 1.341 + orig_pixels[i][1] = i / 2; 1.342 + orig_pixels[i][2] = i / 3; 1.343 + orig_pixels[i][3] = i; 1.344 + } 1.345 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.346 + ARGBGray(&orig_pixels[0][0], 0, 0, 0, 1280, 1); 1.347 + } 1.348 +} 1.349 + 1.350 +TEST_F(libyuvTest, TestARGBGrayTo) { 1.351 + SIMD_ALIGNED(uint8 orig_pixels[1280][4]); 1.352 + SIMD_ALIGNED(uint8 gray_pixels[1280][4]); 1.353 + memset(orig_pixels, 0, sizeof(orig_pixels)); 1.354 + 1.355 + // Test blue 1.356 + orig_pixels[0][0] = 255u; 1.357 + orig_pixels[0][1] = 0u; 1.358 + orig_pixels[0][2] = 0u; 1.359 + orig_pixels[0][3] = 128u; 1.360 + // Test green 1.361 + orig_pixels[1][0] = 0u; 1.362 + orig_pixels[1][1] = 255u; 1.363 + orig_pixels[1][2] = 0u; 1.364 + orig_pixels[1][3] = 0u; 1.365 + // Test red 1.366 + orig_pixels[2][0] = 0u; 1.367 + orig_pixels[2][1] = 0u; 1.368 + orig_pixels[2][2] = 255u; 1.369 + orig_pixels[2][3] = 255u; 1.370 + // Test black 1.371 + orig_pixels[3][0] = 0u; 1.372 + orig_pixels[3][1] = 0u; 1.373 + orig_pixels[3][2] = 0u; 1.374 + orig_pixels[3][3] = 255u; 1.375 + // Test white 1.376 + orig_pixels[4][0] = 255u; 1.377 + orig_pixels[4][1] = 255u; 1.378 + orig_pixels[4][2] = 255u; 1.379 + orig_pixels[4][3] = 255u; 1.380 + // Test color 1.381 + orig_pixels[5][0] = 16u; 1.382 + orig_pixels[5][1] = 64u; 1.383 + orig_pixels[5][2] = 192u; 1.384 + orig_pixels[5][3] = 224u; 1.385 + // Do 16 to test asm version. 1.386 + ARGBGrayTo(&orig_pixels[0][0], 0, &gray_pixels[0][0], 0, 16, 1); 1.387 + EXPECT_EQ(30u, gray_pixels[0][0]); 1.388 + EXPECT_EQ(30u, gray_pixels[0][1]); 1.389 + EXPECT_EQ(30u, gray_pixels[0][2]); 1.390 + EXPECT_EQ(128u, gray_pixels[0][3]); 1.391 + EXPECT_EQ(149u, gray_pixels[1][0]); 1.392 + EXPECT_EQ(149u, gray_pixels[1][1]); 1.393 + EXPECT_EQ(149u, gray_pixels[1][2]); 1.394 + EXPECT_EQ(0u, gray_pixels[1][3]); 1.395 + EXPECT_EQ(76u, gray_pixels[2][0]); 1.396 + EXPECT_EQ(76u, gray_pixels[2][1]); 1.397 + EXPECT_EQ(76u, gray_pixels[2][2]); 1.398 + EXPECT_EQ(255u, gray_pixels[2][3]); 1.399 + EXPECT_EQ(0u, gray_pixels[3][0]); 1.400 + EXPECT_EQ(0u, gray_pixels[3][1]); 1.401 + EXPECT_EQ(0u, gray_pixels[3][2]); 1.402 + EXPECT_EQ(255u, gray_pixels[3][3]); 1.403 + EXPECT_EQ(255u, gray_pixels[4][0]); 1.404 + EXPECT_EQ(255u, gray_pixels[4][1]); 1.405 + EXPECT_EQ(255u, gray_pixels[4][2]); 1.406 + EXPECT_EQ(255u, gray_pixels[4][3]); 1.407 + EXPECT_EQ(96u, gray_pixels[5][0]); 1.408 + EXPECT_EQ(96u, gray_pixels[5][1]); 1.409 + EXPECT_EQ(96u, gray_pixels[5][2]); 1.410 + EXPECT_EQ(224u, gray_pixels[5][3]); 1.411 + for (int i = 0; i < 1280; ++i) { 1.412 + orig_pixels[i][0] = i; 1.413 + orig_pixels[i][1] = i / 2; 1.414 + orig_pixels[i][2] = i / 3; 1.415 + orig_pixels[i][3] = i; 1.416 + } 1.417 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.418 + ARGBGrayTo(&orig_pixels[0][0], 0, &gray_pixels[0][0], 0, 1280, 1); 1.419 + } 1.420 +} 1.421 + 1.422 +TEST_F(libyuvTest, TestARGBSepia) { 1.423 + SIMD_ALIGNED(uint8 orig_pixels[1280][4]); 1.424 + memset(orig_pixels, 0, sizeof(orig_pixels)); 1.425 + 1.426 + // Test blue 1.427 + orig_pixels[0][0] = 255u; 1.428 + orig_pixels[0][1] = 0u; 1.429 + orig_pixels[0][2] = 0u; 1.430 + orig_pixels[0][3] = 128u; 1.431 + // Test green 1.432 + orig_pixels[1][0] = 0u; 1.433 + orig_pixels[1][1] = 255u; 1.434 + orig_pixels[1][2] = 0u; 1.435 + orig_pixels[1][3] = 0u; 1.436 + // Test red 1.437 + orig_pixels[2][0] = 0u; 1.438 + orig_pixels[2][1] = 0u; 1.439 + orig_pixels[2][2] = 255u; 1.440 + orig_pixels[2][3] = 255u; 1.441 + // Test black 1.442 + orig_pixels[3][0] = 0u; 1.443 + orig_pixels[3][1] = 0u; 1.444 + orig_pixels[3][2] = 0u; 1.445 + orig_pixels[3][3] = 255u; 1.446 + // Test white 1.447 + orig_pixels[4][0] = 255u; 1.448 + orig_pixels[4][1] = 255u; 1.449 + orig_pixels[4][2] = 255u; 1.450 + orig_pixels[4][3] = 255u; 1.451 + // Test color 1.452 + orig_pixels[5][0] = 16u; 1.453 + orig_pixels[5][1] = 64u; 1.454 + orig_pixels[5][2] = 192u; 1.455 + orig_pixels[5][3] = 224u; 1.456 + // Do 16 to test asm version. 1.457 + ARGBSepia(&orig_pixels[0][0], 0, 0, 0, 16, 1); 1.458 + EXPECT_EQ(33u, orig_pixels[0][0]); 1.459 + EXPECT_EQ(43u, orig_pixels[0][1]); 1.460 + EXPECT_EQ(47u, orig_pixels[0][2]); 1.461 + EXPECT_EQ(128u, orig_pixels[0][3]); 1.462 + EXPECT_EQ(135u, orig_pixels[1][0]); 1.463 + EXPECT_EQ(175u, orig_pixels[1][1]); 1.464 + EXPECT_EQ(195u, orig_pixels[1][2]); 1.465 + EXPECT_EQ(0u, orig_pixels[1][3]); 1.466 + EXPECT_EQ(69u, orig_pixels[2][0]); 1.467 + EXPECT_EQ(89u, orig_pixels[2][1]); 1.468 + EXPECT_EQ(99u, orig_pixels[2][2]); 1.469 + EXPECT_EQ(255u, orig_pixels[2][3]); 1.470 + EXPECT_EQ(0u, orig_pixels[3][0]); 1.471 + EXPECT_EQ(0u, orig_pixels[3][1]); 1.472 + EXPECT_EQ(0u, orig_pixels[3][2]); 1.473 + EXPECT_EQ(255u, orig_pixels[3][3]); 1.474 + EXPECT_EQ(239u, orig_pixels[4][0]); 1.475 + EXPECT_EQ(255u, orig_pixels[4][1]); 1.476 + EXPECT_EQ(255u, orig_pixels[4][2]); 1.477 + EXPECT_EQ(255u, orig_pixels[4][3]); 1.478 + EXPECT_EQ(88u, orig_pixels[5][0]); 1.479 + EXPECT_EQ(114u, orig_pixels[5][1]); 1.480 + EXPECT_EQ(127u, orig_pixels[5][2]); 1.481 + EXPECT_EQ(224u, orig_pixels[5][3]); 1.482 + 1.483 + for (int i = 0; i < 1280; ++i) { 1.484 + orig_pixels[i][0] = i; 1.485 + orig_pixels[i][1] = i / 2; 1.486 + orig_pixels[i][2] = i / 3; 1.487 + orig_pixels[i][3] = i; 1.488 + } 1.489 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.490 + ARGBSepia(&orig_pixels[0][0], 0, 0, 0, 1280, 1); 1.491 + } 1.492 +} 1.493 + 1.494 +TEST_F(libyuvTest, TestARGBColorMatrix) { 1.495 + SIMD_ALIGNED(uint8 orig_pixels[1280][4]); 1.496 + SIMD_ALIGNED(uint8 dst_pixels_opt[1280][4]); 1.497 + SIMD_ALIGNED(uint8 dst_pixels_c[1280][4]); 1.498 + 1.499 + // Matrix for Sepia. 1.500 + SIMD_ALIGNED(static const int8 kRGBToSepia[]) = { 1.501 + 17 / 2, 68 / 2, 35 / 2, 0, 1.502 + 22 / 2, 88 / 2, 45 / 2, 0, 1.503 + 24 / 2, 98 / 2, 50 / 2, 0, 1.504 + 0, 0, 0, 64, // Copy alpha. 1.505 + }; 1.506 + memset(orig_pixels, 0, sizeof(orig_pixels)); 1.507 + 1.508 + // Test blue 1.509 + orig_pixels[0][0] = 255u; 1.510 + orig_pixels[0][1] = 0u; 1.511 + orig_pixels[0][2] = 0u; 1.512 + orig_pixels[0][3] = 128u; 1.513 + // Test green 1.514 + orig_pixels[1][0] = 0u; 1.515 + orig_pixels[1][1] = 255u; 1.516 + orig_pixels[1][2] = 0u; 1.517 + orig_pixels[1][3] = 0u; 1.518 + // Test red 1.519 + orig_pixels[2][0] = 0u; 1.520 + orig_pixels[2][1] = 0u; 1.521 + orig_pixels[2][2] = 255u; 1.522 + orig_pixels[2][3] = 255u; 1.523 + // Test color 1.524 + orig_pixels[3][0] = 16u; 1.525 + orig_pixels[3][1] = 64u; 1.526 + orig_pixels[3][2] = 192u; 1.527 + orig_pixels[3][3] = 224u; 1.528 + // Do 16 to test asm version. 1.529 + ARGBColorMatrix(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0, 1.530 + &kRGBToSepia[0], 16, 1); 1.531 + EXPECT_EQ(31u, dst_pixels_opt[0][0]); 1.532 + EXPECT_EQ(43u, dst_pixels_opt[0][1]); 1.533 + EXPECT_EQ(47u, dst_pixels_opt[0][2]); 1.534 + EXPECT_EQ(128u, dst_pixels_opt[0][3]); 1.535 + EXPECT_EQ(135u, dst_pixels_opt[1][0]); 1.536 + EXPECT_EQ(175u, dst_pixels_opt[1][1]); 1.537 + EXPECT_EQ(195u, dst_pixels_opt[1][2]); 1.538 + EXPECT_EQ(0u, dst_pixels_opt[1][3]); 1.539 + EXPECT_EQ(67u, dst_pixels_opt[2][0]); 1.540 + EXPECT_EQ(87u, dst_pixels_opt[2][1]); 1.541 + EXPECT_EQ(99u, dst_pixels_opt[2][2]); 1.542 + EXPECT_EQ(255u, dst_pixels_opt[2][3]); 1.543 + EXPECT_EQ(87u, dst_pixels_opt[3][0]); 1.544 + EXPECT_EQ(112u, dst_pixels_opt[3][1]); 1.545 + EXPECT_EQ(127u, dst_pixels_opt[3][2]); 1.546 + EXPECT_EQ(224u, dst_pixels_opt[3][3]); 1.547 + 1.548 + for (int i = 0; i < 1280; ++i) { 1.549 + orig_pixels[i][0] = i; 1.550 + orig_pixels[i][1] = i / 2; 1.551 + orig_pixels[i][2] = i / 3; 1.552 + orig_pixels[i][3] = i; 1.553 + } 1.554 + MaskCpuFlags(0); 1.555 + ARGBColorMatrix(&orig_pixels[0][0], 0, &dst_pixels_c[0][0], 0, 1.556 + &kRGBToSepia[0], 1280, 1); 1.557 + MaskCpuFlags(-1); 1.558 + 1.559 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.560 + ARGBColorMatrix(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0, 1.561 + &kRGBToSepia[0], 1280, 1); 1.562 + } 1.563 + 1.564 + for (int i = 0; i < 1280; ++i) { 1.565 + EXPECT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]); 1.566 + EXPECT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]); 1.567 + EXPECT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]); 1.568 + EXPECT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]); 1.569 + } 1.570 +} 1.571 + 1.572 +TEST_F(libyuvTest, TestRGBColorMatrix) { 1.573 + SIMD_ALIGNED(uint8 orig_pixels[1280][4]); 1.574 + 1.575 + // Matrix for Sepia. 1.576 + SIMD_ALIGNED(static const int8 kRGBToSepia[]) = { 1.577 + 17, 68, 35, 0, 1.578 + 22, 88, 45, 0, 1.579 + 24, 98, 50, 0, 1.580 + 0, 0, 0, 0, // Unused but makes matrix 16 bytes. 1.581 + }; 1.582 + memset(orig_pixels, 0, sizeof(orig_pixels)); 1.583 + 1.584 + // Test blue 1.585 + orig_pixels[0][0] = 255u; 1.586 + orig_pixels[0][1] = 0u; 1.587 + orig_pixels[0][2] = 0u; 1.588 + orig_pixels[0][3] = 128u; 1.589 + // Test green 1.590 + orig_pixels[1][0] = 0u; 1.591 + orig_pixels[1][1] = 255u; 1.592 + orig_pixels[1][2] = 0u; 1.593 + orig_pixels[1][3] = 0u; 1.594 + // Test red 1.595 + orig_pixels[2][0] = 0u; 1.596 + orig_pixels[2][1] = 0u; 1.597 + orig_pixels[2][2] = 255u; 1.598 + orig_pixels[2][3] = 255u; 1.599 + // Test color 1.600 + orig_pixels[3][0] = 16u; 1.601 + orig_pixels[3][1] = 64u; 1.602 + orig_pixels[3][2] = 192u; 1.603 + orig_pixels[3][3] = 224u; 1.604 + // Do 16 to test asm version. 1.605 + RGBColorMatrix(&orig_pixels[0][0], 0, &kRGBToSepia[0], 0, 0, 16, 1); 1.606 + EXPECT_EQ(31u, orig_pixels[0][0]); 1.607 + EXPECT_EQ(43u, orig_pixels[0][1]); 1.608 + EXPECT_EQ(47u, orig_pixels[0][2]); 1.609 + EXPECT_EQ(128u, orig_pixels[0][3]); 1.610 + EXPECT_EQ(135u, orig_pixels[1][0]); 1.611 + EXPECT_EQ(175u, orig_pixels[1][1]); 1.612 + EXPECT_EQ(195u, orig_pixels[1][2]); 1.613 + EXPECT_EQ(0u, orig_pixels[1][3]); 1.614 + EXPECT_EQ(67u, orig_pixels[2][0]); 1.615 + EXPECT_EQ(87u, orig_pixels[2][1]); 1.616 + EXPECT_EQ(99u, orig_pixels[2][2]); 1.617 + EXPECT_EQ(255u, orig_pixels[2][3]); 1.618 + EXPECT_EQ(87u, orig_pixels[3][0]); 1.619 + EXPECT_EQ(112u, orig_pixels[3][1]); 1.620 + EXPECT_EQ(127u, orig_pixels[3][2]); 1.621 + EXPECT_EQ(224u, orig_pixels[3][3]); 1.622 + 1.623 + for (int i = 0; i < 1280; ++i) { 1.624 + orig_pixels[i][0] = i; 1.625 + orig_pixels[i][1] = i / 2; 1.626 + orig_pixels[i][2] = i / 3; 1.627 + orig_pixels[i][3] = i; 1.628 + } 1.629 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.630 + RGBColorMatrix(&orig_pixels[0][0], 0, &kRGBToSepia[0], 0, 0, 1280, 1); 1.631 + } 1.632 +} 1.633 + 1.634 +TEST_F(libyuvTest, TestARGBColorTable) { 1.635 + SIMD_ALIGNED(uint8 orig_pixels[1280][4]); 1.636 + memset(orig_pixels, 0, sizeof(orig_pixels)); 1.637 + 1.638 + // Matrix for Sepia. 1.639 + static const uint8 kARGBTable[256 * 4] = { 1.640 + 1u, 2u, 3u, 4u, 1.641 + 5u, 6u, 7u, 8u, 1.642 + 9u, 10u, 11u, 12u, 1.643 + 13u, 14u, 15u, 16u, 1.644 + }; 1.645 + 1.646 + orig_pixels[0][0] = 0u; 1.647 + orig_pixels[0][1] = 0u; 1.648 + orig_pixels[0][2] = 0u; 1.649 + orig_pixels[0][3] = 0u; 1.650 + orig_pixels[1][0] = 1u; 1.651 + orig_pixels[1][1] = 1u; 1.652 + orig_pixels[1][2] = 1u; 1.653 + orig_pixels[1][3] = 1u; 1.654 + orig_pixels[2][0] = 2u; 1.655 + orig_pixels[2][1] = 2u; 1.656 + orig_pixels[2][2] = 2u; 1.657 + orig_pixels[2][3] = 2u; 1.658 + orig_pixels[3][0] = 0u; 1.659 + orig_pixels[3][1] = 1u; 1.660 + orig_pixels[3][2] = 2u; 1.661 + orig_pixels[3][3] = 3u; 1.662 + // Do 16 to test asm version. 1.663 + ARGBColorTable(&orig_pixels[0][0], 0, &kARGBTable[0], 0, 0, 16, 1); 1.664 + EXPECT_EQ(1u, orig_pixels[0][0]); 1.665 + EXPECT_EQ(2u, orig_pixels[0][1]); 1.666 + EXPECT_EQ(3u, orig_pixels[0][2]); 1.667 + EXPECT_EQ(4u, orig_pixels[0][3]); 1.668 + EXPECT_EQ(5u, orig_pixels[1][0]); 1.669 + EXPECT_EQ(6u, orig_pixels[1][1]); 1.670 + EXPECT_EQ(7u, orig_pixels[1][2]); 1.671 + EXPECT_EQ(8u, orig_pixels[1][3]); 1.672 + EXPECT_EQ(9u, orig_pixels[2][0]); 1.673 + EXPECT_EQ(10u, orig_pixels[2][1]); 1.674 + EXPECT_EQ(11u, orig_pixels[2][2]); 1.675 + EXPECT_EQ(12u, orig_pixels[2][3]); 1.676 + EXPECT_EQ(1u, orig_pixels[3][0]); 1.677 + EXPECT_EQ(6u, orig_pixels[3][1]); 1.678 + EXPECT_EQ(11u, orig_pixels[3][2]); 1.679 + EXPECT_EQ(16u, orig_pixels[3][3]); 1.680 + 1.681 + for (int i = 0; i < 1280; ++i) { 1.682 + orig_pixels[i][0] = i; 1.683 + orig_pixels[i][1] = i / 2; 1.684 + orig_pixels[i][2] = i / 3; 1.685 + orig_pixels[i][3] = i; 1.686 + } 1.687 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.688 + ARGBColorTable(&orig_pixels[0][0], 0, &kARGBTable[0], 0, 0, 1280, 1); 1.689 + } 1.690 +} 1.691 + 1.692 +// Same as TestARGBColorTable except alpha does not change. 1.693 +TEST_F(libyuvTest, TestRGBColorTable) { 1.694 + SIMD_ALIGNED(uint8 orig_pixels[1280][4]); 1.695 + memset(orig_pixels, 0, sizeof(orig_pixels)); 1.696 + 1.697 + // Matrix for Sepia. 1.698 + static const uint8 kARGBTable[256 * 4] = { 1.699 + 1u, 2u, 3u, 4u, 1.700 + 5u, 6u, 7u, 8u, 1.701 + 9u, 10u, 11u, 12u, 1.702 + 13u, 14u, 15u, 16u, 1.703 + }; 1.704 + 1.705 + orig_pixels[0][0] = 0u; 1.706 + orig_pixels[0][1] = 0u; 1.707 + orig_pixels[0][2] = 0u; 1.708 + orig_pixels[0][3] = 0u; 1.709 + orig_pixels[1][0] = 1u; 1.710 + orig_pixels[1][1] = 1u; 1.711 + orig_pixels[1][2] = 1u; 1.712 + orig_pixels[1][3] = 1u; 1.713 + orig_pixels[2][0] = 2u; 1.714 + orig_pixels[2][1] = 2u; 1.715 + orig_pixels[2][2] = 2u; 1.716 + orig_pixels[2][3] = 2u; 1.717 + orig_pixels[3][0] = 0u; 1.718 + orig_pixels[3][1] = 1u; 1.719 + orig_pixels[3][2] = 2u; 1.720 + orig_pixels[3][3] = 3u; 1.721 + // Do 16 to test asm version. 1.722 + RGBColorTable(&orig_pixels[0][0], 0, &kARGBTable[0], 0, 0, 16, 1); 1.723 + EXPECT_EQ(1u, orig_pixels[0][0]); 1.724 + EXPECT_EQ(2u, orig_pixels[0][1]); 1.725 + EXPECT_EQ(3u, orig_pixels[0][2]); 1.726 + EXPECT_EQ(0u, orig_pixels[0][3]); // Alpha unchanged. 1.727 + EXPECT_EQ(5u, orig_pixels[1][0]); 1.728 + EXPECT_EQ(6u, orig_pixels[1][1]); 1.729 + EXPECT_EQ(7u, orig_pixels[1][2]); 1.730 + EXPECT_EQ(1u, orig_pixels[1][3]); // Alpha unchanged. 1.731 + EXPECT_EQ(9u, orig_pixels[2][0]); 1.732 + EXPECT_EQ(10u, orig_pixels[2][1]); 1.733 + EXPECT_EQ(11u, orig_pixels[2][2]); 1.734 + EXPECT_EQ(2u, orig_pixels[2][3]); // Alpha unchanged. 1.735 + EXPECT_EQ(1u, orig_pixels[3][0]); 1.736 + EXPECT_EQ(6u, orig_pixels[3][1]); 1.737 + EXPECT_EQ(11u, orig_pixels[3][2]); 1.738 + EXPECT_EQ(3u, orig_pixels[3][3]); // Alpha unchanged. 1.739 + 1.740 + for (int i = 0; i < 1280; ++i) { 1.741 + orig_pixels[i][0] = i; 1.742 + orig_pixels[i][1] = i / 2; 1.743 + orig_pixels[i][2] = i / 3; 1.744 + orig_pixels[i][3] = i; 1.745 + } 1.746 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.747 + RGBColorTable(&orig_pixels[0][0], 0, &kARGBTable[0], 0, 0, 1280, 1); 1.748 + } 1.749 +} 1.750 + 1.751 +TEST_F(libyuvTest, TestARGBQuantize) { 1.752 + SIMD_ALIGNED(uint8 orig_pixels[1280][4]); 1.753 + 1.754 + for (int i = 0; i < 1280; ++i) { 1.755 + orig_pixels[i][0] = i; 1.756 + orig_pixels[i][1] = i / 2; 1.757 + orig_pixels[i][2] = i / 3; 1.758 + orig_pixels[i][3] = i; 1.759 + } 1.760 + ARGBQuantize(&orig_pixels[0][0], 0, 1.761 + (65536 + (8 / 2)) / 8, 8, 8 / 2, 0, 0, 1280, 1); 1.762 + 1.763 + for (int i = 0; i < 1280; ++i) { 1.764 + EXPECT_EQ((i / 8 * 8 + 8 / 2) & 255, orig_pixels[i][0]); 1.765 + EXPECT_EQ((i / 2 / 8 * 8 + 8 / 2) & 255, orig_pixels[i][1]); 1.766 + EXPECT_EQ((i / 3 / 8 * 8 + 8 / 2) & 255, orig_pixels[i][2]); 1.767 + EXPECT_EQ(i & 255, orig_pixels[i][3]); 1.768 + } 1.769 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.770 + ARGBQuantize(&orig_pixels[0][0], 0, 1.771 + (65536 + (8 / 2)) / 8, 8, 8 / 2, 0, 0, 1280, 1); 1.772 + } 1.773 +} 1.774 + 1.775 +TEST_F(libyuvTest, TestARGBMirror) { 1.776 + SIMD_ALIGNED(uint8 orig_pixels[1280][4]); 1.777 + SIMD_ALIGNED(uint8 dst_pixels[1280][4]); 1.778 + 1.779 + for (int i = 0; i < 1280; ++i) { 1.780 + orig_pixels[i][0] = i; 1.781 + orig_pixels[i][1] = i / 2; 1.782 + orig_pixels[i][2] = i / 3; 1.783 + orig_pixels[i][3] = i / 4; 1.784 + } 1.785 + ARGBMirror(&orig_pixels[0][0], 0, &dst_pixels[0][0], 0, 1280, 1); 1.786 + 1.787 + for (int i = 0; i < 1280; ++i) { 1.788 + EXPECT_EQ(i & 255, dst_pixels[1280 - 1 - i][0]); 1.789 + EXPECT_EQ((i / 2) & 255, dst_pixels[1280 - 1 - i][1]); 1.790 + EXPECT_EQ((i / 3) & 255, dst_pixels[1280 - 1 - i][2]); 1.791 + EXPECT_EQ((i / 4) & 255, dst_pixels[1280 - 1 - i][3]); 1.792 + } 1.793 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.794 + ARGBMirror(&orig_pixels[0][0], 0, &dst_pixels[0][0], 0, 1280, 1); 1.795 + } 1.796 +} 1.797 + 1.798 +TEST_F(libyuvTest, TestShade) { 1.799 + SIMD_ALIGNED(uint8 orig_pixels[1280][4]); 1.800 + SIMD_ALIGNED(uint8 shade_pixels[1280][4]); 1.801 + memset(orig_pixels, 0, sizeof(orig_pixels)); 1.802 + 1.803 + orig_pixels[0][0] = 10u; 1.804 + orig_pixels[0][1] = 20u; 1.805 + orig_pixels[0][2] = 40u; 1.806 + orig_pixels[0][3] = 80u; 1.807 + orig_pixels[1][0] = 0u; 1.808 + orig_pixels[1][1] = 0u; 1.809 + orig_pixels[1][2] = 0u; 1.810 + orig_pixels[1][3] = 255u; 1.811 + orig_pixels[2][0] = 0u; 1.812 + orig_pixels[2][1] = 0u; 1.813 + orig_pixels[2][2] = 0u; 1.814 + orig_pixels[2][3] = 0u; 1.815 + orig_pixels[3][0] = 0u; 1.816 + orig_pixels[3][1] = 0u; 1.817 + orig_pixels[3][2] = 0u; 1.818 + orig_pixels[3][3] = 0u; 1.819 + // Do 8 pixels to allow opt version to be used. 1.820 + ARGBShade(&orig_pixels[0][0], 0, &shade_pixels[0][0], 0, 8, 1, 0x80ffffff); 1.821 + EXPECT_EQ(10u, shade_pixels[0][0]); 1.822 + EXPECT_EQ(20u, shade_pixels[0][1]); 1.823 + EXPECT_EQ(40u, shade_pixels[0][2]); 1.824 + EXPECT_EQ(40u, shade_pixels[0][3]); 1.825 + EXPECT_EQ(0u, shade_pixels[1][0]); 1.826 + EXPECT_EQ(0u, shade_pixels[1][1]); 1.827 + EXPECT_EQ(0u, shade_pixels[1][2]); 1.828 + EXPECT_EQ(128u, shade_pixels[1][3]); 1.829 + EXPECT_EQ(0u, shade_pixels[2][0]); 1.830 + EXPECT_EQ(0u, shade_pixels[2][1]); 1.831 + EXPECT_EQ(0u, shade_pixels[2][2]); 1.832 + EXPECT_EQ(0u, shade_pixels[2][3]); 1.833 + EXPECT_EQ(0u, shade_pixels[3][0]); 1.834 + EXPECT_EQ(0u, shade_pixels[3][1]); 1.835 + EXPECT_EQ(0u, shade_pixels[3][2]); 1.836 + EXPECT_EQ(0u, shade_pixels[3][3]); 1.837 + 1.838 + ARGBShade(&orig_pixels[0][0], 0, &shade_pixels[0][0], 0, 8, 1, 0x80808080); 1.839 + EXPECT_EQ(5u, shade_pixels[0][0]); 1.840 + EXPECT_EQ(10u, shade_pixels[0][1]); 1.841 + EXPECT_EQ(20u, shade_pixels[0][2]); 1.842 + EXPECT_EQ(40u, shade_pixels[0][3]); 1.843 + 1.844 + ARGBShade(&orig_pixels[0][0], 0, &shade_pixels[0][0], 0, 8, 1, 0x10204080); 1.845 + EXPECT_EQ(5u, shade_pixels[0][0]); 1.846 + EXPECT_EQ(5u, shade_pixels[0][1]); 1.847 + EXPECT_EQ(5u, shade_pixels[0][2]); 1.848 + EXPECT_EQ(5u, shade_pixels[0][3]); 1.849 + 1.850 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.851 + ARGBShade(&orig_pixels[0][0], 0, &shade_pixels[0][0], 0, 1280, 1, 1.852 + 0x80808080); 1.853 + } 1.854 +} 1.855 + 1.856 +TEST_F(libyuvTest, TestInterpolate) { 1.857 + SIMD_ALIGNED(uint8 orig_pixels_0[1280][4]); 1.858 + SIMD_ALIGNED(uint8 orig_pixels_1[1280][4]); 1.859 + SIMD_ALIGNED(uint8 interpolate_pixels[1280][4]); 1.860 + memset(orig_pixels_0, 0, sizeof(orig_pixels_0)); 1.861 + memset(orig_pixels_1, 0, sizeof(orig_pixels_1)); 1.862 + 1.863 + orig_pixels_0[0][0] = 16u; 1.864 + orig_pixels_0[0][1] = 32u; 1.865 + orig_pixels_0[0][2] = 64u; 1.866 + orig_pixels_0[0][3] = 128u; 1.867 + orig_pixels_0[1][0] = 0u; 1.868 + orig_pixels_0[1][1] = 0u; 1.869 + orig_pixels_0[1][2] = 0u; 1.870 + orig_pixels_0[1][3] = 255u; 1.871 + orig_pixels_0[2][0] = 0u; 1.872 + orig_pixels_0[2][1] = 0u; 1.873 + orig_pixels_0[2][2] = 0u; 1.874 + orig_pixels_0[2][3] = 0u; 1.875 + orig_pixels_0[3][0] = 0u; 1.876 + orig_pixels_0[3][1] = 0u; 1.877 + orig_pixels_0[3][2] = 0u; 1.878 + orig_pixels_0[3][3] = 0u; 1.879 + 1.880 + orig_pixels_1[0][0] = 0u; 1.881 + orig_pixels_1[0][1] = 0u; 1.882 + orig_pixels_1[0][2] = 0u; 1.883 + orig_pixels_1[0][3] = 0u; 1.884 + orig_pixels_1[1][0] = 0u; 1.885 + orig_pixels_1[1][1] = 0u; 1.886 + orig_pixels_1[1][2] = 0u; 1.887 + orig_pixels_1[1][3] = 0u; 1.888 + orig_pixels_1[2][0] = 0u; 1.889 + orig_pixels_1[2][1] = 0u; 1.890 + orig_pixels_1[2][2] = 0u; 1.891 + orig_pixels_1[2][3] = 0u; 1.892 + orig_pixels_1[3][0] = 255u; 1.893 + orig_pixels_1[3][1] = 255u; 1.894 + orig_pixels_1[3][2] = 255u; 1.895 + orig_pixels_1[3][3] = 255u; 1.896 + 1.897 + ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0, 1.898 + &interpolate_pixels[0][0], 0, 4, 1, 128); 1.899 + EXPECT_EQ(8u, interpolate_pixels[0][0]); 1.900 + EXPECT_EQ(16u, interpolate_pixels[0][1]); 1.901 + EXPECT_EQ(32u, interpolate_pixels[0][2]); 1.902 + EXPECT_EQ(64u, interpolate_pixels[0][3]); 1.903 + EXPECT_EQ(0u, interpolate_pixels[1][0]); 1.904 + EXPECT_EQ(0u, interpolate_pixels[1][1]); 1.905 + EXPECT_EQ(0u, interpolate_pixels[1][2]); 1.906 + EXPECT_NEAR(128u, interpolate_pixels[1][3], 1); // C = 127, SSE = 128. 1.907 + EXPECT_EQ(0u, interpolate_pixels[2][0]); 1.908 + EXPECT_EQ(0u, interpolate_pixels[2][1]); 1.909 + EXPECT_EQ(0u, interpolate_pixels[2][2]); 1.910 + EXPECT_EQ(0u, interpolate_pixels[2][3]); 1.911 + EXPECT_NEAR(128u, interpolate_pixels[3][0], 1); 1.912 + EXPECT_NEAR(128u, interpolate_pixels[3][1], 1); 1.913 + EXPECT_NEAR(128u, interpolate_pixels[3][2], 1); 1.914 + EXPECT_NEAR(128u, interpolate_pixels[3][3], 1); 1.915 + 1.916 + ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0, 1.917 + &interpolate_pixels[0][0], 0, 4, 1, 0); 1.918 + EXPECT_EQ(16u, interpolate_pixels[0][0]); 1.919 + EXPECT_EQ(32u, interpolate_pixels[0][1]); 1.920 + EXPECT_EQ(64u, interpolate_pixels[0][2]); 1.921 + EXPECT_EQ(128u, interpolate_pixels[0][3]); 1.922 + 1.923 + ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0, 1.924 + &interpolate_pixels[0][0], 0, 4, 1, 192); 1.925 + 1.926 + EXPECT_EQ(4u, interpolate_pixels[0][0]); 1.927 + EXPECT_EQ(8u, interpolate_pixels[0][1]); 1.928 + EXPECT_EQ(16u, interpolate_pixels[0][2]); 1.929 + EXPECT_EQ(32u, interpolate_pixels[0][3]); 1.930 + 1.931 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.932 + ARGBInterpolate(&orig_pixels_0[0][0], 0, &orig_pixels_1[0][0], 0, 1.933 + &interpolate_pixels[0][0], 0, 1280, 1, 128); 1.934 + } 1.935 +} 1.936 + 1.937 +#define TESTTERP(FMT_A, BPP_A, STRIDE_A, \ 1.938 + FMT_B, BPP_B, STRIDE_B, \ 1.939 + W1280, TERP, DIFF, N, NEG, OFF) \ 1.940 +TEST_F(libyuvTest, ARGBInterpolate##TERP##N) { \ 1.941 + const int kWidth = ((W1280) > 0) ? (W1280) : 1; \ 1.942 + const int kHeight = benchmark_height_; \ 1.943 + const int kStrideA = (kWidth * BPP_A + STRIDE_A - 1) / STRIDE_A * STRIDE_A; \ 1.944 + const int kStrideB = (kWidth * BPP_B + STRIDE_B - 1) / STRIDE_B * STRIDE_B; \ 1.945 + align_buffer_64(src_argb_a, kStrideA * kHeight + OFF); \ 1.946 + align_buffer_64(src_argb_b, kStrideA * kHeight + OFF); \ 1.947 + align_buffer_64(dst_argb_c, kStrideB * kHeight); \ 1.948 + align_buffer_64(dst_argb_opt, kStrideB * kHeight); \ 1.949 + srandom(time(NULL)); \ 1.950 + for (int i = 0; i < kStrideA * kHeight; ++i) { \ 1.951 + src_argb_a[i + OFF] = (random() & 0xff); \ 1.952 + src_argb_b[i + OFF] = (random() & 0xff); \ 1.953 + } \ 1.954 + MaskCpuFlags(0); \ 1.955 + ARGBInterpolate(src_argb_a + OFF, kStrideA, \ 1.956 + src_argb_b + OFF, kStrideA, \ 1.957 + dst_argb_c, kStrideB, \ 1.958 + kWidth, NEG kHeight, TERP); \ 1.959 + MaskCpuFlags(-1); \ 1.960 + for (int i = 0; i < benchmark_iterations_; ++i) { \ 1.961 + ARGBInterpolate(src_argb_a + OFF, kStrideA, \ 1.962 + src_argb_b + OFF, kStrideA, \ 1.963 + dst_argb_opt, kStrideB, \ 1.964 + kWidth, NEG kHeight, TERP); \ 1.965 + } \ 1.966 + int max_diff = 0; \ 1.967 + for (int i = 0; i < kStrideB * kHeight; ++i) { \ 1.968 + int abs_diff = \ 1.969 + abs(static_cast<int>(dst_argb_c[i]) - \ 1.970 + static_cast<int>(dst_argb_opt[i])); \ 1.971 + if (abs_diff > max_diff) { \ 1.972 + max_diff = abs_diff; \ 1.973 + } \ 1.974 + } \ 1.975 + EXPECT_LE(max_diff, DIFF); \ 1.976 + free_aligned_buffer_64(src_argb_a); \ 1.977 + free_aligned_buffer_64(src_argb_b); \ 1.978 + free_aligned_buffer_64(dst_argb_c); \ 1.979 + free_aligned_buffer_64(dst_argb_opt); \ 1.980 +} 1.981 + 1.982 +#define TESTINTERPOLATE(TERP) \ 1.983 + TESTTERP(ARGB, 4, 1, ARGB, 4, 1, \ 1.984 + benchmark_width_ - 1, TERP, 1, _Any, +, 0) \ 1.985 + TESTTERP(ARGB, 4, 1, ARGB, 4, 1, \ 1.986 + benchmark_width_, TERP, 1, _Unaligned, +, 1) \ 1.987 + TESTTERP(ARGB, 4, 1, ARGB, 4, 1, \ 1.988 + benchmark_width_, TERP, 1, _Invert, -, 0) \ 1.989 + TESTTERP(ARGB, 4, 1, ARGB, 4, 1, \ 1.990 + benchmark_width_, TERP, 1, _Opt, +, 0) \ 1.991 + TESTTERP(ARGB, 4, 1, ARGB, 4, 1, \ 1.992 + benchmark_width_ - 1, TERP, 1, _Any_Invert, -, 0) 1.993 + 1.994 +TESTINTERPOLATE(0) 1.995 +TESTINTERPOLATE(64) 1.996 +TESTINTERPOLATE(128) 1.997 +TESTINTERPOLATE(192) 1.998 +TESTINTERPOLATE(255) 1.999 + 1.1000 +static int TestBlend(int width, int height, int benchmark_iterations, 1.1001 + int invert, int off) { 1.1002 + if (width < 1) { 1.1003 + width = 1; 1.1004 + } 1.1005 + const int kBpp = 4; 1.1006 + const int kStride = width * kBpp; 1.1007 + align_buffer_64(src_argb_a, kStride * height + off); 1.1008 + align_buffer_64(src_argb_b, kStride * height + off); 1.1009 + align_buffer_64(dst_argb_c, kStride * height); 1.1010 + align_buffer_64(dst_argb_opt, kStride * height); 1.1011 + srandom(time(NULL)); 1.1012 + for (int i = 0; i < kStride * height; ++i) { 1.1013 + src_argb_a[i + off] = (random() & 0xff); 1.1014 + src_argb_b[i + off] = (random() & 0xff); 1.1015 + } 1.1016 + ARGBAttenuate(src_argb_a + off, kStride, src_argb_a + off, kStride, width, 1.1017 + height); 1.1018 + ARGBAttenuate(src_argb_b + off, kStride, src_argb_b + off, kStride, width, 1.1019 + height); 1.1020 + memset(dst_argb_c, 255, kStride * height); 1.1021 + memset(dst_argb_opt, 255, kStride * height); 1.1022 + 1.1023 + MaskCpuFlags(0); 1.1024 + ARGBBlend(src_argb_a + off, kStride, 1.1025 + src_argb_b + off, kStride, 1.1026 + dst_argb_c, kStride, 1.1027 + width, invert * height); 1.1028 + MaskCpuFlags(-1); 1.1029 + for (int i = 0; i < benchmark_iterations; ++i) { 1.1030 + ARGBBlend(src_argb_a + off, kStride, 1.1031 + src_argb_b + off, kStride, 1.1032 + dst_argb_opt, kStride, 1.1033 + width, invert * height); 1.1034 + } 1.1035 + int max_diff = 0; 1.1036 + for (int i = 0; i < kStride * height; ++i) { 1.1037 + int abs_diff = 1.1038 + abs(static_cast<int>(dst_argb_c[i]) - 1.1039 + static_cast<int>(dst_argb_opt[i])); 1.1040 + if (abs_diff > max_diff) { 1.1041 + max_diff = abs_diff; 1.1042 + } 1.1043 + } 1.1044 + free_aligned_buffer_64(src_argb_a); 1.1045 + free_aligned_buffer_64(src_argb_b); 1.1046 + free_aligned_buffer_64(dst_argb_c); 1.1047 + free_aligned_buffer_64(dst_argb_opt); 1.1048 + return max_diff; 1.1049 +} 1.1050 + 1.1051 +TEST_F(libyuvTest, ARGBBlend_Any) { 1.1052 + int max_diff = TestBlend(benchmark_width_ - 4, benchmark_height_, 1.1053 + benchmark_iterations_, +1, 0); 1.1054 + EXPECT_LE(max_diff, 1); 1.1055 +} 1.1056 + 1.1057 +TEST_F(libyuvTest, ARGBBlend_Unaligned) { 1.1058 + int max_diff = TestBlend(benchmark_width_, benchmark_height_, 1.1059 + benchmark_iterations_, +1, 1); 1.1060 + EXPECT_LE(max_diff, 1); 1.1061 +} 1.1062 + 1.1063 +TEST_F(libyuvTest, ARGBBlend_Invert) { 1.1064 + int max_diff = TestBlend(benchmark_width_, benchmark_height_, 1.1065 + benchmark_iterations_, -1, 0); 1.1066 + EXPECT_LE(max_diff, 1); 1.1067 +} 1.1068 + 1.1069 +TEST_F(libyuvTest, ARGBBlend_Opt) { 1.1070 + int max_diff = TestBlend(benchmark_width_, benchmark_height_, 1.1071 + benchmark_iterations_, +1, 0); 1.1072 + EXPECT_LE(max_diff, 1); 1.1073 +} 1.1074 + 1.1075 +TEST_F(libyuvTest, TestAffine) { 1.1076 + SIMD_ALIGNED(uint8 orig_pixels_0[1280][4]); 1.1077 + SIMD_ALIGNED(uint8 interpolate_pixels_C[1280][4]); 1.1078 + 1.1079 + for (int i = 0; i < 1280; ++i) { 1.1080 + for (int j = 0; j < 4; ++j) { 1.1081 + orig_pixels_0[i][j] = i; 1.1082 + } 1.1083 + } 1.1084 + 1.1085 + float uv_step[4] = { 0.f, 0.f, 0.75f, 0.f }; 1.1086 + 1.1087 + ARGBAffineRow_C(&orig_pixels_0[0][0], 0, &interpolate_pixels_C[0][0], 1.1088 + uv_step, 1280); 1.1089 + EXPECT_EQ(0u, interpolate_pixels_C[0][0]); 1.1090 + EXPECT_EQ(96u, interpolate_pixels_C[128][0]); 1.1091 + EXPECT_EQ(191u, interpolate_pixels_C[255][3]); 1.1092 + 1.1093 +#if defined(HAS_ARGBAFFINEROW_SSE2) 1.1094 + SIMD_ALIGNED(uint8 interpolate_pixels_Opt[1280][4]); 1.1095 + ARGBAffineRow_SSE2(&orig_pixels_0[0][0], 0, &interpolate_pixels_Opt[0][0], 1.1096 + uv_step, 1280); 1.1097 + EXPECT_EQ(0, memcmp(interpolate_pixels_Opt, interpolate_pixels_C, 1280 * 4)); 1.1098 + 1.1099 + int has_sse2 = TestCpuFlag(kCpuHasSSE2); 1.1100 + if (has_sse2) { 1.1101 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.1102 + ARGBAffineRow_SSE2(&orig_pixels_0[0][0], 0, &interpolate_pixels_Opt[0][0], 1.1103 + uv_step, 1280); 1.1104 + } 1.1105 + } 1.1106 +#endif 1.1107 +} 1.1108 + 1.1109 +TEST_F(libyuvTest, TestSobelX) { 1.1110 + SIMD_ALIGNED(uint8 orig_pixels_0[1280 + 2]); 1.1111 + SIMD_ALIGNED(uint8 orig_pixels_1[1280 + 2]); 1.1112 + SIMD_ALIGNED(uint8 orig_pixels_2[1280 + 2]); 1.1113 + SIMD_ALIGNED(uint8 sobel_pixels_c[1280]); 1.1114 + SIMD_ALIGNED(uint8 sobel_pixels_opt[1280]); 1.1115 + 1.1116 + for (int i = 0; i < 1280 + 2; ++i) { 1.1117 + orig_pixels_0[i] = i; 1.1118 + orig_pixels_1[i] = i * 2; 1.1119 + orig_pixels_2[i] = i * 3; 1.1120 + } 1.1121 + 1.1122 + SobelXRow_C(orig_pixels_0, orig_pixels_1, orig_pixels_2, 1.1123 + sobel_pixels_c, 1280); 1.1124 + 1.1125 + EXPECT_EQ(16u, sobel_pixels_c[0]); 1.1126 + EXPECT_EQ(16u, sobel_pixels_c[100]); 1.1127 + EXPECT_EQ(255u, sobel_pixels_c[255]); 1.1128 + 1.1129 + void (*SobelXRow)(const uint8* src_y0, const uint8* src_y1, 1.1130 + const uint8* src_y2, uint8* dst_sobely, int width) = 1.1131 + SobelXRow_C; 1.1132 +#if defined(HAS_SOBELXROW_SSE2) 1.1133 + if (TestCpuFlag(kCpuHasSSE2)) { 1.1134 + SobelXRow = SobelXRow_SSE2; 1.1135 + } 1.1136 +#endif 1.1137 +#if defined(HAS_SOBELXROW_NEON) 1.1138 + if (TestCpuFlag(kCpuHasNEON)) { 1.1139 + SobelXRow = SobelXRow_NEON; 1.1140 + } 1.1141 +#endif 1.1142 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.1143 + SobelXRow(orig_pixels_0, orig_pixels_1, orig_pixels_2, 1.1144 + sobel_pixels_opt, 1280); 1.1145 + } 1.1146 + for (int i = 0; i < 1280; ++i) { 1.1147 + EXPECT_EQ(sobel_pixels_c[i], sobel_pixels_opt[i]); 1.1148 + } 1.1149 +} 1.1150 + 1.1151 +TEST_F(libyuvTest, TestSobelY) { 1.1152 + SIMD_ALIGNED(uint8 orig_pixels_0[1280 + 2]); 1.1153 + SIMD_ALIGNED(uint8 orig_pixels_1[1280 + 2]); 1.1154 + SIMD_ALIGNED(uint8 sobel_pixels_c[1280]); 1.1155 + SIMD_ALIGNED(uint8 sobel_pixels_opt[1280]); 1.1156 + 1.1157 + for (int i = 0; i < 1280 + 2; ++i) { 1.1158 + orig_pixels_0[i] = i; 1.1159 + orig_pixels_1[i] = i * 2; 1.1160 + } 1.1161 + 1.1162 + SobelYRow_C(orig_pixels_0, orig_pixels_1, sobel_pixels_c, 1280); 1.1163 + 1.1164 + EXPECT_EQ(4u, sobel_pixels_c[0]); 1.1165 + EXPECT_EQ(255u, sobel_pixels_c[100]); 1.1166 + EXPECT_EQ(0u, sobel_pixels_c[255]); 1.1167 + void (*SobelYRow)(const uint8* src_y0, const uint8* src_y1, 1.1168 + uint8* dst_sobely, int width) = SobelYRow_C; 1.1169 +#if defined(HAS_SOBELYROW_SSE2) 1.1170 + if (TestCpuFlag(kCpuHasSSE2)) { 1.1171 + SobelYRow = SobelYRow_SSE2; 1.1172 + } 1.1173 +#endif 1.1174 +#if defined(HAS_SOBELYROW_NEON) 1.1175 + if (TestCpuFlag(kCpuHasNEON)) { 1.1176 + SobelYRow = SobelYRow_NEON; 1.1177 + } 1.1178 +#endif 1.1179 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.1180 + SobelYRow(orig_pixels_0, orig_pixels_1, sobel_pixels_opt, 1280); 1.1181 + } 1.1182 + for (int i = 0; i < 1280; ++i) { 1.1183 + EXPECT_EQ(sobel_pixels_c[i], sobel_pixels_opt[i]); 1.1184 + } 1.1185 +} 1.1186 + 1.1187 +TEST_F(libyuvTest, TestSobel) { 1.1188 + SIMD_ALIGNED(uint8 orig_sobelx[1280]); 1.1189 + SIMD_ALIGNED(uint8 orig_sobely[1280]); 1.1190 + SIMD_ALIGNED(uint8 sobel_pixels_c[1280 * 4]); 1.1191 + SIMD_ALIGNED(uint8 sobel_pixels_opt[1280 * 4]); 1.1192 + 1.1193 + for (int i = 0; i < 1280; ++i) { 1.1194 + orig_sobelx[i] = i; 1.1195 + orig_sobely[i] = i * 2; 1.1196 + } 1.1197 + 1.1198 + SobelRow_C(orig_sobelx, orig_sobely, sobel_pixels_c, 1280); 1.1199 + 1.1200 + EXPECT_EQ(0u, sobel_pixels_c[0]); 1.1201 + EXPECT_EQ(3u, sobel_pixels_c[4]); 1.1202 + EXPECT_EQ(3u, sobel_pixels_c[5]); 1.1203 + EXPECT_EQ(3u, sobel_pixels_c[6]); 1.1204 + EXPECT_EQ(255u, sobel_pixels_c[7]); 1.1205 + EXPECT_EQ(6u, sobel_pixels_c[8]); 1.1206 + EXPECT_EQ(6u, sobel_pixels_c[9]); 1.1207 + EXPECT_EQ(6u, sobel_pixels_c[10]); 1.1208 + EXPECT_EQ(255u, sobel_pixels_c[7]); 1.1209 + EXPECT_EQ(255u, sobel_pixels_c[100 * 4 + 1]); 1.1210 + EXPECT_EQ(255u, sobel_pixels_c[255 * 4 + 1]); 1.1211 + void (*SobelRow)(const uint8* src_sobelx, const uint8* src_sobely, 1.1212 + uint8* dst_argb, int width) = SobelRow_C; 1.1213 +#if defined(HAS_SOBELROW_SSE2) 1.1214 + if (TestCpuFlag(kCpuHasSSE2)) { 1.1215 + SobelRow = SobelRow_SSE2; 1.1216 + } 1.1217 +#endif 1.1218 +#if defined(HAS_SOBELROW_NEON) 1.1219 + if (TestCpuFlag(kCpuHasNEON)) { 1.1220 + SobelRow = SobelRow_NEON; 1.1221 + } 1.1222 +#endif 1.1223 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.1224 + SobelRow(orig_sobelx, orig_sobely, sobel_pixels_opt, 1280); 1.1225 + } 1.1226 + for (int i = 0; i < 1280 * 4; ++i) { 1.1227 + EXPECT_EQ(sobel_pixels_c[i], sobel_pixels_opt[i]); 1.1228 + } 1.1229 +} 1.1230 + 1.1231 +TEST_F(libyuvTest, TestSobelToPlane) { 1.1232 + SIMD_ALIGNED(uint8 orig_sobelx[1280]); 1.1233 + SIMD_ALIGNED(uint8 orig_sobely[1280]); 1.1234 + SIMD_ALIGNED(uint8 sobel_pixels_c[1280]); 1.1235 + SIMD_ALIGNED(uint8 sobel_pixels_opt[1280]); 1.1236 + 1.1237 + for (int i = 0; i < 1280; ++i) { 1.1238 + orig_sobelx[i] = i; 1.1239 + orig_sobely[i] = i * 2; 1.1240 + } 1.1241 + 1.1242 + SobelToPlaneRow_C(orig_sobelx, orig_sobely, sobel_pixels_c, 1280); 1.1243 + 1.1244 + EXPECT_EQ(0u, sobel_pixels_c[0]); 1.1245 + EXPECT_EQ(3u, sobel_pixels_c[1]); 1.1246 + EXPECT_EQ(6u, sobel_pixels_c[2]); 1.1247 + EXPECT_EQ(99u, sobel_pixels_c[33]); 1.1248 + EXPECT_EQ(255u, sobel_pixels_c[100]); 1.1249 + void (*SobelToPlaneRow)(const uint8* src_sobelx, const uint8* src_sobely, 1.1250 + uint8* dst_y, int width) = SobelToPlaneRow_C; 1.1251 +#if defined(HAS_SOBELTOPLANEROW_SSE2) 1.1252 + if (TestCpuFlag(kCpuHasSSE2)) { 1.1253 + SobelToPlaneRow = SobelToPlaneRow_SSE2; 1.1254 + } 1.1255 +#endif 1.1256 +#if defined(HAS_SOBELTOPLANEROW_NEON) 1.1257 + if (TestCpuFlag(kCpuHasNEON)) { 1.1258 + SobelToPlaneRow = SobelToPlaneRow_NEON; 1.1259 + } 1.1260 +#endif 1.1261 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.1262 + SobelToPlaneRow(orig_sobelx, orig_sobely, sobel_pixels_opt, 1280); 1.1263 + } 1.1264 + for (int i = 0; i < 1280; ++i) { 1.1265 + EXPECT_EQ(sobel_pixels_c[i], sobel_pixels_opt[i]); 1.1266 + } 1.1267 +} 1.1268 + 1.1269 +TEST_F(libyuvTest, TestSobelXY) { 1.1270 + SIMD_ALIGNED(uint8 orig_sobelx[1280]); 1.1271 + SIMD_ALIGNED(uint8 orig_sobely[1280]); 1.1272 + SIMD_ALIGNED(uint8 sobel_pixels_c[1280 * 4]); 1.1273 + SIMD_ALIGNED(uint8 sobel_pixels_opt[1280 * 4]); 1.1274 + 1.1275 + for (int i = 0; i < 1280; ++i) { 1.1276 + orig_sobelx[i] = i; 1.1277 + orig_sobely[i] = i * 2; 1.1278 + } 1.1279 + 1.1280 + SobelXYRow_C(orig_sobelx, orig_sobely, sobel_pixels_c, 1280); 1.1281 + 1.1282 + EXPECT_EQ(0u, sobel_pixels_c[0]); 1.1283 + EXPECT_EQ(2u, sobel_pixels_c[4]); 1.1284 + EXPECT_EQ(3u, sobel_pixels_c[5]); 1.1285 + EXPECT_EQ(1u, sobel_pixels_c[6]); 1.1286 + EXPECT_EQ(255u, sobel_pixels_c[7]); 1.1287 + EXPECT_EQ(255u, sobel_pixels_c[100 * 4 + 1]); 1.1288 + EXPECT_EQ(255u, sobel_pixels_c[255 * 4 + 1]); 1.1289 + void (*SobelXYRow)(const uint8* src_sobelx, const uint8* src_sobely, 1.1290 + uint8* dst_argb, int width) = SobelXYRow_C; 1.1291 +#if defined(HAS_SOBELXYROW_SSE2) 1.1292 + if (TestCpuFlag(kCpuHasSSE2)) { 1.1293 + SobelXYRow = SobelXYRow_SSE2; 1.1294 + } 1.1295 +#endif 1.1296 +#if defined(HAS_SOBELXYROW_NEON) 1.1297 + if (TestCpuFlag(kCpuHasNEON)) { 1.1298 + SobelXYRow = SobelXYRow_NEON; 1.1299 + } 1.1300 +#endif 1.1301 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.1302 + SobelXYRow(orig_sobelx, orig_sobely, sobel_pixels_opt, 1280); 1.1303 + } 1.1304 + for (int i = 0; i < 1280 * 4; ++i) { 1.1305 + EXPECT_EQ(sobel_pixels_c[i], sobel_pixels_opt[i]); 1.1306 + } 1.1307 +} 1.1308 + 1.1309 +TEST_F(libyuvTest, TestCopyPlane) { 1.1310 + int err = 0; 1.1311 + int yw = benchmark_width_; 1.1312 + int yh = benchmark_height_; 1.1313 + int b = 12; 1.1314 + int i, j; 1.1315 + 1.1316 + int y_plane_size = (yw + b * 2) * (yh + b * 2); 1.1317 + srandom(time(NULL)); 1.1318 + align_buffer_64(orig_y, y_plane_size); 1.1319 + align_buffer_64(dst_c, y_plane_size); 1.1320 + align_buffer_64(dst_opt, y_plane_size); 1.1321 + 1.1322 + memset(orig_y, 0, y_plane_size); 1.1323 + memset(dst_c, 0, y_plane_size); 1.1324 + memset(dst_opt, 0, y_plane_size); 1.1325 + 1.1326 + // Fill image buffers with random data. 1.1327 + for (i = b; i < (yh + b); ++i) { 1.1328 + for (j = b; j < (yw + b); ++j) { 1.1329 + orig_y[i * (yw + b * 2) + j] = random() & 0xff; 1.1330 + } 1.1331 + } 1.1332 + 1.1333 + // Fill destination buffers with random data. 1.1334 + for (i = 0; i < y_plane_size; ++i) { 1.1335 + uint8 random_number = random() & 0x7f; 1.1336 + dst_c[i] = random_number; 1.1337 + dst_opt[i] = dst_c[i]; 1.1338 + } 1.1339 + 1.1340 + int y_off = b * (yw + b * 2) + b; 1.1341 + 1.1342 + int y_st = yw + b * 2; 1.1343 + int stride = 8; 1.1344 + 1.1345 + // Disable all optimizations. 1.1346 + MaskCpuFlags(0); 1.1347 + double c_time = get_time(); 1.1348 + for (j = 0; j < benchmark_iterations_; j++) { 1.1349 + CopyPlane(orig_y + y_off, y_st, dst_c + y_off, stride, yw, yh); 1.1350 + } 1.1351 + c_time = (get_time() - c_time) / benchmark_iterations_; 1.1352 + 1.1353 + // Enable optimizations. 1.1354 + MaskCpuFlags(-1); 1.1355 + double opt_time = get_time(); 1.1356 + for (j = 0; j < benchmark_iterations_; j++) { 1.1357 + CopyPlane(orig_y + y_off, y_st, dst_opt + y_off, stride, yw, yh); 1.1358 + } 1.1359 + opt_time = (get_time() - opt_time) / benchmark_iterations_; 1.1360 + 1.1361 + for (i = 0; i < y_plane_size; ++i) { 1.1362 + if (dst_c[i] != dst_opt[i]) 1.1363 + ++err; 1.1364 + } 1.1365 + 1.1366 + free_aligned_buffer_64(orig_y); 1.1367 + free_aligned_buffer_64(dst_c); 1.1368 + free_aligned_buffer_64(dst_opt); 1.1369 + 1.1370 + EXPECT_EQ(0, err); 1.1371 +} 1.1372 + 1.1373 +static int TestMultiply(int width, int height, int benchmark_iterations, 1.1374 + int invert, int off) { 1.1375 + if (width < 1) { 1.1376 + width = 1; 1.1377 + } 1.1378 + const int kBpp = 4; 1.1379 + const int kStride = (width * kBpp + 15) & ~15; 1.1380 + align_buffer_64(src_argb_a, kStride * height + off); 1.1381 + align_buffer_64(src_argb_b, kStride * height + off); 1.1382 + align_buffer_64(dst_argb_c, kStride * height); 1.1383 + align_buffer_64(dst_argb_opt, kStride * height); 1.1384 + srandom(time(NULL)); 1.1385 + for (int i = 0; i < kStride * height; ++i) { 1.1386 + src_argb_a[i + off] = (random() & 0xff); 1.1387 + src_argb_b[i + off] = (random() & 0xff); 1.1388 + } 1.1389 + memset(dst_argb_c, 0, kStride * height); 1.1390 + memset(dst_argb_opt, 0, kStride * height); 1.1391 + 1.1392 + MaskCpuFlags(0); 1.1393 + ARGBMultiply(src_argb_a + off, kStride, 1.1394 + src_argb_b + off, kStride, 1.1395 + dst_argb_c, kStride, 1.1396 + width, invert * height); 1.1397 + MaskCpuFlags(-1); 1.1398 + for (int i = 0; i < benchmark_iterations; ++i) { 1.1399 + ARGBMultiply(src_argb_a + off, kStride, 1.1400 + src_argb_b + off, kStride, 1.1401 + dst_argb_opt, kStride, 1.1402 + width, invert * height); 1.1403 + } 1.1404 + int max_diff = 0; 1.1405 + for (int i = 0; i < kStride * height; ++i) { 1.1406 + int abs_diff = 1.1407 + abs(static_cast<int>(dst_argb_c[i]) - 1.1408 + static_cast<int>(dst_argb_opt[i])); 1.1409 + if (abs_diff > max_diff) { 1.1410 + max_diff = abs_diff; 1.1411 + } 1.1412 + } 1.1413 + free_aligned_buffer_64(src_argb_a); 1.1414 + free_aligned_buffer_64(src_argb_b); 1.1415 + free_aligned_buffer_64(dst_argb_c); 1.1416 + free_aligned_buffer_64(dst_argb_opt); 1.1417 + return max_diff; 1.1418 +} 1.1419 + 1.1420 +TEST_F(libyuvTest, ARGBMultiply_Any) { 1.1421 + int max_diff = TestMultiply(benchmark_width_ - 1, benchmark_height_, 1.1422 + benchmark_iterations_, +1, 0); 1.1423 + EXPECT_LE(max_diff, 1); 1.1424 +} 1.1425 + 1.1426 +TEST_F(libyuvTest, ARGBMultiply_Unaligned) { 1.1427 + int max_diff = TestMultiply(benchmark_width_, benchmark_height_, 1.1428 + benchmark_iterations_, +1, 1); 1.1429 + EXPECT_LE(max_diff, 1); 1.1430 +} 1.1431 + 1.1432 +TEST_F(libyuvTest, ARGBMultiply_Invert) { 1.1433 + int max_diff = TestMultiply(benchmark_width_, benchmark_height_, 1.1434 + benchmark_iterations_, -1, 0); 1.1435 + EXPECT_LE(max_diff, 1); 1.1436 +} 1.1437 + 1.1438 +TEST_F(libyuvTest, ARGBMultiply_Opt) { 1.1439 + int max_diff = TestMultiply(benchmark_width_, benchmark_height_, 1.1440 + benchmark_iterations_, +1, 0); 1.1441 + EXPECT_LE(max_diff, 1); 1.1442 +} 1.1443 + 1.1444 +static int TestAdd(int width, int height, int benchmark_iterations, 1.1445 + int invert, int off) { 1.1446 + if (width < 1) { 1.1447 + width = 1; 1.1448 + } 1.1449 + const int kBpp = 4; 1.1450 + const int kStride = (width * kBpp + 15) & ~15; 1.1451 + align_buffer_64(src_argb_a, kStride * height + off); 1.1452 + align_buffer_64(src_argb_b, kStride * height + off); 1.1453 + align_buffer_64(dst_argb_c, kStride * height); 1.1454 + align_buffer_64(dst_argb_opt, kStride * height); 1.1455 + srandom(time(NULL)); 1.1456 + for (int i = 0; i < kStride * height; ++i) { 1.1457 + src_argb_a[i + off] = (random() & 0xff); 1.1458 + src_argb_b[i + off] = (random() & 0xff); 1.1459 + } 1.1460 + memset(dst_argb_c, 0, kStride * height); 1.1461 + memset(dst_argb_opt, 0, kStride * height); 1.1462 + 1.1463 + MaskCpuFlags(0); 1.1464 + ARGBAdd(src_argb_a + off, kStride, 1.1465 + src_argb_b + off, kStride, 1.1466 + dst_argb_c, kStride, 1.1467 + width, invert * height); 1.1468 + MaskCpuFlags(-1); 1.1469 + for (int i = 0; i < benchmark_iterations; ++i) { 1.1470 + ARGBAdd(src_argb_a + off, kStride, 1.1471 + src_argb_b + off, kStride, 1.1472 + dst_argb_opt, kStride, 1.1473 + width, invert * height); 1.1474 + } 1.1475 + int max_diff = 0; 1.1476 + for (int i = 0; i < kStride * height; ++i) { 1.1477 + int abs_diff = 1.1478 + abs(static_cast<int>(dst_argb_c[i]) - 1.1479 + static_cast<int>(dst_argb_opt[i])); 1.1480 + if (abs_diff > max_diff) { 1.1481 + max_diff = abs_diff; 1.1482 + } 1.1483 + } 1.1484 + free_aligned_buffer_64(src_argb_a); 1.1485 + free_aligned_buffer_64(src_argb_b); 1.1486 + free_aligned_buffer_64(dst_argb_c); 1.1487 + free_aligned_buffer_64(dst_argb_opt); 1.1488 + return max_diff; 1.1489 +} 1.1490 + 1.1491 +TEST_F(libyuvTest, ARGBAdd_Any) { 1.1492 + int max_diff = TestAdd(benchmark_width_ - 1, benchmark_height_, 1.1493 + benchmark_iterations_, +1, 0); 1.1494 + EXPECT_LE(max_diff, 1); 1.1495 +} 1.1496 + 1.1497 +TEST_F(libyuvTest, ARGBAdd_Unaligned) { 1.1498 + int max_diff = TestAdd(benchmark_width_, benchmark_height_, 1.1499 + benchmark_iterations_, +1, 1); 1.1500 + EXPECT_LE(max_diff, 1); 1.1501 +} 1.1502 + 1.1503 +TEST_F(libyuvTest, ARGBAdd_Invert) { 1.1504 + int max_diff = TestAdd(benchmark_width_, benchmark_height_, 1.1505 + benchmark_iterations_, -1, 0); 1.1506 + EXPECT_LE(max_diff, 1); 1.1507 +} 1.1508 + 1.1509 +TEST_F(libyuvTest, ARGBAdd_Opt) { 1.1510 + int max_diff = TestAdd(benchmark_width_, benchmark_height_, 1.1511 + benchmark_iterations_, +1, 0); 1.1512 + EXPECT_LE(max_diff, 1); 1.1513 +} 1.1514 + 1.1515 +static int TestSubtract(int width, int height, int benchmark_iterations, 1.1516 + int invert, int off) { 1.1517 + if (width < 1) { 1.1518 + width = 1; 1.1519 + } 1.1520 + const int kBpp = 4; 1.1521 + const int kStride = (width * kBpp + 15) & ~15; 1.1522 + align_buffer_64(src_argb_a, kStride * height + off); 1.1523 + align_buffer_64(src_argb_b, kStride * height + off); 1.1524 + align_buffer_64(dst_argb_c, kStride * height); 1.1525 + align_buffer_64(dst_argb_opt, kStride * height); 1.1526 + srandom(time(NULL)); 1.1527 + for (int i = 0; i < kStride * height; ++i) { 1.1528 + src_argb_a[i + off] = (random() & 0xff); 1.1529 + src_argb_b[i + off] = (random() & 0xff); 1.1530 + } 1.1531 + memset(dst_argb_c, 0, kStride * height); 1.1532 + memset(dst_argb_opt, 0, kStride * height); 1.1533 + 1.1534 + MaskCpuFlags(0); 1.1535 + ARGBSubtract(src_argb_a + off, kStride, 1.1536 + src_argb_b + off, kStride, 1.1537 + dst_argb_c, kStride, 1.1538 + width, invert * height); 1.1539 + MaskCpuFlags(-1); 1.1540 + for (int i = 0; i < benchmark_iterations; ++i) { 1.1541 + ARGBSubtract(src_argb_a + off, kStride, 1.1542 + src_argb_b + off, kStride, 1.1543 + dst_argb_opt, kStride, 1.1544 + width, invert * height); 1.1545 + } 1.1546 + int max_diff = 0; 1.1547 + for (int i = 0; i < kStride * height; ++i) { 1.1548 + int abs_diff = 1.1549 + abs(static_cast<int>(dst_argb_c[i]) - 1.1550 + static_cast<int>(dst_argb_opt[i])); 1.1551 + if (abs_diff > max_diff) { 1.1552 + max_diff = abs_diff; 1.1553 + } 1.1554 + } 1.1555 + free_aligned_buffer_64(src_argb_a); 1.1556 + free_aligned_buffer_64(src_argb_b); 1.1557 + free_aligned_buffer_64(dst_argb_c); 1.1558 + free_aligned_buffer_64(dst_argb_opt); 1.1559 + return max_diff; 1.1560 +} 1.1561 + 1.1562 +TEST_F(libyuvTest, ARGBSubtract_Any) { 1.1563 + int max_diff = TestSubtract(benchmark_width_ - 1, benchmark_height_, 1.1564 + benchmark_iterations_, +1, 0); 1.1565 + EXPECT_LE(max_diff, 1); 1.1566 +} 1.1567 + 1.1568 +TEST_F(libyuvTest, ARGBSubtract_Unaligned) { 1.1569 + int max_diff = TestSubtract(benchmark_width_, benchmark_height_, 1.1570 + benchmark_iterations_, +1, 1); 1.1571 + EXPECT_LE(max_diff, 1); 1.1572 +} 1.1573 + 1.1574 +TEST_F(libyuvTest, ARGBSubtract_Invert) { 1.1575 + int max_diff = TestSubtract(benchmark_width_, benchmark_height_, 1.1576 + benchmark_iterations_, -1, 0); 1.1577 + EXPECT_LE(max_diff, 1); 1.1578 +} 1.1579 + 1.1580 +TEST_F(libyuvTest, ARGBSubtract_Opt) { 1.1581 + int max_diff = TestSubtract(benchmark_width_, benchmark_height_, 1.1582 + benchmark_iterations_, +1, 0); 1.1583 + EXPECT_LE(max_diff, 1); 1.1584 +} 1.1585 + 1.1586 +static int TestSobel(int width, int height, int benchmark_iterations, 1.1587 + int invert, int off) { 1.1588 + if (width < 1) { 1.1589 + width = 1; 1.1590 + } 1.1591 + const int kBpp = 4; 1.1592 + const int kStride = (width * kBpp + 15) & ~15; 1.1593 + align_buffer_64(src_argb_a, kStride * height + off); 1.1594 + align_buffer_64(dst_argb_c, kStride * height); 1.1595 + align_buffer_64(dst_argb_opt, kStride * height); 1.1596 + memset(src_argb_a, 0, kStride * height + off); 1.1597 + srandom(time(NULL)); 1.1598 + for (int i = 0; i < kStride * height; ++i) { 1.1599 + src_argb_a[i + off] = (random() & 0xff); 1.1600 + } 1.1601 + memset(dst_argb_c, 0, kStride * height); 1.1602 + memset(dst_argb_opt, 0, kStride * height); 1.1603 + 1.1604 + MaskCpuFlags(0); 1.1605 + ARGBSobel(src_argb_a + off, kStride, 1.1606 + dst_argb_c, kStride, 1.1607 + width, invert * height); 1.1608 + MaskCpuFlags(-1); 1.1609 + for (int i = 0; i < benchmark_iterations; ++i) { 1.1610 + ARGBSobel(src_argb_a + off, kStride, 1.1611 + dst_argb_opt, kStride, 1.1612 + width, invert * height); 1.1613 + } 1.1614 + int max_diff = 0; 1.1615 + for (int i = 0; i < kStride * height; ++i) { 1.1616 + int abs_diff = 1.1617 + abs(static_cast<int>(dst_argb_c[i]) - 1.1618 + static_cast<int>(dst_argb_opt[i])); 1.1619 + if (abs_diff > max_diff) { 1.1620 + max_diff = abs_diff; 1.1621 + } 1.1622 + } 1.1623 + free_aligned_buffer_64(src_argb_a); 1.1624 + free_aligned_buffer_64(dst_argb_c); 1.1625 + free_aligned_buffer_64(dst_argb_opt); 1.1626 + return max_diff; 1.1627 +} 1.1628 + 1.1629 +TEST_F(libyuvTest, ARGBSobel_Any) { 1.1630 + int max_diff = TestSobel(benchmark_width_ - 1, benchmark_height_, 1.1631 + benchmark_iterations_, +1, 0); 1.1632 + EXPECT_EQ(0, max_diff); 1.1633 +} 1.1634 + 1.1635 +TEST_F(libyuvTest, ARGBSobel_Unaligned) { 1.1636 + int max_diff = TestSobel(benchmark_width_, benchmark_height_, 1.1637 + benchmark_iterations_, +1, 1); 1.1638 + EXPECT_EQ(0, max_diff); 1.1639 +} 1.1640 + 1.1641 +TEST_F(libyuvTest, ARGBSobel_Invert) { 1.1642 + int max_diff = TestSobel(benchmark_width_, benchmark_height_, 1.1643 + benchmark_iterations_, -1, 0); 1.1644 + EXPECT_EQ(0, max_diff); 1.1645 +} 1.1646 + 1.1647 +TEST_F(libyuvTest, ARGBSobel_Opt) { 1.1648 + int max_diff = TestSobel(benchmark_width_, benchmark_height_, 1.1649 + benchmark_iterations_, +1, 0); 1.1650 + EXPECT_EQ(0, max_diff); 1.1651 +} 1.1652 + 1.1653 +static int TestSobelToPlane(int width, int height, int benchmark_iterations, 1.1654 + int invert, int off) { 1.1655 + if (width < 1) { 1.1656 + width = 1; 1.1657 + } 1.1658 + const int kSrcBpp = 4; 1.1659 + const int kDstBpp = 1; 1.1660 + const int kSrcStride = (width * kSrcBpp + 15) & ~15; 1.1661 + const int kDstStride = (width * kDstBpp + 15) & ~15; 1.1662 + align_buffer_64(src_argb_a, kSrcStride * height + off); 1.1663 + align_buffer_64(dst_argb_c, kDstStride * height); 1.1664 + align_buffer_64(dst_argb_opt, kDstStride * height); 1.1665 + memset(src_argb_a, 0, kSrcStride * height + off); 1.1666 + srandom(time(NULL)); 1.1667 + for (int i = 0; i < kSrcStride * height; ++i) { 1.1668 + src_argb_a[i + off] = (random() & 0xff); 1.1669 + } 1.1670 + memset(dst_argb_c, 0, kDstStride * height); 1.1671 + memset(dst_argb_opt, 0, kDstStride * height); 1.1672 + 1.1673 + MaskCpuFlags(0); 1.1674 + ARGBSobelToPlane(src_argb_a + off, kSrcStride, 1.1675 + dst_argb_c, kDstStride, 1.1676 + width, invert * height); 1.1677 + MaskCpuFlags(-1); 1.1678 + for (int i = 0; i < benchmark_iterations; ++i) { 1.1679 + ARGBSobelToPlane(src_argb_a + off, kSrcStride, 1.1680 + dst_argb_opt, kDstStride, 1.1681 + width, invert * height); 1.1682 + } 1.1683 + int max_diff = 0; 1.1684 + for (int i = 0; i < kDstStride * height; ++i) { 1.1685 + int abs_diff = 1.1686 + abs(static_cast<int>(dst_argb_c[i]) - 1.1687 + static_cast<int>(dst_argb_opt[i])); 1.1688 + if (abs_diff > max_diff) { 1.1689 + max_diff = abs_diff; 1.1690 + } 1.1691 + } 1.1692 + free_aligned_buffer_64(src_argb_a); 1.1693 + free_aligned_buffer_64(dst_argb_c); 1.1694 + free_aligned_buffer_64(dst_argb_opt); 1.1695 + return max_diff; 1.1696 +} 1.1697 + 1.1698 +TEST_F(libyuvTest, ARGBSobelToPlane_Any) { 1.1699 + int max_diff = TestSobelToPlane(benchmark_width_ - 1, benchmark_height_, 1.1700 + benchmark_iterations_, +1, 0); 1.1701 + EXPECT_EQ(0, max_diff); 1.1702 +} 1.1703 + 1.1704 +TEST_F(libyuvTest, ARGBSobelToPlane_Unaligned) { 1.1705 + int max_diff = TestSobelToPlane(benchmark_width_, benchmark_height_, 1.1706 + benchmark_iterations_, +1, 1); 1.1707 + EXPECT_EQ(0, max_diff); 1.1708 +} 1.1709 + 1.1710 +TEST_F(libyuvTest, ARGBSobelToPlane_Invert) { 1.1711 + int max_diff = TestSobelToPlane(benchmark_width_, benchmark_height_, 1.1712 + benchmark_iterations_, -1, 0); 1.1713 + EXPECT_EQ(0, max_diff); 1.1714 +} 1.1715 + 1.1716 +TEST_F(libyuvTest, ARGBSobelToPlane_Opt) { 1.1717 + int max_diff = TestSobelToPlane(benchmark_width_, benchmark_height_, 1.1718 + benchmark_iterations_, +1, 0); 1.1719 + EXPECT_EQ(0, max_diff); 1.1720 +} 1.1721 + 1.1722 +static int TestSobelXY(int width, int height, int benchmark_iterations, 1.1723 + int invert, int off) { 1.1724 + if (width < 1) { 1.1725 + width = 1; 1.1726 + } 1.1727 + const int kBpp = 4; 1.1728 + const int kStride = (width * kBpp + 15) & ~15; 1.1729 + align_buffer_64(src_argb_a, kStride * height + off); 1.1730 + align_buffer_64(dst_argb_c, kStride * height); 1.1731 + align_buffer_64(dst_argb_opt, kStride * height); 1.1732 + memset(src_argb_a, 0, kStride * height + off); 1.1733 + srandom(time(NULL)); 1.1734 + for (int i = 0; i < kStride * height; ++i) { 1.1735 + src_argb_a[i + off] = (random() & 0xff); 1.1736 + } 1.1737 + memset(dst_argb_c, 0, kStride * height); 1.1738 + memset(dst_argb_opt, 0, kStride * height); 1.1739 + 1.1740 + MaskCpuFlags(0); 1.1741 + ARGBSobelXY(src_argb_a + off, kStride, 1.1742 + dst_argb_c, kStride, 1.1743 + width, invert * height); 1.1744 + MaskCpuFlags(-1); 1.1745 + for (int i = 0; i < benchmark_iterations; ++i) { 1.1746 + ARGBSobelXY(src_argb_a + off, kStride, 1.1747 + dst_argb_opt, kStride, 1.1748 + width, invert * height); 1.1749 + } 1.1750 + int max_diff = 0; 1.1751 + for (int i = 0; i < kStride * height; ++i) { 1.1752 + int abs_diff = 1.1753 + abs(static_cast<int>(dst_argb_c[i]) - 1.1754 + static_cast<int>(dst_argb_opt[i])); 1.1755 + if (abs_diff > max_diff) { 1.1756 + max_diff = abs_diff; 1.1757 + } 1.1758 + } 1.1759 + free_aligned_buffer_64(src_argb_a); 1.1760 + free_aligned_buffer_64(dst_argb_c); 1.1761 + free_aligned_buffer_64(dst_argb_opt); 1.1762 + return max_diff; 1.1763 +} 1.1764 + 1.1765 +TEST_F(libyuvTest, ARGBSobelXY_Any) { 1.1766 + int max_diff = TestSobelXY(benchmark_width_ - 1, benchmark_height_, 1.1767 + benchmark_iterations_, +1, 0); 1.1768 + EXPECT_EQ(0, max_diff); 1.1769 +} 1.1770 + 1.1771 +TEST_F(libyuvTest, ARGBSobelXY_Unaligned) { 1.1772 + int max_diff = TestSobelXY(benchmark_width_, benchmark_height_, 1.1773 + benchmark_iterations_, +1, 1); 1.1774 + EXPECT_EQ(0, max_diff); 1.1775 +} 1.1776 + 1.1777 +TEST_F(libyuvTest, ARGBSobelXY_Invert) { 1.1778 + int max_diff = TestSobelXY(benchmark_width_, benchmark_height_, 1.1779 + benchmark_iterations_, -1, 0); 1.1780 + EXPECT_EQ(0, max_diff); 1.1781 +} 1.1782 + 1.1783 +TEST_F(libyuvTest, ARGBSobelXY_Opt) { 1.1784 + int max_diff = TestSobelXY(benchmark_width_, benchmark_height_, 1.1785 + benchmark_iterations_, +1, 0); 1.1786 + EXPECT_EQ(0, max_diff); 1.1787 +} 1.1788 + 1.1789 +static int TestBlur(int width, int height, int benchmark_iterations, 1.1790 + int invert, int off, int radius) { 1.1791 + if (width < 1) { 1.1792 + width = 1; 1.1793 + } 1.1794 + const int kBpp = 4; 1.1795 + const int kStride = (width * kBpp + 15) & ~15; 1.1796 + align_buffer_64(src_argb_a, kStride * height + off); 1.1797 + align_buffer_64(dst_cumsum, width * height * 16); 1.1798 + align_buffer_64(dst_argb_c, kStride * height); 1.1799 + align_buffer_64(dst_argb_opt, kStride * height); 1.1800 + srandom(time(NULL)); 1.1801 + for (int i = 0; i < kStride * height; ++i) { 1.1802 + src_argb_a[i + off] = (random() & 0xff); 1.1803 + } 1.1804 + memset(dst_cumsum, 0, width * height * 16); 1.1805 + memset(dst_argb_c, 0, kStride * height); 1.1806 + memset(dst_argb_opt, 0, kStride * height); 1.1807 + 1.1808 + MaskCpuFlags(0); 1.1809 + ARGBBlur(src_argb_a + off, kStride, 1.1810 + dst_argb_c, kStride, 1.1811 + reinterpret_cast<int32*>(dst_cumsum), width * 4, 1.1812 + width, invert * height, radius); 1.1813 + MaskCpuFlags(-1); 1.1814 + for (int i = 0; i < benchmark_iterations; ++i) { 1.1815 + ARGBBlur(src_argb_a + off, kStride, 1.1816 + dst_argb_opt, kStride, 1.1817 + reinterpret_cast<int32*>(dst_cumsum), width * 4, 1.1818 + width, invert * height, radius); 1.1819 + } 1.1820 + int max_diff = 0; 1.1821 + for (int i = 0; i < kStride * height; ++i) { 1.1822 + int abs_diff = 1.1823 + abs(static_cast<int>(dst_argb_c[i]) - 1.1824 + static_cast<int>(dst_argb_opt[i])); 1.1825 + if (abs_diff > max_diff) { 1.1826 + max_diff = abs_diff; 1.1827 + } 1.1828 + } 1.1829 + free_aligned_buffer_64(src_argb_a); 1.1830 + free_aligned_buffer_64(dst_cumsum); 1.1831 + free_aligned_buffer_64(dst_argb_c); 1.1832 + free_aligned_buffer_64(dst_argb_opt); 1.1833 + return max_diff; 1.1834 +} 1.1835 + 1.1836 +static const int kBlurSize = 55; 1.1837 +TEST_F(libyuvTest, ARGBBlur_Any) { 1.1838 + int max_diff = TestBlur(benchmark_width_ - 1, benchmark_height_, 1.1839 + benchmark_iterations_, +1, 0, kBlurSize); 1.1840 + EXPECT_LE(max_diff, 1); 1.1841 +} 1.1842 + 1.1843 +TEST_F(libyuvTest, ARGBBlur_Unaligned) { 1.1844 + int max_diff = TestBlur(benchmark_width_, benchmark_height_, 1.1845 + benchmark_iterations_, +1, 1, kBlurSize); 1.1846 + EXPECT_LE(max_diff, 1); 1.1847 +} 1.1848 + 1.1849 +TEST_F(libyuvTest, ARGBBlur_Invert) { 1.1850 + int max_diff = TestBlur(benchmark_width_, benchmark_height_, 1.1851 + benchmark_iterations_, -1, 0, kBlurSize); 1.1852 + EXPECT_LE(max_diff, 1); 1.1853 +} 1.1854 + 1.1855 +TEST_F(libyuvTest, ARGBBlur_Opt) { 1.1856 + int max_diff = TestBlur(benchmark_width_, benchmark_height_, 1.1857 + benchmark_iterations_, +1, 0, kBlurSize); 1.1858 + EXPECT_LE(max_diff, 1); 1.1859 +} 1.1860 + 1.1861 +static const int kBlurSmallSize = 5; 1.1862 +TEST_F(libyuvTest, ARGBBlurSmall_Any) { 1.1863 + int max_diff = TestBlur(benchmark_width_ - 1, benchmark_height_, 1.1864 + benchmark_iterations_, +1, 0, kBlurSmallSize); 1.1865 + EXPECT_LE(max_diff, 1); 1.1866 +} 1.1867 + 1.1868 +TEST_F(libyuvTest, ARGBBlurSmall_Unaligned) { 1.1869 + int max_diff = TestBlur(benchmark_width_, benchmark_height_, 1.1870 + benchmark_iterations_, +1, 1, kBlurSmallSize); 1.1871 + EXPECT_LE(max_diff, 1); 1.1872 +} 1.1873 + 1.1874 +TEST_F(libyuvTest, ARGBBlurSmall_Invert) { 1.1875 + int max_diff = TestBlur(benchmark_width_, benchmark_height_, 1.1876 + benchmark_iterations_, -1, 0, kBlurSmallSize); 1.1877 + EXPECT_LE(max_diff, 1); 1.1878 +} 1.1879 + 1.1880 +TEST_F(libyuvTest, ARGBBlurSmall_Opt) { 1.1881 + int max_diff = TestBlur(benchmark_width_, benchmark_height_, 1.1882 + benchmark_iterations_, +1, 0, kBlurSmallSize); 1.1883 + EXPECT_LE(max_diff, 1); 1.1884 +} 1.1885 + 1.1886 +TEST_F(libyuvTest, TestARGBPolynomial) { 1.1887 + SIMD_ALIGNED(uint8 orig_pixels[1280][4]); 1.1888 + SIMD_ALIGNED(uint8 dst_pixels_opt[1280][4]); 1.1889 + SIMD_ALIGNED(uint8 dst_pixels_c[1280][4]); 1.1890 + memset(orig_pixels, 0, sizeof(orig_pixels)); 1.1891 + 1.1892 + SIMD_ALIGNED(static const float kWarmifyPolynomial[16]) = { 1.1893 + 0.94230f, -3.03300f, -2.92500f, 0.f, // C0 1.1894 + 0.584500f, 1.112000f, 1.535000f, 1.f, // C1 x 1.1895 + 0.001313f, -0.002503f, -0.004496f, 0.f, // C2 x * x 1.1896 + 0.0f, 0.000006965f, 0.000008781f, 0.f, // C3 x * x * x 1.1897 + }; 1.1898 + 1.1899 + // Test blue 1.1900 + orig_pixels[0][0] = 255u; 1.1901 + orig_pixels[0][1] = 0u; 1.1902 + orig_pixels[0][2] = 0u; 1.1903 + orig_pixels[0][3] = 128u; 1.1904 + // Test green 1.1905 + orig_pixels[1][0] = 0u; 1.1906 + orig_pixels[1][1] = 255u; 1.1907 + orig_pixels[1][2] = 0u; 1.1908 + orig_pixels[1][3] = 0u; 1.1909 + // Test red 1.1910 + orig_pixels[2][0] = 0u; 1.1911 + orig_pixels[2][1] = 0u; 1.1912 + orig_pixels[2][2] = 255u; 1.1913 + orig_pixels[2][3] = 255u; 1.1914 + // Test white 1.1915 + orig_pixels[3][0] = 255u; 1.1916 + orig_pixels[3][1] = 255u; 1.1917 + orig_pixels[3][2] = 255u; 1.1918 + orig_pixels[3][3] = 255u; 1.1919 + // Test color 1.1920 + orig_pixels[4][0] = 16u; 1.1921 + orig_pixels[4][1] = 64u; 1.1922 + orig_pixels[4][2] = 192u; 1.1923 + orig_pixels[4][3] = 224u; 1.1924 + // Do 16 to test asm version. 1.1925 + ARGBPolynomial(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0, 1.1926 + &kWarmifyPolynomial[0], 16, 1); 1.1927 + EXPECT_EQ(235u, dst_pixels_opt[0][0]); 1.1928 + EXPECT_EQ(0u, dst_pixels_opt[0][1]); 1.1929 + EXPECT_EQ(0u, dst_pixels_opt[0][2]); 1.1930 + EXPECT_EQ(128u, dst_pixels_opt[0][3]); 1.1931 + EXPECT_EQ(0u, dst_pixels_opt[1][0]); 1.1932 + EXPECT_EQ(233u, dst_pixels_opt[1][1]); 1.1933 + EXPECT_EQ(0u, dst_pixels_opt[1][2]); 1.1934 + EXPECT_EQ(0u, dst_pixels_opt[1][3]); 1.1935 + EXPECT_EQ(0u, dst_pixels_opt[2][0]); 1.1936 + EXPECT_EQ(0u, dst_pixels_opt[2][1]); 1.1937 + EXPECT_EQ(241u, dst_pixels_opt[2][2]); 1.1938 + EXPECT_EQ(255u, dst_pixels_opt[2][3]); 1.1939 + EXPECT_EQ(235u, dst_pixels_opt[3][0]); 1.1940 + EXPECT_EQ(233u, dst_pixels_opt[3][1]); 1.1941 + EXPECT_EQ(241u, dst_pixels_opt[3][2]); 1.1942 + EXPECT_EQ(255u, dst_pixels_opt[3][3]); 1.1943 + EXPECT_EQ(10u, dst_pixels_opt[4][0]); 1.1944 + EXPECT_EQ(59u, dst_pixels_opt[4][1]); 1.1945 + EXPECT_EQ(188u, dst_pixels_opt[4][2]); 1.1946 + EXPECT_EQ(224u, dst_pixels_opt[4][3]); 1.1947 + 1.1948 + for (int i = 0; i < 1280; ++i) { 1.1949 + orig_pixels[i][0] = i; 1.1950 + orig_pixels[i][1] = i / 2; 1.1951 + orig_pixels[i][2] = i / 3; 1.1952 + orig_pixels[i][3] = i; 1.1953 + } 1.1954 + 1.1955 + MaskCpuFlags(0); 1.1956 + ARGBPolynomial(&orig_pixels[0][0], 0, &dst_pixels_c[0][0], 0, 1.1957 + &kWarmifyPolynomial[0], 1280, 1); 1.1958 + MaskCpuFlags(-1); 1.1959 + 1.1960 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.1961 + ARGBPolynomial(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0, 1.1962 + &kWarmifyPolynomial[0], 1280, 1); 1.1963 + } 1.1964 + 1.1965 + for (int i = 0; i < 1280; ++i) { 1.1966 + EXPECT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]); 1.1967 + EXPECT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]); 1.1968 + EXPECT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]); 1.1969 + EXPECT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]); 1.1970 + } 1.1971 +} 1.1972 + 1.1973 +TEST_F(libyuvTest, TestARGBLumaColorTable) { 1.1974 + SIMD_ALIGNED(uint8 orig_pixels[1280][4]); 1.1975 + SIMD_ALIGNED(uint8 dst_pixels_opt[1280][4]); 1.1976 + SIMD_ALIGNED(uint8 dst_pixels_c[1280][4]); 1.1977 + memset(orig_pixels, 0, sizeof(orig_pixels)); 1.1978 + 1.1979 + align_buffer_64(lumacolortable, 32768); 1.1980 + int v = 0; 1.1981 + for (int i = 0; i < 32768; ++i) { 1.1982 + lumacolortable[i] = v; 1.1983 + v += 3; 1.1984 + } 1.1985 + // Test blue 1.1986 + orig_pixels[0][0] = 255u; 1.1987 + orig_pixels[0][1] = 0u; 1.1988 + orig_pixels[0][2] = 0u; 1.1989 + orig_pixels[0][3] = 128u; 1.1990 + // Test green 1.1991 + orig_pixels[1][0] = 0u; 1.1992 + orig_pixels[1][1] = 255u; 1.1993 + orig_pixels[1][2] = 0u; 1.1994 + orig_pixels[1][3] = 0u; 1.1995 + // Test red 1.1996 + orig_pixels[2][0] = 0u; 1.1997 + orig_pixels[2][1] = 0u; 1.1998 + orig_pixels[2][2] = 255u; 1.1999 + orig_pixels[2][3] = 255u; 1.2000 + // Test color 1.2001 + orig_pixels[3][0] = 16u; 1.2002 + orig_pixels[3][1] = 64u; 1.2003 + orig_pixels[3][2] = 192u; 1.2004 + orig_pixels[3][3] = 224u; 1.2005 + // Do 16 to test asm version. 1.2006 + ARGBLumaColorTable(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0, 1.2007 + &lumacolortable[0], 16, 1); 1.2008 + EXPECT_EQ(253u, dst_pixels_opt[0][0]); 1.2009 + EXPECT_EQ(0u, dst_pixels_opt[0][1]); 1.2010 + EXPECT_EQ(0u, dst_pixels_opt[0][2]); 1.2011 + EXPECT_EQ(128u, dst_pixels_opt[0][3]); 1.2012 + EXPECT_EQ(0u, dst_pixels_opt[1][0]); 1.2013 + EXPECT_EQ(253u, dst_pixels_opt[1][1]); 1.2014 + EXPECT_EQ(0u, dst_pixels_opt[1][2]); 1.2015 + EXPECT_EQ(0u, dst_pixels_opt[1][3]); 1.2016 + EXPECT_EQ(0u, dst_pixels_opt[2][0]); 1.2017 + EXPECT_EQ(0u, dst_pixels_opt[2][1]); 1.2018 + EXPECT_EQ(253u, dst_pixels_opt[2][2]); 1.2019 + EXPECT_EQ(255u, dst_pixels_opt[2][3]); 1.2020 + EXPECT_EQ(48u, dst_pixels_opt[3][0]); 1.2021 + EXPECT_EQ(192u, dst_pixels_opt[3][1]); 1.2022 + EXPECT_EQ(64u, dst_pixels_opt[3][2]); 1.2023 + EXPECT_EQ(224u, dst_pixels_opt[3][3]); 1.2024 + 1.2025 + for (int i = 0; i < 1280; ++i) { 1.2026 + orig_pixels[i][0] = i; 1.2027 + orig_pixels[i][1] = i / 2; 1.2028 + orig_pixels[i][2] = i / 3; 1.2029 + orig_pixels[i][3] = i; 1.2030 + } 1.2031 + 1.2032 + MaskCpuFlags(0); 1.2033 + ARGBLumaColorTable(&orig_pixels[0][0], 0, &dst_pixels_c[0][0], 0, 1.2034 + lumacolortable, 1280, 1); 1.2035 + MaskCpuFlags(-1); 1.2036 + 1.2037 + for (int i = 0; i < benchmark_pixels_div1280_; ++i) { 1.2038 + ARGBLumaColorTable(&orig_pixels[0][0], 0, &dst_pixels_opt[0][0], 0, 1.2039 + lumacolortable, 1280, 1); 1.2040 + } 1.2041 + for (int i = 0; i < 1280; ++i) { 1.2042 + EXPECT_EQ(dst_pixels_c[i][0], dst_pixels_opt[i][0]); 1.2043 + EXPECT_EQ(dst_pixels_c[i][1], dst_pixels_opt[i][1]); 1.2044 + EXPECT_EQ(dst_pixels_c[i][2], dst_pixels_opt[i][2]); 1.2045 + EXPECT_EQ(dst_pixels_c[i][3], dst_pixels_opt[i][3]); 1.2046 + } 1.2047 + 1.2048 + free_aligned_buffer_64(lumacolortable); 1.2049 +} 1.2050 + 1.2051 +TEST_F(libyuvTest, TestARGBCopyAlpha) { 1.2052 + const int kSize = benchmark_width_ * benchmark_height_ * 4; 1.2053 + align_buffer_64(orig_pixels, kSize); 1.2054 + align_buffer_64(dst_pixels_opt, kSize); 1.2055 + align_buffer_64(dst_pixels_c, kSize); 1.2056 + 1.2057 + MemRandomize(orig_pixels, kSize); 1.2058 + MemRandomize(dst_pixels_opt, kSize); 1.2059 + memcpy(dst_pixels_c, dst_pixels_opt, kSize); 1.2060 + 1.2061 + MaskCpuFlags(0); 1.2062 + ARGBCopyAlpha(orig_pixels, benchmark_width_ * 4, 1.2063 + dst_pixels_c, benchmark_width_ * 4, 1.2064 + benchmark_width_, benchmark_height_); 1.2065 + MaskCpuFlags(-1); 1.2066 + 1.2067 + for (int i = 0; i < benchmark_iterations_; ++i) { 1.2068 + ARGBCopyAlpha(orig_pixels, benchmark_width_ * 4, 1.2069 + dst_pixels_opt, benchmark_width_ * 4, 1.2070 + benchmark_width_, benchmark_height_); 1.2071 + } 1.2072 + for (int i = 0; i < kSize; ++i) { 1.2073 + EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); 1.2074 + } 1.2075 + 1.2076 + free_aligned_buffer_64(dst_pixels_c); 1.2077 + free_aligned_buffer_64(dst_pixels_opt); 1.2078 + free_aligned_buffer_64(orig_pixels); 1.2079 +} 1.2080 + 1.2081 +TEST_F(libyuvTest, TestARGBCopyYToAlpha) { 1.2082 + const int kPixels = benchmark_width_ * benchmark_height_; 1.2083 + align_buffer_64(orig_pixels, kPixels); 1.2084 + align_buffer_64(dst_pixels_opt, kPixels * 4); 1.2085 + align_buffer_64(dst_pixels_c, kPixels * 4); 1.2086 + 1.2087 + MemRandomize(orig_pixels, kPixels); 1.2088 + MemRandomize(dst_pixels_opt, kPixels * 4); 1.2089 + memcpy(dst_pixels_c, dst_pixels_opt, kPixels * 4); 1.2090 + 1.2091 + MaskCpuFlags(0); 1.2092 + ARGBCopyYToAlpha(orig_pixels, benchmark_width_, 1.2093 + dst_pixels_c, benchmark_width_ * 4, 1.2094 + benchmark_width_, benchmark_height_); 1.2095 + MaskCpuFlags(-1); 1.2096 + 1.2097 + for (int i = 0; i < benchmark_iterations_; ++i) { 1.2098 + ARGBCopyYToAlpha(orig_pixels, benchmark_width_, 1.2099 + dst_pixels_opt, benchmark_width_ * 4, 1.2100 + benchmark_width_, benchmark_height_); 1.2101 + } 1.2102 + for (int i = 0; i < kPixels * 4; ++i) { 1.2103 + EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]); 1.2104 + } 1.2105 + 1.2106 + free_aligned_buffer_64(dst_pixels_c); 1.2107 + free_aligned_buffer_64(dst_pixels_opt); 1.2108 + free_aligned_buffer_64(orig_pixels); 1.2109 +} 1.2110 + 1.2111 +} // namespace libyuv