react-native-vision-camera-spoof-detector 1.0.22 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/README.md +442 -442
  2. package/android/build.gradle +12 -4
  3. package/android/src/main/cpp/CMakeLists.txt +101 -94
  4. package/android/src/main/cpp/libyuv/.clang-format +6 -6
  5. package/android/src/main/cpp/libyuv/.gn +40 -40
  6. package/android/src/main/cpp/libyuv/.vpython3 +410 -410
  7. package/android/src/main/cpp/libyuv/AUTHORS +7 -7
  8. package/android/src/main/cpp/libyuv/Android.bp +202 -202
  9. package/android/src/main/cpp/libyuv/Android.mk +106 -106
  10. package/android/src/main/cpp/libyuv/BUILD.gn +490 -490
  11. package/android/src/main/cpp/libyuv/CM_linux_packages.cmake +70 -70
  12. package/android/src/main/cpp/libyuv/CMakeLists.txt +259 -252
  13. package/android/src/main/cpp/libyuv/DEPS +935 -935
  14. package/android/src/main/cpp/libyuv/DIR_METADATA +3 -3
  15. package/android/src/main/cpp/libyuv/LICENSE +29 -29
  16. package/android/src/main/cpp/libyuv/OWNERS +11 -11
  17. package/android/src/main/cpp/libyuv/PATENTS +23 -23
  18. package/android/src/main/cpp/libyuv/PRESUBMIT.py +65 -65
  19. package/android/src/main/cpp/libyuv/README.chromium +11 -11
  20. package/android/src/main/cpp/libyuv/README.md +19 -19
  21. package/android/src/main/cpp/libyuv/build_overrides/build.gni +60 -60
  22. package/android/src/main/cpp/libyuv/build_overrides/gtest.gni +19 -19
  23. package/android/src/main/cpp/libyuv/build_overrides/partition_alloc.gni +17 -17
  24. package/android/src/main/cpp/libyuv/codereview.settings +5 -5
  25. package/android/src/main/cpp/libyuv/docs/deprecated_builds.md +409 -409
  26. package/android/src/main/cpp/libyuv/docs/environment_variables.md +64 -64
  27. package/android/src/main/cpp/libyuv/docs/feature_detection.md +108 -108
  28. package/android/src/main/cpp/libyuv/docs/filtering.md +196 -196
  29. package/android/src/main/cpp/libyuv/docs/formats.md +208 -208
  30. package/android/src/main/cpp/libyuv/docs/getting_started.md +296 -296
  31. package/android/src/main/cpp/libyuv/docs/rotation.md +107 -107
  32. package/android/src/main/cpp/libyuv/download_vs_toolchain.py +29 -29
  33. package/android/src/main/cpp/libyuv/include/libyuv/basic_types.h +68 -68
  34. package/android/src/main/cpp/libyuv/include/libyuv/compare.h +111 -111
  35. package/android/src/main/cpp/libyuv/include/libyuv/compare_row.h +112 -112
  36. package/android/src/main/cpp/libyuv/include/libyuv/convert.h +1117 -1117
  37. package/android/src/main/cpp/libyuv/include/libyuv/convert_argb.h +2335 -2335
  38. package/android/src/main/cpp/libyuv/include/libyuv/convert_from.h +203 -203
  39. package/android/src/main/cpp/libyuv/include/libyuv/convert_from_argb.h +394 -394
  40. package/android/src/main/cpp/libyuv/include/libyuv/cpu_id.h +147 -147
  41. package/android/src/main/cpp/libyuv/include/libyuv/cpu_support.h +99 -99
  42. package/android/src/main/cpp/libyuv/include/libyuv/loongson_intrinsics.h +1949 -1949
  43. package/android/src/main/cpp/libyuv/include/libyuv/mjpeg_decoder.h +195 -195
  44. package/android/src/main/cpp/libyuv/include/libyuv/planar_functions.h +1131 -1131
  45. package/android/src/main/cpp/libyuv/include/libyuv/rotate.h +296 -296
  46. package/android/src/main/cpp/libyuv/include/libyuv/rotate_argb.h +37 -37
  47. package/android/src/main/cpp/libyuv/include/libyuv/rotate_row.h +265 -265
  48. package/android/src/main/cpp/libyuv/include/libyuv/row.h +6738 -6738
  49. package/android/src/main/cpp/libyuv/include/libyuv/row_sve.h +2154 -2154
  50. package/android/src/main/cpp/libyuv/include/libyuv/scale.h +336 -336
  51. package/android/src/main/cpp/libyuv/include/libyuv/scale_argb.h +76 -76
  52. package/android/src/main/cpp/libyuv/include/libyuv/scale_rgb.h +42 -42
  53. package/android/src/main/cpp/libyuv/include/libyuv/scale_row.h +1726 -1726
  54. package/android/src/main/cpp/libyuv/include/libyuv/scale_uv.h +51 -51
  55. package/android/src/main/cpp/libyuv/include/libyuv/version.h +16 -16
  56. package/android/src/main/cpp/libyuv/include/libyuv/video_common.h +222 -222
  57. package/android/src/main/cpp/libyuv/include/libyuv.h +33 -33
  58. package/android/src/main/cpp/libyuv/infra/config/OWNERS +3 -3
  59. package/android/src/main/cpp/libyuv/infra/config/PRESUBMIT.py +17 -17
  60. package/android/src/main/cpp/libyuv/infra/config/README.md +2 -2
  61. package/android/src/main/cpp/libyuv/infra/config/codereview.settings +6 -6
  62. package/android/src/main/cpp/libyuv/infra/config/commit-queue.cfg +144 -144
  63. package/android/src/main/cpp/libyuv/infra/config/cr-buildbucket.cfg +1185 -1185
  64. package/android/src/main/cpp/libyuv/infra/config/luci-logdog.cfg +9 -9
  65. package/android/src/main/cpp/libyuv/infra/config/luci-milo.cfg +246 -246
  66. package/android/src/main/cpp/libyuv/infra/config/luci-scheduler.cfg +385 -385
  67. package/android/src/main/cpp/libyuv/infra/config/main.star +402 -402
  68. package/android/src/main/cpp/libyuv/infra/config/project.cfg +16 -16
  69. package/android/src/main/cpp/libyuv/infra/config/realms.cfg +111 -111
  70. package/android/src/main/cpp/libyuv/libyuv.gni +34 -34
  71. package/android/src/main/cpp/libyuv/libyuv.gyp +149 -149
  72. package/android/src/main/cpp/libyuv/libyuv.gypi +87 -87
  73. package/android/src/main/cpp/libyuv/linux.mk +96 -96
  74. package/android/src/main/cpp/libyuv/public.mk +13 -13
  75. package/android/src/main/cpp/libyuv/pylintrc +49 -49
  76. package/android/src/main/cpp/libyuv/riscv_script/prepare_toolchain_qemu.sh +74 -74
  77. package/android/src/main/cpp/libyuv/riscv_script/riscv-clang.cmake +56 -56
  78. package/android/src/main/cpp/libyuv/riscv_script/run_qemu.sh +15 -15
  79. package/android/src/main/cpp/libyuv/source/compare.cc +435 -435
  80. package/android/src/main/cpp/libyuv/source/compare_common.cc +74 -74
  81. package/android/src/main/cpp/libyuv/source/compare_gcc.cc +362 -362
  82. package/android/src/main/cpp/libyuv/source/compare_neon.cc +96 -96
  83. package/android/src/main/cpp/libyuv/source/compare_neon64.cc +223 -223
  84. package/android/src/main/cpp/libyuv/source/compare_win.cc +241 -241
  85. package/android/src/main/cpp/libyuv/source/convert.cc +4746 -4746
  86. package/android/src/main/cpp/libyuv/source/convert_argb.cc +9179 -9179
  87. package/android/src/main/cpp/libyuv/source/convert_from.cc +866 -866
  88. package/android/src/main/cpp/libyuv/source/convert_from_argb.cc +3671 -3671
  89. package/android/src/main/cpp/libyuv/source/convert_jpeg.cc +602 -602
  90. package/android/src/main/cpp/libyuv/source/convert_to_argb.cc +391 -391
  91. package/android/src/main/cpp/libyuv/source/convert_to_i420.cc +288 -288
  92. package/android/src/main/cpp/libyuv/source/cpu_id.cc +496 -496
  93. package/android/src/main/cpp/libyuv/source/mjpeg_decoder.cc +580 -580
  94. package/android/src/main/cpp/libyuv/source/mjpeg_validate.cc +71 -71
  95. package/android/src/main/cpp/libyuv/source/planar_functions.cc +5663 -5663
  96. package/android/src/main/cpp/libyuv/source/rotate.cc +1241 -1241
  97. package/android/src/main/cpp/libyuv/source/rotate_any.cc +76 -76
  98. package/android/src/main/cpp/libyuv/source/rotate_argb.cc +259 -259
  99. package/android/src/main/cpp/libyuv/source/rotate_common.cc +208 -208
  100. package/android/src/main/cpp/libyuv/source/rotate_gcc.cc +505 -505
  101. package/android/src/main/cpp/libyuv/source/rotate_lsx.cc +233 -233
  102. package/android/src/main/cpp/libyuv/source/rotate_neon.cc +219 -219
  103. package/android/src/main/cpp/libyuv/source/rotate_neon64.cc +273 -273
  104. package/android/src/main/cpp/libyuv/source/rotate_sme.cc +174 -174
  105. package/android/src/main/cpp/libyuv/source/rotate_win.cc +253 -253
  106. package/android/src/main/cpp/libyuv/source/row_any.cc +2519 -2519
  107. package/android/src/main/cpp/libyuv/source/row_common.cc +4461 -4461
  108. package/android/src/main/cpp/libyuv/source/row_gcc.cc +9570 -9570
  109. package/android/src/main/cpp/libyuv/source/row_lasx.cc +2343 -2343
  110. package/android/src/main/cpp/libyuv/source/row_lsx.cc +3030 -3030
  111. package/android/src/main/cpp/libyuv/source/row_neon.cc +4026 -4026
  112. package/android/src/main/cpp/libyuv/source/row_neon64.cc +5617 -5617
  113. package/android/src/main/cpp/libyuv/source/row_rvv.cc +2599 -2599
  114. package/android/src/main/cpp/libyuv/source/row_sme.cc +1183 -1183
  115. package/android/src/main/cpp/libyuv/source/row_sve.cc +1088 -1088
  116. package/android/src/main/cpp/libyuv/source/row_win.cc +6453 -6453
  117. package/android/src/main/cpp/libyuv/source/scale.cc +2710 -2710
  118. package/android/src/main/cpp/libyuv/source/scale_any.cc +991 -991
  119. package/android/src/main/cpp/libyuv/source/scale_argb.cc +1158 -1158
  120. package/android/src/main/cpp/libyuv/source/scale_common.cc +1977 -1977
  121. package/android/src/main/cpp/libyuv/source/scale_gcc.cc +2947 -2947
  122. package/android/src/main/cpp/libyuv/source/scale_lsx.cc +739 -739
  123. package/android/src/main/cpp/libyuv/source/scale_neon.cc +1449 -1449
  124. package/android/src/main/cpp/libyuv/source/scale_neon64.cc +1552 -1552
  125. package/android/src/main/cpp/libyuv/source/scale_rgb.cc +82 -82
  126. package/android/src/main/cpp/libyuv/source/scale_rvv.cc +1971 -1971
  127. package/android/src/main/cpp/libyuv/source/scale_sme.cc +555 -555
  128. package/android/src/main/cpp/libyuv/source/scale_uv.cc +1159 -1159
  129. package/android/src/main/cpp/libyuv/source/scale_win.cc +1392 -1392
  130. package/android/src/main/cpp/libyuv/source/test.sh +35 -35
  131. package/android/src/main/cpp/libyuv/source/video_common.cc +62 -62
  132. package/android/src/main/cpp/libyuv/tools_libyuv/OWNERS +4 -4
  133. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/roll_deps.py +931 -931
  134. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py +164 -164
  135. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS +21 -21
  136. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.new +13 -13
  137. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old +13 -13
  138. package/android/src/main/cpp/libyuv/tools_libyuv/get_landmines.py +38 -38
  139. package/android/src/main/cpp/libyuv/tools_libyuv/msan/OWNERS +3 -3
  140. package/android/src/main/cpp/libyuv/tools_libyuv/msan/blacklist.txt +9 -9
  141. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/OWNERS +3 -3
  142. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/blacklist.txt +15 -15
  143. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/vptr_blacklist.txt +25 -25
  144. package/android/src/main/cpp/libyuv/unit_test/basictypes_test.cc +43 -43
  145. package/android/src/main/cpp/libyuv/unit_test/color_test.cc +848 -848
  146. package/android/src/main/cpp/libyuv/unit_test/compare_test.cc +739 -739
  147. package/android/src/main/cpp/libyuv/unit_test/convert_argb_test.cc +2867 -2867
  148. package/android/src/main/cpp/libyuv/unit_test/convert_test.cc +2133 -2133
  149. package/android/src/main/cpp/libyuv/unit_test/cpu_test.cc +427 -427
  150. package/android/src/main/cpp/libyuv/unit_test/cpu_thread_test.cc +63 -63
  151. package/android/src/main/cpp/libyuv/unit_test/math_test.cc +160 -160
  152. package/android/src/main/cpp/libyuv/unit_test/planar_test.cc +4731 -4731
  153. package/android/src/main/cpp/libyuv/unit_test/rotate_argb_test.cc +334 -334
  154. package/android/src/main/cpp/libyuv/unit_test/rotate_test.cc +962 -962
  155. package/android/src/main/cpp/libyuv/unit_test/scale_argb_test.cc +590 -590
  156. package/android/src/main/cpp/libyuv/unit_test/scale_plane_test.cc +465 -465
  157. package/android/src/main/cpp/libyuv/unit_test/scale_rgb_test.cc +280 -280
  158. package/android/src/main/cpp/libyuv/unit_test/scale_test.cc +1135 -1135
  159. package/android/src/main/cpp/libyuv/unit_test/scale_uv_test.cc +249 -249
  160. package/android/src/main/cpp/libyuv/unit_test/testdata/arm_v7.txt +12 -12
  161. package/android/src/main/cpp/libyuv/unit_test/testdata/mips.txt +7 -7
  162. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson2k.txt +5 -5
  163. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson3.txt +10 -10
  164. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson_mmi.txt +7 -7
  165. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64.txt +3 -3
  166. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv.txt +3 -3
  167. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv_zvfh.txt +3 -3
  168. package/android/src/main/cpp/libyuv/unit_test/testdata/tegra3.txt +23 -23
  169. package/android/src/main/cpp/libyuv/unit_test/unit_test.cc +581 -581
  170. package/android/src/main/cpp/libyuv/unit_test/unit_test.h +232 -232
  171. package/android/src/main/cpp/libyuv/unit_test/video_common_test.cc +112 -112
  172. package/android/src/main/cpp/libyuv/util/Makefile +9 -9
  173. package/android/src/main/cpp/libyuv/util/color.cc +120 -120
  174. package/android/src/main/cpp/libyuv/util/compare.cc +67 -67
  175. package/android/src/main/cpp/libyuv/util/cpuid.c +211 -211
  176. package/android/src/main/cpp/libyuv/util/i444tonv12_eg.cc +27 -27
  177. package/android/src/main/cpp/libyuv/util/psnr.cc +291 -291
  178. package/android/src/main/cpp/libyuv/util/psnr.h +47 -47
  179. package/android/src/main/cpp/libyuv/util/psnr_main.cc +620 -620
  180. package/android/src/main/cpp/libyuv/util/ssim.cc +364 -364
  181. package/android/src/main/cpp/libyuv/util/ssim.h +38 -38
  182. package/android/src/main/cpp/libyuv/util/yuvconstants.c +114 -114
  183. package/android/src/main/cpp/libyuv/util/yuvconvert.cc +367 -367
  184. package/android/src/main/cpp/libyuv/winarm.mk +47 -47
  185. package/package.json +86 -86
  186. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  187. package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
  188. package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
  189. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  190. package/android/.gradle/8.9/gc.properties +0 -0
  191. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  192. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  193. package/android/.gradle/vcs-1/gc.properties +0 -0
@@ -1,465 +1,465 @@
1
- /*
2
- * Copyright 2023 The LibYuv Project Authors. All rights reserved.
3
- *
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
6
- * tree. An additional intellectual property rights grant can be found
7
- * in the file PATENTS. All contributing project authors may
8
- * be found in the AUTHORS file in the root of the source tree.
9
- */
10
-
11
- #include <stdlib.h>
12
- #include <time.h>
13
-
14
- #include "../unit_test/unit_test.h"
15
- #include "libyuv/cpu_id.h"
16
- #include "libyuv/scale.h"
17
-
18
- #ifdef ENABLE_ROW_TESTS
19
- #include "libyuv/scale_row.h" // For ScaleRowDown2Box_Odd_C
20
- #endif
21
-
22
- #define STRINGIZE(line) #line
23
- #define FILELINESTR(file, line) file ":" STRINGIZE(line)
24
-
25
- #if defined(__riscv) && !defined(__clang__)
26
- #define DISABLE_SLOW_TESTS
27
- #undef ENABLE_FULL_TESTS
28
- #undef ENABLE_ROW_TESTS
29
- #define LEAN_TESTS
30
- #endif
31
-
32
- #if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__)
33
- // SLOW TESTS are those that are unoptimized C code.
34
- // FULL TESTS are optimized but test many variations of the same code.
35
- #define ENABLE_FULL_TESTS
36
- #endif
37
-
38
- namespace libyuv {
39
-
40
- #ifdef ENABLE_ROW_TESTS
41
- #ifdef HAS_SCALEROWDOWN2_SSSE3
42
- TEST_F(LibYUVScaleTest, TestScaleRowDown2Box_Odd_SSSE3) {
43
- SIMD_ALIGNED(uint8_t orig_pixels[128 * 2]);
44
- SIMD_ALIGNED(uint8_t dst_pixels_opt[64]);
45
- SIMD_ALIGNED(uint8_t dst_pixels_c[64]);
46
- memset(orig_pixels, 0, sizeof(orig_pixels));
47
- memset(dst_pixels_opt, 0, sizeof(dst_pixels_opt));
48
- memset(dst_pixels_c, 0, sizeof(dst_pixels_c));
49
-
50
- int has_ssse3 = TestCpuFlag(kCpuHasSSSE3);
51
- if (!has_ssse3) {
52
- printf("Warning SSSE3 not detected; Skipping test.\n");
53
- } else {
54
- // TL.
55
- orig_pixels[0] = 255u;
56
- orig_pixels[1] = 0u;
57
- orig_pixels[128 + 0] = 0u;
58
- orig_pixels[128 + 1] = 0u;
59
- // TR.
60
- orig_pixels[2] = 0u;
61
- orig_pixels[3] = 100u;
62
- orig_pixels[128 + 2] = 0u;
63
- orig_pixels[128 + 3] = 0u;
64
- // BL.
65
- orig_pixels[4] = 0u;
66
- orig_pixels[5] = 0u;
67
- orig_pixels[128 + 4] = 50u;
68
- orig_pixels[128 + 5] = 0u;
69
- // BR.
70
- orig_pixels[6] = 0u;
71
- orig_pixels[7] = 0u;
72
- orig_pixels[128 + 6] = 0u;
73
- orig_pixels[128 + 7] = 20u;
74
- // Odd.
75
- orig_pixels[126] = 4u;
76
- orig_pixels[127] = 255u;
77
- orig_pixels[128 + 126] = 16u;
78
- orig_pixels[128 + 127] = 255u;
79
-
80
- // Test regular half size.
81
- ScaleRowDown2Box_C(orig_pixels, 128, dst_pixels_c, 64);
82
-
83
- EXPECT_EQ(64u, dst_pixels_c[0]);
84
- EXPECT_EQ(25u, dst_pixels_c[1]);
85
- EXPECT_EQ(13u, dst_pixels_c[2]);
86
- EXPECT_EQ(5u, dst_pixels_c[3]);
87
- EXPECT_EQ(0u, dst_pixels_c[4]);
88
- EXPECT_EQ(133u, dst_pixels_c[63]);
89
-
90
- // Test Odd width version - Last pixel is just 1 horizontal pixel.
91
- ScaleRowDown2Box_Odd_C(orig_pixels, 128, dst_pixels_c, 64);
92
-
93
- EXPECT_EQ(64u, dst_pixels_c[0]);
94
- EXPECT_EQ(25u, dst_pixels_c[1]);
95
- EXPECT_EQ(13u, dst_pixels_c[2]);
96
- EXPECT_EQ(5u, dst_pixels_c[3]);
97
- EXPECT_EQ(0u, dst_pixels_c[4]);
98
- EXPECT_EQ(10u, dst_pixels_c[63]);
99
-
100
- // Test one pixel less, should skip the last pixel.
101
- memset(dst_pixels_c, 0, sizeof(dst_pixels_c));
102
- ScaleRowDown2Box_Odd_C(orig_pixels, 128, dst_pixels_c, 63);
103
-
104
- EXPECT_EQ(64u, dst_pixels_c[0]);
105
- EXPECT_EQ(25u, dst_pixels_c[1]);
106
- EXPECT_EQ(13u, dst_pixels_c[2]);
107
- EXPECT_EQ(5u, dst_pixels_c[3]);
108
- EXPECT_EQ(0u, dst_pixels_c[4]);
109
- EXPECT_EQ(0u, dst_pixels_c[63]);
110
-
111
- // Test regular half size SSSE3.
112
- ScaleRowDown2Box_SSSE3(orig_pixels, 128, dst_pixels_opt, 64);
113
-
114
- EXPECT_EQ(64u, dst_pixels_opt[0]);
115
- EXPECT_EQ(25u, dst_pixels_opt[1]);
116
- EXPECT_EQ(13u, dst_pixels_opt[2]);
117
- EXPECT_EQ(5u, dst_pixels_opt[3]);
118
- EXPECT_EQ(0u, dst_pixels_opt[4]);
119
- EXPECT_EQ(133u, dst_pixels_opt[63]);
120
-
121
- // Compare C and SSSE3 match.
122
- ScaleRowDown2Box_Odd_C(orig_pixels, 128, dst_pixels_c, 64);
123
- ScaleRowDown2Box_Odd_SSSE3(orig_pixels, 128, dst_pixels_opt, 64);
124
- for (int i = 0; i < 64; ++i) {
125
- EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
126
- }
127
- }
128
- }
129
- #endif // HAS_SCALEROWDOWN2_SSSE3
130
-
131
- TEST_F(LibYUVScaleTest, TestScaleRowDown2Box_16) {
132
- SIMD_ALIGNED(uint16_t orig_pixels[2560 * 2]);
133
- SIMD_ALIGNED(uint16_t dst_pixels_c[1280]);
134
- SIMD_ALIGNED(uint16_t dst_pixels_opt[1280]);
135
-
136
- memset(orig_pixels, 0, sizeof(orig_pixels));
137
- memset(dst_pixels_c, 1, sizeof(dst_pixels_c));
138
- memset(dst_pixels_opt, 2, sizeof(dst_pixels_opt));
139
-
140
- for (int i = 0; i < 2560 * 2; ++i) {
141
- orig_pixels[i] = i;
142
- }
143
- ScaleRowDown2Box_16_C(&orig_pixels[0], 2560, &dst_pixels_c[0], 1280);
144
- for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
145
- #if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__)
146
- int has_neon = TestCpuFlag(kCpuHasNEON);
147
- if (has_neon) {
148
- ScaleRowDown2Box_16_NEON(&orig_pixels[0], 2560, &dst_pixels_opt[0], 1280);
149
- } else {
150
- ScaleRowDown2Box_16_C(&orig_pixels[0], 2560, &dst_pixels_opt[0], 1280);
151
- }
152
- #else
153
- ScaleRowDown2Box_16_C(&orig_pixels[0], 2560, &dst_pixels_opt[0], 1280);
154
- #endif
155
- }
156
-
157
- for (int i = 0; i < 1280; ++i) {
158
- EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
159
- }
160
-
161
- EXPECT_EQ(dst_pixels_c[0], (0 + 1 + 2560 + 2561 + 2) / 4);
162
- EXPECT_EQ(dst_pixels_c[1279], 3839);
163
- }
164
- #endif // ENABLE_ROW_TESTS
165
-
166
- // Test scaling plane with 8 bit C vs 12 bit C and return maximum pixel
167
- // difference.
168
- // 0 = exact.
169
- static int TestPlaneFilter_16(int src_width,
170
- int src_height,
171
- int dst_width,
172
- int dst_height,
173
- FilterMode f,
174
- int benchmark_iterations,
175
- int disable_cpu_flags,
176
- int benchmark_cpu_info) {
177
- if (!SizeValid(src_width, src_height, dst_width, dst_height)) {
178
- return 0;
179
- }
180
-
181
- int i;
182
- int64_t src_y_plane_size = (Abs(src_width)) * (Abs(src_height));
183
- int src_stride_y = Abs(src_width);
184
- int dst_y_plane_size = dst_width * dst_height;
185
- int dst_stride_y = dst_width;
186
-
187
- align_buffer_page_end(src_y, src_y_plane_size);
188
- align_buffer_page_end(src_y_16, src_y_plane_size * 2);
189
- align_buffer_page_end(dst_y_8, dst_y_plane_size);
190
- align_buffer_page_end(dst_y_16, dst_y_plane_size * 2);
191
- uint16_t* p_src_y_16 = reinterpret_cast<uint16_t*>(src_y_16);
192
- uint16_t* p_dst_y_16 = reinterpret_cast<uint16_t*>(dst_y_16);
193
-
194
- MemRandomize(src_y, src_y_plane_size);
195
- memset(dst_y_8, 0, dst_y_plane_size);
196
- memset(dst_y_16, 1, dst_y_plane_size * 2);
197
-
198
- for (i = 0; i < src_y_plane_size; ++i) {
199
- p_src_y_16[i] = src_y[i] & 255;
200
- }
201
-
202
- MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization.
203
- ScalePlane(src_y, src_stride_y, src_width, src_height, dst_y_8, dst_stride_y,
204
- dst_width, dst_height, f);
205
- MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization.
206
-
207
- for (i = 0; i < benchmark_iterations; ++i) {
208
- ScalePlane_16(p_src_y_16, src_stride_y, src_width, src_height, p_dst_y_16,
209
- dst_stride_y, dst_width, dst_height, f);
210
- }
211
-
212
- // Expect an exact match.
213
- int max_diff = 0;
214
- for (i = 0; i < dst_y_plane_size; ++i) {
215
- int abs_diff = Abs(dst_y_8[i] - p_dst_y_16[i]);
216
- if (abs_diff > max_diff) {
217
- max_diff = abs_diff;
218
- }
219
- }
220
-
221
- free_aligned_buffer_page_end(dst_y_8);
222
- free_aligned_buffer_page_end(dst_y_16);
223
- free_aligned_buffer_page_end(src_y);
224
- free_aligned_buffer_page_end(src_y_16);
225
-
226
- return max_diff;
227
- }
228
-
229
- // The following adjustments in dimensions ensure the scale factor will be
230
- // exactly achieved.
231
- // 2 is chroma subsample.
232
- #define DX(x, nom, denom) static_cast<int>(((Abs(x) / nom + 1) / 2) * nom * 2)
233
- #define SX(x, nom, denom) static_cast<int>(((x / nom + 1) / 2) * denom * 2)
234
-
235
- #define TEST_FACTOR1(name, filter, nom, denom, max_diff) \
236
- TEST_F(LibYUVScaleTest, DISABLED_##ScalePlaneDownBy##name##_##filter##_16) { \
237
- int diff = TestPlaneFilter_16( \
238
- SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \
239
- DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \
240
- kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \
241
- benchmark_cpu_info_); \
242
- EXPECT_LE(diff, max_diff); \
243
- }
244
-
245
- // Test a scale factor with all 4 filters. Expect unfiltered to be exact, but
246
- // filtering is different fixed point implementations for SSSE3, Neon and C.
247
- #define TEST_FACTOR(name, nom, denom, boxdiff) \
248
- TEST_FACTOR1(name, None, nom, denom, 0) \
249
- TEST_FACTOR1(name, Linear, nom, denom, boxdiff) \
250
- TEST_FACTOR1(name, Bilinear, nom, denom, boxdiff) \
251
- TEST_FACTOR1(name, Box, nom, denom, boxdiff)
252
-
253
- TEST_FACTOR(2, 1, 2, 0)
254
- TEST_FACTOR(4, 1, 4, 0)
255
- // TEST_FACTOR(8, 1, 8, 0) Disable for benchmark performance. Takes 90 seconds.
256
- TEST_FACTOR(3by4, 3, 4, 1)
257
- TEST_FACTOR(3by8, 3, 8, 1)
258
- TEST_FACTOR(3, 1, 3, 0)
259
- #undef TEST_FACTOR1
260
- #undef TEST_FACTOR
261
- #undef SX
262
- #undef DX
263
-
264
- TEST_F(LibYUVScaleTest, PlaneTest3x) {
265
- const int kSrcStride = 480;
266
- const int kDstStride = 160;
267
- const int kSize = kSrcStride * 3;
268
- align_buffer_page_end(orig_pixels, kSize);
269
- for (int i = 0; i < 480 * 3; ++i) {
270
- orig_pixels[i] = i;
271
- }
272
- align_buffer_page_end(dest_pixels, kDstStride);
273
-
274
- int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 *
275
- benchmark_iterations_;
276
- for (int i = 0; i < iterations160; ++i) {
277
- ScalePlane(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1,
278
- kFilterBilinear);
279
- }
280
-
281
- EXPECT_EQ(225, dest_pixels[0]);
282
-
283
- ScalePlane(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1,
284
- kFilterNone);
285
-
286
- EXPECT_EQ(225, dest_pixels[0]);
287
-
288
- free_aligned_buffer_page_end(dest_pixels);
289
- free_aligned_buffer_page_end(orig_pixels);
290
- }
291
-
292
- TEST_F(LibYUVScaleTest, PlaneTest4x) {
293
- const int kSrcStride = 640;
294
- const int kDstStride = 160;
295
- const int kSize = kSrcStride * 4;
296
- align_buffer_page_end(orig_pixels, kSize);
297
- for (int i = 0; i < 640 * 4; ++i) {
298
- orig_pixels[i] = i;
299
- }
300
- align_buffer_page_end(dest_pixels, kDstStride);
301
-
302
- int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 *
303
- benchmark_iterations_;
304
- for (int i = 0; i < iterations160; ++i) {
305
- ScalePlane(orig_pixels, kSrcStride, 640, 4, dest_pixels, kDstStride, 160, 1,
306
- kFilterBilinear);
307
- }
308
-
309
- EXPECT_EQ(66, dest_pixels[0]);
310
-
311
- ScalePlane(orig_pixels, kSrcStride, 640, 4, dest_pixels, kDstStride, 160, 1,
312
- kFilterNone);
313
-
314
- EXPECT_EQ(2, dest_pixels[0]); // expect the 3rd pixel of the 3rd row
315
-
316
- free_aligned_buffer_page_end(dest_pixels);
317
- free_aligned_buffer_page_end(orig_pixels);
318
- }
319
-
320
- // Intent is to test 200x50 to 50x200 but width and height can be parameters.
321
- TEST_F(LibYUVScaleTest, PlaneTestRotate_None) {
322
- const int kSize = benchmark_width_ * benchmark_height_;
323
- align_buffer_page_end(orig_pixels, kSize);
324
- for (int i = 0; i < kSize; ++i) {
325
- orig_pixels[i] = i;
326
- }
327
- align_buffer_page_end(dest_opt_pixels, kSize);
328
- align_buffer_page_end(dest_c_pixels, kSize);
329
-
330
- MaskCpuFlags(disable_cpu_flags_); // Disable all CPU optimization.
331
- ScalePlane(orig_pixels, benchmark_width_, benchmark_width_, benchmark_height_,
332
- dest_c_pixels, benchmark_height_, benchmark_height_,
333
- benchmark_width_, kFilterNone);
334
- MaskCpuFlags(benchmark_cpu_info_); // Enable all CPU optimization.
335
-
336
- for (int i = 0; i < benchmark_iterations_; ++i) {
337
- ScalePlane(orig_pixels, benchmark_width_, benchmark_width_,
338
- benchmark_height_, dest_opt_pixels, benchmark_height_,
339
- benchmark_height_, benchmark_width_, kFilterNone);
340
- }
341
-
342
- for (int i = 0; i < kSize; ++i) {
343
- EXPECT_EQ(dest_c_pixels[i], dest_opt_pixels[i]);
344
- }
345
-
346
- free_aligned_buffer_page_end(dest_c_pixels);
347
- free_aligned_buffer_page_end(dest_opt_pixels);
348
- free_aligned_buffer_page_end(orig_pixels);
349
- }
350
-
351
- TEST_F(LibYUVScaleTest, PlaneTestRotate_Bilinear) {
352
- const int kSize = benchmark_width_ * benchmark_height_;
353
- align_buffer_page_end(orig_pixels, kSize);
354
- for (int i = 0; i < kSize; ++i) {
355
- orig_pixels[i] = i;
356
- }
357
- align_buffer_page_end(dest_opt_pixels, kSize);
358
- align_buffer_page_end(dest_c_pixels, kSize);
359
-
360
- MaskCpuFlags(disable_cpu_flags_); // Disable all CPU optimization.
361
- ScalePlane(orig_pixels, benchmark_width_, benchmark_width_, benchmark_height_,
362
- dest_c_pixels, benchmark_height_, benchmark_height_,
363
- benchmark_width_, kFilterBilinear);
364
- MaskCpuFlags(benchmark_cpu_info_); // Enable all CPU optimization.
365
-
366
- for (int i = 0; i < benchmark_iterations_; ++i) {
367
- ScalePlane(orig_pixels, benchmark_width_, benchmark_width_,
368
- benchmark_height_, dest_opt_pixels, benchmark_height_,
369
- benchmark_height_, benchmark_width_, kFilterBilinear);
370
- }
371
-
372
- for (int i = 0; i < kSize; ++i) {
373
- EXPECT_EQ(dest_c_pixels[i], dest_opt_pixels[i]);
374
- }
375
-
376
- free_aligned_buffer_page_end(dest_c_pixels);
377
- free_aligned_buffer_page_end(dest_opt_pixels);
378
- free_aligned_buffer_page_end(orig_pixels);
379
- }
380
-
381
- // Intent is to test 200x50 to 50x200 but width and height can be parameters.
382
- TEST_F(LibYUVScaleTest, PlaneTestRotate_Box) {
383
- const int kSize = benchmark_width_ * benchmark_height_;
384
- align_buffer_page_end(orig_pixels, kSize);
385
- for (int i = 0; i < kSize; ++i) {
386
- orig_pixels[i] = i;
387
- }
388
- align_buffer_page_end(dest_opt_pixels, kSize);
389
- align_buffer_page_end(dest_c_pixels, kSize);
390
-
391
- MaskCpuFlags(disable_cpu_flags_); // Disable all CPU optimization.
392
- ScalePlane(orig_pixels, benchmark_width_, benchmark_width_, benchmark_height_,
393
- dest_c_pixels, benchmark_height_, benchmark_height_,
394
- benchmark_width_, kFilterBox);
395
- MaskCpuFlags(benchmark_cpu_info_); // Enable all CPU optimization.
396
-
397
- for (int i = 0; i < benchmark_iterations_; ++i) {
398
- ScalePlane(orig_pixels, benchmark_width_, benchmark_width_,
399
- benchmark_height_, dest_opt_pixels, benchmark_height_,
400
- benchmark_height_, benchmark_width_, kFilterBox);
401
- }
402
-
403
- for (int i = 0; i < kSize; ++i) {
404
- EXPECT_EQ(dest_c_pixels[i], dest_opt_pixels[i]);
405
- }
406
-
407
- free_aligned_buffer_page_end(dest_c_pixels);
408
- free_aligned_buffer_page_end(dest_opt_pixels);
409
- free_aligned_buffer_page_end(orig_pixels);
410
- }
411
-
412
- TEST_F(LibYUVScaleTest, PlaneTest1_Box) {
413
- align_buffer_page_end(orig_pixels, 3);
414
- align_buffer_page_end(dst_pixels, 3);
415
-
416
- // Pad the 1x1 byte image with invalid values before and after in case libyuv
417
- // reads outside the memory boundaries.
418
- orig_pixels[0] = 0;
419
- orig_pixels[1] = 1; // scale this pixel
420
- orig_pixels[2] = 2;
421
- dst_pixels[0] = 3;
422
- dst_pixels[1] = 3;
423
- dst_pixels[2] = 3;
424
-
425
- libyuv::ScalePlane(orig_pixels + 1, /* src_stride= */ 1, /* src_width= */ 1,
426
- /* src_height= */ 1, dst_pixels, /* dst_stride= */ 1,
427
- /* dst_width= */ 1, /* dst_height= */ 2,
428
- libyuv::kFilterBox);
429
-
430
- EXPECT_EQ(dst_pixels[0], 1);
431
- EXPECT_EQ(dst_pixels[1], 1);
432
- EXPECT_EQ(dst_pixels[2], 3);
433
-
434
- free_aligned_buffer_page_end(dst_pixels);
435
- free_aligned_buffer_page_end(orig_pixels);
436
- }
437
-
438
- TEST_F(LibYUVScaleTest, PlaneTest1_16_Box) {
439
- align_buffer_page_end(orig_pixels_alloc, 3 * 2);
440
- align_buffer_page_end(dst_pixels_alloc, 3 * 2);
441
- uint16_t* orig_pixels = (uint16_t*)orig_pixels_alloc;
442
- uint16_t* dst_pixels = (uint16_t*)dst_pixels_alloc;
443
-
444
- // Pad the 1x1 byte image with invalid values before and after in case libyuv
445
- // reads outside the memory boundaries.
446
- orig_pixels[0] = 0;
447
- orig_pixels[1] = 1; // scale this pixel
448
- orig_pixels[2] = 2;
449
- dst_pixels[0] = 3;
450
- dst_pixels[1] = 3;
451
- dst_pixels[2] = 3;
452
-
453
- libyuv::ScalePlane_16(
454
- orig_pixels + 1, /* src_stride= */ 1, /* src_width= */ 1,
455
- /* src_height= */ 1, dst_pixels, /* dst_stride= */ 1,
456
- /* dst_width= */ 1, /* dst_height= */ 2, libyuv::kFilterNone);
457
-
458
- EXPECT_EQ(dst_pixels[0], 1);
459
- EXPECT_EQ(dst_pixels[1], 1);
460
- EXPECT_EQ(dst_pixels[2], 3);
461
-
462
- free_aligned_buffer_page_end(dst_pixels_alloc);
463
- free_aligned_buffer_page_end(orig_pixels_alloc);
464
- }
465
- } // namespace libyuv
1
+ /*
2
+ * Copyright 2023 The LibYuv Project Authors. All rights reserved.
3
+ *
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
6
+ * tree. An additional intellectual property rights grant can be found
7
+ * in the file PATENTS. All contributing project authors may
8
+ * be found in the AUTHORS file in the root of the source tree.
9
+ */
10
+
11
+ #include <stdlib.h>
12
+ #include <time.h>
13
+
14
+ #include "../unit_test/unit_test.h"
15
+ #include "libyuv/cpu_id.h"
16
+ #include "libyuv/scale.h"
17
+
18
+ #ifdef ENABLE_ROW_TESTS
19
+ #include "libyuv/scale_row.h" // For ScaleRowDown2Box_Odd_C
20
+ #endif
21
+
22
+ #define STRINGIZE(line) #line
23
+ #define FILELINESTR(file, line) file ":" STRINGIZE(line)
24
+
25
+ #if defined(__riscv) && !defined(__clang__)
26
+ #define DISABLE_SLOW_TESTS
27
+ #undef ENABLE_FULL_TESTS
28
+ #undef ENABLE_ROW_TESTS
29
+ #define LEAN_TESTS
30
+ #endif
31
+
32
+ #if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__)
33
+ // SLOW TESTS are those that are unoptimized C code.
34
+ // FULL TESTS are optimized but test many variations of the same code.
35
+ #define ENABLE_FULL_TESTS
36
+ #endif
37
+
38
+ namespace libyuv {
39
+
40
+ #ifdef ENABLE_ROW_TESTS
41
+ #ifdef HAS_SCALEROWDOWN2_SSSE3
42
+ TEST_F(LibYUVScaleTest, TestScaleRowDown2Box_Odd_SSSE3) {
43
+ SIMD_ALIGNED(uint8_t orig_pixels[128 * 2]);
44
+ SIMD_ALIGNED(uint8_t dst_pixels_opt[64]);
45
+ SIMD_ALIGNED(uint8_t dst_pixels_c[64]);
46
+ memset(orig_pixels, 0, sizeof(orig_pixels));
47
+ memset(dst_pixels_opt, 0, sizeof(dst_pixels_opt));
48
+ memset(dst_pixels_c, 0, sizeof(dst_pixels_c));
49
+
50
+ int has_ssse3 = TestCpuFlag(kCpuHasSSSE3);
51
+ if (!has_ssse3) {
52
+ printf("Warning SSSE3 not detected; Skipping test.\n");
53
+ } else {
54
+ // TL.
55
+ orig_pixels[0] = 255u;
56
+ orig_pixels[1] = 0u;
57
+ orig_pixels[128 + 0] = 0u;
58
+ orig_pixels[128 + 1] = 0u;
59
+ // TR.
60
+ orig_pixels[2] = 0u;
61
+ orig_pixels[3] = 100u;
62
+ orig_pixels[128 + 2] = 0u;
63
+ orig_pixels[128 + 3] = 0u;
64
+ // BL.
65
+ orig_pixels[4] = 0u;
66
+ orig_pixels[5] = 0u;
67
+ orig_pixels[128 + 4] = 50u;
68
+ orig_pixels[128 + 5] = 0u;
69
+ // BR.
70
+ orig_pixels[6] = 0u;
71
+ orig_pixels[7] = 0u;
72
+ orig_pixels[128 + 6] = 0u;
73
+ orig_pixels[128 + 7] = 20u;
74
+ // Odd.
75
+ orig_pixels[126] = 4u;
76
+ orig_pixels[127] = 255u;
77
+ orig_pixels[128 + 126] = 16u;
78
+ orig_pixels[128 + 127] = 255u;
79
+
80
+ // Test regular half size.
81
+ ScaleRowDown2Box_C(orig_pixels, 128, dst_pixels_c, 64);
82
+
83
+ EXPECT_EQ(64u, dst_pixels_c[0]);
84
+ EXPECT_EQ(25u, dst_pixels_c[1]);
85
+ EXPECT_EQ(13u, dst_pixels_c[2]);
86
+ EXPECT_EQ(5u, dst_pixels_c[3]);
87
+ EXPECT_EQ(0u, dst_pixels_c[4]);
88
+ EXPECT_EQ(133u, dst_pixels_c[63]);
89
+
90
+ // Test Odd width version - Last pixel is just 1 horizontal pixel.
91
+ ScaleRowDown2Box_Odd_C(orig_pixels, 128, dst_pixels_c, 64);
92
+
93
+ EXPECT_EQ(64u, dst_pixels_c[0]);
94
+ EXPECT_EQ(25u, dst_pixels_c[1]);
95
+ EXPECT_EQ(13u, dst_pixels_c[2]);
96
+ EXPECT_EQ(5u, dst_pixels_c[3]);
97
+ EXPECT_EQ(0u, dst_pixels_c[4]);
98
+ EXPECT_EQ(10u, dst_pixels_c[63]);
99
+
100
+ // Test one pixel less, should skip the last pixel.
101
+ memset(dst_pixels_c, 0, sizeof(dst_pixels_c));
102
+ ScaleRowDown2Box_Odd_C(orig_pixels, 128, dst_pixels_c, 63);
103
+
104
+ EXPECT_EQ(64u, dst_pixels_c[0]);
105
+ EXPECT_EQ(25u, dst_pixels_c[1]);
106
+ EXPECT_EQ(13u, dst_pixels_c[2]);
107
+ EXPECT_EQ(5u, dst_pixels_c[3]);
108
+ EXPECT_EQ(0u, dst_pixels_c[4]);
109
+ EXPECT_EQ(0u, dst_pixels_c[63]);
110
+
111
+ // Test regular half size SSSE3.
112
+ ScaleRowDown2Box_SSSE3(orig_pixels, 128, dst_pixels_opt, 64);
113
+
114
+ EXPECT_EQ(64u, dst_pixels_opt[0]);
115
+ EXPECT_EQ(25u, dst_pixels_opt[1]);
116
+ EXPECT_EQ(13u, dst_pixels_opt[2]);
117
+ EXPECT_EQ(5u, dst_pixels_opt[3]);
118
+ EXPECT_EQ(0u, dst_pixels_opt[4]);
119
+ EXPECT_EQ(133u, dst_pixels_opt[63]);
120
+
121
+ // Compare C and SSSE3 match.
122
+ ScaleRowDown2Box_Odd_C(orig_pixels, 128, dst_pixels_c, 64);
123
+ ScaleRowDown2Box_Odd_SSSE3(orig_pixels, 128, dst_pixels_opt, 64);
124
+ for (int i = 0; i < 64; ++i) {
125
+ EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
126
+ }
127
+ }
128
+ }
129
+ #endif // HAS_SCALEROWDOWN2_SSSE3
130
+
131
+ TEST_F(LibYUVScaleTest, TestScaleRowDown2Box_16) {
132
+ SIMD_ALIGNED(uint16_t orig_pixels[2560 * 2]);
133
+ SIMD_ALIGNED(uint16_t dst_pixels_c[1280]);
134
+ SIMD_ALIGNED(uint16_t dst_pixels_opt[1280]);
135
+
136
+ memset(orig_pixels, 0, sizeof(orig_pixels));
137
+ memset(dst_pixels_c, 1, sizeof(dst_pixels_c));
138
+ memset(dst_pixels_opt, 2, sizeof(dst_pixels_opt));
139
+
140
+ for (int i = 0; i < 2560 * 2; ++i) {
141
+ orig_pixels[i] = i;
142
+ }
143
+ ScaleRowDown2Box_16_C(&orig_pixels[0], 2560, &dst_pixels_c[0], 1280);
144
+ for (int i = 0; i < benchmark_pixels_div1280_; ++i) {
145
+ #if !defined(LIBYUV_DISABLE_NEON) && defined(__aarch64__)
146
+ int has_neon = TestCpuFlag(kCpuHasNEON);
147
+ if (has_neon) {
148
+ ScaleRowDown2Box_16_NEON(&orig_pixels[0], 2560, &dst_pixels_opt[0], 1280);
149
+ } else {
150
+ ScaleRowDown2Box_16_C(&orig_pixels[0], 2560, &dst_pixels_opt[0], 1280);
151
+ }
152
+ #else
153
+ ScaleRowDown2Box_16_C(&orig_pixels[0], 2560, &dst_pixels_opt[0], 1280);
154
+ #endif
155
+ }
156
+
157
+ for (int i = 0; i < 1280; ++i) {
158
+ EXPECT_EQ(dst_pixels_c[i], dst_pixels_opt[i]);
159
+ }
160
+
161
+ EXPECT_EQ(dst_pixels_c[0], (0 + 1 + 2560 + 2561 + 2) / 4);
162
+ EXPECT_EQ(dst_pixels_c[1279], 3839);
163
+ }
164
+ #endif // ENABLE_ROW_TESTS
165
+
166
+ // Test scaling plane with 8 bit C vs 12 bit C and return maximum pixel
167
+ // difference.
168
+ // 0 = exact.
169
+ static int TestPlaneFilter_16(int src_width,
170
+ int src_height,
171
+ int dst_width,
172
+ int dst_height,
173
+ FilterMode f,
174
+ int benchmark_iterations,
175
+ int disable_cpu_flags,
176
+ int benchmark_cpu_info) {
177
+ if (!SizeValid(src_width, src_height, dst_width, dst_height)) {
178
+ return 0;
179
+ }
180
+
181
+ int i;
182
+ int64_t src_y_plane_size = (Abs(src_width)) * (Abs(src_height));
183
+ int src_stride_y = Abs(src_width);
184
+ int dst_y_plane_size = dst_width * dst_height;
185
+ int dst_stride_y = dst_width;
186
+
187
+ align_buffer_page_end(src_y, src_y_plane_size);
188
+ align_buffer_page_end(src_y_16, src_y_plane_size * 2);
189
+ align_buffer_page_end(dst_y_8, dst_y_plane_size);
190
+ align_buffer_page_end(dst_y_16, dst_y_plane_size * 2);
191
+ uint16_t* p_src_y_16 = reinterpret_cast<uint16_t*>(src_y_16);
192
+ uint16_t* p_dst_y_16 = reinterpret_cast<uint16_t*>(dst_y_16);
193
+
194
+ MemRandomize(src_y, src_y_plane_size);
195
+ memset(dst_y_8, 0, dst_y_plane_size);
196
+ memset(dst_y_16, 1, dst_y_plane_size * 2);
197
+
198
+ for (i = 0; i < src_y_plane_size; ++i) {
199
+ p_src_y_16[i] = src_y[i] & 255;
200
+ }
201
+
202
+ MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization.
203
+ ScalePlane(src_y, src_stride_y, src_width, src_height, dst_y_8, dst_stride_y,
204
+ dst_width, dst_height, f);
205
+ MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization.
206
+
207
+ for (i = 0; i < benchmark_iterations; ++i) {
208
+ ScalePlane_16(p_src_y_16, src_stride_y, src_width, src_height, p_dst_y_16,
209
+ dst_stride_y, dst_width, dst_height, f);
210
+ }
211
+
212
+ // Expect an exact match.
213
+ int max_diff = 0;
214
+ for (i = 0; i < dst_y_plane_size; ++i) {
215
+ int abs_diff = Abs(dst_y_8[i] - p_dst_y_16[i]);
216
+ if (abs_diff > max_diff) {
217
+ max_diff = abs_diff;
218
+ }
219
+ }
220
+
221
+ free_aligned_buffer_page_end(dst_y_8);
222
+ free_aligned_buffer_page_end(dst_y_16);
223
+ free_aligned_buffer_page_end(src_y);
224
+ free_aligned_buffer_page_end(src_y_16);
225
+
226
+ return max_diff;
227
+ }
228
+
229
+ // The following adjustments in dimensions ensure the scale factor will be
230
+ // exactly achieved.
231
+ // 2 is chroma subsample.
232
+ #define DX(x, nom, denom) static_cast<int>(((Abs(x) / nom + 1) / 2) * nom * 2)
233
+ #define SX(x, nom, denom) static_cast<int>(((x / nom + 1) / 2) * denom * 2)
234
+
235
+ #define TEST_FACTOR1(name, filter, nom, denom, max_diff) \
236
+ TEST_F(LibYUVScaleTest, DISABLED_##ScalePlaneDownBy##name##_##filter##_16) { \
237
+ int diff = TestPlaneFilter_16( \
238
+ SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \
239
+ DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \
240
+ kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \
241
+ benchmark_cpu_info_); \
242
+ EXPECT_LE(diff, max_diff); \
243
+ }
244
+
245
+ // Test a scale factor with all 4 filters. Expect unfiltered to be exact, but
246
+ // filtering is different fixed point implementations for SSSE3, Neon and C.
247
+ #define TEST_FACTOR(name, nom, denom, boxdiff) \
248
+ TEST_FACTOR1(name, None, nom, denom, 0) \
249
+ TEST_FACTOR1(name, Linear, nom, denom, boxdiff) \
250
+ TEST_FACTOR1(name, Bilinear, nom, denom, boxdiff) \
251
+ TEST_FACTOR1(name, Box, nom, denom, boxdiff)
252
+
253
+ TEST_FACTOR(2, 1, 2, 0)
254
+ TEST_FACTOR(4, 1, 4, 0)
255
+ // TEST_FACTOR(8, 1, 8, 0) Disable for benchmark performance. Takes 90 seconds.
256
+ TEST_FACTOR(3by4, 3, 4, 1)
257
+ TEST_FACTOR(3by8, 3, 8, 1)
258
+ TEST_FACTOR(3, 1, 3, 0)
259
+ #undef TEST_FACTOR1
260
+ #undef TEST_FACTOR
261
+ #undef SX
262
+ #undef DX
263
+
264
+ TEST_F(LibYUVScaleTest, PlaneTest3x) {
265
+ const int kSrcStride = 480;
266
+ const int kDstStride = 160;
267
+ const int kSize = kSrcStride * 3;
268
+ align_buffer_page_end(orig_pixels, kSize);
269
+ for (int i = 0; i < 480 * 3; ++i) {
270
+ orig_pixels[i] = i;
271
+ }
272
+ align_buffer_page_end(dest_pixels, kDstStride);
273
+
274
+ int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 *
275
+ benchmark_iterations_;
276
+ for (int i = 0; i < iterations160; ++i) {
277
+ ScalePlane(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1,
278
+ kFilterBilinear);
279
+ }
280
+
281
+ EXPECT_EQ(225, dest_pixels[0]);
282
+
283
+ ScalePlane(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1,
284
+ kFilterNone);
285
+
286
+ EXPECT_EQ(225, dest_pixels[0]);
287
+
288
+ free_aligned_buffer_page_end(dest_pixels);
289
+ free_aligned_buffer_page_end(orig_pixels);
290
+ }
291
+
292
+ TEST_F(LibYUVScaleTest, PlaneTest4x) {
293
+ const int kSrcStride = 640;
294
+ const int kDstStride = 160;
295
+ const int kSize = kSrcStride * 4;
296
+ align_buffer_page_end(orig_pixels, kSize);
297
+ for (int i = 0; i < 640 * 4; ++i) {
298
+ orig_pixels[i] = i;
299
+ }
300
+ align_buffer_page_end(dest_pixels, kDstStride);
301
+
302
+ int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 *
303
+ benchmark_iterations_;
304
+ for (int i = 0; i < iterations160; ++i) {
305
+ ScalePlane(orig_pixels, kSrcStride, 640, 4, dest_pixels, kDstStride, 160, 1,
306
+ kFilterBilinear);
307
+ }
308
+
309
+ EXPECT_EQ(66, dest_pixels[0]);
310
+
311
+ ScalePlane(orig_pixels, kSrcStride, 640, 4, dest_pixels, kDstStride, 160, 1,
312
+ kFilterNone);
313
+
314
+ EXPECT_EQ(2, dest_pixels[0]); // expect the 3rd pixel of the 3rd row
315
+
316
+ free_aligned_buffer_page_end(dest_pixels);
317
+ free_aligned_buffer_page_end(orig_pixels);
318
+ }
319
+
320
+ // Intent is to test 200x50 to 50x200 but width and height can be parameters.
321
+ TEST_F(LibYUVScaleTest, PlaneTestRotate_None) {
322
+ const int kSize = benchmark_width_ * benchmark_height_;
323
+ align_buffer_page_end(orig_pixels, kSize);
324
+ for (int i = 0; i < kSize; ++i) {
325
+ orig_pixels[i] = i;
326
+ }
327
+ align_buffer_page_end(dest_opt_pixels, kSize);
328
+ align_buffer_page_end(dest_c_pixels, kSize);
329
+
330
+ MaskCpuFlags(disable_cpu_flags_); // Disable all CPU optimization.
331
+ ScalePlane(orig_pixels, benchmark_width_, benchmark_width_, benchmark_height_,
332
+ dest_c_pixels, benchmark_height_, benchmark_height_,
333
+ benchmark_width_, kFilterNone);
334
+ MaskCpuFlags(benchmark_cpu_info_); // Enable all CPU optimization.
335
+
336
+ for (int i = 0; i < benchmark_iterations_; ++i) {
337
+ ScalePlane(orig_pixels, benchmark_width_, benchmark_width_,
338
+ benchmark_height_, dest_opt_pixels, benchmark_height_,
339
+ benchmark_height_, benchmark_width_, kFilterNone);
340
+ }
341
+
342
+ for (int i = 0; i < kSize; ++i) {
343
+ EXPECT_EQ(dest_c_pixels[i], dest_opt_pixels[i]);
344
+ }
345
+
346
+ free_aligned_buffer_page_end(dest_c_pixels);
347
+ free_aligned_buffer_page_end(dest_opt_pixels);
348
+ free_aligned_buffer_page_end(orig_pixels);
349
+ }
350
+
351
+ TEST_F(LibYUVScaleTest, PlaneTestRotate_Bilinear) {
352
+ const int kSize = benchmark_width_ * benchmark_height_;
353
+ align_buffer_page_end(orig_pixels, kSize);
354
+ for (int i = 0; i < kSize; ++i) {
355
+ orig_pixels[i] = i;
356
+ }
357
+ align_buffer_page_end(dest_opt_pixels, kSize);
358
+ align_buffer_page_end(dest_c_pixels, kSize);
359
+
360
+ MaskCpuFlags(disable_cpu_flags_); // Disable all CPU optimization.
361
+ ScalePlane(orig_pixels, benchmark_width_, benchmark_width_, benchmark_height_,
362
+ dest_c_pixels, benchmark_height_, benchmark_height_,
363
+ benchmark_width_, kFilterBilinear);
364
+ MaskCpuFlags(benchmark_cpu_info_); // Enable all CPU optimization.
365
+
366
+ for (int i = 0; i < benchmark_iterations_; ++i) {
367
+ ScalePlane(orig_pixels, benchmark_width_, benchmark_width_,
368
+ benchmark_height_, dest_opt_pixels, benchmark_height_,
369
+ benchmark_height_, benchmark_width_, kFilterBilinear);
370
+ }
371
+
372
+ for (int i = 0; i < kSize; ++i) {
373
+ EXPECT_EQ(dest_c_pixels[i], dest_opt_pixels[i]);
374
+ }
375
+
376
+ free_aligned_buffer_page_end(dest_c_pixels);
377
+ free_aligned_buffer_page_end(dest_opt_pixels);
378
+ free_aligned_buffer_page_end(orig_pixels);
379
+ }
380
+
381
+ // Intent is to test 200x50 to 50x200 but width and height can be parameters.
382
+ TEST_F(LibYUVScaleTest, PlaneTestRotate_Box) {
383
+ const int kSize = benchmark_width_ * benchmark_height_;
384
+ align_buffer_page_end(orig_pixels, kSize);
385
+ for (int i = 0; i < kSize; ++i) {
386
+ orig_pixels[i] = i;
387
+ }
388
+ align_buffer_page_end(dest_opt_pixels, kSize);
389
+ align_buffer_page_end(dest_c_pixels, kSize);
390
+
391
+ MaskCpuFlags(disable_cpu_flags_); // Disable all CPU optimization.
392
+ ScalePlane(orig_pixels, benchmark_width_, benchmark_width_, benchmark_height_,
393
+ dest_c_pixels, benchmark_height_, benchmark_height_,
394
+ benchmark_width_, kFilterBox);
395
+ MaskCpuFlags(benchmark_cpu_info_); // Enable all CPU optimization.
396
+
397
+ for (int i = 0; i < benchmark_iterations_; ++i) {
398
+ ScalePlane(orig_pixels, benchmark_width_, benchmark_width_,
399
+ benchmark_height_, dest_opt_pixels, benchmark_height_,
400
+ benchmark_height_, benchmark_width_, kFilterBox);
401
+ }
402
+
403
+ for (int i = 0; i < kSize; ++i) {
404
+ EXPECT_EQ(dest_c_pixels[i], dest_opt_pixels[i]);
405
+ }
406
+
407
+ free_aligned_buffer_page_end(dest_c_pixels);
408
+ free_aligned_buffer_page_end(dest_opt_pixels);
409
+ free_aligned_buffer_page_end(orig_pixels);
410
+ }
411
+
412
+ TEST_F(LibYUVScaleTest, PlaneTest1_Box) {
413
+ align_buffer_page_end(orig_pixels, 3);
414
+ align_buffer_page_end(dst_pixels, 3);
415
+
416
+ // Pad the 1x1 byte image with invalid values before and after in case libyuv
417
+ // reads outside the memory boundaries.
418
+ orig_pixels[0] = 0;
419
+ orig_pixels[1] = 1; // scale this pixel
420
+ orig_pixels[2] = 2;
421
+ dst_pixels[0] = 3;
422
+ dst_pixels[1] = 3;
423
+ dst_pixels[2] = 3;
424
+
425
+ libyuv::ScalePlane(orig_pixels + 1, /* src_stride= */ 1, /* src_width= */ 1,
426
+ /* src_height= */ 1, dst_pixels, /* dst_stride= */ 1,
427
+ /* dst_width= */ 1, /* dst_height= */ 2,
428
+ libyuv::kFilterBox);
429
+
430
+ EXPECT_EQ(dst_pixels[0], 1);
431
+ EXPECT_EQ(dst_pixels[1], 1);
432
+ EXPECT_EQ(dst_pixels[2], 3);
433
+
434
+ free_aligned_buffer_page_end(dst_pixels);
435
+ free_aligned_buffer_page_end(orig_pixels);
436
+ }
437
+
438
+ TEST_F(LibYUVScaleTest, PlaneTest1_16_Box) {
439
+ align_buffer_page_end(orig_pixels_alloc, 3 * 2);
440
+ align_buffer_page_end(dst_pixels_alloc, 3 * 2);
441
+ uint16_t* orig_pixels = (uint16_t*)orig_pixels_alloc;
442
+ uint16_t* dst_pixels = (uint16_t*)dst_pixels_alloc;
443
+
444
+ // Pad the 1x1 byte image with invalid values before and after in case libyuv
445
+ // reads outside the memory boundaries.
446
+ orig_pixels[0] = 0;
447
+ orig_pixels[1] = 1; // scale this pixel
448
+ orig_pixels[2] = 2;
449
+ dst_pixels[0] = 3;
450
+ dst_pixels[1] = 3;
451
+ dst_pixels[2] = 3;
452
+
453
+ libyuv::ScalePlane_16(
454
+ orig_pixels + 1, /* src_stride= */ 1, /* src_width= */ 1,
455
+ /* src_height= */ 1, dst_pixels, /* dst_stride= */ 1,
456
+ /* dst_width= */ 1, /* dst_height= */ 2, libyuv::kFilterNone);
457
+
458
+ EXPECT_EQ(dst_pixels[0], 1);
459
+ EXPECT_EQ(dst_pixels[1], 1);
460
+ EXPECT_EQ(dst_pixels[2], 3);
461
+
462
+ free_aligned_buffer_page_end(dst_pixels_alloc);
463
+ free_aligned_buffer_page_end(orig_pixels_alloc);
464
+ }
465
+ } // namespace libyuv