react-native-vision-camera-spoof-detector 1.1.23 → 1.1.25

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 (200) hide show
  1. package/android/CMakeLists.txt +12 -0
  2. package/android/build.gradle +10 -9
  3. package/android/src/main/cpp/cpp-adapter.cpp +6 -3
  4. package/ios/HybridSpoofDetectorOutput.swift +112 -72
  5. package/package.json +1 -1
  6. package/android/src/main/cpp/CMakeLists.txt +0 -33
  7. package/android/src/main/cpp/FaceAntiSpoofJSI.cpp +0 -142
  8. package/android/src/main/cpp/FastYuvJni.cpp +0 -111
  9. package/android/src/main/cpp/fast_yuv.cpp +0 -342
  10. package/android/src/main/cpp/fast_yuv.h +0 -23
  11. package/android/src/main/cpp/libyuv/.clang-format +0 -6
  12. package/android/src/main/cpp/libyuv/.gn +0 -40
  13. package/android/src/main/cpp/libyuv/.vpython3 +0 -410
  14. package/android/src/main/cpp/libyuv/AUTHORS +0 -7
  15. package/android/src/main/cpp/libyuv/Android.bp +0 -202
  16. package/android/src/main/cpp/libyuv/Android.mk +0 -106
  17. package/android/src/main/cpp/libyuv/BUILD.gn +0 -490
  18. package/android/src/main/cpp/libyuv/CM_linux_packages.cmake +0 -70
  19. package/android/src/main/cpp/libyuv/CMakeLists.txt +0 -259
  20. package/android/src/main/cpp/libyuv/DEPS +0 -935
  21. package/android/src/main/cpp/libyuv/DIR_METADATA +0 -3
  22. package/android/src/main/cpp/libyuv/LICENSE +0 -29
  23. package/android/src/main/cpp/libyuv/OWNERS +0 -11
  24. package/android/src/main/cpp/libyuv/PATENTS +0 -24
  25. package/android/src/main/cpp/libyuv/PRESUBMIT.py +0 -65
  26. package/android/src/main/cpp/libyuv/README.chromium +0 -11
  27. package/android/src/main/cpp/libyuv/README.md +0 -19
  28. package/android/src/main/cpp/libyuv/build_overrides/build.gni +0 -60
  29. package/android/src/main/cpp/libyuv/build_overrides/gtest.gni +0 -19
  30. package/android/src/main/cpp/libyuv/build_overrides/partition_alloc.gni +0 -17
  31. package/android/src/main/cpp/libyuv/codereview.settings +0 -5
  32. package/android/src/main/cpp/libyuv/docs/deprecated_builds.md +0 -409
  33. package/android/src/main/cpp/libyuv/docs/environment_variables.md +0 -64
  34. package/android/src/main/cpp/libyuv/docs/feature_detection.md +0 -108
  35. package/android/src/main/cpp/libyuv/docs/filtering.md +0 -196
  36. package/android/src/main/cpp/libyuv/docs/formats.md +0 -208
  37. package/android/src/main/cpp/libyuv/docs/getting_started.md +0 -296
  38. package/android/src/main/cpp/libyuv/docs/rotation.md +0 -107
  39. package/android/src/main/cpp/libyuv/download_vs_toolchain.py +0 -29
  40. package/android/src/main/cpp/libyuv/include/libyuv/basic_types.h +0 -68
  41. package/android/src/main/cpp/libyuv/include/libyuv/compare.h +0 -111
  42. package/android/src/main/cpp/libyuv/include/libyuv/compare_row.h +0 -112
  43. package/android/src/main/cpp/libyuv/include/libyuv/convert.h +0 -1117
  44. package/android/src/main/cpp/libyuv/include/libyuv/convert_argb.h +0 -2335
  45. package/android/src/main/cpp/libyuv/include/libyuv/convert_from.h +0 -203
  46. package/android/src/main/cpp/libyuv/include/libyuv/convert_from_argb.h +0 -394
  47. package/android/src/main/cpp/libyuv/include/libyuv/cpu_id.h +0 -147
  48. package/android/src/main/cpp/libyuv/include/libyuv/cpu_support.h +0 -99
  49. package/android/src/main/cpp/libyuv/include/libyuv/loongson_intrinsics.h +0 -1949
  50. package/android/src/main/cpp/libyuv/include/libyuv/mjpeg_decoder.h +0 -195
  51. package/android/src/main/cpp/libyuv/include/libyuv/planar_functions.h +0 -1131
  52. package/android/src/main/cpp/libyuv/include/libyuv/rotate.h +0 -296
  53. package/android/src/main/cpp/libyuv/include/libyuv/rotate_argb.h +0 -37
  54. package/android/src/main/cpp/libyuv/include/libyuv/rotate_row.h +0 -265
  55. package/android/src/main/cpp/libyuv/include/libyuv/row.h +0 -6738
  56. package/android/src/main/cpp/libyuv/include/libyuv/row_sve.h +0 -2154
  57. package/android/src/main/cpp/libyuv/include/libyuv/scale.h +0 -336
  58. package/android/src/main/cpp/libyuv/include/libyuv/scale_argb.h +0 -76
  59. package/android/src/main/cpp/libyuv/include/libyuv/scale_rgb.h +0 -42
  60. package/android/src/main/cpp/libyuv/include/libyuv/scale_row.h +0 -1726
  61. package/android/src/main/cpp/libyuv/include/libyuv/scale_uv.h +0 -51
  62. package/android/src/main/cpp/libyuv/include/libyuv/version.h +0 -16
  63. package/android/src/main/cpp/libyuv/include/libyuv/video_common.h +0 -222
  64. package/android/src/main/cpp/libyuv/include/libyuv.h +0 -33
  65. package/android/src/main/cpp/libyuv/infra/config/OWNERS +0 -3
  66. package/android/src/main/cpp/libyuv/infra/config/PRESUBMIT.py +0 -17
  67. package/android/src/main/cpp/libyuv/infra/config/README.md +0 -2
  68. package/android/src/main/cpp/libyuv/infra/config/codereview.settings +0 -6
  69. package/android/src/main/cpp/libyuv/infra/config/commit-queue.cfg +0 -144
  70. package/android/src/main/cpp/libyuv/infra/config/cr-buildbucket.cfg +0 -1185
  71. package/android/src/main/cpp/libyuv/infra/config/luci-logdog.cfg +0 -9
  72. package/android/src/main/cpp/libyuv/infra/config/luci-milo.cfg +0 -246
  73. package/android/src/main/cpp/libyuv/infra/config/luci-scheduler.cfg +0 -385
  74. package/android/src/main/cpp/libyuv/infra/config/main.star +0 -402
  75. package/android/src/main/cpp/libyuv/infra/config/project.cfg +0 -16
  76. package/android/src/main/cpp/libyuv/infra/config/realms.cfg +0 -111
  77. package/android/src/main/cpp/libyuv/libyuv.gni +0 -34
  78. package/android/src/main/cpp/libyuv/libyuv.gyp +0 -149
  79. package/android/src/main/cpp/libyuv/libyuv.gypi +0 -87
  80. package/android/src/main/cpp/libyuv/linux.mk +0 -96
  81. package/android/src/main/cpp/libyuv/public.mk +0 -13
  82. package/android/src/main/cpp/libyuv/pylintrc +0 -49
  83. package/android/src/main/cpp/libyuv/riscv_script/prepare_toolchain_qemu.sh +0 -74
  84. package/android/src/main/cpp/libyuv/riscv_script/riscv-clang.cmake +0 -56
  85. package/android/src/main/cpp/libyuv/riscv_script/run_qemu.sh +0 -15
  86. package/android/src/main/cpp/libyuv/source/compare.cc +0 -435
  87. package/android/src/main/cpp/libyuv/source/compare_common.cc +0 -74
  88. package/android/src/main/cpp/libyuv/source/compare_gcc.cc +0 -362
  89. package/android/src/main/cpp/libyuv/source/compare_neon.cc +0 -96
  90. package/android/src/main/cpp/libyuv/source/compare_neon64.cc +0 -223
  91. package/android/src/main/cpp/libyuv/source/compare_win.cc +0 -241
  92. package/android/src/main/cpp/libyuv/source/convert.cc +0 -4746
  93. package/android/src/main/cpp/libyuv/source/convert_argb.cc +0 -9179
  94. package/android/src/main/cpp/libyuv/source/convert_from.cc +0 -866
  95. package/android/src/main/cpp/libyuv/source/convert_from_argb.cc +0 -3671
  96. package/android/src/main/cpp/libyuv/source/convert_jpeg.cc +0 -602
  97. package/android/src/main/cpp/libyuv/source/convert_to_argb.cc +0 -391
  98. package/android/src/main/cpp/libyuv/source/convert_to_i420.cc +0 -288
  99. package/android/src/main/cpp/libyuv/source/cpu_id.cc +0 -496
  100. package/android/src/main/cpp/libyuv/source/mjpeg_decoder.cc +0 -580
  101. package/android/src/main/cpp/libyuv/source/mjpeg_validate.cc +0 -71
  102. package/android/src/main/cpp/libyuv/source/planar_functions.cc +0 -5663
  103. package/android/src/main/cpp/libyuv/source/rotate.cc +0 -1241
  104. package/android/src/main/cpp/libyuv/source/rotate_any.cc +0 -76
  105. package/android/src/main/cpp/libyuv/source/rotate_argb.cc +0 -259
  106. package/android/src/main/cpp/libyuv/source/rotate_common.cc +0 -208
  107. package/android/src/main/cpp/libyuv/source/rotate_gcc.cc +0 -505
  108. package/android/src/main/cpp/libyuv/source/rotate_lsx.cc +0 -233
  109. package/android/src/main/cpp/libyuv/source/rotate_neon.cc +0 -219
  110. package/android/src/main/cpp/libyuv/source/rotate_neon64.cc +0 -273
  111. package/android/src/main/cpp/libyuv/source/rotate_sme.cc +0 -174
  112. package/android/src/main/cpp/libyuv/source/rotate_win.cc +0 -253
  113. package/android/src/main/cpp/libyuv/source/row_any.cc +0 -2519
  114. package/android/src/main/cpp/libyuv/source/row_common.cc +0 -4461
  115. package/android/src/main/cpp/libyuv/source/row_gcc.cc +0 -9570
  116. package/android/src/main/cpp/libyuv/source/row_lasx.cc +0 -2343
  117. package/android/src/main/cpp/libyuv/source/row_lsx.cc +0 -3030
  118. package/android/src/main/cpp/libyuv/source/row_neon.cc +0 -4026
  119. package/android/src/main/cpp/libyuv/source/row_neon64.cc +0 -5617
  120. package/android/src/main/cpp/libyuv/source/row_rvv.cc +0 -2599
  121. package/android/src/main/cpp/libyuv/source/row_sme.cc +0 -1183
  122. package/android/src/main/cpp/libyuv/source/row_sve.cc +0 -1088
  123. package/android/src/main/cpp/libyuv/source/row_win.cc +0 -6453
  124. package/android/src/main/cpp/libyuv/source/scale.cc +0 -2710
  125. package/android/src/main/cpp/libyuv/source/scale_any.cc +0 -991
  126. package/android/src/main/cpp/libyuv/source/scale_argb.cc +0 -1158
  127. package/android/src/main/cpp/libyuv/source/scale_common.cc +0 -1977
  128. package/android/src/main/cpp/libyuv/source/scale_gcc.cc +0 -2947
  129. package/android/src/main/cpp/libyuv/source/scale_lsx.cc +0 -739
  130. package/android/src/main/cpp/libyuv/source/scale_neon.cc +0 -1449
  131. package/android/src/main/cpp/libyuv/source/scale_neon64.cc +0 -1552
  132. package/android/src/main/cpp/libyuv/source/scale_rgb.cc +0 -82
  133. package/android/src/main/cpp/libyuv/source/scale_rvv.cc +0 -1971
  134. package/android/src/main/cpp/libyuv/source/scale_sme.cc +0 -555
  135. package/android/src/main/cpp/libyuv/source/scale_uv.cc +0 -1159
  136. package/android/src/main/cpp/libyuv/source/scale_win.cc +0 -1392
  137. package/android/src/main/cpp/libyuv/source/test.sh +0 -35
  138. package/android/src/main/cpp/libyuv/source/video_common.cc +0 -62
  139. package/android/src/main/cpp/libyuv/tools_libyuv/OWNERS +0 -4
  140. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/roll_deps.py +0 -931
  141. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py +0 -164
  142. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS +0 -21
  143. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.new +0 -13
  144. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old +0 -13
  145. package/android/src/main/cpp/libyuv/tools_libyuv/get_landmines.py +0 -38
  146. package/android/src/main/cpp/libyuv/tools_libyuv/msan/OWNERS +0 -3
  147. package/android/src/main/cpp/libyuv/tools_libyuv/msan/blacklist.txt +0 -9
  148. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/OWNERS +0 -3
  149. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/blacklist.txt +0 -15
  150. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/vptr_blacklist.txt +0 -25
  151. package/android/src/main/cpp/libyuv/unit_test/basictypes_test.cc +0 -43
  152. package/android/src/main/cpp/libyuv/unit_test/color_test.cc +0 -848
  153. package/android/src/main/cpp/libyuv/unit_test/compare_test.cc +0 -739
  154. package/android/src/main/cpp/libyuv/unit_test/convert_argb_test.cc +0 -2867
  155. package/android/src/main/cpp/libyuv/unit_test/convert_test.cc +0 -2133
  156. package/android/src/main/cpp/libyuv/unit_test/cpu_test.cc +0 -427
  157. package/android/src/main/cpp/libyuv/unit_test/cpu_thread_test.cc +0 -63
  158. package/android/src/main/cpp/libyuv/unit_test/math_test.cc +0 -160
  159. package/android/src/main/cpp/libyuv/unit_test/planar_test.cc +0 -4731
  160. package/android/src/main/cpp/libyuv/unit_test/rotate_argb_test.cc +0 -334
  161. package/android/src/main/cpp/libyuv/unit_test/rotate_test.cc +0 -962
  162. package/android/src/main/cpp/libyuv/unit_test/scale_argb_test.cc +0 -590
  163. package/android/src/main/cpp/libyuv/unit_test/scale_plane_test.cc +0 -465
  164. package/android/src/main/cpp/libyuv/unit_test/scale_rgb_test.cc +0 -280
  165. package/android/src/main/cpp/libyuv/unit_test/scale_test.cc +0 -1135
  166. package/android/src/main/cpp/libyuv/unit_test/scale_uv_test.cc +0 -249
  167. package/android/src/main/cpp/libyuv/unit_test/testdata/arm_v7.txt +0 -12
  168. package/android/src/main/cpp/libyuv/unit_test/testdata/mips.txt +0 -7
  169. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson2k.txt +0 -5
  170. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson3.txt +0 -10
  171. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson_mmi.txt +0 -7
  172. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64.txt +0 -4
  173. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv.txt +0 -4
  174. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv_zvfh.txt +0 -4
  175. package/android/src/main/cpp/libyuv/unit_test/testdata/tegra3.txt +0 -23
  176. package/android/src/main/cpp/libyuv/unit_test/testdata/test0.jpg +0 -0
  177. package/android/src/main/cpp/libyuv/unit_test/testdata/test1.jpg +0 -0
  178. package/android/src/main/cpp/libyuv/unit_test/testdata/test2.jpg +0 -0
  179. package/android/src/main/cpp/libyuv/unit_test/testdata/test3.jpg +0 -0
  180. package/android/src/main/cpp/libyuv/unit_test/testdata/test4.jpg +0 -0
  181. package/android/src/main/cpp/libyuv/unit_test/unit_test.cc +0 -581
  182. package/android/src/main/cpp/libyuv/unit_test/unit_test.h +0 -232
  183. package/android/src/main/cpp/libyuv/unit_test/video_common_test.cc +0 -112
  184. package/android/src/main/cpp/libyuv/util/Makefile +0 -9
  185. package/android/src/main/cpp/libyuv/util/color.cc +0 -120
  186. package/android/src/main/cpp/libyuv/util/compare.cc +0 -67
  187. package/android/src/main/cpp/libyuv/util/cpuid.c +0 -211
  188. package/android/src/main/cpp/libyuv/util/i444tonv12_eg.cc +0 -28
  189. package/android/src/main/cpp/libyuv/util/psnr.cc +0 -291
  190. package/android/src/main/cpp/libyuv/util/psnr.h +0 -47
  191. package/android/src/main/cpp/libyuv/util/psnr_main.cc +0 -620
  192. package/android/src/main/cpp/libyuv/util/ssim.cc +0 -364
  193. package/android/src/main/cpp/libyuv/util/ssim.h +0 -38
  194. package/android/src/main/cpp/libyuv/util/yuvconstants.c +0 -114
  195. package/android/src/main/cpp/libyuv/util/yuvconvert.cc +0 -367
  196. package/android/src/main/cpp/libyuv/winarm.mk +0 -47
  197. package/android/src/main/java/com/faceantispoof/ByteBufferPool.kt +0 -68
  198. package/android/src/main/java/com/faceantispoof/FastYuv.kt +0 -51
  199. package/android/src/main/java/com/faceantispoof/YuvToFloatArrayConverter.kt +0 -584
  200. package/android/src/main/java/com/faceantispoof/YuvToRgbConverter.kt +0 -73
@@ -1,1159 +0,0 @@
1
- /*
2
- * Copyright 2020 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 "libyuv/scale_uv.h"
12
-
13
- #include <assert.h>
14
- #include <string.h>
15
-
16
- #include "libyuv/cpu_id.h"
17
- #include "libyuv/planar_functions.h" // For CopyUV
18
- #include "libyuv/row.h"
19
- #include "libyuv/scale_row.h"
20
-
21
- #ifdef __cplusplus
22
- namespace libyuv {
23
- extern "C" {
24
- #endif
25
-
26
- // Macros to enable specialized scalers
27
-
28
- #ifndef HAS_SCALEUVDOWN2
29
- #define HAS_SCALEUVDOWN2 1
30
- #endif
31
- #ifndef HAS_SCALEUVDOWN4BOX
32
- #define HAS_SCALEUVDOWN4BOX 1
33
- #endif
34
- #ifndef HAS_SCALEUVDOWNEVEN
35
- #define HAS_SCALEUVDOWNEVEN 1
36
- #endif
37
- #ifndef HAS_SCALEUVBILINEARDOWN
38
- #define HAS_SCALEUVBILINEARDOWN 1
39
- #endif
40
- #ifndef HAS_SCALEUVBILINEARUP
41
- #define HAS_SCALEUVBILINEARUP 1
42
- #endif
43
- #ifndef HAS_UVCOPY
44
- #define HAS_UVCOPY 1
45
- #endif
46
- #ifndef HAS_SCALEPLANEVERTICAL
47
- #define HAS_SCALEPLANEVERTICAL 1
48
- #endif
49
-
50
- static __inline int Abs(int v) {
51
- return v >= 0 ? v : -v;
52
- }
53
-
54
- // ScaleUV, 1/2
55
- // This is an optimized version for scaling down a UV to 1/2 of
56
- // its original size.
57
- #if HAS_SCALEUVDOWN2
58
- static void ScaleUVDown2(int src_width,
59
- int src_height,
60
- int dst_width,
61
- int dst_height,
62
- int src_stride,
63
- int dst_stride,
64
- const uint8_t* src_uv,
65
- uint8_t* dst_uv,
66
- int x,
67
- int dx,
68
- int y,
69
- int dy,
70
- enum FilterMode filtering) {
71
- int j;
72
- int row_stride = src_stride * (dy >> 16);
73
- void (*ScaleUVRowDown2)(const uint8_t* src_uv, ptrdiff_t src_stride,
74
- uint8_t* dst_uv, int dst_width) =
75
- filtering == kFilterNone
76
- ? ScaleUVRowDown2_C
77
- : (filtering == kFilterLinear ? ScaleUVRowDown2Linear_C
78
- : ScaleUVRowDown2Box_C);
79
- (void)src_width;
80
- (void)src_height;
81
- (void)dx;
82
- assert(dx == 65536 * 2); // Test scale factor of 2.
83
- assert((dy & 0x1ffff) == 0); // Test vertical scale is multiple of 2.
84
- // Advance to odd row, even column.
85
- if (filtering == kFilterBilinear) {
86
- src_uv += (y >> 16) * (intptr_t)src_stride + (x >> 16) * 2;
87
- } else {
88
- src_uv += (y >> 16) * (intptr_t)src_stride + ((x >> 16) - 1) * 2;
89
- }
90
-
91
- #if defined(HAS_SCALEUVROWDOWN2BOX_SSSE3)
92
- if (TestCpuFlag(kCpuHasSSSE3) && filtering) {
93
- ScaleUVRowDown2 = ScaleUVRowDown2Box_Any_SSSE3;
94
- if (IS_ALIGNED(dst_width, 4)) {
95
- ScaleUVRowDown2 = ScaleUVRowDown2Box_SSSE3;
96
- }
97
- }
98
- #endif
99
- #if defined(HAS_SCALEUVROWDOWN2BOX_AVX2)
100
- if (TestCpuFlag(kCpuHasAVX2) && filtering) {
101
- ScaleUVRowDown2 = ScaleUVRowDown2Box_Any_AVX2;
102
- if (IS_ALIGNED(dst_width, 8)) {
103
- ScaleUVRowDown2 = ScaleUVRowDown2Box_AVX2;
104
- }
105
- }
106
- #endif
107
- #if defined(HAS_SCALEUVROWDOWN2_NEON)
108
- if (TestCpuFlag(kCpuHasNEON)) {
109
- ScaleUVRowDown2 =
110
- filtering == kFilterNone
111
- ? ScaleUVRowDown2_Any_NEON
112
- : (filtering == kFilterLinear ? ScaleUVRowDown2Linear_Any_NEON
113
- : ScaleUVRowDown2Box_Any_NEON);
114
- if (IS_ALIGNED(dst_width, 8)) {
115
- ScaleUVRowDown2 =
116
- filtering == kFilterNone
117
- ? ScaleUVRowDown2_NEON
118
- : (filtering == kFilterLinear ? ScaleUVRowDown2Linear_NEON
119
- : ScaleUVRowDown2Box_NEON);
120
- }
121
- }
122
- #endif
123
- #if defined(HAS_SCALEUVROWDOWN2_SME)
124
- if (TestCpuFlag(kCpuHasSME)) {
125
- ScaleUVRowDown2 = filtering == kFilterNone ? ScaleUVRowDown2_SME
126
- : filtering == kFilterLinear ? ScaleUVRowDown2Linear_SME
127
- : ScaleUVRowDown2Box_SME;
128
- }
129
- #endif
130
- #if defined(HAS_SCALEUVROWDOWN2_RVV)
131
- if (TestCpuFlag(kCpuHasRVV)) {
132
- ScaleUVRowDown2 =
133
- filtering == kFilterNone
134
- ? ScaleUVRowDown2_RVV
135
- : (filtering == kFilterLinear ? ScaleUVRowDown2Linear_RVV
136
- : ScaleUVRowDown2Box_RVV);
137
- }
138
- #endif
139
-
140
- // This code is not enabled. Only box filter is available at this time.
141
- #if defined(HAS_SCALEUVROWDOWN2_SSSE3)
142
- if (TestCpuFlag(kCpuHasSSSE3)) {
143
- ScaleUVRowDown2 =
144
- filtering == kFilterNone
145
- ? ScaleUVRowDown2_Any_SSSE3
146
- : (filtering == kFilterLinear ? ScaleUVRowDown2Linear_Any_SSSE3
147
- : ScaleUVRowDown2Box_Any_SSSE3);
148
- if (IS_ALIGNED(dst_width, 2)) {
149
- ScaleUVRowDown2 =
150
- filtering == kFilterNone
151
- ? ScaleUVRowDown2_SSSE3
152
- : (filtering == kFilterLinear ? ScaleUVRowDown2Linear_SSSE3
153
- : ScaleUVRowDown2Box_SSSE3);
154
- }
155
- }
156
- #endif
157
-
158
- if (filtering == kFilterLinear) {
159
- src_stride = 0;
160
- }
161
- for (j = 0; j < dst_height; ++j) {
162
- ScaleUVRowDown2(src_uv, src_stride, dst_uv, dst_width);
163
- src_uv += row_stride;
164
- dst_uv += dst_stride;
165
- }
166
- }
167
- #endif // HAS_SCALEUVDOWN2
168
-
169
- // ScaleUV, 1/4
170
- // This is an optimized version for scaling down a UV to 1/4 of
171
- // its original size.
172
- #if HAS_SCALEUVDOWN4BOX
173
- static int ScaleUVDown4Box(int src_width,
174
- int src_height,
175
- int dst_width,
176
- int dst_height,
177
- int src_stride,
178
- int dst_stride,
179
- const uint8_t* src_uv,
180
- uint8_t* dst_uv,
181
- int x,
182
- int dx,
183
- int y,
184
- int dy) {
185
- int j;
186
- // Allocate 2 rows of UV.
187
- const int row_size = (dst_width * 2 * 2 + 15) & ~15;
188
- align_buffer_64(row, row_size * 2);
189
- if (!row)
190
- return 1;
191
- int row_stride = src_stride * (dy >> 16);
192
- void (*ScaleUVRowDown2)(const uint8_t* src_uv, ptrdiff_t src_stride,
193
- uint8_t* dst_uv, int dst_width) =
194
- ScaleUVRowDown2Box_C;
195
- // Advance to odd row, even column.
196
- src_uv += (y >> 16) * (intptr_t)src_stride + (x >> 16) * 2;
197
- (void)src_width;
198
- (void)src_height;
199
- (void)dx;
200
- assert(dx == 65536 * 4); // Test scale factor of 4.
201
- assert((dy & 0x3ffff) == 0); // Test vertical scale is multiple of 4.
202
-
203
- #if defined(HAS_SCALEUVROWDOWN2BOX_SSSE3)
204
- if (TestCpuFlag(kCpuHasSSSE3)) {
205
- ScaleUVRowDown2 = ScaleUVRowDown2Box_Any_SSSE3;
206
- if (IS_ALIGNED(dst_width, 4)) {
207
- ScaleUVRowDown2 = ScaleUVRowDown2Box_SSSE3;
208
- }
209
- }
210
- #endif
211
- #if defined(HAS_SCALEUVROWDOWN2BOX_AVX2)
212
- if (TestCpuFlag(kCpuHasAVX2)) {
213
- ScaleUVRowDown2 = ScaleUVRowDown2Box_Any_AVX2;
214
- if (IS_ALIGNED(dst_width, 8)) {
215
- ScaleUVRowDown2 = ScaleUVRowDown2Box_AVX2;
216
- }
217
- }
218
- #endif
219
- #if defined(HAS_SCALEUVROWDOWN2BOX_NEON)
220
- if (TestCpuFlag(kCpuHasNEON)) {
221
- ScaleUVRowDown2 = ScaleUVRowDown2Box_Any_NEON;
222
- if (IS_ALIGNED(dst_width, 8)) {
223
- ScaleUVRowDown2 = ScaleUVRowDown2Box_NEON;
224
- }
225
- }
226
- #endif
227
- #if defined(HAS_SCALEUVROWDOWN2BOX_SME)
228
- if (TestCpuFlag(kCpuHasSME)) {
229
- ScaleUVRowDown2 = ScaleUVRowDown2Box_SME;
230
- }
231
- #endif
232
- #if defined(HAS_SCALEUVROWDOWN2BOX_RVV)
233
- if (TestCpuFlag(kCpuHasRVV)) {
234
- ScaleUVRowDown2 = ScaleUVRowDown2Box_RVV;
235
- }
236
- #endif
237
-
238
- for (j = 0; j < dst_height; ++j) {
239
- ScaleUVRowDown2(src_uv, src_stride, row, dst_width * 2);
240
- ScaleUVRowDown2(src_uv + src_stride * 2, src_stride, row + row_size,
241
- dst_width * 2);
242
- ScaleUVRowDown2(row, row_size, dst_uv, dst_width);
243
- src_uv += row_stride;
244
- dst_uv += dst_stride;
245
- }
246
- free_aligned_buffer_64(row);
247
- return 0;
248
- }
249
- #endif // HAS_SCALEUVDOWN4BOX
250
-
251
- // ScaleUV Even
252
- // This is an optimized version for scaling down a UV to even
253
- // multiple of its original size.
254
- #if HAS_SCALEUVDOWNEVEN
255
- static void ScaleUVDownEven(int src_width,
256
- int src_height,
257
- int dst_width,
258
- int dst_height,
259
- int src_stride,
260
- int dst_stride,
261
- const uint8_t* src_uv,
262
- uint8_t* dst_uv,
263
- int x,
264
- int dx,
265
- int y,
266
- int dy,
267
- enum FilterMode filtering) {
268
- int j;
269
- int col_step = dx >> 16;
270
- ptrdiff_t row_stride = (ptrdiff_t)((dy >> 16) * (intptr_t)src_stride);
271
- void (*ScaleUVRowDownEven)(const uint8_t* src_uv, ptrdiff_t src_stride,
272
- int src_step, uint8_t* dst_uv, int dst_width) =
273
- filtering ? ScaleUVRowDownEvenBox_C : ScaleUVRowDownEven_C;
274
- (void)src_width;
275
- (void)src_height;
276
- assert(IS_ALIGNED(src_width, 2));
277
- assert(IS_ALIGNED(src_height, 2));
278
- src_uv += (y >> 16) * (intptr_t)src_stride + (x >> 16) * 2;
279
- #if defined(HAS_SCALEUVROWDOWNEVEN_SSSE3)
280
- if (TestCpuFlag(kCpuHasSSSE3)) {
281
- ScaleUVRowDownEven = filtering ? ScaleUVRowDownEvenBox_Any_SSSE3
282
- : ScaleUVRowDownEven_Any_SSSE3;
283
- if (IS_ALIGNED(dst_width, 4)) {
284
- ScaleUVRowDownEven =
285
- filtering ? ScaleUVRowDownEvenBox_SSE2 : ScaleUVRowDownEven_SSSE3;
286
- }
287
- }
288
- #endif
289
- #if defined(HAS_SCALEUVROWDOWNEVEN_NEON)
290
- if (TestCpuFlag(kCpuHasNEON) && !filtering) {
291
- ScaleUVRowDownEven = ScaleUVRowDownEven_Any_NEON;
292
- if (IS_ALIGNED(dst_width, 4)) {
293
- ScaleUVRowDownEven = ScaleUVRowDownEven_NEON;
294
- }
295
- }
296
- #endif // TODO(fbarchard): Enable Box filter
297
- #if defined(HAS_SCALEUVROWDOWNEVENBOX_NEON)
298
- if (TestCpuFlag(kCpuHasNEON)) {
299
- ScaleUVRowDownEven = filtering ? ScaleUVRowDownEvenBox_Any_NEON
300
- : ScaleUVRowDownEven_Any_NEON;
301
- if (IS_ALIGNED(dst_width, 4)) {
302
- ScaleUVRowDownEven =
303
- filtering ? ScaleUVRowDownEvenBox_NEON : ScaleUVRowDownEven_NEON;
304
- }
305
- }
306
- #endif
307
- #if defined(HAS_SCALEUVROWDOWNEVEN_RVV) || defined(HAS_SCALEUVROWDOWN4_RVV)
308
- if (TestCpuFlag(kCpuHasRVV) && !filtering) {
309
- #if defined(HAS_SCALEUVROWDOWNEVEN_RVV)
310
- ScaleUVRowDownEven = ScaleUVRowDownEven_RVV;
311
- #endif
312
- #if defined(HAS_SCALEUVROWDOWN4_RVV)
313
- if (col_step == 4) {
314
- ScaleUVRowDownEven = ScaleUVRowDown4_RVV;
315
- }
316
- #endif
317
- }
318
- #endif
319
-
320
- if (filtering == kFilterLinear) {
321
- src_stride = 0;
322
- }
323
- for (j = 0; j < dst_height; ++j) {
324
- ScaleUVRowDownEven(src_uv, src_stride, col_step, dst_uv, dst_width);
325
- src_uv += row_stride;
326
- dst_uv += dst_stride;
327
- }
328
- }
329
- #endif
330
-
331
- // Scale UV down with bilinear interpolation.
332
- #if HAS_SCALEUVBILINEARDOWN
333
- static int ScaleUVBilinearDown(int src_width,
334
- int src_height,
335
- int dst_width,
336
- int dst_height,
337
- int src_stride,
338
- int dst_stride,
339
- const uint8_t* src_uv,
340
- uint8_t* dst_uv,
341
- int x,
342
- int dx,
343
- int y,
344
- int dy,
345
- enum FilterMode filtering) {
346
- int j;
347
- void (*InterpolateRow)(uint8_t* dst_uv, const uint8_t* src_uv,
348
- ptrdiff_t src_stride, int dst_width,
349
- int source_y_fraction) = InterpolateRow_C;
350
- void (*ScaleUVFilterCols)(uint8_t* dst_uv, const uint8_t* src_uv,
351
- int dst_width, int x, int dx) =
352
- (src_width >= 32768) ? ScaleUVFilterCols64_C : ScaleUVFilterCols_C;
353
- int64_t xlast = x + (int64_t)(dst_width - 1) * dx;
354
- int64_t xl = (dx >= 0) ? x : xlast;
355
- int64_t xr = (dx >= 0) ? xlast : x;
356
- int clip_src_width;
357
- xl = (xl >> 16) & ~3; // Left edge aligned.
358
- xr = (xr >> 16) + 1; // Right most pixel used. Bilinear uses 2 pixels.
359
- xr = (xr + 1 + 3) & ~3; // 1 beyond 4 pixel aligned right most pixel.
360
- if (xr > src_width) {
361
- xr = src_width;
362
- }
363
- clip_src_width = (int)(xr - xl) * 2; // Width aligned to 2.
364
- src_uv += xl * 2;
365
- x -= (int)(xl << 16);
366
- #if defined(HAS_INTERPOLATEROW_SSSE3)
367
- if (TestCpuFlag(kCpuHasSSSE3)) {
368
- InterpolateRow = InterpolateRow_Any_SSSE3;
369
- if (IS_ALIGNED(clip_src_width, 16)) {
370
- InterpolateRow = InterpolateRow_SSSE3;
371
- }
372
- }
373
- #endif
374
- #if defined(HAS_INTERPOLATEROW_AVX2)
375
- if (TestCpuFlag(kCpuHasAVX2)) {
376
- InterpolateRow = InterpolateRow_Any_AVX2;
377
- if (IS_ALIGNED(clip_src_width, 32)) {
378
- InterpolateRow = InterpolateRow_AVX2;
379
- }
380
- }
381
- #endif
382
- #if defined(HAS_INTERPOLATEROW_NEON)
383
- if (TestCpuFlag(kCpuHasNEON)) {
384
- InterpolateRow = InterpolateRow_Any_NEON;
385
- if (IS_ALIGNED(clip_src_width, 16)) {
386
- InterpolateRow = InterpolateRow_NEON;
387
- }
388
- }
389
- #endif
390
- #if defined(HAS_INTERPOLATEROW_SME)
391
- if (TestCpuFlag(kCpuHasSME)) {
392
- InterpolateRow = InterpolateRow_SME;
393
- }
394
- #endif
395
- #if defined(HAS_INTERPOLATEROW_LSX)
396
- if (TestCpuFlag(kCpuHasLSX)) {
397
- InterpolateRow = InterpolateRow_Any_LSX;
398
- if (IS_ALIGNED(clip_src_width, 32)) {
399
- InterpolateRow = InterpolateRow_LSX;
400
- }
401
- }
402
- #endif
403
- #if defined(HAS_INTERPOLATEROW_RVV)
404
- if (TestCpuFlag(kCpuHasRVV)) {
405
- InterpolateRow = InterpolateRow_RVV;
406
- }
407
- #endif
408
- #if defined(HAS_SCALEUVFILTERCOLS_SSSE3)
409
- if (TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) {
410
- ScaleUVFilterCols = ScaleUVFilterCols_SSSE3;
411
- }
412
- #endif
413
- #if defined(HAS_SCALEUVFILTERCOLS_NEON)
414
- if (TestCpuFlag(kCpuHasNEON)) {
415
- ScaleUVFilterCols = ScaleUVFilterCols_Any_NEON;
416
- if (IS_ALIGNED(dst_width, 4)) {
417
- ScaleUVFilterCols = ScaleUVFilterCols_NEON;
418
- }
419
- }
420
- #endif
421
- // TODO(fbarchard): Consider not allocating row buffer for kFilterLinear.
422
- // Allocate a row of UV.
423
- {
424
- const int max_y = (src_height - 1) << 16;
425
- align_buffer_64(row, clip_src_width * 2);
426
- if (!row)
427
- return 1;
428
- if (y > max_y) {
429
- y = max_y;
430
- }
431
- for (j = 0; j < dst_height; ++j) {
432
- int yi = y >> 16;
433
- const uint8_t* src = src_uv + yi * (intptr_t)src_stride;
434
- if (filtering == kFilterLinear) {
435
- ScaleUVFilterCols(dst_uv, src, dst_width, x, dx);
436
- } else {
437
- int yf = (y >> 8) & 255;
438
- InterpolateRow(row, src, src_stride, clip_src_width, yf);
439
- ScaleUVFilterCols(dst_uv, row, dst_width, x, dx);
440
- }
441
- dst_uv += dst_stride;
442
- y += dy;
443
- if (y > max_y) {
444
- y = max_y;
445
- }
446
- }
447
- free_aligned_buffer_64(row);
448
- }
449
- return 0;
450
- }
451
- #endif
452
-
453
- // Scale UV up with bilinear interpolation.
454
- #if HAS_SCALEUVBILINEARUP
455
- static int ScaleUVBilinearUp(int src_width,
456
- int src_height,
457
- int dst_width,
458
- int dst_height,
459
- int src_stride,
460
- int dst_stride,
461
- const uint8_t* src_uv,
462
- uint8_t* dst_uv,
463
- int x,
464
- int dx,
465
- int y,
466
- int dy,
467
- enum FilterMode filtering) {
468
- int j;
469
- void (*InterpolateRow)(uint8_t* dst_uv, const uint8_t* src_uv,
470
- ptrdiff_t src_stride, int dst_width,
471
- int source_y_fraction) = InterpolateRow_C;
472
- void (*ScaleUVFilterCols)(uint8_t* dst_uv, const uint8_t* src_uv,
473
- int dst_width, int x, int dx) =
474
- filtering ? ScaleUVFilterCols_C : ScaleUVCols_C;
475
- const int max_y = (src_height - 1) << 16;
476
- #if defined(HAS_INTERPOLATEROW_SSSE3)
477
- if (TestCpuFlag(kCpuHasSSSE3)) {
478
- InterpolateRow = InterpolateRow_Any_SSSE3;
479
- if (IS_ALIGNED(dst_width, 8)) {
480
- InterpolateRow = InterpolateRow_SSSE3;
481
- }
482
- }
483
- #endif
484
- #if defined(HAS_INTERPOLATEROW_AVX2)
485
- if (TestCpuFlag(kCpuHasAVX2)) {
486
- InterpolateRow = InterpolateRow_Any_AVX2;
487
- if (IS_ALIGNED(dst_width, 16)) {
488
- InterpolateRow = InterpolateRow_AVX2;
489
- }
490
- }
491
- #endif
492
- #if defined(HAS_INTERPOLATEROW_NEON)
493
- if (TestCpuFlag(kCpuHasNEON)) {
494
- InterpolateRow = InterpolateRow_Any_NEON;
495
- if (IS_ALIGNED(dst_width, 8)) {
496
- InterpolateRow = InterpolateRow_NEON;
497
- }
498
- }
499
- #endif
500
- #if defined(HAS_INTERPOLATEROW_SME)
501
- if (TestCpuFlag(kCpuHasSME)) {
502
- InterpolateRow = InterpolateRow_SME;
503
- }
504
- #endif
505
- #if defined(HAS_INTERPOLATEROW_LSX)
506
- if (TestCpuFlag(kCpuHasLSX)) {
507
- InterpolateRow = InterpolateRow_Any_LSX;
508
- if (IS_ALIGNED(dst_width, 16)) {
509
- InterpolateRow = InterpolateRow_LSX;
510
- }
511
- }
512
- #endif
513
- #if defined(HAS_INTERPOLATEROW_RVV)
514
- if (TestCpuFlag(kCpuHasRVV)) {
515
- InterpolateRow = InterpolateRow_RVV;
516
- }
517
- #endif
518
- if (src_width >= 32768) {
519
- ScaleUVFilterCols = filtering ? ScaleUVFilterCols64_C : ScaleUVCols64_C;
520
- }
521
- #if defined(HAS_SCALEUVFILTERCOLS_SSSE3)
522
- if (filtering && TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) {
523
- ScaleUVFilterCols = ScaleUVFilterCols_SSSE3;
524
- }
525
- #endif
526
- #if defined(HAS_SCALEUVFILTERCOLS_NEON)
527
- if (filtering && TestCpuFlag(kCpuHasNEON)) {
528
- ScaleUVFilterCols = ScaleUVFilterCols_Any_NEON;
529
- if (IS_ALIGNED(dst_width, 8)) {
530
- ScaleUVFilterCols = ScaleUVFilterCols_NEON;
531
- }
532
- }
533
- #endif
534
- #if defined(HAS_SCALEUVCOLS_SSSE3)
535
- if (!filtering && TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) {
536
- ScaleUVFilterCols = ScaleUVCols_SSSE3;
537
- }
538
- #endif
539
- #if defined(HAS_SCALEUVCOLS_NEON)
540
- if (!filtering && TestCpuFlag(kCpuHasNEON)) {
541
- ScaleUVFilterCols = ScaleUVCols_Any_NEON;
542
- if (IS_ALIGNED(dst_width, 16)) {
543
- ScaleUVFilterCols = ScaleUVCols_NEON;
544
- }
545
- }
546
- #endif
547
- if (!filtering && src_width * 2 == dst_width && x < 0x8000) {
548
- ScaleUVFilterCols = ScaleUVColsUp2_C;
549
- #if defined(HAS_SCALEUVCOLSUP2_SSSE3)
550
- if (TestCpuFlag(kCpuHasSSSE3) && IS_ALIGNED(dst_width, 8)) {
551
- ScaleUVFilterCols = ScaleUVColsUp2_SSSE3;
552
- }
553
- #endif
554
- }
555
-
556
- if (y > max_y) {
557
- y = max_y;
558
- }
559
-
560
- {
561
- int yi = y >> 16;
562
- const uint8_t* src = src_uv + yi * (intptr_t)src_stride;
563
-
564
- // Allocate 2 rows of UV.
565
- const int row_size = (dst_width * 2 + 15) & ~15;
566
- align_buffer_64(row, row_size * 2);
567
- if (!row)
568
- return 1;
569
-
570
- uint8_t* rowptr = row;
571
- int rowstride = row_size;
572
- int lasty = yi;
573
-
574
- ScaleUVFilterCols(rowptr, src, dst_width, x, dx);
575
- if (src_height > 1) {
576
- src += src_stride;
577
- }
578
- ScaleUVFilterCols(rowptr + rowstride, src, dst_width, x, dx);
579
- if (src_height > 2) {
580
- src += src_stride;
581
- }
582
-
583
- for (j = 0; j < dst_height; ++j) {
584
- yi = y >> 16;
585
- if (yi != lasty) {
586
- if (y > max_y) {
587
- y = max_y;
588
- yi = y >> 16;
589
- src = src_uv + yi * (intptr_t)src_stride;
590
- }
591
- if (yi != lasty) {
592
- ScaleUVFilterCols(rowptr, src, dst_width, x, dx);
593
- rowptr += rowstride;
594
- rowstride = -rowstride;
595
- lasty = yi;
596
- if ((y + 65536) < max_y) {
597
- src += src_stride;
598
- }
599
- }
600
- }
601
- if (filtering == kFilterLinear) {
602
- InterpolateRow(dst_uv, rowptr, 0, dst_width * 2, 0);
603
- } else {
604
- int yf = (y >> 8) & 255;
605
- InterpolateRow(dst_uv, rowptr, rowstride, dst_width * 2, yf);
606
- }
607
- dst_uv += dst_stride;
608
- y += dy;
609
- }
610
- free_aligned_buffer_64(row);
611
- }
612
- return 0;
613
- }
614
- #endif // HAS_SCALEUVBILINEARUP
615
-
616
- // Scale UV, horizontally up by 2 times.
617
- // Uses linear filter horizontally, nearest vertically.
618
- // This is an optimized version for scaling up a plane to 2 times of
619
- // its original width, using linear interpolation.
620
- // This is used to scale U and V planes of NV16 to NV24.
621
- static void ScaleUVLinearUp2(int src_width,
622
- int src_height,
623
- int dst_width,
624
- int dst_height,
625
- int src_stride,
626
- int dst_stride,
627
- const uint8_t* src_uv,
628
- uint8_t* dst_uv) {
629
- void (*ScaleRowUp)(const uint8_t* src_uv, uint8_t* dst_uv, int dst_width) =
630
- ScaleUVRowUp2_Linear_Any_C;
631
- int i;
632
- int y;
633
- int dy;
634
-
635
- // This function can only scale up by 2 times horizontally.
636
- (void)src_width;
637
- assert(src_width == ((dst_width + 1) / 2));
638
-
639
- #ifdef HAS_SCALEUVROWUP2_LINEAR_SSSE3
640
- if (TestCpuFlag(kCpuHasSSSE3)) {
641
- ScaleRowUp = ScaleUVRowUp2_Linear_Any_SSSE3;
642
- }
643
- #endif
644
-
645
- #ifdef HAS_SCALEUVROWUP2_LINEAR_AVX2
646
- if (TestCpuFlag(kCpuHasAVX2)) {
647
- ScaleRowUp = ScaleUVRowUp2_Linear_Any_AVX2;
648
- }
649
- #endif
650
-
651
- #ifdef HAS_SCALEUVROWUP2_LINEAR_NEON
652
- if (TestCpuFlag(kCpuHasNEON)) {
653
- ScaleRowUp = ScaleUVRowUp2_Linear_Any_NEON;
654
- }
655
- #endif
656
-
657
- #ifdef HAS_SCALEUVROWUP2_LINEAR_RVV
658
- if (TestCpuFlag(kCpuHasRVV)) {
659
- ScaleRowUp = ScaleUVRowUp2_Linear_RVV;
660
- }
661
- #endif
662
-
663
- if (dst_height == 1) {
664
- ScaleRowUp(src_uv + ((src_height - 1) / 2) * (intptr_t)src_stride, dst_uv,
665
- dst_width);
666
- } else {
667
- dy = FixedDiv(src_height - 1, dst_height - 1);
668
- y = (1 << 15) - 1;
669
- for (i = 0; i < dst_height; ++i) {
670
- ScaleRowUp(src_uv + (y >> 16) * (intptr_t)src_stride, dst_uv, dst_width);
671
- dst_uv += dst_stride;
672
- y += dy;
673
- }
674
- }
675
- }
676
-
677
- // Scale plane, up by 2 times.
678
- // This is an optimized version for scaling up a plane to 2 times of
679
- // its original size, using bilinear interpolation.
680
- // This is used to scale U and V planes of NV12 to NV24.
681
- static void ScaleUVBilinearUp2(int src_width,
682
- int src_height,
683
- int dst_width,
684
- int dst_height,
685
- int src_stride,
686
- int dst_stride,
687
- const uint8_t* src_ptr,
688
- uint8_t* dst_ptr) {
689
- void (*Scale2RowUp)(const uint8_t* src_ptr, ptrdiff_t src_stride,
690
- uint8_t* dst_ptr, ptrdiff_t dst_stride, int dst_width) =
691
- ScaleUVRowUp2_Bilinear_Any_C;
692
- int x;
693
-
694
- // This function can only scale up by 2 times.
695
- (void)src_width;
696
- assert(src_width == ((dst_width + 1) / 2));
697
- assert(src_height == ((dst_height + 1) / 2));
698
-
699
- #ifdef HAS_SCALEUVROWUP2_BILINEAR_SSSE3
700
- if (TestCpuFlag(kCpuHasSSSE3)) {
701
- Scale2RowUp = ScaleUVRowUp2_Bilinear_Any_SSSE3;
702
- }
703
- #endif
704
-
705
- #ifdef HAS_SCALEUVROWUP2_BILINEAR_AVX2
706
- if (TestCpuFlag(kCpuHasAVX2)) {
707
- Scale2RowUp = ScaleUVRowUp2_Bilinear_Any_AVX2;
708
- }
709
- #endif
710
-
711
- #ifdef HAS_SCALEUVROWUP2_BILINEAR_NEON
712
- if (TestCpuFlag(kCpuHasNEON)) {
713
- Scale2RowUp = ScaleUVRowUp2_Bilinear_Any_NEON;
714
- }
715
- #endif
716
-
717
- #ifdef HAS_SCALEUVROWUP2_BILINEAR_RVV
718
- if (TestCpuFlag(kCpuHasRVV)) {
719
- Scale2RowUp = ScaleUVRowUp2_Bilinear_RVV;
720
- }
721
- #endif
722
-
723
- Scale2RowUp(src_ptr, 0, dst_ptr, 0, dst_width);
724
- dst_ptr += dst_stride;
725
- for (x = 0; x < src_height - 1; ++x) {
726
- Scale2RowUp(src_ptr, src_stride, dst_ptr, dst_stride, dst_width);
727
- src_ptr += src_stride;
728
- // TODO(fbarchard): Test performance of writing one row of destination at a
729
- // time.
730
- dst_ptr += 2 * dst_stride;
731
- }
732
- if (!(dst_height & 1)) {
733
- Scale2RowUp(src_ptr, 0, dst_ptr, 0, dst_width);
734
- }
735
- }
736
-
737
- // Scale 16 bit UV, horizontally up by 2 times.
738
- // Uses linear filter horizontally, nearest vertically.
739
- // This is an optimized version for scaling up a plane to 2 times of
740
- // its original width, using linear interpolation.
741
- // This is used to scale U and V planes of P210 to P410.
742
- static void ScaleUVLinearUp2_16(int src_width,
743
- int src_height,
744
- int dst_width,
745
- int dst_height,
746
- int src_stride,
747
- int dst_stride,
748
- const uint16_t* src_uv,
749
- uint16_t* dst_uv) {
750
- void (*ScaleRowUp)(const uint16_t* src_uv, uint16_t* dst_uv, int dst_width) =
751
- ScaleUVRowUp2_Linear_16_Any_C;
752
- int i;
753
- int y;
754
- int dy;
755
-
756
- // This function can only scale up by 2 times horizontally.
757
- (void)src_width;
758
- assert(src_width == ((dst_width + 1) / 2));
759
-
760
- #ifdef HAS_SCALEUVROWUP2_LINEAR_16_SSE41
761
- if (TestCpuFlag(kCpuHasSSE41)) {
762
- ScaleRowUp = ScaleUVRowUp2_Linear_16_Any_SSE41;
763
- }
764
- #endif
765
-
766
- #ifdef HAS_SCALEUVROWUP2_LINEAR_16_AVX2
767
- if (TestCpuFlag(kCpuHasAVX2)) {
768
- ScaleRowUp = ScaleUVRowUp2_Linear_16_Any_AVX2;
769
- }
770
- #endif
771
-
772
- #ifdef HAS_SCALEUVROWUP2_LINEAR_16_NEON
773
- if (TestCpuFlag(kCpuHasNEON)) {
774
- ScaleRowUp = ScaleUVRowUp2_Linear_16_Any_NEON;
775
- }
776
- #endif
777
-
778
- if (dst_height == 1) {
779
- ScaleRowUp(src_uv + ((src_height - 1) / 2) * (intptr_t)src_stride, dst_uv,
780
- dst_width);
781
- } else {
782
- dy = FixedDiv(src_height - 1, dst_height - 1);
783
- y = (1 << 15) - 1;
784
- for (i = 0; i < dst_height; ++i) {
785
- ScaleRowUp(src_uv + (y >> 16) * (intptr_t)src_stride, dst_uv, dst_width);
786
- dst_uv += dst_stride;
787
- y += dy;
788
- }
789
- }
790
- }
791
-
792
- // Scale 16 bit UV, up by 2 times.
793
- // This is an optimized version for scaling up a plane to 2 times of
794
- // its original size, using bilinear interpolation.
795
- // This is used to scale U and V planes of P010 to P410.
796
- static void ScaleUVBilinearUp2_16(int src_width,
797
- int src_height,
798
- int dst_width,
799
- int dst_height,
800
- int src_stride,
801
- int dst_stride,
802
- const uint16_t* src_ptr,
803
- uint16_t* dst_ptr) {
804
- void (*Scale2RowUp)(const uint16_t* src_ptr, ptrdiff_t src_stride,
805
- uint16_t* dst_ptr, ptrdiff_t dst_stride, int dst_width) =
806
- ScaleUVRowUp2_Bilinear_16_Any_C;
807
- int x;
808
-
809
- // This function can only scale up by 2 times.
810
- (void)src_width;
811
- assert(src_width == ((dst_width + 1) / 2));
812
- assert(src_height == ((dst_height + 1) / 2));
813
-
814
- #ifdef HAS_SCALEUVROWUP2_BILINEAR_16_SSE41
815
- if (TestCpuFlag(kCpuHasSSE41)) {
816
- Scale2RowUp = ScaleUVRowUp2_Bilinear_16_Any_SSE41;
817
- }
818
- #endif
819
-
820
- #ifdef HAS_SCALEUVROWUP2_BILINEAR_16_AVX2
821
- if (TestCpuFlag(kCpuHasAVX2)) {
822
- Scale2RowUp = ScaleUVRowUp2_Bilinear_16_Any_AVX2;
823
- }
824
- #endif
825
-
826
- #ifdef HAS_SCALEUVROWUP2_BILINEAR_16_NEON
827
- if (TestCpuFlag(kCpuHasNEON)) {
828
- Scale2RowUp = ScaleUVRowUp2_Bilinear_16_Any_NEON;
829
- }
830
- #endif
831
-
832
- Scale2RowUp(src_ptr, 0, dst_ptr, 0, dst_width);
833
- dst_ptr += dst_stride;
834
- for (x = 0; x < src_height - 1; ++x) {
835
- Scale2RowUp(src_ptr, src_stride, dst_ptr, dst_stride, dst_width);
836
- src_ptr += src_stride;
837
- // TODO(fbarchard): Test performance of writing one row of destination at a
838
- // time.
839
- dst_ptr += 2 * dst_stride;
840
- }
841
- if (!(dst_height & 1)) {
842
- Scale2RowUp(src_ptr, 0, dst_ptr, 0, dst_width);
843
- }
844
- }
845
-
846
- // Scale UV to/from any dimensions, without interpolation.
847
- // Fixed point math is used for performance: The upper 16 bits
848
- // of x and dx is the integer part of the source position and
849
- // the lower 16 bits are the fixed decimal part.
850
-
851
- static void ScaleUVSimple(int src_width,
852
- int src_height,
853
- int dst_width,
854
- int dst_height,
855
- int src_stride,
856
- int dst_stride,
857
- const uint8_t* src_uv,
858
- uint8_t* dst_uv,
859
- int x,
860
- int dx,
861
- int y,
862
- int dy) {
863
- int j;
864
- void (*ScaleUVCols)(uint8_t* dst_uv, const uint8_t* src_uv, int dst_width,
865
- int x, int dx) =
866
- (src_width >= 32768) ? ScaleUVCols64_C : ScaleUVCols_C;
867
- (void)src_height;
868
- #if defined(HAS_SCALEUVCOLS_SSSE3)
869
- if (TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) {
870
- ScaleUVCols = ScaleUVCols_SSSE3;
871
- }
872
- #endif
873
- #if defined(HAS_SCALEUVCOLS_NEON)
874
- if (TestCpuFlag(kCpuHasNEON)) {
875
- ScaleUVCols = ScaleUVCols_Any_NEON;
876
- if (IS_ALIGNED(dst_width, 8)) {
877
- ScaleUVCols = ScaleUVCols_NEON;
878
- }
879
- }
880
- #endif
881
- if (src_width * 2 == dst_width && x < 0x8000) {
882
- ScaleUVCols = ScaleUVColsUp2_C;
883
- #if defined(HAS_SCALEUVCOLSUP2_SSSE3)
884
- if (TestCpuFlag(kCpuHasSSSE3) && IS_ALIGNED(dst_width, 8)) {
885
- ScaleUVCols = ScaleUVColsUp2_SSSE3;
886
- }
887
- #endif
888
- }
889
-
890
- for (j = 0; j < dst_height; ++j) {
891
- ScaleUVCols(dst_uv, src_uv + (y >> 16) * (intptr_t)src_stride, dst_width, x,
892
- dx);
893
- dst_uv += dst_stride;
894
- y += dy;
895
- }
896
- }
897
-
898
- // Copy UV with optional flipping
899
- #if HAS_UVCOPY
900
- static int UVCopy(const uint8_t* src_uv,
901
- int src_stride_uv,
902
- uint8_t* dst_uv,
903
- int dst_stride_uv,
904
- int width,
905
- int height) {
906
- if (!src_uv || !dst_uv || width <= 0 || height == 0) {
907
- return -1;
908
- }
909
- // Negative height means invert the image.
910
- if (height < 0) {
911
- height = -height;
912
- src_uv = src_uv + (height - 1) * (intptr_t)src_stride_uv;
913
- src_stride_uv = -src_stride_uv;
914
- }
915
-
916
- CopyPlane(src_uv, src_stride_uv, dst_uv, dst_stride_uv, width * 2, height);
917
- return 0;
918
- }
919
-
920
- static int UVCopy_16(const uint16_t* src_uv,
921
- int src_stride_uv,
922
- uint16_t* dst_uv,
923
- int dst_stride_uv,
924
- int width,
925
- int height) {
926
- if (!src_uv || !dst_uv || width <= 0 || height == 0) {
927
- return -1;
928
- }
929
- // Negative height means invert the image.
930
- if (height < 0) {
931
- height = -height;
932
- src_uv = src_uv + (height - 1) * (intptr_t)src_stride_uv;
933
- src_stride_uv = -src_stride_uv;
934
- }
935
-
936
- CopyPlane_16(src_uv, src_stride_uv, dst_uv, dst_stride_uv, width * 2, height);
937
- return 0;
938
- }
939
- #endif // HAS_UVCOPY
940
-
941
- // Scale a UV plane (from NV12)
942
- // This function in turn calls a scaling function
943
- // suitable for handling the desired resolutions.
944
- static int ScaleUV(const uint8_t* src,
945
- int src_stride,
946
- int src_width,
947
- int src_height,
948
- uint8_t* dst,
949
- int dst_stride,
950
- int dst_width,
951
- int dst_height,
952
- int clip_x,
953
- int clip_y,
954
- int clip_width,
955
- int clip_height,
956
- enum FilterMode filtering) {
957
- // Initial source x/y coordinate and step values as 16.16 fixed point.
958
- int x = 0;
959
- int y = 0;
960
- int dx = 0;
961
- int dy = 0;
962
- // UV does not support box filter yet, but allow the user to pass it.
963
- // Simplify filtering when possible.
964
- filtering = ScaleFilterReduce(src_width, src_height, dst_width, dst_height,
965
- filtering);
966
-
967
- // Negative src_height means invert the image.
968
- if (src_height < 0) {
969
- src_height = -src_height;
970
- src = src + (src_height - 1) * (intptr_t)src_stride;
971
- src_stride = -src_stride;
972
- }
973
- ScaleSlope(src_width, src_height, dst_width, dst_height, filtering, &x, &y,
974
- &dx, &dy);
975
- src_width = Abs(src_width);
976
- if (clip_x) {
977
- int64_t clipf = (int64_t)(clip_x)*dx;
978
- x += (clipf & 0xffff);
979
- src += (clipf >> 16) * 2;
980
- dst += clip_x * 2;
981
- }
982
- if (clip_y) {
983
- int64_t clipf = (int64_t)(clip_y)*dy;
984
- y += (clipf & 0xffff);
985
- src += (clipf >> 16) * (intptr_t)src_stride;
986
- dst += clip_y * dst_stride;
987
- }
988
-
989
- // Special case for integer step values.
990
- if (((dx | dy) & 0xffff) == 0) {
991
- if (!dx || !dy) { // 1 pixel wide and/or tall.
992
- filtering = kFilterNone;
993
- } else {
994
- // Optimized even scale down. ie 2, 4, 6, 8, 10x.
995
- if (!(dx & 0x10000) && !(dy & 0x10000)) {
996
- #if HAS_SCALEUVDOWN2
997
- if (dx == 0x20000 && dy == 0x20000) {
998
- // Optimized 1/2 downsample.
999
- ScaleUVDown2(src_width, src_height, clip_width, clip_height,
1000
- src_stride, dst_stride, src, dst, x, dx, y, dy,
1001
- filtering);
1002
- return 0;
1003
- }
1004
- #endif
1005
- #if HAS_SCALEUVDOWN4BOX
1006
- if (dx == 0x40000 && dy == 0x40000 && filtering == kFilterBox) {
1007
- // Optimized 1/4 box downsample.
1008
- return ScaleUVDown4Box(src_width, src_height, clip_width, clip_height,
1009
- src_stride, dst_stride, src, dst, x, dx, y,
1010
- dy);
1011
- }
1012
- #endif
1013
- #if HAS_SCALEUVDOWNEVEN
1014
- ScaleUVDownEven(src_width, src_height, clip_width, clip_height,
1015
- src_stride, dst_stride, src, dst, x, dx, y, dy,
1016
- filtering);
1017
- return 0;
1018
- #endif
1019
- }
1020
- // Optimized odd scale down. ie 3, 5, 7, 9x.
1021
- if ((dx & 0x10000) && (dy & 0x10000)) {
1022
- filtering = kFilterNone;
1023
- #ifdef HAS_UVCOPY
1024
- if (dx == 0x10000 && dy == 0x10000) {
1025
- // Straight copy.
1026
- UVCopy(src + (y >> 16) * (intptr_t)src_stride + (x >> 16) * 2,
1027
- src_stride, dst, dst_stride, clip_width, clip_height);
1028
- return 0;
1029
- }
1030
- #endif
1031
- }
1032
- }
1033
- }
1034
- // HAS_SCALEPLANEVERTICAL
1035
- if (dx == 0x10000 && (x & 0xffff) == 0) {
1036
- // Arbitrary scale vertically, but unscaled horizontally.
1037
- ScalePlaneVertical(src_height, clip_width, clip_height, src_stride,
1038
- dst_stride, src, dst, x, y, dy, /*bpp=*/2, filtering);
1039
- return 0;
1040
- }
1041
- if ((filtering == kFilterLinear) && ((dst_width + 1) / 2 == src_width)) {
1042
- ScaleUVLinearUp2(src_width, src_height, clip_width, clip_height, src_stride,
1043
- dst_stride, src, dst);
1044
- return 0;
1045
- }
1046
- if ((clip_height + 1) / 2 == src_height &&
1047
- (clip_width + 1) / 2 == src_width &&
1048
- (filtering == kFilterBilinear || filtering == kFilterBox)) {
1049
- ScaleUVBilinearUp2(src_width, src_height, clip_width, clip_height,
1050
- src_stride, dst_stride, src, dst);
1051
- return 0;
1052
- }
1053
- #if HAS_SCALEUVBILINEARUP
1054
- if (filtering && dy < 65536) {
1055
- return ScaleUVBilinearUp(src_width, src_height, clip_width, clip_height,
1056
- src_stride, dst_stride, src, dst, x, dx, y, dy,
1057
- filtering);
1058
- }
1059
- #endif
1060
- #if HAS_SCALEUVBILINEARDOWN
1061
- if (filtering) {
1062
- return ScaleUVBilinearDown(src_width, src_height, clip_width, clip_height,
1063
- src_stride, dst_stride, src, dst, x, dx, y, dy,
1064
- filtering);
1065
- }
1066
- #endif
1067
- ScaleUVSimple(src_width, src_height, clip_width, clip_height, src_stride,
1068
- dst_stride, src, dst, x, dx, y, dy);
1069
- return 0;
1070
- }
1071
-
1072
- // Scale an UV image.
1073
- LIBYUV_API
1074
- int UVScale(const uint8_t* src_uv,
1075
- int src_stride_uv,
1076
- int src_width,
1077
- int src_height,
1078
- uint8_t* dst_uv,
1079
- int dst_stride_uv,
1080
- int dst_width,
1081
- int dst_height,
1082
- enum FilterMode filtering) {
1083
- if (!src_uv || src_width <= 0 || src_height == 0 || src_width > 32768 ||
1084
- src_height > 32768 || !dst_uv || dst_width <= 0 || dst_height <= 0) {
1085
- return -1;
1086
- }
1087
- return ScaleUV(src_uv, src_stride_uv, src_width, src_height, dst_uv,
1088
- dst_stride_uv, dst_width, dst_height, 0, 0, dst_width,
1089
- dst_height, filtering);
1090
- }
1091
-
1092
- // Scale a 16 bit UV image.
1093
- // This function is currently incomplete, it can't handle all cases.
1094
- LIBYUV_API
1095
- int UVScale_16(const uint16_t* src_uv,
1096
- int src_stride_uv,
1097
- int src_width,
1098
- int src_height,
1099
- uint16_t* dst_uv,
1100
- int dst_stride_uv,
1101
- int dst_width,
1102
- int dst_height,
1103
- enum FilterMode filtering) {
1104
- int dy = 0;
1105
-
1106
- if (!src_uv || src_width <= 0 || src_height == 0 || src_width > 32768 ||
1107
- src_height > 32768 || !dst_uv || dst_width <= 0 || dst_height <= 0) {
1108
- return -1;
1109
- }
1110
-
1111
- // UV does not support box filter yet, but allow the user to pass it.
1112
- // Simplify filtering when possible.
1113
- filtering = ScaleFilterReduce(src_width, src_height, dst_width, dst_height,
1114
- filtering);
1115
-
1116
- // Negative src_height means invert the image.
1117
- if (src_height < 0) {
1118
- src_height = -src_height;
1119
- src_uv = src_uv + (src_height - 1) * (intptr_t)src_stride_uv;
1120
- src_stride_uv = -src_stride_uv;
1121
- }
1122
- src_width = Abs(src_width);
1123
-
1124
- #ifdef HAS_UVCOPY
1125
- if (!filtering && src_width == dst_width && (src_height % dst_height == 0)) {
1126
- if (dst_height == 1) {
1127
- UVCopy_16(src_uv + ((src_height - 1) / 2) * (intptr_t)src_stride_uv,
1128
- src_stride_uv, dst_uv, dst_stride_uv, dst_width, dst_height);
1129
- } else {
1130
- dy = src_height / dst_height;
1131
- UVCopy_16(src_uv + ((dy - 1) / 2) * (intptr_t)src_stride_uv,
1132
- (int)(dy * (intptr_t)src_stride_uv), dst_uv, dst_stride_uv,
1133
- dst_width, dst_height);
1134
- }
1135
-
1136
- return 0;
1137
- }
1138
- #endif
1139
-
1140
- if ((filtering == kFilterLinear) && ((dst_width + 1) / 2 == src_width)) {
1141
- ScaleUVLinearUp2_16(src_width, src_height, dst_width, dst_height,
1142
- src_stride_uv, dst_stride_uv, src_uv, dst_uv);
1143
- return 0;
1144
- }
1145
-
1146
- if ((dst_height + 1) / 2 == src_height && (dst_width + 1) / 2 == src_width &&
1147
- (filtering == kFilterBilinear || filtering == kFilterBox)) {
1148
- ScaleUVBilinearUp2_16(src_width, src_height, dst_width, dst_height,
1149
- src_stride_uv, dst_stride_uv, src_uv, dst_uv);
1150
- return 0;
1151
- }
1152
-
1153
- return -1;
1154
- }
1155
-
1156
- #ifdef __cplusplus
1157
- } // extern "C"
1158
- } // namespace libyuv
1159
- #endif