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,1159 +1,1159 @@
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
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