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

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 (206) hide show
  1. package/README.md +442 -442
  2. package/android/.gradle/9.2.0/checksums/checksums.lock +0 -0
  3. package/android/.gradle/9.2.0/fileHashes/fileHashes.bin +0 -0
  4. package/android/.gradle/9.2.0/fileHashes/fileHashes.lock +0 -0
  5. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  6. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  7. package/android/build/reports/problems/problems-report.html +659 -0
  8. package/android/build.gradle +12 -4
  9. package/android/src/main/cpp/CMakeLists.txt +101 -94
  10. package/android/src/main/cpp/libyuv/.clang-format +6 -6
  11. package/android/src/main/cpp/libyuv/.gn +40 -40
  12. package/android/src/main/cpp/libyuv/.vpython3 +410 -410
  13. package/android/src/main/cpp/libyuv/AUTHORS +7 -7
  14. package/android/src/main/cpp/libyuv/Android.bp +202 -202
  15. package/android/src/main/cpp/libyuv/Android.mk +106 -106
  16. package/android/src/main/cpp/libyuv/BUILD.gn +490 -490
  17. package/android/src/main/cpp/libyuv/CM_linux_packages.cmake +70 -70
  18. package/android/src/main/cpp/libyuv/CMakeLists.txt +259 -252
  19. package/android/src/main/cpp/libyuv/DEPS +935 -935
  20. package/android/src/main/cpp/libyuv/DIR_METADATA +3 -3
  21. package/android/src/main/cpp/libyuv/LICENSE +29 -29
  22. package/android/src/main/cpp/libyuv/OWNERS +11 -11
  23. package/android/src/main/cpp/libyuv/PATENTS +23 -23
  24. package/android/src/main/cpp/libyuv/PRESUBMIT.py +65 -65
  25. package/android/src/main/cpp/libyuv/README.chromium +11 -11
  26. package/android/src/main/cpp/libyuv/README.md +19 -19
  27. package/android/src/main/cpp/libyuv/build_overrides/build.gni +60 -60
  28. package/android/src/main/cpp/libyuv/build_overrides/gtest.gni +19 -19
  29. package/android/src/main/cpp/libyuv/build_overrides/partition_alloc.gni +17 -17
  30. package/android/src/main/cpp/libyuv/codereview.settings +5 -5
  31. package/android/src/main/cpp/libyuv/docs/deprecated_builds.md +409 -409
  32. package/android/src/main/cpp/libyuv/docs/environment_variables.md +64 -64
  33. package/android/src/main/cpp/libyuv/docs/feature_detection.md +108 -108
  34. package/android/src/main/cpp/libyuv/docs/filtering.md +196 -196
  35. package/android/src/main/cpp/libyuv/docs/formats.md +208 -208
  36. package/android/src/main/cpp/libyuv/docs/getting_started.md +296 -296
  37. package/android/src/main/cpp/libyuv/docs/rotation.md +107 -107
  38. package/android/src/main/cpp/libyuv/download_vs_toolchain.py +29 -29
  39. package/android/src/main/cpp/libyuv/include/libyuv/basic_types.h +68 -68
  40. package/android/src/main/cpp/libyuv/include/libyuv/compare.h +111 -111
  41. package/android/src/main/cpp/libyuv/include/libyuv/compare_row.h +112 -112
  42. package/android/src/main/cpp/libyuv/include/libyuv/convert.h +1117 -1117
  43. package/android/src/main/cpp/libyuv/include/libyuv/convert_argb.h +2335 -2335
  44. package/android/src/main/cpp/libyuv/include/libyuv/convert_from.h +203 -203
  45. package/android/src/main/cpp/libyuv/include/libyuv/convert_from_argb.h +394 -394
  46. package/android/src/main/cpp/libyuv/include/libyuv/cpu_id.h +147 -147
  47. package/android/src/main/cpp/libyuv/include/libyuv/cpu_support.h +99 -99
  48. package/android/src/main/cpp/libyuv/include/libyuv/loongson_intrinsics.h +1949 -1949
  49. package/android/src/main/cpp/libyuv/include/libyuv/mjpeg_decoder.h +195 -195
  50. package/android/src/main/cpp/libyuv/include/libyuv/planar_functions.h +1131 -1131
  51. package/android/src/main/cpp/libyuv/include/libyuv/rotate.h +296 -296
  52. package/android/src/main/cpp/libyuv/include/libyuv/rotate_argb.h +37 -37
  53. package/android/src/main/cpp/libyuv/include/libyuv/rotate_row.h +265 -265
  54. package/android/src/main/cpp/libyuv/include/libyuv/row.h +6738 -6738
  55. package/android/src/main/cpp/libyuv/include/libyuv/row_sve.h +2154 -2154
  56. package/android/src/main/cpp/libyuv/include/libyuv/scale.h +336 -336
  57. package/android/src/main/cpp/libyuv/include/libyuv/scale_argb.h +76 -76
  58. package/android/src/main/cpp/libyuv/include/libyuv/scale_rgb.h +42 -42
  59. package/android/src/main/cpp/libyuv/include/libyuv/scale_row.h +1726 -1726
  60. package/android/src/main/cpp/libyuv/include/libyuv/scale_uv.h +51 -51
  61. package/android/src/main/cpp/libyuv/include/libyuv/version.h +16 -16
  62. package/android/src/main/cpp/libyuv/include/libyuv/video_common.h +222 -222
  63. package/android/src/main/cpp/libyuv/include/libyuv.h +33 -33
  64. package/android/src/main/cpp/libyuv/infra/config/OWNERS +3 -3
  65. package/android/src/main/cpp/libyuv/infra/config/PRESUBMIT.py +17 -17
  66. package/android/src/main/cpp/libyuv/infra/config/README.md +2 -2
  67. package/android/src/main/cpp/libyuv/infra/config/codereview.settings +6 -6
  68. package/android/src/main/cpp/libyuv/infra/config/commit-queue.cfg +144 -144
  69. package/android/src/main/cpp/libyuv/infra/config/cr-buildbucket.cfg +1185 -1185
  70. package/android/src/main/cpp/libyuv/infra/config/luci-logdog.cfg +9 -9
  71. package/android/src/main/cpp/libyuv/infra/config/luci-milo.cfg +246 -246
  72. package/android/src/main/cpp/libyuv/infra/config/luci-scheduler.cfg +385 -385
  73. package/android/src/main/cpp/libyuv/infra/config/main.star +402 -402
  74. package/android/src/main/cpp/libyuv/infra/config/project.cfg +16 -16
  75. package/android/src/main/cpp/libyuv/infra/config/realms.cfg +111 -111
  76. package/android/src/main/cpp/libyuv/libyuv.gni +34 -34
  77. package/android/src/main/cpp/libyuv/libyuv.gyp +149 -149
  78. package/android/src/main/cpp/libyuv/libyuv.gypi +87 -87
  79. package/android/src/main/cpp/libyuv/linux.mk +96 -96
  80. package/android/src/main/cpp/libyuv/public.mk +13 -13
  81. package/android/src/main/cpp/libyuv/pylintrc +49 -49
  82. package/android/src/main/cpp/libyuv/riscv_script/prepare_toolchain_qemu.sh +74 -74
  83. package/android/src/main/cpp/libyuv/riscv_script/riscv-clang.cmake +56 -56
  84. package/android/src/main/cpp/libyuv/riscv_script/run_qemu.sh +15 -15
  85. package/android/src/main/cpp/libyuv/source/compare.cc +435 -435
  86. package/android/src/main/cpp/libyuv/source/compare_common.cc +74 -74
  87. package/android/src/main/cpp/libyuv/source/compare_gcc.cc +362 -362
  88. package/android/src/main/cpp/libyuv/source/compare_neon.cc +96 -96
  89. package/android/src/main/cpp/libyuv/source/compare_neon64.cc +223 -223
  90. package/android/src/main/cpp/libyuv/source/compare_win.cc +241 -241
  91. package/android/src/main/cpp/libyuv/source/convert.cc +4746 -4746
  92. package/android/src/main/cpp/libyuv/source/convert_argb.cc +9179 -9179
  93. package/android/src/main/cpp/libyuv/source/convert_from.cc +866 -866
  94. package/android/src/main/cpp/libyuv/source/convert_from_argb.cc +3671 -3671
  95. package/android/src/main/cpp/libyuv/source/convert_jpeg.cc +602 -602
  96. package/android/src/main/cpp/libyuv/source/convert_to_argb.cc +391 -391
  97. package/android/src/main/cpp/libyuv/source/convert_to_i420.cc +288 -288
  98. package/android/src/main/cpp/libyuv/source/cpu_id.cc +496 -496
  99. package/android/src/main/cpp/libyuv/source/mjpeg_decoder.cc +580 -580
  100. package/android/src/main/cpp/libyuv/source/mjpeg_validate.cc +71 -71
  101. package/android/src/main/cpp/libyuv/source/planar_functions.cc +5663 -5663
  102. package/android/src/main/cpp/libyuv/source/rotate.cc +1241 -1241
  103. package/android/src/main/cpp/libyuv/source/rotate_any.cc +76 -76
  104. package/android/src/main/cpp/libyuv/source/rotate_argb.cc +259 -259
  105. package/android/src/main/cpp/libyuv/source/rotate_common.cc +208 -208
  106. package/android/src/main/cpp/libyuv/source/rotate_gcc.cc +505 -505
  107. package/android/src/main/cpp/libyuv/source/rotate_lsx.cc +233 -233
  108. package/android/src/main/cpp/libyuv/source/rotate_neon.cc +219 -219
  109. package/android/src/main/cpp/libyuv/source/rotate_neon64.cc +273 -273
  110. package/android/src/main/cpp/libyuv/source/rotate_sme.cc +174 -174
  111. package/android/src/main/cpp/libyuv/source/rotate_win.cc +253 -253
  112. package/android/src/main/cpp/libyuv/source/row_any.cc +2519 -2519
  113. package/android/src/main/cpp/libyuv/source/row_common.cc +4461 -4461
  114. package/android/src/main/cpp/libyuv/source/row_gcc.cc +9570 -9570
  115. package/android/src/main/cpp/libyuv/source/row_lasx.cc +2343 -2343
  116. package/android/src/main/cpp/libyuv/source/row_lsx.cc +3030 -3030
  117. package/android/src/main/cpp/libyuv/source/row_neon.cc +4026 -4026
  118. package/android/src/main/cpp/libyuv/source/row_neon64.cc +5617 -5617
  119. package/android/src/main/cpp/libyuv/source/row_rvv.cc +2599 -2599
  120. package/android/src/main/cpp/libyuv/source/row_sme.cc +1183 -1183
  121. package/android/src/main/cpp/libyuv/source/row_sve.cc +1088 -1088
  122. package/android/src/main/cpp/libyuv/source/row_win.cc +6453 -6453
  123. package/android/src/main/cpp/libyuv/source/scale.cc +2710 -2710
  124. package/android/src/main/cpp/libyuv/source/scale_any.cc +991 -991
  125. package/android/src/main/cpp/libyuv/source/scale_argb.cc +1158 -1158
  126. package/android/src/main/cpp/libyuv/source/scale_common.cc +1977 -1977
  127. package/android/src/main/cpp/libyuv/source/scale_gcc.cc +2947 -2947
  128. package/android/src/main/cpp/libyuv/source/scale_lsx.cc +739 -739
  129. package/android/src/main/cpp/libyuv/source/scale_neon.cc +1449 -1449
  130. package/android/src/main/cpp/libyuv/source/scale_neon64.cc +1552 -1552
  131. package/android/src/main/cpp/libyuv/source/scale_rgb.cc +82 -82
  132. package/android/src/main/cpp/libyuv/source/scale_rvv.cc +1971 -1971
  133. package/android/src/main/cpp/libyuv/source/scale_sme.cc +555 -555
  134. package/android/src/main/cpp/libyuv/source/scale_uv.cc +1159 -1159
  135. package/android/src/main/cpp/libyuv/source/scale_win.cc +1392 -1392
  136. package/android/src/main/cpp/libyuv/source/test.sh +35 -35
  137. package/android/src/main/cpp/libyuv/source/video_common.cc +62 -62
  138. package/android/src/main/cpp/libyuv/tools_libyuv/OWNERS +4 -4
  139. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/roll_deps.py +931 -931
  140. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py +164 -164
  141. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS +21 -21
  142. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.new +13 -13
  143. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old +13 -13
  144. package/android/src/main/cpp/libyuv/tools_libyuv/get_landmines.py +38 -38
  145. package/android/src/main/cpp/libyuv/tools_libyuv/msan/OWNERS +3 -3
  146. package/android/src/main/cpp/libyuv/tools_libyuv/msan/blacklist.txt +9 -9
  147. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/OWNERS +3 -3
  148. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/blacklist.txt +15 -15
  149. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/vptr_blacklist.txt +25 -25
  150. package/android/src/main/cpp/libyuv/unit_test/basictypes_test.cc +43 -43
  151. package/android/src/main/cpp/libyuv/unit_test/color_test.cc +848 -848
  152. package/android/src/main/cpp/libyuv/unit_test/compare_test.cc +739 -739
  153. package/android/src/main/cpp/libyuv/unit_test/convert_argb_test.cc +2867 -2867
  154. package/android/src/main/cpp/libyuv/unit_test/convert_test.cc +2133 -2133
  155. package/android/src/main/cpp/libyuv/unit_test/cpu_test.cc +427 -427
  156. package/android/src/main/cpp/libyuv/unit_test/cpu_thread_test.cc +63 -63
  157. package/android/src/main/cpp/libyuv/unit_test/math_test.cc +160 -160
  158. package/android/src/main/cpp/libyuv/unit_test/planar_test.cc +4731 -4731
  159. package/android/src/main/cpp/libyuv/unit_test/rotate_argb_test.cc +334 -334
  160. package/android/src/main/cpp/libyuv/unit_test/rotate_test.cc +962 -962
  161. package/android/src/main/cpp/libyuv/unit_test/scale_argb_test.cc +590 -590
  162. package/android/src/main/cpp/libyuv/unit_test/scale_plane_test.cc +465 -465
  163. package/android/src/main/cpp/libyuv/unit_test/scale_rgb_test.cc +280 -280
  164. package/android/src/main/cpp/libyuv/unit_test/scale_test.cc +1135 -1135
  165. package/android/src/main/cpp/libyuv/unit_test/scale_uv_test.cc +249 -249
  166. package/android/src/main/cpp/libyuv/unit_test/testdata/arm_v7.txt +12 -12
  167. package/android/src/main/cpp/libyuv/unit_test/testdata/mips.txt +7 -7
  168. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson2k.txt +5 -5
  169. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson3.txt +10 -10
  170. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson_mmi.txt +7 -7
  171. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64.txt +3 -3
  172. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv.txt +3 -3
  173. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv_zvfh.txt +3 -3
  174. package/android/src/main/cpp/libyuv/unit_test/testdata/tegra3.txt +23 -23
  175. package/android/src/main/cpp/libyuv/unit_test/unit_test.cc +581 -581
  176. package/android/src/main/cpp/libyuv/unit_test/unit_test.h +232 -232
  177. package/android/src/main/cpp/libyuv/unit_test/video_common_test.cc +112 -112
  178. package/android/src/main/cpp/libyuv/util/Makefile +9 -9
  179. package/android/src/main/cpp/libyuv/util/color.cc +120 -120
  180. package/android/src/main/cpp/libyuv/util/compare.cc +67 -67
  181. package/android/src/main/cpp/libyuv/util/cpuid.c +211 -211
  182. package/android/src/main/cpp/libyuv/util/i444tonv12_eg.cc +27 -27
  183. package/android/src/main/cpp/libyuv/util/psnr.cc +291 -291
  184. package/android/src/main/cpp/libyuv/util/psnr.h +47 -47
  185. package/android/src/main/cpp/libyuv/util/psnr_main.cc +620 -620
  186. package/android/src/main/cpp/libyuv/util/ssim.cc +364 -364
  187. package/android/src/main/cpp/libyuv/util/ssim.h +38 -38
  188. package/android/src/main/cpp/libyuv/util/yuvconstants.c +114 -114
  189. package/android/src/main/cpp/libyuv/util/yuvconvert.cc +367 -367
  190. package/android/src/main/cpp/libyuv/winarm.mk +47 -47
  191. package/index.js +17 -1
  192. package/ios/FaceAntiSpoofFrameProcessor.swift +283 -0
  193. package/ios/FaceAntiSpoofJSI.h +12 -0
  194. package/ios/FaceAntiSpoofJSI.mm +92 -0
  195. package/ios/FaceAntiSpoofManager.swift +63 -0
  196. package/ios/FaceAntiSpoofModule.m +191 -0
  197. package/ios/FaceAntiSpoofPluginRegister.m +42 -0
  198. package/ios/models/FaceAntiSpoofing.tflite +0 -0
  199. package/ios/models/model_spec.json +16 -0
  200. package/package.json +87 -86
  201. package/.gitignore +0 -27
  202. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  203. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  204. package/android/.gradle/8.9/gc.properties +0 -0
  205. /package/android/.gradle/{8.9 → 9.2.0}/fileChanges/last-build.bin +0 -0
  206. /package/android/.gradle/{8.9/dependencies-accessors → 9.2.0}/gc.properties +0 -0
@@ -1,590 +1,590 @@
1
- /*
2
- * Copyright 2011 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/convert_argb.h"
16
- #include "libyuv/cpu_id.h"
17
- #include "libyuv/scale_argb.h"
18
- #include "libyuv/video_common.h"
19
-
20
- namespace libyuv {
21
-
22
- #define STRINGIZE(line) #line
23
- #define FILELINESTR(file, line) file ":" STRINGIZE(line)
24
-
25
- #if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__)
26
- // SLOW TESTS are those that are unoptimized C code.
27
- // FULL TESTS are optimized but test many variations of the same code.
28
- #define ENABLE_FULL_TESTS
29
- #endif
30
-
31
- // Test scaling with C vs Opt and return maximum pixel difference. 0 = exact.
32
- static int ARGBTestFilter(int src_width,
33
- int src_height,
34
- int dst_width,
35
- int dst_height,
36
- FilterMode f,
37
- int benchmark_iterations,
38
- int disable_cpu_flags,
39
- int benchmark_cpu_info) {
40
- if (!SizeValid(src_width, src_height, dst_width, dst_height)) {
41
- return 0;
42
- }
43
-
44
- int i, j;
45
- const int b = 0; // 128 to test for padding/stride.
46
- int64_t src_argb_plane_size =
47
- (Abs(src_width) + b * 2) * (Abs(src_height) + b * 2) * 4LL;
48
- int src_stride_argb = (b * 2 + Abs(src_width)) * 4;
49
-
50
- align_buffer_page_end(src_argb, src_argb_plane_size);
51
- if (!src_argb) {
52
- printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n");
53
- return 0;
54
- }
55
- MemRandomize(src_argb, src_argb_plane_size);
56
-
57
- int64_t dst_argb_plane_size =
58
- (dst_width + b * 2) * (dst_height + b * 2) * 4LL;
59
- int dst_stride_argb = (b * 2 + dst_width) * 4;
60
-
61
- align_buffer_page_end(dst_argb_c, dst_argb_plane_size);
62
- align_buffer_page_end(dst_argb_opt, dst_argb_plane_size);
63
- if (!dst_argb_c || !dst_argb_opt) {
64
- printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n");
65
- return 0;
66
- }
67
- memset(dst_argb_c, 2, dst_argb_plane_size);
68
- memset(dst_argb_opt, 3, dst_argb_plane_size);
69
-
70
- // Warm up both versions for consistent benchmarks.
71
- MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization.
72
- ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb,
73
- src_width, src_height, dst_argb_c + (dst_stride_argb * b) + b * 4,
74
- dst_stride_argb, dst_width, dst_height, f);
75
- MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization.
76
- ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb,
77
- src_width, src_height, dst_argb_opt + (dst_stride_argb * b) + b * 4,
78
- dst_stride_argb, dst_width, dst_height, f);
79
-
80
- MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization.
81
- double c_time = get_time();
82
- ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb,
83
- src_width, src_height, dst_argb_c + (dst_stride_argb * b) + b * 4,
84
- dst_stride_argb, dst_width, dst_height, f);
85
-
86
- c_time = (get_time() - c_time);
87
-
88
- MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization.
89
- double opt_time = get_time();
90
- for (i = 0; i < benchmark_iterations; ++i) {
91
- ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb,
92
- src_width, src_height,
93
- dst_argb_opt + (dst_stride_argb * b) + b * 4, dst_stride_argb,
94
- dst_width, dst_height, f);
95
- }
96
- opt_time = (get_time() - opt_time) / benchmark_iterations;
97
-
98
- // Report performance of C vs OPT
99
- printf("filter %d - %8d us C - %8d us OPT\n", f,
100
- static_cast<int>(c_time * 1e6), static_cast<int>(opt_time * 1e6));
101
-
102
- // C version may be a little off from the optimized. Order of
103
- // operations may introduce rounding somewhere. So do a difference
104
- // of the buffers and look to see that the max difference isn't
105
- // over 2.
106
- int max_diff = 0;
107
- for (i = b; i < (dst_height + b); ++i) {
108
- for (j = b * 4; j < (dst_width + b) * 4; ++j) {
109
- int abs_diff = Abs(dst_argb_c[(i * dst_stride_argb) + j] -
110
- dst_argb_opt[(i * dst_stride_argb) + j]);
111
- if (abs_diff > max_diff) {
112
- max_diff = abs_diff;
113
- }
114
- }
115
- }
116
-
117
- free_aligned_buffer_page_end(dst_argb_c);
118
- free_aligned_buffer_page_end(dst_argb_opt);
119
- free_aligned_buffer_page_end(src_argb);
120
- return max_diff;
121
- }
122
-
123
- static const int kTileX = 64;
124
- static const int kTileY = 64;
125
-
126
- static int TileARGBScale(const uint8_t* src_argb,
127
- int src_stride_argb,
128
- int src_width,
129
- int src_height,
130
- uint8_t* dst_argb,
131
- int dst_stride_argb,
132
- int dst_width,
133
- int dst_height,
134
- FilterMode filtering) {
135
- for (int y = 0; y < dst_height; y += kTileY) {
136
- for (int x = 0; x < dst_width; x += kTileX) {
137
- int clip_width = kTileX;
138
- if (x + clip_width > dst_width) {
139
- clip_width = dst_width - x;
140
- }
141
- int clip_height = kTileY;
142
- if (y + clip_height > dst_height) {
143
- clip_height = dst_height - y;
144
- }
145
- int r = ARGBScaleClip(src_argb, src_stride_argb, src_width, src_height,
146
- dst_argb, dst_stride_argb, dst_width, dst_height, x,
147
- y, clip_width, clip_height, filtering);
148
- if (r) {
149
- return r;
150
- }
151
- }
152
- }
153
- return 0;
154
- }
155
-
156
- static int ARGBClipTestFilter(int src_width,
157
- int src_height,
158
- int dst_width,
159
- int dst_height,
160
- FilterMode f,
161
- int benchmark_iterations) {
162
- if (!SizeValid(src_width, src_height, dst_width, dst_height)) {
163
- return 0;
164
- }
165
-
166
- const int b = 128;
167
- int64_t src_argb_plane_size =
168
- (Abs(src_width) + b * 2) * (Abs(src_height) + b * 2) * 4;
169
- int src_stride_argb = (b * 2 + Abs(src_width)) * 4;
170
-
171
- align_buffer_page_end(src_argb, src_argb_plane_size);
172
- if (!src_argb) {
173
- printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n");
174
- return 0;
175
- }
176
- memset(src_argb, 1, src_argb_plane_size);
177
-
178
- int64_t dst_argb_plane_size = (dst_width + b * 2) * (dst_height + b * 2) * 4;
179
- int dst_stride_argb = (b * 2 + dst_width) * 4;
180
-
181
- int i, j;
182
- for (i = b; i < (Abs(src_height) + b); ++i) {
183
- for (j = b; j < (Abs(src_width) + b) * 4; ++j) {
184
- src_argb[(i * src_stride_argb) + j] = (fastrand() & 0xff);
185
- }
186
- }
187
-
188
- align_buffer_page_end(dst_argb_c, dst_argb_plane_size);
189
- align_buffer_page_end(dst_argb_opt, dst_argb_plane_size);
190
- if (!dst_argb_c || !dst_argb_opt) {
191
- printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n");
192
- return 0;
193
- }
194
- memset(dst_argb_c, 2, dst_argb_plane_size);
195
- memset(dst_argb_opt, 3, dst_argb_plane_size);
196
-
197
- // Do full image, no clipping.
198
- double c_time = get_time();
199
- ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb,
200
- src_width, src_height, dst_argb_c + (dst_stride_argb * b) + b * 4,
201
- dst_stride_argb, dst_width, dst_height, f);
202
- c_time = (get_time() - c_time);
203
-
204
- // Do tiled image, clipping scale to a tile at a time.
205
- double opt_time = get_time();
206
- for (i = 0; i < benchmark_iterations; ++i) {
207
- TileARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb,
208
- src_width, src_height,
209
- dst_argb_opt + (dst_stride_argb * b) + b * 4, dst_stride_argb,
210
- dst_width, dst_height, f);
211
- }
212
- opt_time = (get_time() - opt_time) / benchmark_iterations;
213
-
214
- // Report performance of Full vs Tiled.
215
- printf("filter %d - %8d us Full - %8d us Tiled\n", f,
216
- static_cast<int>(c_time * 1e6), static_cast<int>(opt_time * 1e6));
217
-
218
- // Compare full scaled image vs tiled image.
219
- int max_diff = 0;
220
- for (i = b; i < (dst_height + b); ++i) {
221
- for (j = b * 4; j < (dst_width + b) * 4; ++j) {
222
- int abs_diff = Abs(dst_argb_c[(i * dst_stride_argb) + j] -
223
- dst_argb_opt[(i * dst_stride_argb) + j]);
224
- if (abs_diff > max_diff) {
225
- max_diff = abs_diff;
226
- }
227
- }
228
- }
229
-
230
- free_aligned_buffer_page_end(dst_argb_c);
231
- free_aligned_buffer_page_end(dst_argb_opt);
232
- free_aligned_buffer_page_end(src_argb);
233
- return max_diff;
234
- }
235
-
236
- // The following adjustments in dimensions ensure the scale factor will be
237
- // exactly achieved.
238
- #define DX(x, nom, denom) static_cast<int>((Abs(x) / nom) * nom)
239
- #define SX(x, nom, denom) static_cast<int>((x / nom) * denom)
240
-
241
- #define TEST_FACTOR1(DISABLED_, name, filter, nom, denom, max_diff) \
242
- TEST_F(LibYUVScaleTest, ARGBScaleDownBy##name##_##filter) { \
243
- int diff = ARGBTestFilter( \
244
- SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \
245
- DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \
246
- kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \
247
- benchmark_cpu_info_); \
248
- EXPECT_LE(diff, max_diff); \
249
- } \
250
- TEST_F(LibYUVScaleTest, DISABLED_##ARGBScaleDownClipBy##name##_##filter) { \
251
- int diff = ARGBClipTestFilter( \
252
- SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \
253
- DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \
254
- kFilter##filter, benchmark_iterations_); \
255
- EXPECT_LE(diff, max_diff); \
256
- }
257
-
258
- // Test a scale factor with all 4 filters. Expect unfiltered to be exact, but
259
- // filtering is different fixed point implementations for SSSE3, Neon and C.
260
- #ifndef DISABLE_SLOW_TESTS
261
- #define TEST_FACTOR(name, nom, denom) \
262
- TEST_FACTOR1(, name, None, nom, denom, 0) \
263
- TEST_FACTOR1(, name, Linear, nom, denom, 3) \
264
- TEST_FACTOR1(, name, Bilinear, nom, denom, 3) \
265
- TEST_FACTOR1(, name, Box, nom, denom, 3)
266
- #else
267
- #if defined(ENABLE_FULL_TESTS)
268
- #define TEST_FACTOR(name, nom, denom) \
269
- TEST_FACTOR1(DISABLED_, name, None, nom, denom, 0) \
270
- TEST_FACTOR1(DISABLED_, name, Linear, nom, denom, 3) \
271
- TEST_FACTOR1(DISABLED_, name, Bilinear, nom, denom, 3) \
272
- TEST_FACTOR1(DISABLED_, name, Box, nom, denom, 3)
273
- #else
274
- #define TEST_FACTOR(name, nom, denom) \
275
- TEST_FACTOR1(DISABLED_, name, Bilinear, nom, denom, 3)
276
- #endif
277
- #endif
278
-
279
- TEST_FACTOR(2, 1, 2)
280
- TEST_FACTOR(4, 1, 4)
281
- #ifndef DISABLE_SLOW_TESTS
282
- TEST_FACTOR(8, 1, 8)
283
- #endif
284
- TEST_FACTOR(3by4, 3, 4)
285
- TEST_FACTOR(3by8, 3, 8)
286
- TEST_FACTOR(3, 1, 3)
287
- #undef TEST_FACTOR1
288
- #undef TEST_FACTOR
289
- #undef SX
290
- #undef DX
291
-
292
- #define TEST_SCALETO1(DISABLED_, name, width, height, filter, max_diff) \
293
- TEST_F(LibYUVScaleTest, name##To##width##x##height##_##filter) { \
294
- int diff = ARGBTestFilter(benchmark_width_, benchmark_height_, width, \
295
- height, kFilter##filter, benchmark_iterations_, \
296
- disable_cpu_flags_, benchmark_cpu_info_); \
297
- EXPECT_LE(diff, max_diff); \
298
- } \
299
- TEST_F(LibYUVScaleTest, name##From##width##x##height##_##filter) { \
300
- int diff = ARGBTestFilter(width, height, Abs(benchmark_width_), \
301
- Abs(benchmark_height_), kFilter##filter, \
302
- benchmark_iterations_, disable_cpu_flags_, \
303
- benchmark_cpu_info_); \
304
- EXPECT_LE(diff, max_diff); \
305
- } \
306
- TEST_F(LibYUVScaleTest, \
307
- DISABLED_##name##ClipTo##width##x##height##_##filter) { \
308
- int diff = \
309
- ARGBClipTestFilter(benchmark_width_, benchmark_height_, width, height, \
310
- kFilter##filter, benchmark_iterations_); \
311
- EXPECT_LE(diff, max_diff); \
312
- } \
313
- TEST_F(LibYUVScaleTest, \
314
- DISABLED_##name##ClipFrom##width##x##height##_##filter) { \
315
- int diff = ARGBClipTestFilter(width, height, Abs(benchmark_width_), \
316
- Abs(benchmark_height_), kFilter##filter, \
317
- benchmark_iterations_); \
318
- EXPECT_LE(diff, max_diff); \
319
- }
320
-
321
- #ifndef DISABLE_SLOW_TESTS
322
- // Test scale to a specified size with all 4 filters.
323
- #define TEST_SCALETO(name, width, height) \
324
- TEST_SCALETO1(, name, width, height, None, 0) \
325
- TEST_SCALETO1(, name, width, height, Linear, 3) \
326
- TEST_SCALETO1(, name, width, height, Bilinear, 3) \
327
- TEST_SCALETO1(, name, width, height, Box, 3)
328
- #else
329
- #if defined(ENABLE_FULL_TESTS)
330
- #define TEST_SCALETO(name, width, height) \
331
- TEST_SCALETO1(DISABLED_, name, width, height, None, 0) \
332
- TEST_SCALETO1(DISABLED_, name, width, height, Linear, 3) \
333
- TEST_SCALETO1(DISABLED_, name, width, height, Bilinear, 3) \
334
- TEST_SCALETO1(DISABLED_, name, width, height, Box, 3)
335
- #else
336
- #define TEST_SCALETO(name, width, height) \
337
- TEST_SCALETO1(DISABLED_, name, width, height, Bilinear, 3)
338
- #endif
339
- #endif
340
-
341
- TEST_SCALETO(ARGBScale, 1, 1)
342
- TEST_SCALETO(ARGBScale, 569, 480)
343
- TEST_SCALETO(ARGBScale, 640, 360)
344
- #ifndef DISABLE_SLOW_TESTS
345
- TEST_SCALETO(ARGBScale, 50, 1)
346
- TEST_SCALETO(ARGBScale, 256, 144) /* 128x72 * 2 */
347
- TEST_SCALETO(ARGBScale, 320, 240)
348
- TEST_SCALETO(ARGBScale, 1280, 720)
349
- TEST_SCALETO(ARGBScale, 1920, 1080)
350
- #endif // DISABLE_SLOW_TESTS
351
- #undef TEST_SCALETO1
352
- #undef TEST_SCALETO
353
-
354
- #define TEST_SCALESWAPXY1(name, filter, max_diff) \
355
- TEST_F(LibYUVScaleTest, name##SwapXY_##filter) { \
356
- int diff = ARGBTestFilter(benchmark_width_, benchmark_height_, \
357
- benchmark_height_, benchmark_width_, \
358
- kFilter##filter, benchmark_iterations_, \
359
- disable_cpu_flags_, benchmark_cpu_info_); \
360
- EXPECT_LE(diff, max_diff); \
361
- }
362
-
363
- #if defined(ENABLE_FULL_TESTS)
364
- // Test scale with swapped width and height with all 3 filters.
365
- TEST_SCALESWAPXY1(ARGBScale, None, 0)
366
- TEST_SCALESWAPXY1(ARGBScale, Linear, 0)
367
- TEST_SCALESWAPXY1(ARGBScale, Bilinear, 0)
368
- #else
369
- TEST_SCALESWAPXY1(ARGBScale, Bilinear, 0)
370
- #endif
371
- #undef TEST_SCALESWAPXY1
372
-
373
- // Scale with YUV conversion to ARGB and clipping.
374
- // TODO(fbarchard): Add fourcc support. All 4 ARGB formats is easy to support.
375
- static int YUVToARGBScaleReference2(const uint8_t* src_y,
376
- int src_stride_y,
377
- const uint8_t* src_u,
378
- int src_stride_u,
379
- const uint8_t* src_v,
380
- int src_stride_v,
381
- uint32_t /* src_fourcc */,
382
- int src_width,
383
- int src_height,
384
- uint8_t* dst_argb,
385
- int dst_stride_argb,
386
- uint32_t /* dst_fourcc */,
387
- int dst_width,
388
- int dst_height,
389
- int clip_x,
390
- int clip_y,
391
- int clip_width,
392
- int clip_height,
393
- enum FilterMode filtering) {
394
- uint8_t* argb_buffer =
395
- static_cast<uint8_t*>(malloc(src_width * src_height * 4));
396
- int r;
397
- I420ToARGB(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
398
- argb_buffer, src_width * 4, src_width, src_height);
399
-
400
- r = ARGBScaleClip(argb_buffer, src_width * 4, src_width, src_height, dst_argb,
401
- dst_stride_argb, dst_width, dst_height, clip_x, clip_y,
402
- clip_width, clip_height, filtering);
403
- free(argb_buffer);
404
- return r;
405
- }
406
-
407
- static void FillRamp(uint8_t* buf,
408
- int width,
409
- int height,
410
- int v,
411
- int dx,
412
- int dy) {
413
- int rv = v;
414
- for (int y = 0; y < height; ++y) {
415
- for (int x = 0; x < width; ++x) {
416
- *buf++ = v;
417
- v += dx;
418
- if (v < 0 || v > 255) {
419
- dx = -dx;
420
- v += dx;
421
- }
422
- }
423
- v = rv + dy;
424
- if (v < 0 || v > 255) {
425
- dy = -dy;
426
- v += dy;
427
- }
428
- rv = v;
429
- }
430
- }
431
-
432
- // Test scaling with C vs Opt and return maximum pixel difference. 0 = exact.
433
- static int YUVToARGBTestFilter(int src_width,
434
- int src_height,
435
- int dst_width,
436
- int dst_height,
437
- FilterMode f,
438
- int benchmark_iterations) {
439
- int64_t src_y_plane_size = Abs(src_width) * Abs(src_height);
440
- int64_t src_uv_plane_size =
441
- ((Abs(src_width) + 1) / 2) * ((Abs(src_height) + 1) / 2);
442
- int src_stride_y = Abs(src_width);
443
- int src_stride_uv = (Abs(src_width) + 1) / 2;
444
-
445
- align_buffer_page_end(src_y, src_y_plane_size);
446
- align_buffer_page_end(src_u, src_uv_plane_size);
447
- align_buffer_page_end(src_v, src_uv_plane_size);
448
-
449
- int64_t dst_argb_plane_size = (dst_width) * (dst_height)*4LL;
450
- int dst_stride_argb = (dst_width)*4;
451
- align_buffer_page_end(dst_argb_c, dst_argb_plane_size);
452
- align_buffer_page_end(dst_argb_opt, dst_argb_plane_size);
453
- if (!dst_argb_c || !dst_argb_opt || !src_y || !src_u || !src_v) {
454
- printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n");
455
- return 0;
456
- }
457
- // Fill YUV image with continuous ramp, which is less sensitive to
458
- // subsampling and filtering differences for test purposes.
459
- FillRamp(src_y, Abs(src_width), Abs(src_height), 128, 1, 1);
460
- FillRamp(src_u, (Abs(src_width) + 1) / 2, (Abs(src_height) + 1) / 2, 3, 1, 1);
461
- FillRamp(src_v, (Abs(src_width) + 1) / 2, (Abs(src_height) + 1) / 2, 4, 1, 1);
462
- memset(dst_argb_c, 2, dst_argb_plane_size);
463
- memset(dst_argb_opt, 3, dst_argb_plane_size);
464
-
465
- YUVToARGBScaleReference2(src_y, src_stride_y, src_u, src_stride_uv, src_v,
466
- src_stride_uv, libyuv::FOURCC_I420, src_width,
467
- src_height, dst_argb_c, dst_stride_argb,
468
- libyuv::FOURCC_I420, dst_width, dst_height, 0, 0,
469
- dst_width, dst_height, f);
470
-
471
- for (int i = 0; i < benchmark_iterations; ++i) {
472
- YUVToARGBScaleClip(src_y, src_stride_y, src_u, src_stride_uv, src_v,
473
- src_stride_uv, libyuv::FOURCC_I420, src_width,
474
- src_height, dst_argb_opt, dst_stride_argb,
475
- libyuv::FOURCC_I420, dst_width, dst_height, 0, 0,
476
- dst_width, dst_height, f);
477
- }
478
- int max_diff = 0;
479
- for (int i = 0; i < dst_height; ++i) {
480
- for (int j = 0; j < dst_width * 4; ++j) {
481
- int abs_diff = Abs(dst_argb_c[(i * dst_stride_argb) + j] -
482
- dst_argb_opt[(i * dst_stride_argb) + j]);
483
- if (abs_diff > max_diff) {
484
- printf("error %d at %d,%d c %d opt %d", abs_diff, j, i,
485
- dst_argb_c[(i * dst_stride_argb) + j],
486
- dst_argb_opt[(i * dst_stride_argb) + j]);
487
- EXPECT_LE(abs_diff, 40);
488
- max_diff = abs_diff;
489
- }
490
- }
491
- }
492
-
493
- free_aligned_buffer_page_end(dst_argb_c);
494
- free_aligned_buffer_page_end(dst_argb_opt);
495
- free_aligned_buffer_page_end(src_y);
496
- free_aligned_buffer_page_end(src_u);
497
- free_aligned_buffer_page_end(src_v);
498
- return max_diff;
499
- }
500
-
501
- TEST_F(LibYUVScaleTest, YUVToRGBScaleUp) {
502
- int diff =
503
- YUVToARGBTestFilter(benchmark_width_, benchmark_height_,
504
- benchmark_width_ * 3 / 2, benchmark_height_ * 3 / 2,
505
- libyuv::kFilterBilinear, benchmark_iterations_);
506
- EXPECT_LE(diff, 10);
507
- }
508
-
509
- TEST_F(LibYUVScaleTest, YUVToRGBScaleDown) {
510
- int diff = YUVToARGBTestFilter(
511
- benchmark_width_ * 3 / 2, benchmark_height_ * 3 / 2, benchmark_width_,
512
- benchmark_height_, libyuv::kFilterBilinear, benchmark_iterations_);
513
- EXPECT_LE(diff, 10);
514
- }
515
-
516
- TEST_F(LibYUVScaleTest, ARGBTest3x) {
517
- const int kSrcStride = 480 * 4;
518
- const int kDstStride = 160 * 4;
519
- const int kSize = kSrcStride * 3;
520
- align_buffer_page_end(orig_pixels, kSize);
521
- for (int i = 0; i < 480 * 3; ++i) {
522
- orig_pixels[i * 4 + 0] = i;
523
- orig_pixels[i * 4 + 1] = 255 - i;
524
- orig_pixels[i * 4 + 2] = i + 1;
525
- orig_pixels[i * 4 + 3] = i + 10;
526
- }
527
- align_buffer_page_end(dest_pixels, kDstStride);
528
-
529
- int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 *
530
- benchmark_iterations_;
531
- for (int i = 0; i < iterations160; ++i) {
532
- ARGBScale(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1,
533
- kFilterBilinear);
534
- }
535
-
536
- EXPECT_EQ(225, dest_pixels[0]);
537
- EXPECT_EQ(255 - 225, dest_pixels[1]);
538
- EXPECT_EQ(226, dest_pixels[2]);
539
- EXPECT_EQ(235, dest_pixels[3]);
540
-
541
- ARGBScale(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1,
542
- kFilterNone);
543
-
544
- EXPECT_EQ(225, dest_pixels[0]);
545
- EXPECT_EQ(255 - 225, dest_pixels[1]);
546
- EXPECT_EQ(226, dest_pixels[2]);
547
- EXPECT_EQ(235, dest_pixels[3]);
548
-
549
- free_aligned_buffer_page_end(dest_pixels);
550
- free_aligned_buffer_page_end(orig_pixels);
551
- }
552
-
553
- TEST_F(LibYUVScaleTest, ARGBTest4x) {
554
- const int kSrcStride = 640 * 4;
555
- const int kDstStride = 160 * 4;
556
- const int kSize = kSrcStride * 4;
557
- align_buffer_page_end(orig_pixels, kSize);
558
- for (int i = 0; i < 640 * 4; ++i) {
559
- orig_pixels[i * 4 + 0] = i;
560
- orig_pixels[i * 4 + 1] = 255 - i;
561
- orig_pixels[i * 4 + 2] = i + 1;
562
- orig_pixels[i * 4 + 3] = i + 10;
563
- }
564
- align_buffer_page_end(dest_pixels, kDstStride);
565
-
566
- int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 *
567
- benchmark_iterations_;
568
- for (int i = 0; i < iterations160; ++i) {
569
- ARGBScale(orig_pixels, kSrcStride, 640, 4, dest_pixels, kDstStride, 160, 1,
570
- kFilterBilinear);
571
- }
572
-
573
- EXPECT_NEAR(66, dest_pixels[0], 4);
574
- EXPECT_NEAR(255 - 66, dest_pixels[1], 4);
575
- EXPECT_NEAR(67, dest_pixels[2], 4);
576
- EXPECT_NEAR(76, dest_pixels[3], 4);
577
-
578
- ARGBScale(orig_pixels, kSrcStride, 640, 4, dest_pixels, kDstStride, 160, 1,
579
- kFilterNone);
580
-
581
- EXPECT_EQ(2, dest_pixels[0]);
582
- EXPECT_EQ(255 - 2, dest_pixels[1]);
583
- EXPECT_EQ(3, dest_pixels[2]);
584
- EXPECT_EQ(12, dest_pixels[3]);
585
-
586
- free_aligned_buffer_page_end(dest_pixels);
587
- free_aligned_buffer_page_end(orig_pixels);
588
- }
589
-
590
- } // namespace libyuv
1
+ /*
2
+ * Copyright 2011 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/convert_argb.h"
16
+ #include "libyuv/cpu_id.h"
17
+ #include "libyuv/scale_argb.h"
18
+ #include "libyuv/video_common.h"
19
+
20
+ namespace libyuv {
21
+
22
+ #define STRINGIZE(line) #line
23
+ #define FILELINESTR(file, line) file ":" STRINGIZE(line)
24
+
25
+ #if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__)
26
+ // SLOW TESTS are those that are unoptimized C code.
27
+ // FULL TESTS are optimized but test many variations of the same code.
28
+ #define ENABLE_FULL_TESTS
29
+ #endif
30
+
31
+ // Test scaling with C vs Opt and return maximum pixel difference. 0 = exact.
32
+ static int ARGBTestFilter(int src_width,
33
+ int src_height,
34
+ int dst_width,
35
+ int dst_height,
36
+ FilterMode f,
37
+ int benchmark_iterations,
38
+ int disable_cpu_flags,
39
+ int benchmark_cpu_info) {
40
+ if (!SizeValid(src_width, src_height, dst_width, dst_height)) {
41
+ return 0;
42
+ }
43
+
44
+ int i, j;
45
+ const int b = 0; // 128 to test for padding/stride.
46
+ int64_t src_argb_plane_size =
47
+ (Abs(src_width) + b * 2) * (Abs(src_height) + b * 2) * 4LL;
48
+ int src_stride_argb = (b * 2 + Abs(src_width)) * 4;
49
+
50
+ align_buffer_page_end(src_argb, src_argb_plane_size);
51
+ if (!src_argb) {
52
+ printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n");
53
+ return 0;
54
+ }
55
+ MemRandomize(src_argb, src_argb_plane_size);
56
+
57
+ int64_t dst_argb_plane_size =
58
+ (dst_width + b * 2) * (dst_height + b * 2) * 4LL;
59
+ int dst_stride_argb = (b * 2 + dst_width) * 4;
60
+
61
+ align_buffer_page_end(dst_argb_c, dst_argb_plane_size);
62
+ align_buffer_page_end(dst_argb_opt, dst_argb_plane_size);
63
+ if (!dst_argb_c || !dst_argb_opt) {
64
+ printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n");
65
+ return 0;
66
+ }
67
+ memset(dst_argb_c, 2, dst_argb_plane_size);
68
+ memset(dst_argb_opt, 3, dst_argb_plane_size);
69
+
70
+ // Warm up both versions for consistent benchmarks.
71
+ MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization.
72
+ ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb,
73
+ src_width, src_height, dst_argb_c + (dst_stride_argb * b) + b * 4,
74
+ dst_stride_argb, dst_width, dst_height, f);
75
+ MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization.
76
+ ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb,
77
+ src_width, src_height, dst_argb_opt + (dst_stride_argb * b) + b * 4,
78
+ dst_stride_argb, dst_width, dst_height, f);
79
+
80
+ MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization.
81
+ double c_time = get_time();
82
+ ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb,
83
+ src_width, src_height, dst_argb_c + (dst_stride_argb * b) + b * 4,
84
+ dst_stride_argb, dst_width, dst_height, f);
85
+
86
+ c_time = (get_time() - c_time);
87
+
88
+ MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization.
89
+ double opt_time = get_time();
90
+ for (i = 0; i < benchmark_iterations; ++i) {
91
+ ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb,
92
+ src_width, src_height,
93
+ dst_argb_opt + (dst_stride_argb * b) + b * 4, dst_stride_argb,
94
+ dst_width, dst_height, f);
95
+ }
96
+ opt_time = (get_time() - opt_time) / benchmark_iterations;
97
+
98
+ // Report performance of C vs OPT
99
+ printf("filter %d - %8d us C - %8d us OPT\n", f,
100
+ static_cast<int>(c_time * 1e6), static_cast<int>(opt_time * 1e6));
101
+
102
+ // C version may be a little off from the optimized. Order of
103
+ // operations may introduce rounding somewhere. So do a difference
104
+ // of the buffers and look to see that the max difference isn't
105
+ // over 2.
106
+ int max_diff = 0;
107
+ for (i = b; i < (dst_height + b); ++i) {
108
+ for (j = b * 4; j < (dst_width + b) * 4; ++j) {
109
+ int abs_diff = Abs(dst_argb_c[(i * dst_stride_argb) + j] -
110
+ dst_argb_opt[(i * dst_stride_argb) + j]);
111
+ if (abs_diff > max_diff) {
112
+ max_diff = abs_diff;
113
+ }
114
+ }
115
+ }
116
+
117
+ free_aligned_buffer_page_end(dst_argb_c);
118
+ free_aligned_buffer_page_end(dst_argb_opt);
119
+ free_aligned_buffer_page_end(src_argb);
120
+ return max_diff;
121
+ }
122
+
123
+ static const int kTileX = 64;
124
+ static const int kTileY = 64;
125
+
126
+ static int TileARGBScale(const uint8_t* src_argb,
127
+ int src_stride_argb,
128
+ int src_width,
129
+ int src_height,
130
+ uint8_t* dst_argb,
131
+ int dst_stride_argb,
132
+ int dst_width,
133
+ int dst_height,
134
+ FilterMode filtering) {
135
+ for (int y = 0; y < dst_height; y += kTileY) {
136
+ for (int x = 0; x < dst_width; x += kTileX) {
137
+ int clip_width = kTileX;
138
+ if (x + clip_width > dst_width) {
139
+ clip_width = dst_width - x;
140
+ }
141
+ int clip_height = kTileY;
142
+ if (y + clip_height > dst_height) {
143
+ clip_height = dst_height - y;
144
+ }
145
+ int r = ARGBScaleClip(src_argb, src_stride_argb, src_width, src_height,
146
+ dst_argb, dst_stride_argb, dst_width, dst_height, x,
147
+ y, clip_width, clip_height, filtering);
148
+ if (r) {
149
+ return r;
150
+ }
151
+ }
152
+ }
153
+ return 0;
154
+ }
155
+
156
+ static int ARGBClipTestFilter(int src_width,
157
+ int src_height,
158
+ int dst_width,
159
+ int dst_height,
160
+ FilterMode f,
161
+ int benchmark_iterations) {
162
+ if (!SizeValid(src_width, src_height, dst_width, dst_height)) {
163
+ return 0;
164
+ }
165
+
166
+ const int b = 128;
167
+ int64_t src_argb_plane_size =
168
+ (Abs(src_width) + b * 2) * (Abs(src_height) + b * 2) * 4;
169
+ int src_stride_argb = (b * 2 + Abs(src_width)) * 4;
170
+
171
+ align_buffer_page_end(src_argb, src_argb_plane_size);
172
+ if (!src_argb) {
173
+ printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n");
174
+ return 0;
175
+ }
176
+ memset(src_argb, 1, src_argb_plane_size);
177
+
178
+ int64_t dst_argb_plane_size = (dst_width + b * 2) * (dst_height + b * 2) * 4;
179
+ int dst_stride_argb = (b * 2 + dst_width) * 4;
180
+
181
+ int i, j;
182
+ for (i = b; i < (Abs(src_height) + b); ++i) {
183
+ for (j = b; j < (Abs(src_width) + b) * 4; ++j) {
184
+ src_argb[(i * src_stride_argb) + j] = (fastrand() & 0xff);
185
+ }
186
+ }
187
+
188
+ align_buffer_page_end(dst_argb_c, dst_argb_plane_size);
189
+ align_buffer_page_end(dst_argb_opt, dst_argb_plane_size);
190
+ if (!dst_argb_c || !dst_argb_opt) {
191
+ printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n");
192
+ return 0;
193
+ }
194
+ memset(dst_argb_c, 2, dst_argb_plane_size);
195
+ memset(dst_argb_opt, 3, dst_argb_plane_size);
196
+
197
+ // Do full image, no clipping.
198
+ double c_time = get_time();
199
+ ARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb,
200
+ src_width, src_height, dst_argb_c + (dst_stride_argb * b) + b * 4,
201
+ dst_stride_argb, dst_width, dst_height, f);
202
+ c_time = (get_time() - c_time);
203
+
204
+ // Do tiled image, clipping scale to a tile at a time.
205
+ double opt_time = get_time();
206
+ for (i = 0; i < benchmark_iterations; ++i) {
207
+ TileARGBScale(src_argb + (src_stride_argb * b) + b * 4, src_stride_argb,
208
+ src_width, src_height,
209
+ dst_argb_opt + (dst_stride_argb * b) + b * 4, dst_stride_argb,
210
+ dst_width, dst_height, f);
211
+ }
212
+ opt_time = (get_time() - opt_time) / benchmark_iterations;
213
+
214
+ // Report performance of Full vs Tiled.
215
+ printf("filter %d - %8d us Full - %8d us Tiled\n", f,
216
+ static_cast<int>(c_time * 1e6), static_cast<int>(opt_time * 1e6));
217
+
218
+ // Compare full scaled image vs tiled image.
219
+ int max_diff = 0;
220
+ for (i = b; i < (dst_height + b); ++i) {
221
+ for (j = b * 4; j < (dst_width + b) * 4; ++j) {
222
+ int abs_diff = Abs(dst_argb_c[(i * dst_stride_argb) + j] -
223
+ dst_argb_opt[(i * dst_stride_argb) + j]);
224
+ if (abs_diff > max_diff) {
225
+ max_diff = abs_diff;
226
+ }
227
+ }
228
+ }
229
+
230
+ free_aligned_buffer_page_end(dst_argb_c);
231
+ free_aligned_buffer_page_end(dst_argb_opt);
232
+ free_aligned_buffer_page_end(src_argb);
233
+ return max_diff;
234
+ }
235
+
236
+ // The following adjustments in dimensions ensure the scale factor will be
237
+ // exactly achieved.
238
+ #define DX(x, nom, denom) static_cast<int>((Abs(x) / nom) * nom)
239
+ #define SX(x, nom, denom) static_cast<int>((x / nom) * denom)
240
+
241
+ #define TEST_FACTOR1(DISABLED_, name, filter, nom, denom, max_diff) \
242
+ TEST_F(LibYUVScaleTest, ARGBScaleDownBy##name##_##filter) { \
243
+ int diff = ARGBTestFilter( \
244
+ SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \
245
+ DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \
246
+ kFilter##filter, benchmark_iterations_, disable_cpu_flags_, \
247
+ benchmark_cpu_info_); \
248
+ EXPECT_LE(diff, max_diff); \
249
+ } \
250
+ TEST_F(LibYUVScaleTest, DISABLED_##ARGBScaleDownClipBy##name##_##filter) { \
251
+ int diff = ARGBClipTestFilter( \
252
+ SX(benchmark_width_, nom, denom), SX(benchmark_height_, nom, denom), \
253
+ DX(benchmark_width_, nom, denom), DX(benchmark_height_, nom, denom), \
254
+ kFilter##filter, benchmark_iterations_); \
255
+ EXPECT_LE(diff, max_diff); \
256
+ }
257
+
258
+ // Test a scale factor with all 4 filters. Expect unfiltered to be exact, but
259
+ // filtering is different fixed point implementations for SSSE3, Neon and C.
260
+ #ifndef DISABLE_SLOW_TESTS
261
+ #define TEST_FACTOR(name, nom, denom) \
262
+ TEST_FACTOR1(, name, None, nom, denom, 0) \
263
+ TEST_FACTOR1(, name, Linear, nom, denom, 3) \
264
+ TEST_FACTOR1(, name, Bilinear, nom, denom, 3) \
265
+ TEST_FACTOR1(, name, Box, nom, denom, 3)
266
+ #else
267
+ #if defined(ENABLE_FULL_TESTS)
268
+ #define TEST_FACTOR(name, nom, denom) \
269
+ TEST_FACTOR1(DISABLED_, name, None, nom, denom, 0) \
270
+ TEST_FACTOR1(DISABLED_, name, Linear, nom, denom, 3) \
271
+ TEST_FACTOR1(DISABLED_, name, Bilinear, nom, denom, 3) \
272
+ TEST_FACTOR1(DISABLED_, name, Box, nom, denom, 3)
273
+ #else
274
+ #define TEST_FACTOR(name, nom, denom) \
275
+ TEST_FACTOR1(DISABLED_, name, Bilinear, nom, denom, 3)
276
+ #endif
277
+ #endif
278
+
279
+ TEST_FACTOR(2, 1, 2)
280
+ TEST_FACTOR(4, 1, 4)
281
+ #ifndef DISABLE_SLOW_TESTS
282
+ TEST_FACTOR(8, 1, 8)
283
+ #endif
284
+ TEST_FACTOR(3by4, 3, 4)
285
+ TEST_FACTOR(3by8, 3, 8)
286
+ TEST_FACTOR(3, 1, 3)
287
+ #undef TEST_FACTOR1
288
+ #undef TEST_FACTOR
289
+ #undef SX
290
+ #undef DX
291
+
292
+ #define TEST_SCALETO1(DISABLED_, name, width, height, filter, max_diff) \
293
+ TEST_F(LibYUVScaleTest, name##To##width##x##height##_##filter) { \
294
+ int diff = ARGBTestFilter(benchmark_width_, benchmark_height_, width, \
295
+ height, kFilter##filter, benchmark_iterations_, \
296
+ disable_cpu_flags_, benchmark_cpu_info_); \
297
+ EXPECT_LE(diff, max_diff); \
298
+ } \
299
+ TEST_F(LibYUVScaleTest, name##From##width##x##height##_##filter) { \
300
+ int diff = ARGBTestFilter(width, height, Abs(benchmark_width_), \
301
+ Abs(benchmark_height_), kFilter##filter, \
302
+ benchmark_iterations_, disable_cpu_flags_, \
303
+ benchmark_cpu_info_); \
304
+ EXPECT_LE(diff, max_diff); \
305
+ } \
306
+ TEST_F(LibYUVScaleTest, \
307
+ DISABLED_##name##ClipTo##width##x##height##_##filter) { \
308
+ int diff = \
309
+ ARGBClipTestFilter(benchmark_width_, benchmark_height_, width, height, \
310
+ kFilter##filter, benchmark_iterations_); \
311
+ EXPECT_LE(diff, max_diff); \
312
+ } \
313
+ TEST_F(LibYUVScaleTest, \
314
+ DISABLED_##name##ClipFrom##width##x##height##_##filter) { \
315
+ int diff = ARGBClipTestFilter(width, height, Abs(benchmark_width_), \
316
+ Abs(benchmark_height_), kFilter##filter, \
317
+ benchmark_iterations_); \
318
+ EXPECT_LE(diff, max_diff); \
319
+ }
320
+
321
+ #ifndef DISABLE_SLOW_TESTS
322
+ // Test scale to a specified size with all 4 filters.
323
+ #define TEST_SCALETO(name, width, height) \
324
+ TEST_SCALETO1(, name, width, height, None, 0) \
325
+ TEST_SCALETO1(, name, width, height, Linear, 3) \
326
+ TEST_SCALETO1(, name, width, height, Bilinear, 3) \
327
+ TEST_SCALETO1(, name, width, height, Box, 3)
328
+ #else
329
+ #if defined(ENABLE_FULL_TESTS)
330
+ #define TEST_SCALETO(name, width, height) \
331
+ TEST_SCALETO1(DISABLED_, name, width, height, None, 0) \
332
+ TEST_SCALETO1(DISABLED_, name, width, height, Linear, 3) \
333
+ TEST_SCALETO1(DISABLED_, name, width, height, Bilinear, 3) \
334
+ TEST_SCALETO1(DISABLED_, name, width, height, Box, 3)
335
+ #else
336
+ #define TEST_SCALETO(name, width, height) \
337
+ TEST_SCALETO1(DISABLED_, name, width, height, Bilinear, 3)
338
+ #endif
339
+ #endif
340
+
341
+ TEST_SCALETO(ARGBScale, 1, 1)
342
+ TEST_SCALETO(ARGBScale, 569, 480)
343
+ TEST_SCALETO(ARGBScale, 640, 360)
344
+ #ifndef DISABLE_SLOW_TESTS
345
+ TEST_SCALETO(ARGBScale, 50, 1)
346
+ TEST_SCALETO(ARGBScale, 256, 144) /* 128x72 * 2 */
347
+ TEST_SCALETO(ARGBScale, 320, 240)
348
+ TEST_SCALETO(ARGBScale, 1280, 720)
349
+ TEST_SCALETO(ARGBScale, 1920, 1080)
350
+ #endif // DISABLE_SLOW_TESTS
351
+ #undef TEST_SCALETO1
352
+ #undef TEST_SCALETO
353
+
354
+ #define TEST_SCALESWAPXY1(name, filter, max_diff) \
355
+ TEST_F(LibYUVScaleTest, name##SwapXY_##filter) { \
356
+ int diff = ARGBTestFilter(benchmark_width_, benchmark_height_, \
357
+ benchmark_height_, benchmark_width_, \
358
+ kFilter##filter, benchmark_iterations_, \
359
+ disable_cpu_flags_, benchmark_cpu_info_); \
360
+ EXPECT_LE(diff, max_diff); \
361
+ }
362
+
363
+ #if defined(ENABLE_FULL_TESTS)
364
+ // Test scale with swapped width and height with all 3 filters.
365
+ TEST_SCALESWAPXY1(ARGBScale, None, 0)
366
+ TEST_SCALESWAPXY1(ARGBScale, Linear, 0)
367
+ TEST_SCALESWAPXY1(ARGBScale, Bilinear, 0)
368
+ #else
369
+ TEST_SCALESWAPXY1(ARGBScale, Bilinear, 0)
370
+ #endif
371
+ #undef TEST_SCALESWAPXY1
372
+
373
+ // Scale with YUV conversion to ARGB and clipping.
374
+ // TODO(fbarchard): Add fourcc support. All 4 ARGB formats is easy to support.
375
+ static int YUVToARGBScaleReference2(const uint8_t* src_y,
376
+ int src_stride_y,
377
+ const uint8_t* src_u,
378
+ int src_stride_u,
379
+ const uint8_t* src_v,
380
+ int src_stride_v,
381
+ uint32_t /* src_fourcc */,
382
+ int src_width,
383
+ int src_height,
384
+ uint8_t* dst_argb,
385
+ int dst_stride_argb,
386
+ uint32_t /* dst_fourcc */,
387
+ int dst_width,
388
+ int dst_height,
389
+ int clip_x,
390
+ int clip_y,
391
+ int clip_width,
392
+ int clip_height,
393
+ enum FilterMode filtering) {
394
+ uint8_t* argb_buffer =
395
+ static_cast<uint8_t*>(malloc(src_width * src_height * 4));
396
+ int r;
397
+ I420ToARGB(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
398
+ argb_buffer, src_width * 4, src_width, src_height);
399
+
400
+ r = ARGBScaleClip(argb_buffer, src_width * 4, src_width, src_height, dst_argb,
401
+ dst_stride_argb, dst_width, dst_height, clip_x, clip_y,
402
+ clip_width, clip_height, filtering);
403
+ free(argb_buffer);
404
+ return r;
405
+ }
406
+
407
+ static void FillRamp(uint8_t* buf,
408
+ int width,
409
+ int height,
410
+ int v,
411
+ int dx,
412
+ int dy) {
413
+ int rv = v;
414
+ for (int y = 0; y < height; ++y) {
415
+ for (int x = 0; x < width; ++x) {
416
+ *buf++ = v;
417
+ v += dx;
418
+ if (v < 0 || v > 255) {
419
+ dx = -dx;
420
+ v += dx;
421
+ }
422
+ }
423
+ v = rv + dy;
424
+ if (v < 0 || v > 255) {
425
+ dy = -dy;
426
+ v += dy;
427
+ }
428
+ rv = v;
429
+ }
430
+ }
431
+
432
+ // Test scaling with C vs Opt and return maximum pixel difference. 0 = exact.
433
+ static int YUVToARGBTestFilter(int src_width,
434
+ int src_height,
435
+ int dst_width,
436
+ int dst_height,
437
+ FilterMode f,
438
+ int benchmark_iterations) {
439
+ int64_t src_y_plane_size = Abs(src_width) * Abs(src_height);
440
+ int64_t src_uv_plane_size =
441
+ ((Abs(src_width) + 1) / 2) * ((Abs(src_height) + 1) / 2);
442
+ int src_stride_y = Abs(src_width);
443
+ int src_stride_uv = (Abs(src_width) + 1) / 2;
444
+
445
+ align_buffer_page_end(src_y, src_y_plane_size);
446
+ align_buffer_page_end(src_u, src_uv_plane_size);
447
+ align_buffer_page_end(src_v, src_uv_plane_size);
448
+
449
+ int64_t dst_argb_plane_size = (dst_width) * (dst_height)*4LL;
450
+ int dst_stride_argb = (dst_width)*4;
451
+ align_buffer_page_end(dst_argb_c, dst_argb_plane_size);
452
+ align_buffer_page_end(dst_argb_opt, dst_argb_plane_size);
453
+ if (!dst_argb_c || !dst_argb_opt || !src_y || !src_u || !src_v) {
454
+ printf("Skipped. Alloc failed " FILELINESTR(__FILE__, __LINE__) "\n");
455
+ return 0;
456
+ }
457
+ // Fill YUV image with continuous ramp, which is less sensitive to
458
+ // subsampling and filtering differences for test purposes.
459
+ FillRamp(src_y, Abs(src_width), Abs(src_height), 128, 1, 1);
460
+ FillRamp(src_u, (Abs(src_width) + 1) / 2, (Abs(src_height) + 1) / 2, 3, 1, 1);
461
+ FillRamp(src_v, (Abs(src_width) + 1) / 2, (Abs(src_height) + 1) / 2, 4, 1, 1);
462
+ memset(dst_argb_c, 2, dst_argb_plane_size);
463
+ memset(dst_argb_opt, 3, dst_argb_plane_size);
464
+
465
+ YUVToARGBScaleReference2(src_y, src_stride_y, src_u, src_stride_uv, src_v,
466
+ src_stride_uv, libyuv::FOURCC_I420, src_width,
467
+ src_height, dst_argb_c, dst_stride_argb,
468
+ libyuv::FOURCC_I420, dst_width, dst_height, 0, 0,
469
+ dst_width, dst_height, f);
470
+
471
+ for (int i = 0; i < benchmark_iterations; ++i) {
472
+ YUVToARGBScaleClip(src_y, src_stride_y, src_u, src_stride_uv, src_v,
473
+ src_stride_uv, libyuv::FOURCC_I420, src_width,
474
+ src_height, dst_argb_opt, dst_stride_argb,
475
+ libyuv::FOURCC_I420, dst_width, dst_height, 0, 0,
476
+ dst_width, dst_height, f);
477
+ }
478
+ int max_diff = 0;
479
+ for (int i = 0; i < dst_height; ++i) {
480
+ for (int j = 0; j < dst_width * 4; ++j) {
481
+ int abs_diff = Abs(dst_argb_c[(i * dst_stride_argb) + j] -
482
+ dst_argb_opt[(i * dst_stride_argb) + j]);
483
+ if (abs_diff > max_diff) {
484
+ printf("error %d at %d,%d c %d opt %d", abs_diff, j, i,
485
+ dst_argb_c[(i * dst_stride_argb) + j],
486
+ dst_argb_opt[(i * dst_stride_argb) + j]);
487
+ EXPECT_LE(abs_diff, 40);
488
+ max_diff = abs_diff;
489
+ }
490
+ }
491
+ }
492
+
493
+ free_aligned_buffer_page_end(dst_argb_c);
494
+ free_aligned_buffer_page_end(dst_argb_opt);
495
+ free_aligned_buffer_page_end(src_y);
496
+ free_aligned_buffer_page_end(src_u);
497
+ free_aligned_buffer_page_end(src_v);
498
+ return max_diff;
499
+ }
500
+
501
+ TEST_F(LibYUVScaleTest, YUVToRGBScaleUp) {
502
+ int diff =
503
+ YUVToARGBTestFilter(benchmark_width_, benchmark_height_,
504
+ benchmark_width_ * 3 / 2, benchmark_height_ * 3 / 2,
505
+ libyuv::kFilterBilinear, benchmark_iterations_);
506
+ EXPECT_LE(diff, 10);
507
+ }
508
+
509
+ TEST_F(LibYUVScaleTest, YUVToRGBScaleDown) {
510
+ int diff = YUVToARGBTestFilter(
511
+ benchmark_width_ * 3 / 2, benchmark_height_ * 3 / 2, benchmark_width_,
512
+ benchmark_height_, libyuv::kFilterBilinear, benchmark_iterations_);
513
+ EXPECT_LE(diff, 10);
514
+ }
515
+
516
+ TEST_F(LibYUVScaleTest, ARGBTest3x) {
517
+ const int kSrcStride = 480 * 4;
518
+ const int kDstStride = 160 * 4;
519
+ const int kSize = kSrcStride * 3;
520
+ align_buffer_page_end(orig_pixels, kSize);
521
+ for (int i = 0; i < 480 * 3; ++i) {
522
+ orig_pixels[i * 4 + 0] = i;
523
+ orig_pixels[i * 4 + 1] = 255 - i;
524
+ orig_pixels[i * 4 + 2] = i + 1;
525
+ orig_pixels[i * 4 + 3] = i + 10;
526
+ }
527
+ align_buffer_page_end(dest_pixels, kDstStride);
528
+
529
+ int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 *
530
+ benchmark_iterations_;
531
+ for (int i = 0; i < iterations160; ++i) {
532
+ ARGBScale(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1,
533
+ kFilterBilinear);
534
+ }
535
+
536
+ EXPECT_EQ(225, dest_pixels[0]);
537
+ EXPECT_EQ(255 - 225, dest_pixels[1]);
538
+ EXPECT_EQ(226, dest_pixels[2]);
539
+ EXPECT_EQ(235, dest_pixels[3]);
540
+
541
+ ARGBScale(orig_pixels, kSrcStride, 480, 3, dest_pixels, kDstStride, 160, 1,
542
+ kFilterNone);
543
+
544
+ EXPECT_EQ(225, dest_pixels[0]);
545
+ EXPECT_EQ(255 - 225, dest_pixels[1]);
546
+ EXPECT_EQ(226, dest_pixels[2]);
547
+ EXPECT_EQ(235, dest_pixels[3]);
548
+
549
+ free_aligned_buffer_page_end(dest_pixels);
550
+ free_aligned_buffer_page_end(orig_pixels);
551
+ }
552
+
553
+ TEST_F(LibYUVScaleTest, ARGBTest4x) {
554
+ const int kSrcStride = 640 * 4;
555
+ const int kDstStride = 160 * 4;
556
+ const int kSize = kSrcStride * 4;
557
+ align_buffer_page_end(orig_pixels, kSize);
558
+ for (int i = 0; i < 640 * 4; ++i) {
559
+ orig_pixels[i * 4 + 0] = i;
560
+ orig_pixels[i * 4 + 1] = 255 - i;
561
+ orig_pixels[i * 4 + 2] = i + 1;
562
+ orig_pixels[i * 4 + 3] = i + 10;
563
+ }
564
+ align_buffer_page_end(dest_pixels, kDstStride);
565
+
566
+ int iterations160 = (benchmark_width_ * benchmark_height_ + (160 - 1)) / 160 *
567
+ benchmark_iterations_;
568
+ for (int i = 0; i < iterations160; ++i) {
569
+ ARGBScale(orig_pixels, kSrcStride, 640, 4, dest_pixels, kDstStride, 160, 1,
570
+ kFilterBilinear);
571
+ }
572
+
573
+ EXPECT_NEAR(66, dest_pixels[0], 4);
574
+ EXPECT_NEAR(255 - 66, dest_pixels[1], 4);
575
+ EXPECT_NEAR(67, dest_pixels[2], 4);
576
+ EXPECT_NEAR(76, dest_pixels[3], 4);
577
+
578
+ ARGBScale(orig_pixels, kSrcStride, 640, 4, dest_pixels, kDstStride, 160, 1,
579
+ kFilterNone);
580
+
581
+ EXPECT_EQ(2, dest_pixels[0]);
582
+ EXPECT_EQ(255 - 2, dest_pixels[1]);
583
+ EXPECT_EQ(3, dest_pixels[2]);
584
+ EXPECT_EQ(12, dest_pixels[3]);
585
+
586
+ free_aligned_buffer_page_end(dest_pixels);
587
+ free_aligned_buffer_page_end(orig_pixels);
588
+ }
589
+
590
+ } // namespace libyuv