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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/.gitattributes +2 -0
  2. package/.gitignore +27 -0
  3. package/CHANGELOG.md +2 -2
  4. package/CONTRIBUTING.md +2 -2
  5. package/README.md +442 -443
  6. package/android/build.gradle +12 -4
  7. package/android/src/main/cpp/CMakeLists.txt +101 -94
  8. package/android/src/main/cpp/libyuv/.clang-format +6 -6
  9. package/android/src/main/cpp/libyuv/.gn +40 -40
  10. package/android/src/main/cpp/libyuv/.vpython3 +410 -410
  11. package/android/src/main/cpp/libyuv/AUTHORS +7 -7
  12. package/android/src/main/cpp/libyuv/Android.bp +202 -202
  13. package/android/src/main/cpp/libyuv/Android.mk +106 -106
  14. package/android/src/main/cpp/libyuv/BUILD.gn +490 -490
  15. package/android/src/main/cpp/libyuv/CM_linux_packages.cmake +70 -70
  16. package/android/src/main/cpp/libyuv/CMakeLists.txt +259 -252
  17. package/android/src/main/cpp/libyuv/DEPS +935 -935
  18. package/android/src/main/cpp/libyuv/DIR_METADATA +3 -3
  19. package/android/src/main/cpp/libyuv/LICENSE +29 -29
  20. package/android/src/main/cpp/libyuv/OWNERS +11 -11
  21. package/android/src/main/cpp/libyuv/PATENTS +23 -23
  22. package/android/src/main/cpp/libyuv/PRESUBMIT.py +65 -65
  23. package/android/src/main/cpp/libyuv/README.chromium +11 -11
  24. package/android/src/main/cpp/libyuv/README.md +19 -19
  25. package/android/src/main/cpp/libyuv/build_overrides/build.gni +60 -60
  26. package/android/src/main/cpp/libyuv/build_overrides/gtest.gni +19 -19
  27. package/android/src/main/cpp/libyuv/build_overrides/partition_alloc.gni +17 -17
  28. package/android/src/main/cpp/libyuv/codereview.settings +5 -5
  29. package/android/src/main/cpp/libyuv/docs/deprecated_builds.md +409 -409
  30. package/android/src/main/cpp/libyuv/docs/environment_variables.md +64 -64
  31. package/android/src/main/cpp/libyuv/docs/feature_detection.md +108 -108
  32. package/android/src/main/cpp/libyuv/docs/filtering.md +196 -196
  33. package/android/src/main/cpp/libyuv/docs/formats.md +208 -208
  34. package/android/src/main/cpp/libyuv/docs/getting_started.md +296 -296
  35. package/android/src/main/cpp/libyuv/docs/rotation.md +107 -107
  36. package/android/src/main/cpp/libyuv/download_vs_toolchain.py +29 -29
  37. package/android/src/main/cpp/libyuv/include/libyuv/basic_types.h +68 -68
  38. package/android/src/main/cpp/libyuv/include/libyuv/compare.h +111 -111
  39. package/android/src/main/cpp/libyuv/include/libyuv/compare_row.h +112 -112
  40. package/android/src/main/cpp/libyuv/include/libyuv/convert.h +1117 -1117
  41. package/android/src/main/cpp/libyuv/include/libyuv/convert_argb.h +2335 -2335
  42. package/android/src/main/cpp/libyuv/include/libyuv/convert_from.h +203 -203
  43. package/android/src/main/cpp/libyuv/include/libyuv/convert_from_argb.h +394 -394
  44. package/android/src/main/cpp/libyuv/include/libyuv/cpu_id.h +147 -147
  45. package/android/src/main/cpp/libyuv/include/libyuv/cpu_support.h +99 -99
  46. package/android/src/main/cpp/libyuv/include/libyuv/loongson_intrinsics.h +1949 -1949
  47. package/android/src/main/cpp/libyuv/include/libyuv/mjpeg_decoder.h +195 -195
  48. package/android/src/main/cpp/libyuv/include/libyuv/planar_functions.h +1131 -1131
  49. package/android/src/main/cpp/libyuv/include/libyuv/rotate.h +296 -296
  50. package/android/src/main/cpp/libyuv/include/libyuv/rotate_argb.h +37 -37
  51. package/android/src/main/cpp/libyuv/include/libyuv/rotate_row.h +265 -265
  52. package/android/src/main/cpp/libyuv/include/libyuv/row.h +6738 -6738
  53. package/android/src/main/cpp/libyuv/include/libyuv/row_sve.h +2154 -2154
  54. package/android/src/main/cpp/libyuv/include/libyuv/scale.h +336 -336
  55. package/android/src/main/cpp/libyuv/include/libyuv/scale_argb.h +76 -76
  56. package/android/src/main/cpp/libyuv/include/libyuv/scale_rgb.h +42 -42
  57. package/android/src/main/cpp/libyuv/include/libyuv/scale_row.h +1726 -1726
  58. package/android/src/main/cpp/libyuv/include/libyuv/scale_uv.h +51 -51
  59. package/android/src/main/cpp/libyuv/include/libyuv/version.h +16 -16
  60. package/android/src/main/cpp/libyuv/include/libyuv/video_common.h +222 -222
  61. package/android/src/main/cpp/libyuv/include/libyuv.h +33 -33
  62. package/android/src/main/cpp/libyuv/infra/config/OWNERS +3 -3
  63. package/android/src/main/cpp/libyuv/infra/config/PRESUBMIT.py +17 -17
  64. package/android/src/main/cpp/libyuv/infra/config/README.md +2 -2
  65. package/android/src/main/cpp/libyuv/infra/config/codereview.settings +6 -6
  66. package/android/src/main/cpp/libyuv/infra/config/commit-queue.cfg +144 -144
  67. package/android/src/main/cpp/libyuv/infra/config/cr-buildbucket.cfg +1185 -1185
  68. package/android/src/main/cpp/libyuv/infra/config/luci-logdog.cfg +9 -9
  69. package/android/src/main/cpp/libyuv/infra/config/luci-milo.cfg +246 -246
  70. package/android/src/main/cpp/libyuv/infra/config/luci-scheduler.cfg +385 -385
  71. package/android/src/main/cpp/libyuv/infra/config/main.star +402 -402
  72. package/android/src/main/cpp/libyuv/infra/config/project.cfg +16 -16
  73. package/android/src/main/cpp/libyuv/infra/config/realms.cfg +111 -111
  74. package/android/src/main/cpp/libyuv/libyuv.gni +34 -34
  75. package/android/src/main/cpp/libyuv/libyuv.gyp +149 -149
  76. package/android/src/main/cpp/libyuv/libyuv.gypi +87 -87
  77. package/android/src/main/cpp/libyuv/linux.mk +96 -96
  78. package/android/src/main/cpp/libyuv/public.mk +13 -13
  79. package/android/src/main/cpp/libyuv/pylintrc +49 -49
  80. package/android/src/main/cpp/libyuv/riscv_script/prepare_toolchain_qemu.sh +74 -74
  81. package/android/src/main/cpp/libyuv/riscv_script/riscv-clang.cmake +56 -56
  82. package/android/src/main/cpp/libyuv/riscv_script/run_qemu.sh +15 -15
  83. package/android/src/main/cpp/libyuv/source/compare.cc +435 -435
  84. package/android/src/main/cpp/libyuv/source/compare_common.cc +74 -74
  85. package/android/src/main/cpp/libyuv/source/compare_gcc.cc +362 -362
  86. package/android/src/main/cpp/libyuv/source/compare_neon.cc +96 -96
  87. package/android/src/main/cpp/libyuv/source/compare_neon64.cc +223 -223
  88. package/android/src/main/cpp/libyuv/source/compare_win.cc +241 -241
  89. package/android/src/main/cpp/libyuv/source/convert.cc +4746 -4746
  90. package/android/src/main/cpp/libyuv/source/convert_argb.cc +9179 -9179
  91. package/android/src/main/cpp/libyuv/source/convert_from.cc +866 -866
  92. package/android/src/main/cpp/libyuv/source/convert_from_argb.cc +3671 -3671
  93. package/android/src/main/cpp/libyuv/source/convert_jpeg.cc +602 -602
  94. package/android/src/main/cpp/libyuv/source/convert_to_argb.cc +391 -391
  95. package/android/src/main/cpp/libyuv/source/convert_to_i420.cc +288 -288
  96. package/android/src/main/cpp/libyuv/source/cpu_id.cc +496 -496
  97. package/android/src/main/cpp/libyuv/source/mjpeg_decoder.cc +580 -580
  98. package/android/src/main/cpp/libyuv/source/mjpeg_validate.cc +71 -71
  99. package/android/src/main/cpp/libyuv/source/planar_functions.cc +5663 -5663
  100. package/android/src/main/cpp/libyuv/source/rotate.cc +1241 -1241
  101. package/android/src/main/cpp/libyuv/source/rotate_any.cc +76 -76
  102. package/android/src/main/cpp/libyuv/source/rotate_argb.cc +259 -259
  103. package/android/src/main/cpp/libyuv/source/rotate_common.cc +208 -208
  104. package/android/src/main/cpp/libyuv/source/rotate_gcc.cc +505 -505
  105. package/android/src/main/cpp/libyuv/source/rotate_lsx.cc +233 -233
  106. package/android/src/main/cpp/libyuv/source/rotate_neon.cc +219 -219
  107. package/android/src/main/cpp/libyuv/source/rotate_neon64.cc +273 -273
  108. package/android/src/main/cpp/libyuv/source/rotate_sme.cc +174 -174
  109. package/android/src/main/cpp/libyuv/source/rotate_win.cc +253 -253
  110. package/android/src/main/cpp/libyuv/source/row_any.cc +2519 -2519
  111. package/android/src/main/cpp/libyuv/source/row_common.cc +4461 -4461
  112. package/android/src/main/cpp/libyuv/source/row_gcc.cc +9570 -9570
  113. package/android/src/main/cpp/libyuv/source/row_lasx.cc +2343 -2343
  114. package/android/src/main/cpp/libyuv/source/row_lsx.cc +3030 -3030
  115. package/android/src/main/cpp/libyuv/source/row_neon.cc +4026 -4026
  116. package/android/src/main/cpp/libyuv/source/row_neon64.cc +5617 -5617
  117. package/android/src/main/cpp/libyuv/source/row_rvv.cc +2599 -2599
  118. package/android/src/main/cpp/libyuv/source/row_sme.cc +1183 -1183
  119. package/android/src/main/cpp/libyuv/source/row_sve.cc +1088 -1088
  120. package/android/src/main/cpp/libyuv/source/row_win.cc +6453 -6453
  121. package/android/src/main/cpp/libyuv/source/scale.cc +2710 -2710
  122. package/android/src/main/cpp/libyuv/source/scale_any.cc +991 -991
  123. package/android/src/main/cpp/libyuv/source/scale_argb.cc +1158 -1158
  124. package/android/src/main/cpp/libyuv/source/scale_common.cc +1977 -1977
  125. package/android/src/main/cpp/libyuv/source/scale_gcc.cc +2947 -2947
  126. package/android/src/main/cpp/libyuv/source/scale_lsx.cc +739 -739
  127. package/android/src/main/cpp/libyuv/source/scale_neon.cc +1449 -1449
  128. package/android/src/main/cpp/libyuv/source/scale_neon64.cc +1552 -1552
  129. package/android/src/main/cpp/libyuv/source/scale_rgb.cc +82 -82
  130. package/android/src/main/cpp/libyuv/source/scale_rvv.cc +1971 -1971
  131. package/android/src/main/cpp/libyuv/source/scale_sme.cc +555 -555
  132. package/android/src/main/cpp/libyuv/source/scale_uv.cc +1159 -1159
  133. package/android/src/main/cpp/libyuv/source/scale_win.cc +1392 -1392
  134. package/android/src/main/cpp/libyuv/source/test.sh +35 -35
  135. package/android/src/main/cpp/libyuv/source/video_common.cc +62 -62
  136. package/android/src/main/cpp/libyuv/tools_libyuv/OWNERS +4 -4
  137. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/roll_deps.py +931 -931
  138. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py +164 -164
  139. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS +21 -21
  140. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.new +13 -13
  141. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old +13 -13
  142. package/android/src/main/cpp/libyuv/tools_libyuv/get_landmines.py +38 -38
  143. package/android/src/main/cpp/libyuv/tools_libyuv/msan/OWNERS +3 -3
  144. package/android/src/main/cpp/libyuv/tools_libyuv/msan/blacklist.txt +9 -9
  145. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/OWNERS +3 -3
  146. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/blacklist.txt +15 -15
  147. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/vptr_blacklist.txt +25 -25
  148. package/android/src/main/cpp/libyuv/unit_test/basictypes_test.cc +43 -43
  149. package/android/src/main/cpp/libyuv/unit_test/color_test.cc +848 -848
  150. package/android/src/main/cpp/libyuv/unit_test/compare_test.cc +739 -739
  151. package/android/src/main/cpp/libyuv/unit_test/convert_argb_test.cc +2867 -2867
  152. package/android/src/main/cpp/libyuv/unit_test/convert_test.cc +2133 -2133
  153. package/android/src/main/cpp/libyuv/unit_test/cpu_test.cc +427 -427
  154. package/android/src/main/cpp/libyuv/unit_test/cpu_thread_test.cc +63 -63
  155. package/android/src/main/cpp/libyuv/unit_test/math_test.cc +160 -160
  156. package/android/src/main/cpp/libyuv/unit_test/planar_test.cc +4731 -4731
  157. package/android/src/main/cpp/libyuv/unit_test/rotate_argb_test.cc +334 -334
  158. package/android/src/main/cpp/libyuv/unit_test/rotate_test.cc +962 -962
  159. package/android/src/main/cpp/libyuv/unit_test/scale_argb_test.cc +590 -590
  160. package/android/src/main/cpp/libyuv/unit_test/scale_plane_test.cc +465 -465
  161. package/android/src/main/cpp/libyuv/unit_test/scale_rgb_test.cc +280 -280
  162. package/android/src/main/cpp/libyuv/unit_test/scale_test.cc +1135 -1135
  163. package/android/src/main/cpp/libyuv/unit_test/scale_uv_test.cc +249 -249
  164. package/android/src/main/cpp/libyuv/unit_test/testdata/arm_v7.txt +12 -12
  165. package/android/src/main/cpp/libyuv/unit_test/testdata/mips.txt +7 -7
  166. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson2k.txt +5 -5
  167. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson3.txt +10 -10
  168. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson_mmi.txt +7 -7
  169. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64.txt +3 -3
  170. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv.txt +3 -3
  171. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv_zvfh.txt +3 -3
  172. package/android/src/main/cpp/libyuv/unit_test/testdata/tegra3.txt +23 -23
  173. package/android/src/main/cpp/libyuv/unit_test/unit_test.cc +581 -581
  174. package/android/src/main/cpp/libyuv/unit_test/unit_test.h +232 -232
  175. package/android/src/main/cpp/libyuv/unit_test/video_common_test.cc +112 -112
  176. package/android/src/main/cpp/libyuv/util/Makefile +9 -9
  177. package/android/src/main/cpp/libyuv/util/color.cc +120 -120
  178. package/android/src/main/cpp/libyuv/util/compare.cc +67 -67
  179. package/android/src/main/cpp/libyuv/util/cpuid.c +211 -211
  180. package/android/src/main/cpp/libyuv/util/i444tonv12_eg.cc +27 -27
  181. package/android/src/main/cpp/libyuv/util/psnr.cc +291 -291
  182. package/android/src/main/cpp/libyuv/util/psnr.h +47 -47
  183. package/android/src/main/cpp/libyuv/util/psnr_main.cc +620 -620
  184. package/android/src/main/cpp/libyuv/util/ssim.cc +364 -364
  185. package/android/src/main/cpp/libyuv/util/ssim.h +38 -38
  186. package/android/src/main/cpp/libyuv/util/yuvconstants.c +114 -114
  187. package/android/src/main/cpp/libyuv/util/yuvconvert.cc +367 -367
  188. package/android/src/main/cpp/libyuv/winarm.mk +47 -47
  189. package/package.json +86 -84
  190. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  191. package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
  192. package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
  193. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  194. package/android/.gradle/8.9/gc.properties +0 -0
  195. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  196. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  197. package/android/.gradle/vcs-1/gc.properties +0 -0
@@ -1,1158 +1,1158 @@
1
- /*
2
- * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3
- *
4
- * Use of this source code is governed by a BSD-style license
5
- * that can be found in the LICENSE file in the root of the source
6
- * tree. An additional intellectual property rights grant can be found
7
- * in the file PATENTS. All contributing project authors may
8
- * be found in the AUTHORS file in the root of the source tree.
9
- */
10
-
11
- #include "libyuv/scale.h"
12
-
13
- #include <assert.h>
14
- #include <limits.h>
15
- #include <stdint.h>
16
- #include <stdlib.h>
17
- #include <string.h>
18
-
19
- #include "libyuv/cpu_id.h"
20
- #include "libyuv/planar_functions.h" // For CopyARGB
21
- #include "libyuv/row.h"
22
- #include "libyuv/scale_argb.h"
23
- #include "libyuv/scale_row.h"
24
-
25
- #ifdef __cplusplus
26
- namespace libyuv {
27
- extern "C" {
28
- #endif
29
-
30
- static __inline int Abs(int v) {
31
- return v >= 0 ? v : -v;
32
- }
33
-
34
- // ScaleARGB ARGB, 1/2
35
- // This is an optimized version for scaling down a ARGB to 1/2 of
36
- // its original size.
37
- static void ScaleARGBDown2(int src_width,
38
- int src_height,
39
- int dst_width,
40
- int dst_height,
41
- int src_stride,
42
- int dst_stride,
43
- const uint8_t* src_argb,
44
- uint8_t* dst_argb,
45
- int x,
46
- int dx,
47
- int y,
48
- int dy,
49
- enum FilterMode filtering) {
50
- int j;
51
- int row_stride = src_stride * (dy >> 16);
52
- void (*ScaleARGBRowDown2)(const uint8_t* src_argb, ptrdiff_t src_stride,
53
- uint8_t* dst_argb, int dst_width) =
54
- filtering == kFilterNone
55
- ? ScaleARGBRowDown2_C
56
- : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_C
57
- : ScaleARGBRowDown2Box_C);
58
- (void)src_width;
59
- (void)src_height;
60
- (void)dx;
61
- assert(dx == 65536 * 2); // Test scale factor of 2.
62
- assert((dy & 0x1ffff) == 0); // Test vertical scale is multiple of 2.
63
- // Advance to odd row, even column.
64
- if (filtering == kFilterBilinear) {
65
- src_argb += (y >> 16) * (intptr_t)src_stride + (x >> 16) * 4;
66
- } else {
67
- src_argb += (y >> 16) * (intptr_t)src_stride + ((x >> 16) - 1) * 4;
68
- }
69
-
70
- #if defined(HAS_SCALEARGBROWDOWN2_SSE2)
71
- if (TestCpuFlag(kCpuHasSSE2)) {
72
- ScaleARGBRowDown2 =
73
- filtering == kFilterNone
74
- ? ScaleARGBRowDown2_Any_SSE2
75
- : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_Any_SSE2
76
- : ScaleARGBRowDown2Box_Any_SSE2);
77
- if (IS_ALIGNED(dst_width, 4)) {
78
- ScaleARGBRowDown2 =
79
- filtering == kFilterNone
80
- ? ScaleARGBRowDown2_SSE2
81
- : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_SSE2
82
- : ScaleARGBRowDown2Box_SSE2);
83
- }
84
- }
85
- #endif
86
- #if defined(HAS_SCALEARGBROWDOWN2_NEON)
87
- if (TestCpuFlag(kCpuHasNEON)) {
88
- ScaleARGBRowDown2 =
89
- filtering == kFilterNone
90
- ? ScaleARGBRowDown2_Any_NEON
91
- : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_Any_NEON
92
- : ScaleARGBRowDown2Box_Any_NEON);
93
- if (IS_ALIGNED(dst_width, 8)) {
94
- ScaleARGBRowDown2 =
95
- filtering == kFilterNone
96
- ? ScaleARGBRowDown2_NEON
97
- : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_NEON
98
- : ScaleARGBRowDown2Box_NEON);
99
- }
100
- }
101
- #endif
102
- #if defined(HAS_SCALEARGBROWDOWN2_SME)
103
- if (TestCpuFlag(kCpuHasSME)) {
104
- ScaleARGBRowDown2 = filtering == kFilterNone ? ScaleARGBRowDown2_SME
105
- : filtering == kFilterLinear
106
- ? ScaleARGBRowDown2Linear_SME
107
- : ScaleARGBRowDown2Box_SME;
108
- }
109
- #endif
110
- #if defined(HAS_SCALEARGBROWDOWN2_LSX)
111
- if (TestCpuFlag(kCpuHasLSX)) {
112
- ScaleARGBRowDown2 =
113
- filtering == kFilterNone
114
- ? ScaleARGBRowDown2_Any_LSX
115
- : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_Any_LSX
116
- : ScaleARGBRowDown2Box_Any_LSX);
117
- if (IS_ALIGNED(dst_width, 4)) {
118
- ScaleARGBRowDown2 =
119
- filtering == kFilterNone
120
- ? ScaleARGBRowDown2_LSX
121
- : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_LSX
122
- : ScaleARGBRowDown2Box_LSX);
123
- }
124
- }
125
- #endif
126
- #if defined(HAS_SCALEARGBROWDOWN2_RVV) && \
127
- defined(HAS_SCALEARGBROWDOWN2LINEAR_RVV) && \
128
- defined(HAS_SCALEARGBROWDOWN2BOX_RVV)
129
- if (TestCpuFlag(kCpuHasRVV)) {
130
- ScaleARGBRowDown2 =
131
- filtering == kFilterNone
132
- ? ScaleARGBRowDown2_RVV
133
- : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_RVV
134
- : ScaleARGBRowDown2Box_RVV);
135
- }
136
- #endif
137
-
138
- if (filtering == kFilterLinear) {
139
- src_stride = 0;
140
- }
141
- for (j = 0; j < dst_height; ++j) {
142
- ScaleARGBRowDown2(src_argb, src_stride, dst_argb, dst_width);
143
- src_argb += row_stride;
144
- dst_argb += dst_stride;
145
- }
146
- }
147
-
148
- // ScaleARGB ARGB, 1/4
149
- // This is an optimized version for scaling down a ARGB to 1/4 of
150
- // its original size.
151
- static int ScaleARGBDown4Box(int src_width,
152
- int src_height,
153
- int dst_width,
154
- int dst_height,
155
- int src_stride,
156
- int dst_stride,
157
- const uint8_t* src_argb,
158
- uint8_t* dst_argb,
159
- int x,
160
- int dx,
161
- int y,
162
- int dy) {
163
- int j;
164
- // Allocate 2 rows of ARGB.
165
- const int row_size = (dst_width * 2 * 4 + 31) & ~31;
166
- // TODO(fbarchard): Remove this row buffer and implement a ScaleARGBRowDown4
167
- // but implemented via a 2 pass wrapper that uses a very small array on the
168
- // stack with a horizontal loop.
169
- align_buffer_64(row, row_size * 2);
170
- if (!row)
171
- return 1;
172
- int row_stride = src_stride * (dy >> 16);
173
- void (*ScaleARGBRowDown2)(const uint8_t* src_argb, ptrdiff_t src_stride,
174
- uint8_t* dst_argb, int dst_width) =
175
- ScaleARGBRowDown2Box_C;
176
- // Advance to odd row, even column.
177
- src_argb += (y >> 16) * (intptr_t)src_stride + (x >> 16) * 4;
178
- (void)src_width;
179
- (void)src_height;
180
- (void)dx;
181
- assert(dx == 65536 * 4); // Test scale factor of 4.
182
- assert((dy & 0x3ffff) == 0); // Test vertical scale is multiple of 4.
183
- #if defined(HAS_SCALEARGBROWDOWN2_SSE2)
184
- if (TestCpuFlag(kCpuHasSSE2)) {
185
- ScaleARGBRowDown2 = ScaleARGBRowDown2Box_Any_SSE2;
186
- if (IS_ALIGNED(dst_width, 4)) {
187
- ScaleARGBRowDown2 = ScaleARGBRowDown2Box_SSE2;
188
- }
189
- }
190
- #endif
191
- #if defined(HAS_SCALEARGBROWDOWN2_NEON)
192
- if (TestCpuFlag(kCpuHasNEON)) {
193
- ScaleARGBRowDown2 = ScaleARGBRowDown2Box_Any_NEON;
194
- if (IS_ALIGNED(dst_width, 8)) {
195
- ScaleARGBRowDown2 = ScaleARGBRowDown2Box_NEON;
196
- }
197
- }
198
- #endif
199
- #if defined(HAS_SCALEARGBROWDOWN2_SME)
200
- if (TestCpuFlag(kCpuHasSME)) {
201
- ScaleARGBRowDown2 = ScaleARGBRowDown2Box_SME;
202
- }
203
- #endif
204
- #if defined(HAS_SCALEARGBROWDOWN2BOX_RVV)
205
- if (TestCpuFlag(kCpuHasRVV)) {
206
- ScaleARGBRowDown2 = ScaleARGBRowDown2Box_RVV;
207
- }
208
- #endif
209
-
210
- for (j = 0; j < dst_height; ++j) {
211
- ScaleARGBRowDown2(src_argb, src_stride, row, dst_width * 2);
212
- ScaleARGBRowDown2(src_argb + src_stride * 2, src_stride, row + row_size,
213
- dst_width * 2);
214
- ScaleARGBRowDown2(row, row_size, dst_argb, dst_width);
215
- src_argb += row_stride;
216
- dst_argb += dst_stride;
217
- }
218
- free_aligned_buffer_64(row);
219
- return 0;
220
- }
221
-
222
- // ScaleARGB ARGB Even
223
- // This is an optimized version for scaling down a ARGB to even
224
- // multiple of its original size.
225
- static void ScaleARGBDownEven(int src_width,
226
- int src_height,
227
- int dst_width,
228
- int dst_height,
229
- int src_stride,
230
- int dst_stride,
231
- const uint8_t* src_argb,
232
- uint8_t* dst_argb,
233
- int x,
234
- int dx,
235
- int y,
236
- int dy,
237
- enum FilterMode filtering) {
238
- int j;
239
- int col_step = dx >> 16;
240
- ptrdiff_t row_stride = (ptrdiff_t)((dy >> 16) * (intptr_t)src_stride);
241
- void (*ScaleARGBRowDownEven)(const uint8_t* src_argb, ptrdiff_t src_stride,
242
- int src_step, uint8_t* dst_argb, int dst_width) =
243
- filtering ? ScaleARGBRowDownEvenBox_C : ScaleARGBRowDownEven_C;
244
- (void)src_width;
245
- (void)src_height;
246
- assert(IS_ALIGNED(src_width, 2));
247
- assert(IS_ALIGNED(src_height, 2));
248
- src_argb += (y >> 16) * (intptr_t)src_stride + (x >> 16) * 4;
249
- #if defined(HAS_SCALEARGBROWDOWNEVEN_SSE2)
250
- if (TestCpuFlag(kCpuHasSSE2)) {
251
- ScaleARGBRowDownEven = filtering ? ScaleARGBRowDownEvenBox_Any_SSE2
252
- : ScaleARGBRowDownEven_Any_SSE2;
253
- if (IS_ALIGNED(dst_width, 4)) {
254
- ScaleARGBRowDownEven =
255
- filtering ? ScaleARGBRowDownEvenBox_SSE2 : ScaleARGBRowDownEven_SSE2;
256
- }
257
- }
258
- #endif
259
- #if defined(HAS_SCALEARGBROWDOWNEVEN_NEON)
260
- if (TestCpuFlag(kCpuHasNEON)) {
261
- ScaleARGBRowDownEven = filtering ? ScaleARGBRowDownEvenBox_Any_NEON
262
- : ScaleARGBRowDownEven_Any_NEON;
263
- if (IS_ALIGNED(dst_width, 4)) {
264
- ScaleARGBRowDownEven =
265
- filtering ? ScaleARGBRowDownEvenBox_NEON : ScaleARGBRowDownEven_NEON;
266
- }
267
- }
268
- #endif
269
- #if defined(HAS_SCALEARGBROWDOWNEVEN_LSX)
270
- if (TestCpuFlag(kCpuHasLSX)) {
271
- ScaleARGBRowDownEven = filtering ? ScaleARGBRowDownEvenBox_Any_LSX
272
- : ScaleARGBRowDownEven_Any_LSX;
273
- if (IS_ALIGNED(dst_width, 4)) {
274
- ScaleARGBRowDownEven =
275
- filtering ? ScaleARGBRowDownEvenBox_LSX : ScaleARGBRowDownEven_LSX;
276
- }
277
- }
278
- #endif
279
- #if defined(HAS_SCALEARGBROWDOWNEVENBOX_RVV)
280
- if (filtering && TestCpuFlag(kCpuHasRVV)) {
281
- ScaleARGBRowDownEven = ScaleARGBRowDownEvenBox_RVV;
282
- }
283
- #endif
284
- #if defined(HAS_SCALEARGBROWDOWNEVEN_RVV)
285
- if (!filtering && TestCpuFlag(kCpuHasRVV)) {
286
- ScaleARGBRowDownEven = ScaleARGBRowDownEven_RVV;
287
- }
288
- #endif
289
-
290
- if (filtering == kFilterLinear) {
291
- src_stride = 0;
292
- }
293
- for (j = 0; j < dst_height; ++j) {
294
- ScaleARGBRowDownEven(src_argb, src_stride, col_step, dst_argb, dst_width);
295
- src_argb += row_stride;
296
- dst_argb += dst_stride;
297
- }
298
- }
299
-
300
- // Scale ARGB down with bilinear interpolation.
301
- static int ScaleARGBBilinearDown(int src_width,
302
- int src_height,
303
- int dst_width,
304
- int dst_height,
305
- int src_stride,
306
- int dst_stride,
307
- const uint8_t* src_argb,
308
- uint8_t* dst_argb,
309
- int x,
310
- int dx,
311
- int y,
312
- int dy,
313
- enum FilterMode filtering) {
314
- int j;
315
- void (*InterpolateRow)(uint8_t* dst_argb, const uint8_t* src_argb,
316
- ptrdiff_t src_stride, int dst_width,
317
- int source_y_fraction) = InterpolateRow_C;
318
- void (*ScaleARGBFilterCols)(uint8_t* dst_argb, const uint8_t* src_argb,
319
- int dst_width, int x, int dx) =
320
- (src_width >= 32768) ? ScaleARGBFilterCols64_C : ScaleARGBFilterCols_C;
321
- int64_t xlast = x + (int64_t)(dst_width - 1) * dx;
322
- int64_t xl = (dx >= 0) ? x : xlast;
323
- int64_t xr = (dx >= 0) ? xlast : x;
324
- int clip_src_width;
325
- xl = (xl >> 16) & ~3; // Left edge aligned.
326
- xr = (xr >> 16) + 1; // Right most pixel used. Bilinear uses 2 pixels.
327
- xr = (xr + 1 + 3) & ~3; // 1 beyond 4 pixel aligned right most pixel.
328
- if (xr > src_width) {
329
- xr = src_width;
330
- }
331
- clip_src_width = (int)(xr - xl) * 4; // Width aligned to 4.
332
- src_argb += xl * 4;
333
- x -= (int)(xl << 16);
334
- #if defined(HAS_INTERPOLATEROW_SSSE3)
335
- if (TestCpuFlag(kCpuHasSSSE3)) {
336
- InterpolateRow = InterpolateRow_Any_SSSE3;
337
- if (IS_ALIGNED(clip_src_width, 16)) {
338
- InterpolateRow = InterpolateRow_SSSE3;
339
- }
340
- }
341
- #endif
342
- #if defined(HAS_INTERPOLATEROW_AVX2)
343
- if (TestCpuFlag(kCpuHasAVX2)) {
344
- InterpolateRow = InterpolateRow_Any_AVX2;
345
- if (IS_ALIGNED(clip_src_width, 32)) {
346
- InterpolateRow = InterpolateRow_AVX2;
347
- }
348
- }
349
- #endif
350
- #if defined(HAS_INTERPOLATEROW_NEON)
351
- if (TestCpuFlag(kCpuHasNEON)) {
352
- InterpolateRow = InterpolateRow_Any_NEON;
353
- if (IS_ALIGNED(clip_src_width, 16)) {
354
- InterpolateRow = InterpolateRow_NEON;
355
- }
356
- }
357
- #endif
358
- #if defined(HAS_INTERPOLATEROW_SME)
359
- if (TestCpuFlag(kCpuHasSME)) {
360
- InterpolateRow = InterpolateRow_SME;
361
- }
362
- #endif
363
- #if defined(HAS_INTERPOLATEROW_LSX)
364
- if (TestCpuFlag(kCpuHasLSX)) {
365
- InterpolateRow = InterpolateRow_Any_LSX;
366
- if (IS_ALIGNED(clip_src_width, 32)) {
367
- InterpolateRow = InterpolateRow_LSX;
368
- }
369
- }
370
- #endif
371
- #if defined(HAS_INTERPOLATEROW_RVV)
372
- if (TestCpuFlag(kCpuHasRVV)) {
373
- InterpolateRow = InterpolateRow_RVV;
374
- }
375
- #endif
376
- #if defined(HAS_SCALEARGBFILTERCOLS_SSSE3)
377
- if (TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) {
378
- ScaleARGBFilterCols = ScaleARGBFilterCols_SSSE3;
379
- }
380
- #endif
381
- #if defined(HAS_SCALEARGBFILTERCOLS_NEON)
382
- if (TestCpuFlag(kCpuHasNEON)) {
383
- ScaleARGBFilterCols = ScaleARGBFilterCols_Any_NEON;
384
- if (IS_ALIGNED(dst_width, 4)) {
385
- ScaleARGBFilterCols = ScaleARGBFilterCols_NEON;
386
- }
387
- }
388
- #endif
389
- #if defined(HAS_SCALEARGBFILTERCOLS_LSX)
390
- if (TestCpuFlag(kCpuHasLSX)) {
391
- ScaleARGBFilterCols = ScaleARGBFilterCols_Any_LSX;
392
- if (IS_ALIGNED(dst_width, 8)) {
393
- ScaleARGBFilterCols = ScaleARGBFilterCols_LSX;
394
- }
395
- }
396
- #endif
397
- #if defined(HAS_SCALEARGBFILTERCOLS_RVV)
398
- if (TestCpuFlag(kCpuHasRVV)) {
399
- ScaleARGBFilterCols = ScaleARGBFilterCols_RVV;
400
- }
401
- #endif
402
-
403
- // TODO(fbarchard): Consider not allocating row buffer for kFilterLinear.
404
- // Allocate a row of ARGB.
405
- {
406
- align_buffer_64(row, clip_src_width * 4);
407
- if (!row)
408
- return 1;
409
-
410
- const int max_y = (src_height - 1) << 16;
411
- if (y > max_y) {
412
- y = max_y;
413
- }
414
- for (j = 0; j < dst_height; ++j) {
415
- int yi = y >> 16;
416
- const uint8_t* src = src_argb + yi * (intptr_t)src_stride;
417
- if (filtering == kFilterLinear) {
418
- ScaleARGBFilterCols(dst_argb, src, dst_width, x, dx);
419
- } else {
420
- int yf = (y >> 8) & 255;
421
- InterpolateRow(row, src, src_stride, clip_src_width, yf);
422
- ScaleARGBFilterCols(dst_argb, row, dst_width, x, dx);
423
- }
424
- dst_argb += dst_stride;
425
- y += dy;
426
- if (y > max_y) {
427
- y = max_y;
428
- }
429
- }
430
- free_aligned_buffer_64(row);
431
- }
432
- return 0;
433
- }
434
-
435
- // Scale ARGB up with bilinear interpolation.
436
- static int ScaleARGBBilinearUp(int src_width,
437
- int src_height,
438
- int dst_width,
439
- int dst_height,
440
- int src_stride,
441
- int dst_stride,
442
- const uint8_t* src_argb,
443
- uint8_t* dst_argb,
444
- int x,
445
- int dx,
446
- int y,
447
- int dy,
448
- enum FilterMode filtering) {
449
- int j;
450
- void (*InterpolateRow)(uint8_t* dst_argb, const uint8_t* src_argb,
451
- ptrdiff_t src_stride, int dst_width,
452
- int source_y_fraction) = InterpolateRow_C;
453
- void (*ScaleARGBFilterCols)(uint8_t* dst_argb, const uint8_t* src_argb,
454
- int dst_width, int x, int dx) =
455
- filtering ? ScaleARGBFilterCols_C : ScaleARGBCols_C;
456
- const int max_y = (src_height - 1) << 16;
457
- #if defined(HAS_INTERPOLATEROW_SSSE3)
458
- if (TestCpuFlag(kCpuHasSSSE3)) {
459
- InterpolateRow = InterpolateRow_Any_SSSE3;
460
- if (IS_ALIGNED(dst_width, 4)) {
461
- InterpolateRow = InterpolateRow_SSSE3;
462
- }
463
- }
464
- #endif
465
- #if defined(HAS_INTERPOLATEROW_AVX2)
466
- if (TestCpuFlag(kCpuHasAVX2)) {
467
- InterpolateRow = InterpolateRow_Any_AVX2;
468
- if (IS_ALIGNED(dst_width, 8)) {
469
- InterpolateRow = InterpolateRow_AVX2;
470
- }
471
- }
472
- #endif
473
- #if defined(HAS_INTERPOLATEROW_NEON)
474
- if (TestCpuFlag(kCpuHasNEON)) {
475
- InterpolateRow = InterpolateRow_Any_NEON;
476
- if (IS_ALIGNED(dst_width, 4)) {
477
- InterpolateRow = InterpolateRow_NEON;
478
- }
479
- }
480
- #endif
481
- #if defined(HAS_INTERPOLATEROW_SME)
482
- if (TestCpuFlag(kCpuHasSME)) {
483
- InterpolateRow = InterpolateRow_SME;
484
- }
485
- #endif
486
- #if defined(HAS_INTERPOLATEROW_LSX)
487
- if (TestCpuFlag(kCpuHasLSX)) {
488
- InterpolateRow = InterpolateRow_Any_LSX;
489
- if (IS_ALIGNED(dst_width, 8)) {
490
- InterpolateRow = InterpolateRow_LSX;
491
- }
492
- }
493
- #endif
494
- #if defined(HAS_INTERPOLATEROW_RVV)
495
- if (TestCpuFlag(kCpuHasRVV)) {
496
- InterpolateRow = InterpolateRow_RVV;
497
- }
498
- #endif
499
- if (src_width >= 32768) {
500
- ScaleARGBFilterCols =
501
- filtering ? ScaleARGBFilterCols64_C : ScaleARGBCols64_C;
502
- }
503
- #if defined(HAS_SCALEARGBFILTERCOLS_SSSE3)
504
- if (filtering && TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) {
505
- ScaleARGBFilterCols = ScaleARGBFilterCols_SSSE3;
506
- }
507
- #endif
508
- #if defined(HAS_SCALEARGBFILTERCOLS_NEON)
509
- if (filtering && TestCpuFlag(kCpuHasNEON)) {
510
- ScaleARGBFilterCols = ScaleARGBFilterCols_Any_NEON;
511
- if (IS_ALIGNED(dst_width, 4)) {
512
- ScaleARGBFilterCols = ScaleARGBFilterCols_NEON;
513
- }
514
- }
515
- #endif
516
- #if defined(HAS_SCALEARGBFILTERCOLS_LSX)
517
- if (filtering && TestCpuFlag(kCpuHasLSX)) {
518
- ScaleARGBFilterCols = ScaleARGBFilterCols_Any_LSX;
519
- if (IS_ALIGNED(dst_width, 8)) {
520
- ScaleARGBFilterCols = ScaleARGBFilterCols_LSX;
521
- }
522
- }
523
- #endif
524
- #if defined(HAS_SCALEARGBFILTERCOLS_RVV)
525
- if (filtering && TestCpuFlag(kCpuHasRVV)) {
526
- ScaleARGBFilterCols = ScaleARGBFilterCols_RVV;
527
- }
528
- #endif
529
- #if defined(HAS_SCALEARGBCOLS_SSE2)
530
- if (!filtering && TestCpuFlag(kCpuHasSSE2) && src_width < 32768) {
531
- ScaleARGBFilterCols = ScaleARGBCols_SSE2;
532
- }
533
- #endif
534
- #if defined(HAS_SCALEARGBCOLS_NEON)
535
- if (!filtering && TestCpuFlag(kCpuHasNEON)) {
536
- ScaleARGBFilterCols = ScaleARGBCols_Any_NEON;
537
- if (IS_ALIGNED(dst_width, 8)) {
538
- ScaleARGBFilterCols = ScaleARGBCols_NEON;
539
- }
540
- }
541
- #endif
542
- #if defined(HAS_SCALEARGBCOLS_LSX)
543
- if (!filtering && TestCpuFlag(kCpuHasLSX)) {
544
- ScaleARGBFilterCols = ScaleARGBCols_Any_LSX;
545
- if (IS_ALIGNED(dst_width, 4)) {
546
- ScaleARGBFilterCols = ScaleARGBCols_LSX;
547
- }
548
- }
549
- #endif
550
- if (!filtering && src_width * 2 == dst_width && x < 0x8000) {
551
- ScaleARGBFilterCols = ScaleARGBColsUp2_C;
552
- #if defined(HAS_SCALEARGBCOLSUP2_SSE2)
553
- if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) {
554
- ScaleARGBFilterCols = ScaleARGBColsUp2_SSE2;
555
- }
556
- #endif
557
- }
558
-
559
- if (y > max_y) {
560
- y = max_y;
561
- }
562
-
563
- {
564
- int yi = y >> 16;
565
- const uint8_t* src = src_argb + yi * (intptr_t)src_stride;
566
-
567
- // Allocate 2 rows of ARGB.
568
- const int row_size = (dst_width * 4 + 31) & ~31;
569
- align_buffer_64(row, row_size * 2);
570
- if (!row)
571
- return 1;
572
-
573
- uint8_t* rowptr = row;
574
- int rowstride = row_size;
575
- int lasty = yi;
576
-
577
- ScaleARGBFilterCols(rowptr, src, dst_width, x, dx);
578
- if (src_height > 1) {
579
- src += src_stride;
580
- }
581
- ScaleARGBFilterCols(rowptr + rowstride, src, dst_width, x, dx);
582
- if (src_height > 2) {
583
- src += src_stride;
584
- }
585
-
586
- for (j = 0; j < dst_height; ++j) {
587
- yi = y >> 16;
588
- if (yi != lasty) {
589
- if (y > max_y) {
590
- y = max_y;
591
- yi = y >> 16;
592
- src = src_argb + yi * (intptr_t)src_stride;
593
- }
594
- if (yi != lasty) {
595
- ScaleARGBFilterCols(rowptr, src, dst_width, x, dx);
596
- rowptr += rowstride;
597
- rowstride = -rowstride;
598
- lasty = yi;
599
- if ((y + 65536) < max_y) {
600
- src += src_stride;
601
- }
602
- }
603
- }
604
- if (filtering == kFilterLinear) {
605
- InterpolateRow(dst_argb, rowptr, 0, dst_width * 4, 0);
606
- } else {
607
- int yf = (y >> 8) & 255;
608
- InterpolateRow(dst_argb, rowptr, rowstride, dst_width * 4, yf);
609
- }
610
- dst_argb += dst_stride;
611
- y += dy;
612
- }
613
- free_aligned_buffer_64(row);
614
- }
615
- return 0;
616
- }
617
-
618
- #ifdef YUVSCALEUP
619
- // Scale YUV to ARGB up with bilinear interpolation.
620
- static int ScaleYUVToARGBBilinearUp(int src_width,
621
- int src_height,
622
- int dst_width,
623
- int dst_height,
624
- int src_stride_y,
625
- int src_stride_u,
626
- int src_stride_v,
627
- int dst_stride_argb,
628
- const uint8_t* src_y,
629
- const uint8_t* src_u,
630
- const uint8_t* src_v,
631
- uint8_t* dst_argb,
632
- int x,
633
- int dx,
634
- int y,
635
- int dy,
636
- enum FilterMode filtering) {
637
- int j;
638
- void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
639
- const uint8_t* v_buf, uint8_t* rgb_buf, int width) =
640
- I422ToARGBRow_C;
641
- #if defined(HAS_I422TOARGBROW_SSSE3)
642
- if (TestCpuFlag(kCpuHasSSSE3)) {
643
- I422ToARGBRow = I422ToARGBRow_Any_SSSE3;
644
- if (IS_ALIGNED(src_width, 8)) {
645
- I422ToARGBRow = I422ToARGBRow_SSSE3;
646
- }
647
- }
648
- #endif
649
- #if defined(HAS_I422TOARGBROW_AVX2)
650
- if (TestCpuFlag(kCpuHasAVX2)) {
651
- I422ToARGBRow = I422ToARGBRow_Any_AVX2;
652
- if (IS_ALIGNED(src_width, 16)) {
653
- I422ToARGBRow = I422ToARGBRow_AVX2;
654
- }
655
- }
656
- #endif
657
- #if defined(HAS_I422TOARGBROW_AVX512BW)
658
- if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) ==
659
- (kCpuHasAVX512BW | kCpuHasAVX512VL)) {
660
- I422ToARGBRow = I422ToARGBRow_Any_AVX512BW;
661
- if (IS_ALIGNED(src_width, 32)) {
662
- I422ToARGBRow = I422ToARGBRow_AVX512BW;
663
- }
664
- }
665
- #endif
666
- #if defined(HAS_I422TOARGBROW_NEON)
667
- if (TestCpuFlag(kCpuHasNEON)) {
668
- I422ToARGBRow = I422ToARGBRow_Any_NEON;
669
- if (IS_ALIGNED(src_width, 8)) {
670
- I422ToARGBRow = I422ToARGBRow_NEON;
671
- }
672
- }
673
- #endif
674
- #if defined(HAS_I422TOARGBROW_SVE2)
675
- if (TestCpuFlag(kCpuHasSVE2)) {
676
- I422ToARGBRow = I422ToARGBRow_SVE2;
677
- }
678
- #endif
679
- #if defined(HAS_I422TOARGBROW_SME)
680
- if (TestCpuFlag(kCpuHasSME)) {
681
- I422ToARGBRow = I422ToARGBRow_SME;
682
- }
683
- #endif
684
- #if defined(HAS_I422TOARGBROW_LSX)
685
- if (TestCpuFlag(kCpuHasLSX)) {
686
- I422ToARGBRow = I422ToARGBRow_Any_LSX;
687
- if (IS_ALIGNED(src_width, 16)) {
688
- I422ToARGBRow = I422ToARGBRow_LSX;
689
- }
690
- }
691
- #endif
692
- #if defined(HAS_I422TOARGBROW_LASX)
693
- if (TestCpuFlag(kCpuHasLASX)) {
694
- I422ToARGBRow = I422ToARGBRow_Any_LASX;
695
- if (IS_ALIGNED(src_width, 32)) {
696
- I422ToARGBRow = I422ToARGBRow_LASX;
697
- }
698
- }
699
- #endif
700
- #if defined(HAS_I422TOARGBROW_RVV)
701
- if (TestCpuFlag(kCpuHasRVV)) {
702
- I422ToARGBRow = I422ToARGBRow_RVV;
703
- }
704
- #endif
705
-
706
- void (*InterpolateRow)(uint8_t* dst_argb, const uint8_t* src_argb,
707
- ptrdiff_t src_stride, int dst_width,
708
- int source_y_fraction) = InterpolateRow_C;
709
- #if defined(HAS_INTERPOLATEROW_SSSE3)
710
- if (TestCpuFlag(kCpuHasSSSE3)) {
711
- InterpolateRow = InterpolateRow_Any_SSSE3;
712
- if (IS_ALIGNED(dst_width, 4)) {
713
- InterpolateRow = InterpolateRow_SSSE3;
714
- }
715
- }
716
- #endif
717
- #if defined(HAS_INTERPOLATEROW_AVX2)
718
- if (TestCpuFlag(kCpuHasAVX2)) {
719
- InterpolateRow = InterpolateRow_Any_AVX2;
720
- if (IS_ALIGNED(dst_width, 8)) {
721
- InterpolateRow = InterpolateRow_AVX2;
722
- }
723
- }
724
- #endif
725
- #if defined(HAS_INTERPOLATEROW_NEON)
726
- if (TestCpuFlag(kCpuHasNEON)) {
727
- InterpolateRow = InterpolateRow_Any_NEON;
728
- if (IS_ALIGNED(dst_width, 4)) {
729
- InterpolateRow = InterpolateRow_NEON;
730
- }
731
- }
732
- #endif
733
- #if defined(HAS_INTERPOLATEROW_SME)
734
- if (TestCpuFlag(kCpuHasSME)) {
735
- InterpolateRow = InterpolateRow_SME;
736
- }
737
- #endif
738
- #if defined(HAS_INTERPOLATEROW_LSX)
739
- if (TestCpuFlag(kCpuHasLSX)) {
740
- InterpolateRow = InterpolateRow_Any_LSX;
741
- if (IS_ALIGNED(dst_width, 8)) {
742
- InterpolateRow = InterpolateRow_LSX;
743
- }
744
- }
745
- #endif
746
- #if defined(HAS_INTERPOLATEROW_RVV)
747
- if (TestCpuFlag(kCpuHasRVV)) {
748
- InterpolateRow = InterpolateRow_RVV;
749
- }
750
- #endif
751
-
752
- void (*ScaleARGBFilterCols)(uint8_t* dst_argb, const uint8_t* src_argb,
753
- int dst_width, int x, int dx) =
754
- filtering ? ScaleARGBFilterCols_C : ScaleARGBCols_C;
755
- if (src_width >= 32768) {
756
- ScaleARGBFilterCols =
757
- filtering ? ScaleARGBFilterCols64_C : ScaleARGBCols64_C;
758
- }
759
- #if defined(HAS_SCALEARGBFILTERCOLS_SSSE3)
760
- if (filtering && TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) {
761
- ScaleARGBFilterCols = ScaleARGBFilterCols_SSSE3;
762
- }
763
- #endif
764
- #if defined(HAS_SCALEARGBFILTERCOLS_NEON)
765
- if (filtering && TestCpuFlag(kCpuHasNEON)) {
766
- ScaleARGBFilterCols = ScaleARGBFilterCols_Any_NEON;
767
- if (IS_ALIGNED(dst_width, 4)) {
768
- ScaleARGBFilterCols = ScaleARGBFilterCols_NEON;
769
- }
770
- }
771
- #endif
772
- #if defined(HAS_SCALEARGBFILTERCOLS_LSX)
773
- if (filtering && TestCpuFlag(kCpuHasLSX)) {
774
- ScaleARGBFilterCols = ScaleARGBFilterCols_Any_LSX;
775
- if (IS_ALIGNED(dst_width, 8)) {
776
- ScaleARGBFilterCols = ScaleARGBFilterCols_LSX;
777
- }
778
- }
779
- #endif
780
- #if defined(HAS_SCALEARGBFILTERCOLS_RVV)
781
- if (filtering && TestCpuFlag(kCpuHasRVV)) {
782
- ScaleARGBFilterCols = ScaleARGBFilterCols_RVV;
783
- }
784
- #endif
785
- #if defined(HAS_SCALEARGBCOLS_SSE2)
786
- if (!filtering && TestCpuFlag(kCpuHasSSE2) && src_width < 32768) {
787
- ScaleARGBFilterCols = ScaleARGBCols_SSE2;
788
- }
789
- #endif
790
- #if defined(HAS_SCALEARGBCOLS_NEON)
791
- if (!filtering && TestCpuFlag(kCpuHasNEON)) {
792
- ScaleARGBFilterCols = ScaleARGBCols_Any_NEON;
793
- if (IS_ALIGNED(dst_width, 8)) {
794
- ScaleARGBFilterCols = ScaleARGBCols_NEON;
795
- }
796
- }
797
- #endif
798
- #if defined(HAS_SCALEARGBCOLS_LSX)
799
- if (!filtering && TestCpuFlag(kCpuHasLSX)) {
800
- ScaleARGBFilterCols = ScaleARGBCols_Any_LSX;
801
- if (IS_ALIGNED(dst_width, 4)) {
802
- ScaleARGBFilterCols = ScaleARGBCols_LSX;
803
- }
804
- }
805
- #endif
806
- if (!filtering && src_width * 2 == dst_width && x < 0x8000) {
807
- ScaleARGBFilterCols = ScaleARGBColsUp2_C;
808
- #if defined(HAS_SCALEARGBCOLSUP2_SSE2)
809
- if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) {
810
- ScaleARGBFilterCols = ScaleARGBColsUp2_SSE2;
811
- }
812
- #endif
813
- }
814
-
815
- const int max_y = (src_height - 1) << 16;
816
- if (y > max_y) {
817
- y = max_y;
818
- }
819
- const int kYShift = 1; // Shift Y by 1 to convert Y plane to UV coordinate.
820
- int yi = y >> 16;
821
- int uv_yi = yi >> kYShift;
822
- const uint8_t* src_row_y = src_y + yi * (intptr_t)src_stride_y;
823
- const uint8_t* src_row_u = src_u + uv_yi * (intptr_t)src_stride_u;
824
- const uint8_t* src_row_v = src_v + uv_yi * (intptr_t)src_stride_v;
825
-
826
- // Allocate 1 row of ARGB for source conversion and 2 rows of ARGB
827
- // scaled horizontally to the destination width.
828
- const int row_size = (dst_width * 4 + 31) & ~31;
829
- align_buffer_64(row, row_size * 2 + src_width * 4);
830
-
831
- uint8_t* argb_row = row + row_size * 2;
832
- uint8_t* rowptr = row;
833
- int rowstride = row_size;
834
- int lasty = yi;
835
- if (!row)
836
- return 1;
837
-
838
- // TODO(fbarchard): Convert first 2 rows of YUV to ARGB.
839
- ScaleARGBFilterCols(rowptr, src_row_y, dst_width, x, dx);
840
- if (src_height > 1) {
841
- src_row_y += src_stride_y;
842
- if (yi & 1) {
843
- src_row_u += src_stride_u;
844
- src_row_v += src_stride_v;
845
- }
846
- }
847
- ScaleARGBFilterCols(rowptr + rowstride, src_row_y, dst_width, x, dx);
848
- if (src_height > 2) {
849
- src_row_y += src_stride_y;
850
- if (!(yi & 1)) {
851
- src_row_u += src_stride_u;
852
- src_row_v += src_stride_v;
853
- }
854
- }
855
-
856
- for (j = 0; j < dst_height; ++j) {
857
- yi = y >> 16;
858
- if (yi != lasty) {
859
- if (y > max_y) {
860
- y = max_y;
861
- yi = y >> 16;
862
- uv_yi = yi >> kYShift;
863
- src_row_y = src_y + yi * (intptr_t)src_stride_y;
864
- src_row_u = src_u + uv_yi * (intptr_t)src_stride_u;
865
- src_row_v = src_v + uv_yi * (intptr_t)src_stride_v;
866
- }
867
- if (yi != lasty) {
868
- // TODO(fbarchard): Convert the clipped region of row.
869
- I422ToARGBRow(src_row_y, src_row_u, src_row_v, argb_row, src_width);
870
- ScaleARGBFilterCols(rowptr, argb_row, dst_width, x, dx);
871
- rowptr += rowstride;
872
- rowstride = -rowstride;
873
- lasty = yi;
874
- src_row_y += src_stride_y;
875
- if (yi & 1) {
876
- src_row_u += src_stride_u;
877
- src_row_v += src_stride_v;
878
- }
879
- }
880
- }
881
- if (filtering == kFilterLinear) {
882
- InterpolateRow(dst_argb, rowptr, 0, dst_width * 4, 0);
883
- } else {
884
- int yf = (y >> 8) & 255;
885
- InterpolateRow(dst_argb, rowptr, rowstride, dst_width * 4, yf);
886
- }
887
- dst_argb += dst_stride_argb;
888
- y += dy;
889
- }
890
- free_aligned_buffer_64(row);
891
- return 0;
892
- }
893
- #endif
894
-
895
- // Scale ARGB to/from any dimensions, without interpolation.
896
- // Fixed point math is used for performance: The upper 16 bits
897
- // of x and dx is the integer part of the source position and
898
- // the lower 16 bits are the fixed decimal part.
899
-
900
- static void ScaleARGBSimple(int src_width,
901
- int src_height,
902
- int dst_width,
903
- int dst_height,
904
- int src_stride,
905
- int dst_stride,
906
- const uint8_t* src_argb,
907
- uint8_t* dst_argb,
908
- int x,
909
- int dx,
910
- int y,
911
- int dy) {
912
- int j;
913
- void (*ScaleARGBCols)(uint8_t* dst_argb, const uint8_t* src_argb,
914
- int dst_width, int x, int dx) =
915
- (src_width >= 32768) ? ScaleARGBCols64_C : ScaleARGBCols_C;
916
- (void)src_height;
917
- #if defined(HAS_SCALEARGBCOLS_SSE2)
918
- if (TestCpuFlag(kCpuHasSSE2) && src_width < 32768) {
919
- ScaleARGBCols = ScaleARGBCols_SSE2;
920
- }
921
- #endif
922
- #if defined(HAS_SCALEARGBCOLS_NEON)
923
- if (TestCpuFlag(kCpuHasNEON)) {
924
- ScaleARGBCols = ScaleARGBCols_Any_NEON;
925
- if (IS_ALIGNED(dst_width, 8)) {
926
- ScaleARGBCols = ScaleARGBCols_NEON;
927
- }
928
- }
929
- #endif
930
- #if defined(HAS_SCALEARGBCOLS_LSX)
931
- if (TestCpuFlag(kCpuHasLSX)) {
932
- ScaleARGBCols = ScaleARGBCols_Any_LSX;
933
- if (IS_ALIGNED(dst_width, 4)) {
934
- ScaleARGBCols = ScaleARGBCols_LSX;
935
- }
936
- }
937
- #endif
938
- if (src_width * 2 == dst_width && x < 0x8000) {
939
- ScaleARGBCols = ScaleARGBColsUp2_C;
940
- #if defined(HAS_SCALEARGBCOLSUP2_SSE2)
941
- if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) {
942
- ScaleARGBCols = ScaleARGBColsUp2_SSE2;
943
- }
944
- #endif
945
- }
946
-
947
- for (j = 0; j < dst_height; ++j) {
948
- ScaleARGBCols(dst_argb, src_argb + (y >> 16) * (intptr_t)src_stride,
949
- dst_width, x, dx);
950
- dst_argb += dst_stride;
951
- y += dy;
952
- }
953
- }
954
-
955
- // ScaleARGB a ARGB.
956
- // This function in turn calls a scaling function
957
- // suitable for handling the desired resolutions.
958
- static int ScaleARGB(const uint8_t* src,
959
- int src_stride,
960
- int src_width,
961
- int src_height,
962
- uint8_t* dst,
963
- int dst_stride,
964
- int dst_width,
965
- int dst_height,
966
- int clip_x,
967
- int clip_y,
968
- int clip_width,
969
- int clip_height,
970
- enum FilterMode filtering) {
971
- // Initial source x/y coordinate and step values as 16.16 fixed point.
972
- int x = 0;
973
- int y = 0;
974
- int dx = 0;
975
- int dy = 0;
976
- // ARGB does not support box filter yet, but allow the user to pass it.
977
- // Simplify filtering when possible.
978
- filtering = ScaleFilterReduce(src_width, src_height, dst_width, dst_height,
979
- filtering);
980
-
981
- // Negative src_height means invert the image.
982
- if (src_height < 0) {
983
- src_height = -src_height;
984
- src = src + (src_height - 1) * (intptr_t)src_stride;
985
- src_stride = -src_stride;
986
- }
987
- ScaleSlope(src_width, src_height, dst_width, dst_height, filtering, &x, &y,
988
- &dx, &dy);
989
- src_width = Abs(src_width);
990
- if (clip_x) {
991
- int64_t clipf = (int64_t)(clip_x)*dx;
992
- x += (clipf & 0xffff);
993
- src += (clipf >> 16) * 4;
994
- dst += clip_x * 4;
995
- }
996
- if (clip_y) {
997
- int64_t clipf = (int64_t)(clip_y)*dy;
998
- y += (clipf & 0xffff);
999
- src += (clipf >> 16) * (intptr_t)src_stride;
1000
- dst += clip_y * dst_stride;
1001
- }
1002
-
1003
- // Special case for integer step values.
1004
- if (((dx | dy) & 0xffff) == 0) {
1005
- if (!dx || !dy) { // 1 pixel wide and/or tall.
1006
- filtering = kFilterNone;
1007
- } else {
1008
- // Optimized even scale down. ie 2, 4, 6, 8, 10x.
1009
- if (!(dx & 0x10000) && !(dy & 0x10000)) {
1010
- if (dx == 0x20000 && dy == 0x20000) {
1011
- // Optimized 1/2 downsample.
1012
- ScaleARGBDown2(src_width, src_height, clip_width, clip_height,
1013
- src_stride, dst_stride, src, dst, x, dx, y, dy,
1014
- filtering);
1015
- return 0;
1016
- }
1017
- if (dx == 0x40000 && dy == 0x40000 && filtering == kFilterBox) {
1018
- // Optimized 1/4 box downsample.
1019
- return ScaleARGBDown4Box(src_width, src_height, clip_width,
1020
- clip_height, src_stride, dst_stride, src,
1021
- dst, x, dx, y, dy);
1022
- }
1023
- ScaleARGBDownEven(src_width, src_height, clip_width, clip_height,
1024
- src_stride, dst_stride, src, dst, x, dx, y, dy,
1025
- filtering);
1026
- return 0;
1027
- }
1028
- // Optimized odd scale down. ie 3, 5, 7, 9x.
1029
- if ((dx & 0x10000) && (dy & 0x10000)) {
1030
- filtering = kFilterNone;
1031
- if (dx == 0x10000 && dy == 0x10000) {
1032
- // Straight copy.
1033
- ARGBCopy(src + (y >> 16) * (intptr_t)src_stride + (x >> 16) * 4,
1034
- src_stride, dst, dst_stride, clip_width, clip_height);
1035
- return 0;
1036
- }
1037
- }
1038
- }
1039
- }
1040
- if (dx == 0x10000 && (x & 0xffff) == 0) {
1041
- // Arbitrary scale vertically, but unscaled horizontally.
1042
- ScalePlaneVertical(src_height, clip_width, clip_height, src_stride,
1043
- dst_stride, src, dst, x, y, dy, /*bpp=*/4, filtering);
1044
- return 0;
1045
- }
1046
- if (filtering && dy < 65536) {
1047
- return ScaleARGBBilinearUp(src_width, src_height, clip_width, clip_height,
1048
- src_stride, dst_stride, src, dst, x, dx, y, dy,
1049
- filtering);
1050
- }
1051
- if (filtering) {
1052
- return ScaleARGBBilinearDown(src_width, src_height, clip_width, clip_height,
1053
- src_stride, dst_stride, src, dst, x, dx, y, dy,
1054
- filtering);
1055
- }
1056
- ScaleARGBSimple(src_width, src_height, clip_width, clip_height, src_stride,
1057
- dst_stride, src, dst, x, dx, y, dy);
1058
- return 0;
1059
- }
1060
-
1061
- LIBYUV_API
1062
- int ARGBScaleClip(const uint8_t* src_argb,
1063
- int src_stride_argb,
1064
- int src_width,
1065
- int src_height,
1066
- uint8_t* dst_argb,
1067
- int dst_stride_argb,
1068
- int dst_width,
1069
- int dst_height,
1070
- int clip_x,
1071
- int clip_y,
1072
- int clip_width,
1073
- int clip_height,
1074
- enum FilterMode filtering) {
1075
- if (!src_argb || src_width == 0 || src_height == 0 || !dst_argb ||
1076
- dst_width <= 0 || dst_height <= 0 || clip_x < 0 || clip_y < 0 ||
1077
- clip_width > 32768 || clip_height > 32768 ||
1078
- (clip_x + clip_width) > dst_width ||
1079
- (clip_y + clip_height) > dst_height) {
1080
- return -1;
1081
- }
1082
- return ScaleARGB(src_argb, src_stride_argb, src_width, src_height, dst_argb,
1083
- dst_stride_argb, dst_width, dst_height, clip_x, clip_y,
1084
- clip_width, clip_height, filtering);
1085
- }
1086
-
1087
- // Scale an ARGB image.
1088
- LIBYUV_API
1089
- int ARGBScale(const uint8_t* src_argb,
1090
- int src_stride_argb,
1091
- int src_width,
1092
- int src_height,
1093
- uint8_t* dst_argb,
1094
- int dst_stride_argb,
1095
- int dst_width,
1096
- int dst_height,
1097
- enum FilterMode filtering) {
1098
- if (!src_argb || src_width == 0 || src_height == 0 || src_width > 32768 ||
1099
- src_height > 32768 || !dst_argb || dst_width <= 0 || dst_height <= 0) {
1100
- return -1;
1101
- }
1102
- return ScaleARGB(src_argb, src_stride_argb, src_width, src_height, dst_argb,
1103
- dst_stride_argb, dst_width, dst_height, 0, 0, dst_width,
1104
- dst_height, filtering);
1105
- }
1106
-
1107
- // Scale with YUV conversion to ARGB and clipping.
1108
- LIBYUV_API
1109
- int YUVToARGBScaleClip(const uint8_t* src_y,
1110
- int src_stride_y,
1111
- const uint8_t* src_u,
1112
- int src_stride_u,
1113
- const uint8_t* src_v,
1114
- int src_stride_v,
1115
- uint32_t src_fourcc,
1116
- int src_width,
1117
- int src_height,
1118
- uint8_t* dst_argb,
1119
- int dst_stride_argb,
1120
- uint32_t dst_fourcc,
1121
- int dst_width,
1122
- int dst_height,
1123
- int clip_x,
1124
- int clip_y,
1125
- int clip_width,
1126
- int clip_height,
1127
- enum FilterMode filtering) {
1128
- int r;
1129
- (void)src_fourcc; // TODO(fbarchard): implement and/or assert.
1130
- (void)dst_fourcc;
1131
- const int abs_src_height = (src_height < 0) ? -src_height : src_height;
1132
- if (!src_y || !src_u || !src_v || !dst_argb || src_width <= 0 ||
1133
- src_width > INT_MAX / 4 || src_height == 0 || dst_width <= 0 ||
1134
- dst_height <= 0 || clip_width <= 0 || clip_height <= 0) {
1135
- return -1;
1136
- }
1137
- const uint64_t argb_buffer_size = (uint64_t)src_width * abs_src_height * 4;
1138
- if (argb_buffer_size > SIZE_MAX) {
1139
- return -1; // Invalid size.
1140
- }
1141
- uint8_t* argb_buffer = (uint8_t*)malloc((size_t)argb_buffer_size);
1142
- if (!argb_buffer) {
1143
- return 1; // Out of memory runtime error.
1144
- }
1145
- I420ToARGB(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
1146
- argb_buffer, src_width * 4, src_width, src_height);
1147
-
1148
- r = ARGBScaleClip(argb_buffer, src_width * 4, src_width, abs_src_height,
1149
- dst_argb, dst_stride_argb, dst_width, dst_height, clip_x,
1150
- clip_y, clip_width, clip_height, filtering);
1151
- free(argb_buffer);
1152
- return r;
1153
- }
1154
-
1155
- #ifdef __cplusplus
1156
- } // extern "C"
1157
- } // namespace libyuv
1158
- #endif
1
+ /*
2
+ * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3
+ *
4
+ * Use of this source code is governed by a BSD-style license
5
+ * that can be found in the LICENSE file in the root of the source
6
+ * tree. An additional intellectual property rights grant can be found
7
+ * in the file PATENTS. All contributing project authors may
8
+ * be found in the AUTHORS file in the root of the source tree.
9
+ */
10
+
11
+ #include "libyuv/scale.h"
12
+
13
+ #include <assert.h>
14
+ #include <limits.h>
15
+ #include <stdint.h>
16
+ #include <stdlib.h>
17
+ #include <string.h>
18
+
19
+ #include "libyuv/cpu_id.h"
20
+ #include "libyuv/planar_functions.h" // For CopyARGB
21
+ #include "libyuv/row.h"
22
+ #include "libyuv/scale_argb.h"
23
+ #include "libyuv/scale_row.h"
24
+
25
+ #ifdef __cplusplus
26
+ namespace libyuv {
27
+ extern "C" {
28
+ #endif
29
+
30
+ static __inline int Abs(int v) {
31
+ return v >= 0 ? v : -v;
32
+ }
33
+
34
+ // ScaleARGB ARGB, 1/2
35
+ // This is an optimized version for scaling down a ARGB to 1/2 of
36
+ // its original size.
37
+ static void ScaleARGBDown2(int src_width,
38
+ int src_height,
39
+ int dst_width,
40
+ int dst_height,
41
+ int src_stride,
42
+ int dst_stride,
43
+ const uint8_t* src_argb,
44
+ uint8_t* dst_argb,
45
+ int x,
46
+ int dx,
47
+ int y,
48
+ int dy,
49
+ enum FilterMode filtering) {
50
+ int j;
51
+ int row_stride = src_stride * (dy >> 16);
52
+ void (*ScaleARGBRowDown2)(const uint8_t* src_argb, ptrdiff_t src_stride,
53
+ uint8_t* dst_argb, int dst_width) =
54
+ filtering == kFilterNone
55
+ ? ScaleARGBRowDown2_C
56
+ : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_C
57
+ : ScaleARGBRowDown2Box_C);
58
+ (void)src_width;
59
+ (void)src_height;
60
+ (void)dx;
61
+ assert(dx == 65536 * 2); // Test scale factor of 2.
62
+ assert((dy & 0x1ffff) == 0); // Test vertical scale is multiple of 2.
63
+ // Advance to odd row, even column.
64
+ if (filtering == kFilterBilinear) {
65
+ src_argb += (y >> 16) * (intptr_t)src_stride + (x >> 16) * 4;
66
+ } else {
67
+ src_argb += (y >> 16) * (intptr_t)src_stride + ((x >> 16) - 1) * 4;
68
+ }
69
+
70
+ #if defined(HAS_SCALEARGBROWDOWN2_SSE2)
71
+ if (TestCpuFlag(kCpuHasSSE2)) {
72
+ ScaleARGBRowDown2 =
73
+ filtering == kFilterNone
74
+ ? ScaleARGBRowDown2_Any_SSE2
75
+ : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_Any_SSE2
76
+ : ScaleARGBRowDown2Box_Any_SSE2);
77
+ if (IS_ALIGNED(dst_width, 4)) {
78
+ ScaleARGBRowDown2 =
79
+ filtering == kFilterNone
80
+ ? ScaleARGBRowDown2_SSE2
81
+ : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_SSE2
82
+ : ScaleARGBRowDown2Box_SSE2);
83
+ }
84
+ }
85
+ #endif
86
+ #if defined(HAS_SCALEARGBROWDOWN2_NEON)
87
+ if (TestCpuFlag(kCpuHasNEON)) {
88
+ ScaleARGBRowDown2 =
89
+ filtering == kFilterNone
90
+ ? ScaleARGBRowDown2_Any_NEON
91
+ : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_Any_NEON
92
+ : ScaleARGBRowDown2Box_Any_NEON);
93
+ if (IS_ALIGNED(dst_width, 8)) {
94
+ ScaleARGBRowDown2 =
95
+ filtering == kFilterNone
96
+ ? ScaleARGBRowDown2_NEON
97
+ : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_NEON
98
+ : ScaleARGBRowDown2Box_NEON);
99
+ }
100
+ }
101
+ #endif
102
+ #if defined(HAS_SCALEARGBROWDOWN2_SME)
103
+ if (TestCpuFlag(kCpuHasSME)) {
104
+ ScaleARGBRowDown2 = filtering == kFilterNone ? ScaleARGBRowDown2_SME
105
+ : filtering == kFilterLinear
106
+ ? ScaleARGBRowDown2Linear_SME
107
+ : ScaleARGBRowDown2Box_SME;
108
+ }
109
+ #endif
110
+ #if defined(HAS_SCALEARGBROWDOWN2_LSX)
111
+ if (TestCpuFlag(kCpuHasLSX)) {
112
+ ScaleARGBRowDown2 =
113
+ filtering == kFilterNone
114
+ ? ScaleARGBRowDown2_Any_LSX
115
+ : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_Any_LSX
116
+ : ScaleARGBRowDown2Box_Any_LSX);
117
+ if (IS_ALIGNED(dst_width, 4)) {
118
+ ScaleARGBRowDown2 =
119
+ filtering == kFilterNone
120
+ ? ScaleARGBRowDown2_LSX
121
+ : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_LSX
122
+ : ScaleARGBRowDown2Box_LSX);
123
+ }
124
+ }
125
+ #endif
126
+ #if defined(HAS_SCALEARGBROWDOWN2_RVV) && \
127
+ defined(HAS_SCALEARGBROWDOWN2LINEAR_RVV) && \
128
+ defined(HAS_SCALEARGBROWDOWN2BOX_RVV)
129
+ if (TestCpuFlag(kCpuHasRVV)) {
130
+ ScaleARGBRowDown2 =
131
+ filtering == kFilterNone
132
+ ? ScaleARGBRowDown2_RVV
133
+ : (filtering == kFilterLinear ? ScaleARGBRowDown2Linear_RVV
134
+ : ScaleARGBRowDown2Box_RVV);
135
+ }
136
+ #endif
137
+
138
+ if (filtering == kFilterLinear) {
139
+ src_stride = 0;
140
+ }
141
+ for (j = 0; j < dst_height; ++j) {
142
+ ScaleARGBRowDown2(src_argb, src_stride, dst_argb, dst_width);
143
+ src_argb += row_stride;
144
+ dst_argb += dst_stride;
145
+ }
146
+ }
147
+
148
+ // ScaleARGB ARGB, 1/4
149
+ // This is an optimized version for scaling down a ARGB to 1/4 of
150
+ // its original size.
151
+ static int ScaleARGBDown4Box(int src_width,
152
+ int src_height,
153
+ int dst_width,
154
+ int dst_height,
155
+ int src_stride,
156
+ int dst_stride,
157
+ const uint8_t* src_argb,
158
+ uint8_t* dst_argb,
159
+ int x,
160
+ int dx,
161
+ int y,
162
+ int dy) {
163
+ int j;
164
+ // Allocate 2 rows of ARGB.
165
+ const int row_size = (dst_width * 2 * 4 + 31) & ~31;
166
+ // TODO(fbarchard): Remove this row buffer and implement a ScaleARGBRowDown4
167
+ // but implemented via a 2 pass wrapper that uses a very small array on the
168
+ // stack with a horizontal loop.
169
+ align_buffer_64(row, row_size * 2);
170
+ if (!row)
171
+ return 1;
172
+ int row_stride = src_stride * (dy >> 16);
173
+ void (*ScaleARGBRowDown2)(const uint8_t* src_argb, ptrdiff_t src_stride,
174
+ uint8_t* dst_argb, int dst_width) =
175
+ ScaleARGBRowDown2Box_C;
176
+ // Advance to odd row, even column.
177
+ src_argb += (y >> 16) * (intptr_t)src_stride + (x >> 16) * 4;
178
+ (void)src_width;
179
+ (void)src_height;
180
+ (void)dx;
181
+ assert(dx == 65536 * 4); // Test scale factor of 4.
182
+ assert((dy & 0x3ffff) == 0); // Test vertical scale is multiple of 4.
183
+ #if defined(HAS_SCALEARGBROWDOWN2_SSE2)
184
+ if (TestCpuFlag(kCpuHasSSE2)) {
185
+ ScaleARGBRowDown2 = ScaleARGBRowDown2Box_Any_SSE2;
186
+ if (IS_ALIGNED(dst_width, 4)) {
187
+ ScaleARGBRowDown2 = ScaleARGBRowDown2Box_SSE2;
188
+ }
189
+ }
190
+ #endif
191
+ #if defined(HAS_SCALEARGBROWDOWN2_NEON)
192
+ if (TestCpuFlag(kCpuHasNEON)) {
193
+ ScaleARGBRowDown2 = ScaleARGBRowDown2Box_Any_NEON;
194
+ if (IS_ALIGNED(dst_width, 8)) {
195
+ ScaleARGBRowDown2 = ScaleARGBRowDown2Box_NEON;
196
+ }
197
+ }
198
+ #endif
199
+ #if defined(HAS_SCALEARGBROWDOWN2_SME)
200
+ if (TestCpuFlag(kCpuHasSME)) {
201
+ ScaleARGBRowDown2 = ScaleARGBRowDown2Box_SME;
202
+ }
203
+ #endif
204
+ #if defined(HAS_SCALEARGBROWDOWN2BOX_RVV)
205
+ if (TestCpuFlag(kCpuHasRVV)) {
206
+ ScaleARGBRowDown2 = ScaleARGBRowDown2Box_RVV;
207
+ }
208
+ #endif
209
+
210
+ for (j = 0; j < dst_height; ++j) {
211
+ ScaleARGBRowDown2(src_argb, src_stride, row, dst_width * 2);
212
+ ScaleARGBRowDown2(src_argb + src_stride * 2, src_stride, row + row_size,
213
+ dst_width * 2);
214
+ ScaleARGBRowDown2(row, row_size, dst_argb, dst_width);
215
+ src_argb += row_stride;
216
+ dst_argb += dst_stride;
217
+ }
218
+ free_aligned_buffer_64(row);
219
+ return 0;
220
+ }
221
+
222
+ // ScaleARGB ARGB Even
223
+ // This is an optimized version for scaling down a ARGB to even
224
+ // multiple of its original size.
225
+ static void ScaleARGBDownEven(int src_width,
226
+ int src_height,
227
+ int dst_width,
228
+ int dst_height,
229
+ int src_stride,
230
+ int dst_stride,
231
+ const uint8_t* src_argb,
232
+ uint8_t* dst_argb,
233
+ int x,
234
+ int dx,
235
+ int y,
236
+ int dy,
237
+ enum FilterMode filtering) {
238
+ int j;
239
+ int col_step = dx >> 16;
240
+ ptrdiff_t row_stride = (ptrdiff_t)((dy >> 16) * (intptr_t)src_stride);
241
+ void (*ScaleARGBRowDownEven)(const uint8_t* src_argb, ptrdiff_t src_stride,
242
+ int src_step, uint8_t* dst_argb, int dst_width) =
243
+ filtering ? ScaleARGBRowDownEvenBox_C : ScaleARGBRowDownEven_C;
244
+ (void)src_width;
245
+ (void)src_height;
246
+ assert(IS_ALIGNED(src_width, 2));
247
+ assert(IS_ALIGNED(src_height, 2));
248
+ src_argb += (y >> 16) * (intptr_t)src_stride + (x >> 16) * 4;
249
+ #if defined(HAS_SCALEARGBROWDOWNEVEN_SSE2)
250
+ if (TestCpuFlag(kCpuHasSSE2)) {
251
+ ScaleARGBRowDownEven = filtering ? ScaleARGBRowDownEvenBox_Any_SSE2
252
+ : ScaleARGBRowDownEven_Any_SSE2;
253
+ if (IS_ALIGNED(dst_width, 4)) {
254
+ ScaleARGBRowDownEven =
255
+ filtering ? ScaleARGBRowDownEvenBox_SSE2 : ScaleARGBRowDownEven_SSE2;
256
+ }
257
+ }
258
+ #endif
259
+ #if defined(HAS_SCALEARGBROWDOWNEVEN_NEON)
260
+ if (TestCpuFlag(kCpuHasNEON)) {
261
+ ScaleARGBRowDownEven = filtering ? ScaleARGBRowDownEvenBox_Any_NEON
262
+ : ScaleARGBRowDownEven_Any_NEON;
263
+ if (IS_ALIGNED(dst_width, 4)) {
264
+ ScaleARGBRowDownEven =
265
+ filtering ? ScaleARGBRowDownEvenBox_NEON : ScaleARGBRowDownEven_NEON;
266
+ }
267
+ }
268
+ #endif
269
+ #if defined(HAS_SCALEARGBROWDOWNEVEN_LSX)
270
+ if (TestCpuFlag(kCpuHasLSX)) {
271
+ ScaleARGBRowDownEven = filtering ? ScaleARGBRowDownEvenBox_Any_LSX
272
+ : ScaleARGBRowDownEven_Any_LSX;
273
+ if (IS_ALIGNED(dst_width, 4)) {
274
+ ScaleARGBRowDownEven =
275
+ filtering ? ScaleARGBRowDownEvenBox_LSX : ScaleARGBRowDownEven_LSX;
276
+ }
277
+ }
278
+ #endif
279
+ #if defined(HAS_SCALEARGBROWDOWNEVENBOX_RVV)
280
+ if (filtering && TestCpuFlag(kCpuHasRVV)) {
281
+ ScaleARGBRowDownEven = ScaleARGBRowDownEvenBox_RVV;
282
+ }
283
+ #endif
284
+ #if defined(HAS_SCALEARGBROWDOWNEVEN_RVV)
285
+ if (!filtering && TestCpuFlag(kCpuHasRVV)) {
286
+ ScaleARGBRowDownEven = ScaleARGBRowDownEven_RVV;
287
+ }
288
+ #endif
289
+
290
+ if (filtering == kFilterLinear) {
291
+ src_stride = 0;
292
+ }
293
+ for (j = 0; j < dst_height; ++j) {
294
+ ScaleARGBRowDownEven(src_argb, src_stride, col_step, dst_argb, dst_width);
295
+ src_argb += row_stride;
296
+ dst_argb += dst_stride;
297
+ }
298
+ }
299
+
300
+ // Scale ARGB down with bilinear interpolation.
301
+ static int ScaleARGBBilinearDown(int src_width,
302
+ int src_height,
303
+ int dst_width,
304
+ int dst_height,
305
+ int src_stride,
306
+ int dst_stride,
307
+ const uint8_t* src_argb,
308
+ uint8_t* dst_argb,
309
+ int x,
310
+ int dx,
311
+ int y,
312
+ int dy,
313
+ enum FilterMode filtering) {
314
+ int j;
315
+ void (*InterpolateRow)(uint8_t* dst_argb, const uint8_t* src_argb,
316
+ ptrdiff_t src_stride, int dst_width,
317
+ int source_y_fraction) = InterpolateRow_C;
318
+ void (*ScaleARGBFilterCols)(uint8_t* dst_argb, const uint8_t* src_argb,
319
+ int dst_width, int x, int dx) =
320
+ (src_width >= 32768) ? ScaleARGBFilterCols64_C : ScaleARGBFilterCols_C;
321
+ int64_t xlast = x + (int64_t)(dst_width - 1) * dx;
322
+ int64_t xl = (dx >= 0) ? x : xlast;
323
+ int64_t xr = (dx >= 0) ? xlast : x;
324
+ int clip_src_width;
325
+ xl = (xl >> 16) & ~3; // Left edge aligned.
326
+ xr = (xr >> 16) + 1; // Right most pixel used. Bilinear uses 2 pixels.
327
+ xr = (xr + 1 + 3) & ~3; // 1 beyond 4 pixel aligned right most pixel.
328
+ if (xr > src_width) {
329
+ xr = src_width;
330
+ }
331
+ clip_src_width = (int)(xr - xl) * 4; // Width aligned to 4.
332
+ src_argb += xl * 4;
333
+ x -= (int)(xl << 16);
334
+ #if defined(HAS_INTERPOLATEROW_SSSE3)
335
+ if (TestCpuFlag(kCpuHasSSSE3)) {
336
+ InterpolateRow = InterpolateRow_Any_SSSE3;
337
+ if (IS_ALIGNED(clip_src_width, 16)) {
338
+ InterpolateRow = InterpolateRow_SSSE3;
339
+ }
340
+ }
341
+ #endif
342
+ #if defined(HAS_INTERPOLATEROW_AVX2)
343
+ if (TestCpuFlag(kCpuHasAVX2)) {
344
+ InterpolateRow = InterpolateRow_Any_AVX2;
345
+ if (IS_ALIGNED(clip_src_width, 32)) {
346
+ InterpolateRow = InterpolateRow_AVX2;
347
+ }
348
+ }
349
+ #endif
350
+ #if defined(HAS_INTERPOLATEROW_NEON)
351
+ if (TestCpuFlag(kCpuHasNEON)) {
352
+ InterpolateRow = InterpolateRow_Any_NEON;
353
+ if (IS_ALIGNED(clip_src_width, 16)) {
354
+ InterpolateRow = InterpolateRow_NEON;
355
+ }
356
+ }
357
+ #endif
358
+ #if defined(HAS_INTERPOLATEROW_SME)
359
+ if (TestCpuFlag(kCpuHasSME)) {
360
+ InterpolateRow = InterpolateRow_SME;
361
+ }
362
+ #endif
363
+ #if defined(HAS_INTERPOLATEROW_LSX)
364
+ if (TestCpuFlag(kCpuHasLSX)) {
365
+ InterpolateRow = InterpolateRow_Any_LSX;
366
+ if (IS_ALIGNED(clip_src_width, 32)) {
367
+ InterpolateRow = InterpolateRow_LSX;
368
+ }
369
+ }
370
+ #endif
371
+ #if defined(HAS_INTERPOLATEROW_RVV)
372
+ if (TestCpuFlag(kCpuHasRVV)) {
373
+ InterpolateRow = InterpolateRow_RVV;
374
+ }
375
+ #endif
376
+ #if defined(HAS_SCALEARGBFILTERCOLS_SSSE3)
377
+ if (TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) {
378
+ ScaleARGBFilterCols = ScaleARGBFilterCols_SSSE3;
379
+ }
380
+ #endif
381
+ #if defined(HAS_SCALEARGBFILTERCOLS_NEON)
382
+ if (TestCpuFlag(kCpuHasNEON)) {
383
+ ScaleARGBFilterCols = ScaleARGBFilterCols_Any_NEON;
384
+ if (IS_ALIGNED(dst_width, 4)) {
385
+ ScaleARGBFilterCols = ScaleARGBFilterCols_NEON;
386
+ }
387
+ }
388
+ #endif
389
+ #if defined(HAS_SCALEARGBFILTERCOLS_LSX)
390
+ if (TestCpuFlag(kCpuHasLSX)) {
391
+ ScaleARGBFilterCols = ScaleARGBFilterCols_Any_LSX;
392
+ if (IS_ALIGNED(dst_width, 8)) {
393
+ ScaleARGBFilterCols = ScaleARGBFilterCols_LSX;
394
+ }
395
+ }
396
+ #endif
397
+ #if defined(HAS_SCALEARGBFILTERCOLS_RVV)
398
+ if (TestCpuFlag(kCpuHasRVV)) {
399
+ ScaleARGBFilterCols = ScaleARGBFilterCols_RVV;
400
+ }
401
+ #endif
402
+
403
+ // TODO(fbarchard): Consider not allocating row buffer for kFilterLinear.
404
+ // Allocate a row of ARGB.
405
+ {
406
+ align_buffer_64(row, clip_src_width * 4);
407
+ if (!row)
408
+ return 1;
409
+
410
+ const int max_y = (src_height - 1) << 16;
411
+ if (y > max_y) {
412
+ y = max_y;
413
+ }
414
+ for (j = 0; j < dst_height; ++j) {
415
+ int yi = y >> 16;
416
+ const uint8_t* src = src_argb + yi * (intptr_t)src_stride;
417
+ if (filtering == kFilterLinear) {
418
+ ScaleARGBFilterCols(dst_argb, src, dst_width, x, dx);
419
+ } else {
420
+ int yf = (y >> 8) & 255;
421
+ InterpolateRow(row, src, src_stride, clip_src_width, yf);
422
+ ScaleARGBFilterCols(dst_argb, row, dst_width, x, dx);
423
+ }
424
+ dst_argb += dst_stride;
425
+ y += dy;
426
+ if (y > max_y) {
427
+ y = max_y;
428
+ }
429
+ }
430
+ free_aligned_buffer_64(row);
431
+ }
432
+ return 0;
433
+ }
434
+
435
+ // Scale ARGB up with bilinear interpolation.
436
+ static int ScaleARGBBilinearUp(int src_width,
437
+ int src_height,
438
+ int dst_width,
439
+ int dst_height,
440
+ int src_stride,
441
+ int dst_stride,
442
+ const uint8_t* src_argb,
443
+ uint8_t* dst_argb,
444
+ int x,
445
+ int dx,
446
+ int y,
447
+ int dy,
448
+ enum FilterMode filtering) {
449
+ int j;
450
+ void (*InterpolateRow)(uint8_t* dst_argb, const uint8_t* src_argb,
451
+ ptrdiff_t src_stride, int dst_width,
452
+ int source_y_fraction) = InterpolateRow_C;
453
+ void (*ScaleARGBFilterCols)(uint8_t* dst_argb, const uint8_t* src_argb,
454
+ int dst_width, int x, int dx) =
455
+ filtering ? ScaleARGBFilterCols_C : ScaleARGBCols_C;
456
+ const int max_y = (src_height - 1) << 16;
457
+ #if defined(HAS_INTERPOLATEROW_SSSE3)
458
+ if (TestCpuFlag(kCpuHasSSSE3)) {
459
+ InterpolateRow = InterpolateRow_Any_SSSE3;
460
+ if (IS_ALIGNED(dst_width, 4)) {
461
+ InterpolateRow = InterpolateRow_SSSE3;
462
+ }
463
+ }
464
+ #endif
465
+ #if defined(HAS_INTERPOLATEROW_AVX2)
466
+ if (TestCpuFlag(kCpuHasAVX2)) {
467
+ InterpolateRow = InterpolateRow_Any_AVX2;
468
+ if (IS_ALIGNED(dst_width, 8)) {
469
+ InterpolateRow = InterpolateRow_AVX2;
470
+ }
471
+ }
472
+ #endif
473
+ #if defined(HAS_INTERPOLATEROW_NEON)
474
+ if (TestCpuFlag(kCpuHasNEON)) {
475
+ InterpolateRow = InterpolateRow_Any_NEON;
476
+ if (IS_ALIGNED(dst_width, 4)) {
477
+ InterpolateRow = InterpolateRow_NEON;
478
+ }
479
+ }
480
+ #endif
481
+ #if defined(HAS_INTERPOLATEROW_SME)
482
+ if (TestCpuFlag(kCpuHasSME)) {
483
+ InterpolateRow = InterpolateRow_SME;
484
+ }
485
+ #endif
486
+ #if defined(HAS_INTERPOLATEROW_LSX)
487
+ if (TestCpuFlag(kCpuHasLSX)) {
488
+ InterpolateRow = InterpolateRow_Any_LSX;
489
+ if (IS_ALIGNED(dst_width, 8)) {
490
+ InterpolateRow = InterpolateRow_LSX;
491
+ }
492
+ }
493
+ #endif
494
+ #if defined(HAS_INTERPOLATEROW_RVV)
495
+ if (TestCpuFlag(kCpuHasRVV)) {
496
+ InterpolateRow = InterpolateRow_RVV;
497
+ }
498
+ #endif
499
+ if (src_width >= 32768) {
500
+ ScaleARGBFilterCols =
501
+ filtering ? ScaleARGBFilterCols64_C : ScaleARGBCols64_C;
502
+ }
503
+ #if defined(HAS_SCALEARGBFILTERCOLS_SSSE3)
504
+ if (filtering && TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) {
505
+ ScaleARGBFilterCols = ScaleARGBFilterCols_SSSE3;
506
+ }
507
+ #endif
508
+ #if defined(HAS_SCALEARGBFILTERCOLS_NEON)
509
+ if (filtering && TestCpuFlag(kCpuHasNEON)) {
510
+ ScaleARGBFilterCols = ScaleARGBFilterCols_Any_NEON;
511
+ if (IS_ALIGNED(dst_width, 4)) {
512
+ ScaleARGBFilterCols = ScaleARGBFilterCols_NEON;
513
+ }
514
+ }
515
+ #endif
516
+ #if defined(HAS_SCALEARGBFILTERCOLS_LSX)
517
+ if (filtering && TestCpuFlag(kCpuHasLSX)) {
518
+ ScaleARGBFilterCols = ScaleARGBFilterCols_Any_LSX;
519
+ if (IS_ALIGNED(dst_width, 8)) {
520
+ ScaleARGBFilterCols = ScaleARGBFilterCols_LSX;
521
+ }
522
+ }
523
+ #endif
524
+ #if defined(HAS_SCALEARGBFILTERCOLS_RVV)
525
+ if (filtering && TestCpuFlag(kCpuHasRVV)) {
526
+ ScaleARGBFilterCols = ScaleARGBFilterCols_RVV;
527
+ }
528
+ #endif
529
+ #if defined(HAS_SCALEARGBCOLS_SSE2)
530
+ if (!filtering && TestCpuFlag(kCpuHasSSE2) && src_width < 32768) {
531
+ ScaleARGBFilterCols = ScaleARGBCols_SSE2;
532
+ }
533
+ #endif
534
+ #if defined(HAS_SCALEARGBCOLS_NEON)
535
+ if (!filtering && TestCpuFlag(kCpuHasNEON)) {
536
+ ScaleARGBFilterCols = ScaleARGBCols_Any_NEON;
537
+ if (IS_ALIGNED(dst_width, 8)) {
538
+ ScaleARGBFilterCols = ScaleARGBCols_NEON;
539
+ }
540
+ }
541
+ #endif
542
+ #if defined(HAS_SCALEARGBCOLS_LSX)
543
+ if (!filtering && TestCpuFlag(kCpuHasLSX)) {
544
+ ScaleARGBFilterCols = ScaleARGBCols_Any_LSX;
545
+ if (IS_ALIGNED(dst_width, 4)) {
546
+ ScaleARGBFilterCols = ScaleARGBCols_LSX;
547
+ }
548
+ }
549
+ #endif
550
+ if (!filtering && src_width * 2 == dst_width && x < 0x8000) {
551
+ ScaleARGBFilterCols = ScaleARGBColsUp2_C;
552
+ #if defined(HAS_SCALEARGBCOLSUP2_SSE2)
553
+ if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) {
554
+ ScaleARGBFilterCols = ScaleARGBColsUp2_SSE2;
555
+ }
556
+ #endif
557
+ }
558
+
559
+ if (y > max_y) {
560
+ y = max_y;
561
+ }
562
+
563
+ {
564
+ int yi = y >> 16;
565
+ const uint8_t* src = src_argb + yi * (intptr_t)src_stride;
566
+
567
+ // Allocate 2 rows of ARGB.
568
+ const int row_size = (dst_width * 4 + 31) & ~31;
569
+ align_buffer_64(row, row_size * 2);
570
+ if (!row)
571
+ return 1;
572
+
573
+ uint8_t* rowptr = row;
574
+ int rowstride = row_size;
575
+ int lasty = yi;
576
+
577
+ ScaleARGBFilterCols(rowptr, src, dst_width, x, dx);
578
+ if (src_height > 1) {
579
+ src += src_stride;
580
+ }
581
+ ScaleARGBFilterCols(rowptr + rowstride, src, dst_width, x, dx);
582
+ if (src_height > 2) {
583
+ src += src_stride;
584
+ }
585
+
586
+ for (j = 0; j < dst_height; ++j) {
587
+ yi = y >> 16;
588
+ if (yi != lasty) {
589
+ if (y > max_y) {
590
+ y = max_y;
591
+ yi = y >> 16;
592
+ src = src_argb + yi * (intptr_t)src_stride;
593
+ }
594
+ if (yi != lasty) {
595
+ ScaleARGBFilterCols(rowptr, src, dst_width, x, dx);
596
+ rowptr += rowstride;
597
+ rowstride = -rowstride;
598
+ lasty = yi;
599
+ if ((y + 65536) < max_y) {
600
+ src += src_stride;
601
+ }
602
+ }
603
+ }
604
+ if (filtering == kFilterLinear) {
605
+ InterpolateRow(dst_argb, rowptr, 0, dst_width * 4, 0);
606
+ } else {
607
+ int yf = (y >> 8) & 255;
608
+ InterpolateRow(dst_argb, rowptr, rowstride, dst_width * 4, yf);
609
+ }
610
+ dst_argb += dst_stride;
611
+ y += dy;
612
+ }
613
+ free_aligned_buffer_64(row);
614
+ }
615
+ return 0;
616
+ }
617
+
618
+ #ifdef YUVSCALEUP
619
+ // Scale YUV to ARGB up with bilinear interpolation.
620
+ static int ScaleYUVToARGBBilinearUp(int src_width,
621
+ int src_height,
622
+ int dst_width,
623
+ int dst_height,
624
+ int src_stride_y,
625
+ int src_stride_u,
626
+ int src_stride_v,
627
+ int dst_stride_argb,
628
+ const uint8_t* src_y,
629
+ const uint8_t* src_u,
630
+ const uint8_t* src_v,
631
+ uint8_t* dst_argb,
632
+ int x,
633
+ int dx,
634
+ int y,
635
+ int dy,
636
+ enum FilterMode filtering) {
637
+ int j;
638
+ void (*I422ToARGBRow)(const uint8_t* y_buf, const uint8_t* u_buf,
639
+ const uint8_t* v_buf, uint8_t* rgb_buf, int width) =
640
+ I422ToARGBRow_C;
641
+ #if defined(HAS_I422TOARGBROW_SSSE3)
642
+ if (TestCpuFlag(kCpuHasSSSE3)) {
643
+ I422ToARGBRow = I422ToARGBRow_Any_SSSE3;
644
+ if (IS_ALIGNED(src_width, 8)) {
645
+ I422ToARGBRow = I422ToARGBRow_SSSE3;
646
+ }
647
+ }
648
+ #endif
649
+ #if defined(HAS_I422TOARGBROW_AVX2)
650
+ if (TestCpuFlag(kCpuHasAVX2)) {
651
+ I422ToARGBRow = I422ToARGBRow_Any_AVX2;
652
+ if (IS_ALIGNED(src_width, 16)) {
653
+ I422ToARGBRow = I422ToARGBRow_AVX2;
654
+ }
655
+ }
656
+ #endif
657
+ #if defined(HAS_I422TOARGBROW_AVX512BW)
658
+ if (TestCpuFlag(kCpuHasAVX512BW | kCpuHasAVX512VL) ==
659
+ (kCpuHasAVX512BW | kCpuHasAVX512VL)) {
660
+ I422ToARGBRow = I422ToARGBRow_Any_AVX512BW;
661
+ if (IS_ALIGNED(src_width, 32)) {
662
+ I422ToARGBRow = I422ToARGBRow_AVX512BW;
663
+ }
664
+ }
665
+ #endif
666
+ #if defined(HAS_I422TOARGBROW_NEON)
667
+ if (TestCpuFlag(kCpuHasNEON)) {
668
+ I422ToARGBRow = I422ToARGBRow_Any_NEON;
669
+ if (IS_ALIGNED(src_width, 8)) {
670
+ I422ToARGBRow = I422ToARGBRow_NEON;
671
+ }
672
+ }
673
+ #endif
674
+ #if defined(HAS_I422TOARGBROW_SVE2)
675
+ if (TestCpuFlag(kCpuHasSVE2)) {
676
+ I422ToARGBRow = I422ToARGBRow_SVE2;
677
+ }
678
+ #endif
679
+ #if defined(HAS_I422TOARGBROW_SME)
680
+ if (TestCpuFlag(kCpuHasSME)) {
681
+ I422ToARGBRow = I422ToARGBRow_SME;
682
+ }
683
+ #endif
684
+ #if defined(HAS_I422TOARGBROW_LSX)
685
+ if (TestCpuFlag(kCpuHasLSX)) {
686
+ I422ToARGBRow = I422ToARGBRow_Any_LSX;
687
+ if (IS_ALIGNED(src_width, 16)) {
688
+ I422ToARGBRow = I422ToARGBRow_LSX;
689
+ }
690
+ }
691
+ #endif
692
+ #if defined(HAS_I422TOARGBROW_LASX)
693
+ if (TestCpuFlag(kCpuHasLASX)) {
694
+ I422ToARGBRow = I422ToARGBRow_Any_LASX;
695
+ if (IS_ALIGNED(src_width, 32)) {
696
+ I422ToARGBRow = I422ToARGBRow_LASX;
697
+ }
698
+ }
699
+ #endif
700
+ #if defined(HAS_I422TOARGBROW_RVV)
701
+ if (TestCpuFlag(kCpuHasRVV)) {
702
+ I422ToARGBRow = I422ToARGBRow_RVV;
703
+ }
704
+ #endif
705
+
706
+ void (*InterpolateRow)(uint8_t* dst_argb, const uint8_t* src_argb,
707
+ ptrdiff_t src_stride, int dst_width,
708
+ int source_y_fraction) = InterpolateRow_C;
709
+ #if defined(HAS_INTERPOLATEROW_SSSE3)
710
+ if (TestCpuFlag(kCpuHasSSSE3)) {
711
+ InterpolateRow = InterpolateRow_Any_SSSE3;
712
+ if (IS_ALIGNED(dst_width, 4)) {
713
+ InterpolateRow = InterpolateRow_SSSE3;
714
+ }
715
+ }
716
+ #endif
717
+ #if defined(HAS_INTERPOLATEROW_AVX2)
718
+ if (TestCpuFlag(kCpuHasAVX2)) {
719
+ InterpolateRow = InterpolateRow_Any_AVX2;
720
+ if (IS_ALIGNED(dst_width, 8)) {
721
+ InterpolateRow = InterpolateRow_AVX2;
722
+ }
723
+ }
724
+ #endif
725
+ #if defined(HAS_INTERPOLATEROW_NEON)
726
+ if (TestCpuFlag(kCpuHasNEON)) {
727
+ InterpolateRow = InterpolateRow_Any_NEON;
728
+ if (IS_ALIGNED(dst_width, 4)) {
729
+ InterpolateRow = InterpolateRow_NEON;
730
+ }
731
+ }
732
+ #endif
733
+ #if defined(HAS_INTERPOLATEROW_SME)
734
+ if (TestCpuFlag(kCpuHasSME)) {
735
+ InterpolateRow = InterpolateRow_SME;
736
+ }
737
+ #endif
738
+ #if defined(HAS_INTERPOLATEROW_LSX)
739
+ if (TestCpuFlag(kCpuHasLSX)) {
740
+ InterpolateRow = InterpolateRow_Any_LSX;
741
+ if (IS_ALIGNED(dst_width, 8)) {
742
+ InterpolateRow = InterpolateRow_LSX;
743
+ }
744
+ }
745
+ #endif
746
+ #if defined(HAS_INTERPOLATEROW_RVV)
747
+ if (TestCpuFlag(kCpuHasRVV)) {
748
+ InterpolateRow = InterpolateRow_RVV;
749
+ }
750
+ #endif
751
+
752
+ void (*ScaleARGBFilterCols)(uint8_t* dst_argb, const uint8_t* src_argb,
753
+ int dst_width, int x, int dx) =
754
+ filtering ? ScaleARGBFilterCols_C : ScaleARGBCols_C;
755
+ if (src_width >= 32768) {
756
+ ScaleARGBFilterCols =
757
+ filtering ? ScaleARGBFilterCols64_C : ScaleARGBCols64_C;
758
+ }
759
+ #if defined(HAS_SCALEARGBFILTERCOLS_SSSE3)
760
+ if (filtering && TestCpuFlag(kCpuHasSSSE3) && src_width < 32768) {
761
+ ScaleARGBFilterCols = ScaleARGBFilterCols_SSSE3;
762
+ }
763
+ #endif
764
+ #if defined(HAS_SCALEARGBFILTERCOLS_NEON)
765
+ if (filtering && TestCpuFlag(kCpuHasNEON)) {
766
+ ScaleARGBFilterCols = ScaleARGBFilterCols_Any_NEON;
767
+ if (IS_ALIGNED(dst_width, 4)) {
768
+ ScaleARGBFilterCols = ScaleARGBFilterCols_NEON;
769
+ }
770
+ }
771
+ #endif
772
+ #if defined(HAS_SCALEARGBFILTERCOLS_LSX)
773
+ if (filtering && TestCpuFlag(kCpuHasLSX)) {
774
+ ScaleARGBFilterCols = ScaleARGBFilterCols_Any_LSX;
775
+ if (IS_ALIGNED(dst_width, 8)) {
776
+ ScaleARGBFilterCols = ScaleARGBFilterCols_LSX;
777
+ }
778
+ }
779
+ #endif
780
+ #if defined(HAS_SCALEARGBFILTERCOLS_RVV)
781
+ if (filtering && TestCpuFlag(kCpuHasRVV)) {
782
+ ScaleARGBFilterCols = ScaleARGBFilterCols_RVV;
783
+ }
784
+ #endif
785
+ #if defined(HAS_SCALEARGBCOLS_SSE2)
786
+ if (!filtering && TestCpuFlag(kCpuHasSSE2) && src_width < 32768) {
787
+ ScaleARGBFilterCols = ScaleARGBCols_SSE2;
788
+ }
789
+ #endif
790
+ #if defined(HAS_SCALEARGBCOLS_NEON)
791
+ if (!filtering && TestCpuFlag(kCpuHasNEON)) {
792
+ ScaleARGBFilterCols = ScaleARGBCols_Any_NEON;
793
+ if (IS_ALIGNED(dst_width, 8)) {
794
+ ScaleARGBFilterCols = ScaleARGBCols_NEON;
795
+ }
796
+ }
797
+ #endif
798
+ #if defined(HAS_SCALEARGBCOLS_LSX)
799
+ if (!filtering && TestCpuFlag(kCpuHasLSX)) {
800
+ ScaleARGBFilterCols = ScaleARGBCols_Any_LSX;
801
+ if (IS_ALIGNED(dst_width, 4)) {
802
+ ScaleARGBFilterCols = ScaleARGBCols_LSX;
803
+ }
804
+ }
805
+ #endif
806
+ if (!filtering && src_width * 2 == dst_width && x < 0x8000) {
807
+ ScaleARGBFilterCols = ScaleARGBColsUp2_C;
808
+ #if defined(HAS_SCALEARGBCOLSUP2_SSE2)
809
+ if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) {
810
+ ScaleARGBFilterCols = ScaleARGBColsUp2_SSE2;
811
+ }
812
+ #endif
813
+ }
814
+
815
+ const int max_y = (src_height - 1) << 16;
816
+ if (y > max_y) {
817
+ y = max_y;
818
+ }
819
+ const int kYShift = 1; // Shift Y by 1 to convert Y plane to UV coordinate.
820
+ int yi = y >> 16;
821
+ int uv_yi = yi >> kYShift;
822
+ const uint8_t* src_row_y = src_y + yi * (intptr_t)src_stride_y;
823
+ const uint8_t* src_row_u = src_u + uv_yi * (intptr_t)src_stride_u;
824
+ const uint8_t* src_row_v = src_v + uv_yi * (intptr_t)src_stride_v;
825
+
826
+ // Allocate 1 row of ARGB for source conversion and 2 rows of ARGB
827
+ // scaled horizontally to the destination width.
828
+ const int row_size = (dst_width * 4 + 31) & ~31;
829
+ align_buffer_64(row, row_size * 2 + src_width * 4);
830
+
831
+ uint8_t* argb_row = row + row_size * 2;
832
+ uint8_t* rowptr = row;
833
+ int rowstride = row_size;
834
+ int lasty = yi;
835
+ if (!row)
836
+ return 1;
837
+
838
+ // TODO(fbarchard): Convert first 2 rows of YUV to ARGB.
839
+ ScaleARGBFilterCols(rowptr, src_row_y, dst_width, x, dx);
840
+ if (src_height > 1) {
841
+ src_row_y += src_stride_y;
842
+ if (yi & 1) {
843
+ src_row_u += src_stride_u;
844
+ src_row_v += src_stride_v;
845
+ }
846
+ }
847
+ ScaleARGBFilterCols(rowptr + rowstride, src_row_y, dst_width, x, dx);
848
+ if (src_height > 2) {
849
+ src_row_y += src_stride_y;
850
+ if (!(yi & 1)) {
851
+ src_row_u += src_stride_u;
852
+ src_row_v += src_stride_v;
853
+ }
854
+ }
855
+
856
+ for (j = 0; j < dst_height; ++j) {
857
+ yi = y >> 16;
858
+ if (yi != lasty) {
859
+ if (y > max_y) {
860
+ y = max_y;
861
+ yi = y >> 16;
862
+ uv_yi = yi >> kYShift;
863
+ src_row_y = src_y + yi * (intptr_t)src_stride_y;
864
+ src_row_u = src_u + uv_yi * (intptr_t)src_stride_u;
865
+ src_row_v = src_v + uv_yi * (intptr_t)src_stride_v;
866
+ }
867
+ if (yi != lasty) {
868
+ // TODO(fbarchard): Convert the clipped region of row.
869
+ I422ToARGBRow(src_row_y, src_row_u, src_row_v, argb_row, src_width);
870
+ ScaleARGBFilterCols(rowptr, argb_row, dst_width, x, dx);
871
+ rowptr += rowstride;
872
+ rowstride = -rowstride;
873
+ lasty = yi;
874
+ src_row_y += src_stride_y;
875
+ if (yi & 1) {
876
+ src_row_u += src_stride_u;
877
+ src_row_v += src_stride_v;
878
+ }
879
+ }
880
+ }
881
+ if (filtering == kFilterLinear) {
882
+ InterpolateRow(dst_argb, rowptr, 0, dst_width * 4, 0);
883
+ } else {
884
+ int yf = (y >> 8) & 255;
885
+ InterpolateRow(dst_argb, rowptr, rowstride, dst_width * 4, yf);
886
+ }
887
+ dst_argb += dst_stride_argb;
888
+ y += dy;
889
+ }
890
+ free_aligned_buffer_64(row);
891
+ return 0;
892
+ }
893
+ #endif
894
+
895
+ // Scale ARGB to/from any dimensions, without interpolation.
896
+ // Fixed point math is used for performance: The upper 16 bits
897
+ // of x and dx is the integer part of the source position and
898
+ // the lower 16 bits are the fixed decimal part.
899
+
900
+ static void ScaleARGBSimple(int src_width,
901
+ int src_height,
902
+ int dst_width,
903
+ int dst_height,
904
+ int src_stride,
905
+ int dst_stride,
906
+ const uint8_t* src_argb,
907
+ uint8_t* dst_argb,
908
+ int x,
909
+ int dx,
910
+ int y,
911
+ int dy) {
912
+ int j;
913
+ void (*ScaleARGBCols)(uint8_t* dst_argb, const uint8_t* src_argb,
914
+ int dst_width, int x, int dx) =
915
+ (src_width >= 32768) ? ScaleARGBCols64_C : ScaleARGBCols_C;
916
+ (void)src_height;
917
+ #if defined(HAS_SCALEARGBCOLS_SSE2)
918
+ if (TestCpuFlag(kCpuHasSSE2) && src_width < 32768) {
919
+ ScaleARGBCols = ScaleARGBCols_SSE2;
920
+ }
921
+ #endif
922
+ #if defined(HAS_SCALEARGBCOLS_NEON)
923
+ if (TestCpuFlag(kCpuHasNEON)) {
924
+ ScaleARGBCols = ScaleARGBCols_Any_NEON;
925
+ if (IS_ALIGNED(dst_width, 8)) {
926
+ ScaleARGBCols = ScaleARGBCols_NEON;
927
+ }
928
+ }
929
+ #endif
930
+ #if defined(HAS_SCALEARGBCOLS_LSX)
931
+ if (TestCpuFlag(kCpuHasLSX)) {
932
+ ScaleARGBCols = ScaleARGBCols_Any_LSX;
933
+ if (IS_ALIGNED(dst_width, 4)) {
934
+ ScaleARGBCols = ScaleARGBCols_LSX;
935
+ }
936
+ }
937
+ #endif
938
+ if (src_width * 2 == dst_width && x < 0x8000) {
939
+ ScaleARGBCols = ScaleARGBColsUp2_C;
940
+ #if defined(HAS_SCALEARGBCOLSUP2_SSE2)
941
+ if (TestCpuFlag(kCpuHasSSE2) && IS_ALIGNED(dst_width, 8)) {
942
+ ScaleARGBCols = ScaleARGBColsUp2_SSE2;
943
+ }
944
+ #endif
945
+ }
946
+
947
+ for (j = 0; j < dst_height; ++j) {
948
+ ScaleARGBCols(dst_argb, src_argb + (y >> 16) * (intptr_t)src_stride,
949
+ dst_width, x, dx);
950
+ dst_argb += dst_stride;
951
+ y += dy;
952
+ }
953
+ }
954
+
955
+ // ScaleARGB a ARGB.
956
+ // This function in turn calls a scaling function
957
+ // suitable for handling the desired resolutions.
958
+ static int ScaleARGB(const uint8_t* src,
959
+ int src_stride,
960
+ int src_width,
961
+ int src_height,
962
+ uint8_t* dst,
963
+ int dst_stride,
964
+ int dst_width,
965
+ int dst_height,
966
+ int clip_x,
967
+ int clip_y,
968
+ int clip_width,
969
+ int clip_height,
970
+ enum FilterMode filtering) {
971
+ // Initial source x/y coordinate and step values as 16.16 fixed point.
972
+ int x = 0;
973
+ int y = 0;
974
+ int dx = 0;
975
+ int dy = 0;
976
+ // ARGB does not support box filter yet, but allow the user to pass it.
977
+ // Simplify filtering when possible.
978
+ filtering = ScaleFilterReduce(src_width, src_height, dst_width, dst_height,
979
+ filtering);
980
+
981
+ // Negative src_height means invert the image.
982
+ if (src_height < 0) {
983
+ src_height = -src_height;
984
+ src = src + (src_height - 1) * (intptr_t)src_stride;
985
+ src_stride = -src_stride;
986
+ }
987
+ ScaleSlope(src_width, src_height, dst_width, dst_height, filtering, &x, &y,
988
+ &dx, &dy);
989
+ src_width = Abs(src_width);
990
+ if (clip_x) {
991
+ int64_t clipf = (int64_t)(clip_x)*dx;
992
+ x += (clipf & 0xffff);
993
+ src += (clipf >> 16) * 4;
994
+ dst += clip_x * 4;
995
+ }
996
+ if (clip_y) {
997
+ int64_t clipf = (int64_t)(clip_y)*dy;
998
+ y += (clipf & 0xffff);
999
+ src += (clipf >> 16) * (intptr_t)src_stride;
1000
+ dst += clip_y * dst_stride;
1001
+ }
1002
+
1003
+ // Special case for integer step values.
1004
+ if (((dx | dy) & 0xffff) == 0) {
1005
+ if (!dx || !dy) { // 1 pixel wide and/or tall.
1006
+ filtering = kFilterNone;
1007
+ } else {
1008
+ // Optimized even scale down. ie 2, 4, 6, 8, 10x.
1009
+ if (!(dx & 0x10000) && !(dy & 0x10000)) {
1010
+ if (dx == 0x20000 && dy == 0x20000) {
1011
+ // Optimized 1/2 downsample.
1012
+ ScaleARGBDown2(src_width, src_height, clip_width, clip_height,
1013
+ src_stride, dst_stride, src, dst, x, dx, y, dy,
1014
+ filtering);
1015
+ return 0;
1016
+ }
1017
+ if (dx == 0x40000 && dy == 0x40000 && filtering == kFilterBox) {
1018
+ // Optimized 1/4 box downsample.
1019
+ return ScaleARGBDown4Box(src_width, src_height, clip_width,
1020
+ clip_height, src_stride, dst_stride, src,
1021
+ dst, x, dx, y, dy);
1022
+ }
1023
+ ScaleARGBDownEven(src_width, src_height, clip_width, clip_height,
1024
+ src_stride, dst_stride, src, dst, x, dx, y, dy,
1025
+ filtering);
1026
+ return 0;
1027
+ }
1028
+ // Optimized odd scale down. ie 3, 5, 7, 9x.
1029
+ if ((dx & 0x10000) && (dy & 0x10000)) {
1030
+ filtering = kFilterNone;
1031
+ if (dx == 0x10000 && dy == 0x10000) {
1032
+ // Straight copy.
1033
+ ARGBCopy(src + (y >> 16) * (intptr_t)src_stride + (x >> 16) * 4,
1034
+ src_stride, dst, dst_stride, clip_width, clip_height);
1035
+ return 0;
1036
+ }
1037
+ }
1038
+ }
1039
+ }
1040
+ if (dx == 0x10000 && (x & 0xffff) == 0) {
1041
+ // Arbitrary scale vertically, but unscaled horizontally.
1042
+ ScalePlaneVertical(src_height, clip_width, clip_height, src_stride,
1043
+ dst_stride, src, dst, x, y, dy, /*bpp=*/4, filtering);
1044
+ return 0;
1045
+ }
1046
+ if (filtering && dy < 65536) {
1047
+ return ScaleARGBBilinearUp(src_width, src_height, clip_width, clip_height,
1048
+ src_stride, dst_stride, src, dst, x, dx, y, dy,
1049
+ filtering);
1050
+ }
1051
+ if (filtering) {
1052
+ return ScaleARGBBilinearDown(src_width, src_height, clip_width, clip_height,
1053
+ src_stride, dst_stride, src, dst, x, dx, y, dy,
1054
+ filtering);
1055
+ }
1056
+ ScaleARGBSimple(src_width, src_height, clip_width, clip_height, src_stride,
1057
+ dst_stride, src, dst, x, dx, y, dy);
1058
+ return 0;
1059
+ }
1060
+
1061
+ LIBYUV_API
1062
+ int ARGBScaleClip(const uint8_t* src_argb,
1063
+ int src_stride_argb,
1064
+ int src_width,
1065
+ int src_height,
1066
+ uint8_t* dst_argb,
1067
+ int dst_stride_argb,
1068
+ int dst_width,
1069
+ int dst_height,
1070
+ int clip_x,
1071
+ int clip_y,
1072
+ int clip_width,
1073
+ int clip_height,
1074
+ enum FilterMode filtering) {
1075
+ if (!src_argb || src_width == 0 || src_height == 0 || !dst_argb ||
1076
+ dst_width <= 0 || dst_height <= 0 || clip_x < 0 || clip_y < 0 ||
1077
+ clip_width > 32768 || clip_height > 32768 ||
1078
+ (clip_x + clip_width) > dst_width ||
1079
+ (clip_y + clip_height) > dst_height) {
1080
+ return -1;
1081
+ }
1082
+ return ScaleARGB(src_argb, src_stride_argb, src_width, src_height, dst_argb,
1083
+ dst_stride_argb, dst_width, dst_height, clip_x, clip_y,
1084
+ clip_width, clip_height, filtering);
1085
+ }
1086
+
1087
+ // Scale an ARGB image.
1088
+ LIBYUV_API
1089
+ int ARGBScale(const uint8_t* src_argb,
1090
+ int src_stride_argb,
1091
+ int src_width,
1092
+ int src_height,
1093
+ uint8_t* dst_argb,
1094
+ int dst_stride_argb,
1095
+ int dst_width,
1096
+ int dst_height,
1097
+ enum FilterMode filtering) {
1098
+ if (!src_argb || src_width == 0 || src_height == 0 || src_width > 32768 ||
1099
+ src_height > 32768 || !dst_argb || dst_width <= 0 || dst_height <= 0) {
1100
+ return -1;
1101
+ }
1102
+ return ScaleARGB(src_argb, src_stride_argb, src_width, src_height, dst_argb,
1103
+ dst_stride_argb, dst_width, dst_height, 0, 0, dst_width,
1104
+ dst_height, filtering);
1105
+ }
1106
+
1107
+ // Scale with YUV conversion to ARGB and clipping.
1108
+ LIBYUV_API
1109
+ int YUVToARGBScaleClip(const uint8_t* src_y,
1110
+ int src_stride_y,
1111
+ const uint8_t* src_u,
1112
+ int src_stride_u,
1113
+ const uint8_t* src_v,
1114
+ int src_stride_v,
1115
+ uint32_t src_fourcc,
1116
+ int src_width,
1117
+ int src_height,
1118
+ uint8_t* dst_argb,
1119
+ int dst_stride_argb,
1120
+ uint32_t dst_fourcc,
1121
+ int dst_width,
1122
+ int dst_height,
1123
+ int clip_x,
1124
+ int clip_y,
1125
+ int clip_width,
1126
+ int clip_height,
1127
+ enum FilterMode filtering) {
1128
+ int r;
1129
+ (void)src_fourcc; // TODO(fbarchard): implement and/or assert.
1130
+ (void)dst_fourcc;
1131
+ const int abs_src_height = (src_height < 0) ? -src_height : src_height;
1132
+ if (!src_y || !src_u || !src_v || !dst_argb || src_width <= 0 ||
1133
+ src_width > INT_MAX / 4 || src_height == 0 || dst_width <= 0 ||
1134
+ dst_height <= 0 || clip_width <= 0 || clip_height <= 0) {
1135
+ return -1;
1136
+ }
1137
+ const uint64_t argb_buffer_size = (uint64_t)src_width * abs_src_height * 4;
1138
+ if (argb_buffer_size > SIZE_MAX) {
1139
+ return -1; // Invalid size.
1140
+ }
1141
+ uint8_t* argb_buffer = (uint8_t*)malloc((size_t)argb_buffer_size);
1142
+ if (!argb_buffer) {
1143
+ return 1; // Out of memory runtime error.
1144
+ }
1145
+ I420ToARGB(src_y, src_stride_y, src_u, src_stride_u, src_v, src_stride_v,
1146
+ argb_buffer, src_width * 4, src_width, src_height);
1147
+
1148
+ r = ARGBScaleClip(argb_buffer, src_width * 4, src_width, abs_src_height,
1149
+ dst_argb, dst_stride_argb, dst_width, dst_height, clip_x,
1150
+ clip_y, clip_width, clip_height, filtering);
1151
+ free(argb_buffer);
1152
+ return r;
1153
+ }
1154
+
1155
+ #ifdef __cplusplus
1156
+ } // extern "C"
1157
+ } // namespace libyuv
1158
+ #endif