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,866 +1,866 @@
1
- /*
2
- * Copyright 2012 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/convert_from.h"
12
-
13
- #include "libyuv/basic_types.h"
14
- #include "libyuv/convert.h" // For I420Copy
15
- #include "libyuv/cpu_id.h"
16
- #include "libyuv/planar_functions.h"
17
- #include "libyuv/rotate.h"
18
- #include "libyuv/row.h"
19
- #include "libyuv/scale.h" // For ScalePlane()
20
- #include "libyuv/video_common.h"
21
-
22
- #ifdef __cplusplus
23
- namespace libyuv {
24
- extern "C" {
25
- #endif
26
-
27
- #define SUBSAMPLE(v, a, s) (v < 0) ? (-((-v + a) >> s)) : ((v + a) >> s)
28
- static __inline int Abs(int v) {
29
- return v >= 0 ? v : -v;
30
- }
31
-
32
- // I420 To any I4xx YUV format with mirroring.
33
- static int I420ToI4xx(const uint8_t* src_y,
34
- int src_stride_y,
35
- const uint8_t* src_u,
36
- int src_stride_u,
37
- const uint8_t* src_v,
38
- int src_stride_v,
39
- uint8_t* dst_y,
40
- int dst_stride_y,
41
- uint8_t* dst_u,
42
- int dst_stride_u,
43
- uint8_t* dst_v,
44
- int dst_stride_v,
45
- int src_y_width,
46
- int src_y_height,
47
- int dst_uv_width,
48
- int dst_uv_height) {
49
- const int src_uv_width = SUBSAMPLE(src_y_width, 1, 1);
50
- const int src_uv_height = SUBSAMPLE(src_y_height, 1, 1);
51
- int r;
52
- if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v ||
53
- src_y_width <= 0 || src_y_height == 0 || dst_uv_width <= 0 ||
54
- dst_uv_height <= 0) {
55
- return -1;
56
- }
57
- if (dst_y) {
58
- CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, src_y_width,
59
- src_y_height);
60
- }
61
- r = ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, dst_u,
62
- dst_stride_u, dst_uv_width, dst_uv_height, kFilterBilinear);
63
- if (r != 0) {
64
- return r;
65
- }
66
- r = ScalePlane(src_v, src_stride_v, src_uv_width, src_uv_height, dst_v,
67
- dst_stride_v, dst_uv_width, dst_uv_height, kFilterBilinear);
68
- return r;
69
- }
70
-
71
- // Convert 8 bit YUV to 10 bit.
72
- LIBYUV_API
73
- int I420ToI010(const uint8_t* src_y,
74
- int src_stride_y,
75
- const uint8_t* src_u,
76
- int src_stride_u,
77
- const uint8_t* src_v,
78
- int src_stride_v,
79
- uint16_t* dst_y,
80
- int dst_stride_y,
81
- uint16_t* dst_u,
82
- int dst_stride_u,
83
- uint16_t* dst_v,
84
- int dst_stride_v,
85
- int width,
86
- int height) {
87
- int halfwidth = (width + 1) >> 1;
88
- int halfheight = (height + 1) >> 1;
89
- if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 ||
90
- height == 0) {
91
- return -1;
92
- }
93
- // Negative height means invert the image.
94
- if (height < 0) {
95
- height = -height;
96
- halfheight = (height + 1) >> 1;
97
- src_y = src_y + (height - 1) * src_stride_y;
98
- src_u = src_u + (halfheight - 1) * src_stride_u;
99
- src_v = src_v + (halfheight - 1) * src_stride_v;
100
- src_stride_y = -src_stride_y;
101
- src_stride_u = -src_stride_u;
102
- src_stride_v = -src_stride_v;
103
- }
104
-
105
- // Convert Y plane.
106
- Convert8To16Plane(src_y, src_stride_y, dst_y, dst_stride_y, 1024, width,
107
- height);
108
- // Convert UV planes.
109
- Convert8To16Plane(src_u, src_stride_u, dst_u, dst_stride_u, 1024, halfwidth,
110
- halfheight);
111
- Convert8To16Plane(src_v, src_stride_v, dst_v, dst_stride_v, 1024, halfwidth,
112
- halfheight);
113
- return 0;
114
- }
115
-
116
- // Convert 8 bit YUV to 12 bit.
117
- LIBYUV_API
118
- int I420ToI012(const uint8_t* src_y,
119
- int src_stride_y,
120
- const uint8_t* src_u,
121
- int src_stride_u,
122
- const uint8_t* src_v,
123
- int src_stride_v,
124
- uint16_t* dst_y,
125
- int dst_stride_y,
126
- uint16_t* dst_u,
127
- int dst_stride_u,
128
- uint16_t* dst_v,
129
- int dst_stride_v,
130
- int width,
131
- int height) {
132
- int halfwidth = (width + 1) >> 1;
133
- int halfheight = (height + 1) >> 1;
134
- if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 ||
135
- height == 0) {
136
- return -1;
137
- }
138
- // Negative height means invert the image.
139
- if (height < 0) {
140
- height = -height;
141
- halfheight = (height + 1) >> 1;
142
- src_y = src_y + (height - 1) * src_stride_y;
143
- src_u = src_u + (halfheight - 1) * src_stride_u;
144
- src_v = src_v + (halfheight - 1) * src_stride_v;
145
- src_stride_y = -src_stride_y;
146
- src_stride_u = -src_stride_u;
147
- src_stride_v = -src_stride_v;
148
- }
149
-
150
- // Convert Y plane.
151
- Convert8To16Plane(src_y, src_stride_y, dst_y, dst_stride_y, 4096, width,
152
- height);
153
- // Convert UV planes.
154
- Convert8To16Plane(src_u, src_stride_u, dst_u, dst_stride_u, 4096, halfwidth,
155
- halfheight);
156
- Convert8To16Plane(src_v, src_stride_v, dst_v, dst_stride_v, 4096, halfwidth,
157
- halfheight);
158
- return 0;
159
- }
160
-
161
- // 420 chroma is 1/2 width, 1/2 height
162
- // 422 chroma is 1/2 width, 1x height
163
- LIBYUV_API
164
- int I420ToI422(const uint8_t* src_y,
165
- int src_stride_y,
166
- const uint8_t* src_u,
167
- int src_stride_u,
168
- const uint8_t* src_v,
169
- int src_stride_v,
170
- uint8_t* dst_y,
171
- int dst_stride_y,
172
- uint8_t* dst_u,
173
- int dst_stride_u,
174
- uint8_t* dst_v,
175
- int dst_stride_v,
176
- int width,
177
- int height) {
178
- const int dst_uv_width = (Abs(width) + 1) >> 1;
179
- const int dst_uv_height = Abs(height);
180
- return I420ToI4xx(src_y, src_stride_y, src_u, src_stride_u, src_v,
181
- src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u,
182
- dst_v, dst_stride_v, width, height, dst_uv_width,
183
- dst_uv_height);
184
- }
185
-
186
- // 420 chroma is 1/2 width, 1/2 height
187
- // 444 chroma is 1x width, 1x height
188
- LIBYUV_API
189
- int I420ToI444(const uint8_t* src_y,
190
- int src_stride_y,
191
- const uint8_t* src_u,
192
- int src_stride_u,
193
- const uint8_t* src_v,
194
- int src_stride_v,
195
- uint8_t* dst_y,
196
- int dst_stride_y,
197
- uint8_t* dst_u,
198
- int dst_stride_u,
199
- uint8_t* dst_v,
200
- int dst_stride_v,
201
- int width,
202
- int height) {
203
- const int dst_uv_width = Abs(width);
204
- const int dst_uv_height = Abs(height);
205
- return I420ToI4xx(src_y, src_stride_y, src_u, src_stride_u, src_v,
206
- src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u,
207
- dst_v, dst_stride_v, width, height, dst_uv_width,
208
- dst_uv_height);
209
- }
210
-
211
- // 420 chroma to 444 chroma, 10/12 bit version
212
- LIBYUV_API
213
- int I010ToI410(const uint16_t* src_y,
214
- int src_stride_y,
215
- const uint16_t* src_u,
216
- int src_stride_u,
217
- const uint16_t* src_v,
218
- int src_stride_v,
219
- uint16_t* dst_y,
220
- int dst_stride_y,
221
- uint16_t* dst_u,
222
- int dst_stride_u,
223
- uint16_t* dst_v,
224
- int dst_stride_v,
225
- int width,
226
- int height) {
227
- int r;
228
- if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 ||
229
- height == 0) {
230
- return -1;
231
- }
232
-
233
- if (dst_y) {
234
- CopyPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
235
- }
236
- r = ScalePlane_12(src_u, src_stride_u, SUBSAMPLE(width, 1, 1),
237
- SUBSAMPLE(height, 1, 1), dst_u, dst_stride_u, width,
238
- Abs(height), kFilterBilinear);
239
- if (r != 0) {
240
- return r;
241
- }
242
- r = ScalePlane_12(src_v, src_stride_v, SUBSAMPLE(width, 1, 1),
243
- SUBSAMPLE(height, 1, 1), dst_v, dst_stride_v, width,
244
- Abs(height), kFilterBilinear);
245
- return r;
246
- }
247
-
248
- // 422 chroma to 444 chroma, 10/12 bit version
249
- LIBYUV_API
250
- int I210ToI410(const uint16_t* src_y,
251
- int src_stride_y,
252
- const uint16_t* src_u,
253
- int src_stride_u,
254
- const uint16_t* src_v,
255
- int src_stride_v,
256
- uint16_t* dst_y,
257
- int dst_stride_y,
258
- uint16_t* dst_u,
259
- int dst_stride_u,
260
- uint16_t* dst_v,
261
- int dst_stride_v,
262
- int width,
263
- int height) {
264
- int r;
265
- if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 ||
266
- height == 0) {
267
- return -1;
268
- }
269
-
270
- if (dst_y) {
271
- CopyPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
272
- }
273
- r = ScalePlane_12(src_u, src_stride_u, SUBSAMPLE(width, 1, 1), height, dst_u,
274
- dst_stride_u, width, Abs(height), kFilterBilinear);
275
- if (r != 0) {
276
- return r;
277
- }
278
- r = ScalePlane_12(src_v, src_stride_v, SUBSAMPLE(width, 1, 1), height, dst_v,
279
- dst_stride_v, width, Abs(height), kFilterBilinear);
280
- return r;
281
- }
282
-
283
- // 422 chroma is 1/2 width, 1x height
284
- // 444 chroma is 1x width, 1x height
285
- LIBYUV_API
286
- int I422ToI444(const uint8_t* src_y,
287
- int src_stride_y,
288
- const uint8_t* src_u,
289
- int src_stride_u,
290
- const uint8_t* src_v,
291
- int src_stride_v,
292
- uint8_t* dst_y,
293
- int dst_stride_y,
294
- uint8_t* dst_u,
295
- int dst_stride_u,
296
- uint8_t* dst_v,
297
- int dst_stride_v,
298
- int width,
299
- int height) {
300
- int r;
301
- if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 ||
302
- height == 0) {
303
- return -1;
304
- }
305
-
306
- if (dst_y) {
307
- CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
308
- }
309
- r = ScalePlane(src_u, src_stride_u, SUBSAMPLE(width, 1, 1), height, dst_u,
310
- dst_stride_u, width, Abs(height), kFilterBilinear);
311
- if (r != 0) {
312
- return r;
313
- }
314
- r = ScalePlane(src_v, src_stride_v, SUBSAMPLE(width, 1, 1), height, dst_v,
315
- dst_stride_v, width, Abs(height), kFilterBilinear);
316
- return r;
317
- }
318
-
319
- // Copy to I400. Source can be I420,422,444,400,NV12,NV21
320
- LIBYUV_API
321
- int I400Copy(const uint8_t* src_y,
322
- int src_stride_y,
323
- uint8_t* dst_y,
324
- int dst_stride_y,
325
- int width,
326
- int height) {
327
- if (!src_y || !dst_y || width <= 0 || height == 0) {
328
- return -1;
329
- }
330
- CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
331
- return 0;
332
- }
333
-
334
- LIBYUV_API
335
- int I422ToYUY2(const uint8_t* src_y,
336
- int src_stride_y,
337
- const uint8_t* src_u,
338
- int src_stride_u,
339
- const uint8_t* src_v,
340
- int src_stride_v,
341
- uint8_t* dst_yuy2,
342
- int dst_stride_yuy2,
343
- int width,
344
- int height) {
345
- int y;
346
- void (*I422ToYUY2Row)(const uint8_t* src_y, const uint8_t* src_u,
347
- const uint8_t* src_v, uint8_t* dst_yuy2, int width) =
348
- I422ToYUY2Row_C;
349
- if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0) {
350
- return -1;
351
- }
352
- // Negative height means invert the image.
353
- if (height < 0) {
354
- height = -height;
355
- dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2;
356
- dst_stride_yuy2 = -dst_stride_yuy2;
357
- }
358
- // Coalesce rows.
359
- if (src_stride_y == width && src_stride_u * 2 == width &&
360
- src_stride_v * 2 == width && dst_stride_yuy2 == width * 2) {
361
- width *= height;
362
- height = 1;
363
- src_stride_y = src_stride_u = src_stride_v = dst_stride_yuy2 = 0;
364
- }
365
- #if defined(HAS_I422TOYUY2ROW_SSE2)
366
- if (TestCpuFlag(kCpuHasSSE2)) {
367
- I422ToYUY2Row = I422ToYUY2Row_Any_SSE2;
368
- if (IS_ALIGNED(width, 16)) {
369
- I422ToYUY2Row = I422ToYUY2Row_SSE2;
370
- }
371
- }
372
- #endif
373
- #if defined(HAS_I422TOYUY2ROW_AVX2)
374
- if (TestCpuFlag(kCpuHasAVX2)) {
375
- I422ToYUY2Row = I422ToYUY2Row_Any_AVX2;
376
- if (IS_ALIGNED(width, 32)) {
377
- I422ToYUY2Row = I422ToYUY2Row_AVX2;
378
- }
379
- }
380
- #endif
381
- #if defined(HAS_I422TOYUY2ROW_NEON)
382
- if (TestCpuFlag(kCpuHasNEON)) {
383
- I422ToYUY2Row = I422ToYUY2Row_Any_NEON;
384
- if (IS_ALIGNED(width, 16)) {
385
- I422ToYUY2Row = I422ToYUY2Row_NEON;
386
- }
387
- }
388
- #endif
389
-
390
- for (y = 0; y < height; ++y) {
391
- I422ToYUY2Row(src_y, src_u, src_v, dst_yuy2, width);
392
- src_y += src_stride_y;
393
- src_u += src_stride_u;
394
- src_v += src_stride_v;
395
- dst_yuy2 += dst_stride_yuy2;
396
- }
397
- return 0;
398
- }
399
-
400
- LIBYUV_API
401
- int I420ToYUY2(const uint8_t* src_y,
402
- int src_stride_y,
403
- const uint8_t* src_u,
404
- int src_stride_u,
405
- const uint8_t* src_v,
406
- int src_stride_v,
407
- uint8_t* dst_yuy2,
408
- int dst_stride_yuy2,
409
- int width,
410
- int height) {
411
- int y;
412
- void (*I422ToYUY2Row)(const uint8_t* src_y, const uint8_t* src_u,
413
- const uint8_t* src_v, uint8_t* dst_yuy2, int width) =
414
- I422ToYUY2Row_C;
415
- if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0) {
416
- return -1;
417
- }
418
- // Negative height means invert the image.
419
- if (height < 0) {
420
- height = -height;
421
- dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2;
422
- dst_stride_yuy2 = -dst_stride_yuy2;
423
- }
424
- #if defined(HAS_I422TOYUY2ROW_SSE2)
425
- if (TestCpuFlag(kCpuHasSSE2)) {
426
- I422ToYUY2Row = I422ToYUY2Row_Any_SSE2;
427
- if (IS_ALIGNED(width, 16)) {
428
- I422ToYUY2Row = I422ToYUY2Row_SSE2;
429
- }
430
- }
431
- #endif
432
- #if defined(HAS_I422TOYUY2ROW_AVX2)
433
- if (TestCpuFlag(kCpuHasAVX2)) {
434
- I422ToYUY2Row = I422ToYUY2Row_Any_AVX2;
435
- if (IS_ALIGNED(width, 32)) {
436
- I422ToYUY2Row = I422ToYUY2Row_AVX2;
437
- }
438
- }
439
- #endif
440
- #if defined(HAS_I422TOYUY2ROW_NEON)
441
- if (TestCpuFlag(kCpuHasNEON)) {
442
- I422ToYUY2Row = I422ToYUY2Row_Any_NEON;
443
- if (IS_ALIGNED(width, 16)) {
444
- I422ToYUY2Row = I422ToYUY2Row_NEON;
445
- }
446
- }
447
- #endif
448
- #if defined(HAS_I422TOYUY2ROW_LSX)
449
- if (TestCpuFlag(kCpuHasLSX)) {
450
- I422ToYUY2Row = I422ToYUY2Row_Any_LSX;
451
- if (IS_ALIGNED(width, 16)) {
452
- I422ToYUY2Row = I422ToYUY2Row_LSX;
453
- }
454
- }
455
- #endif
456
- #if defined(HAS_I422TOYUY2ROW_LASX)
457
- if (TestCpuFlag(kCpuHasLASX)) {
458
- I422ToYUY2Row = I422ToYUY2Row_Any_LASX;
459
- if (IS_ALIGNED(width, 32)) {
460
- I422ToYUY2Row = I422ToYUY2Row_LASX;
461
- }
462
- }
463
- #endif
464
-
465
- for (y = 0; y < height - 1; y += 2) {
466
- I422ToYUY2Row(src_y, src_u, src_v, dst_yuy2, width);
467
- I422ToYUY2Row(src_y + src_stride_y, src_u, src_v,
468
- dst_yuy2 + dst_stride_yuy2, width);
469
- src_y += src_stride_y * 2;
470
- src_u += src_stride_u;
471
- src_v += src_stride_v;
472
- dst_yuy2 += dst_stride_yuy2 * 2;
473
- }
474
- if (height & 1) {
475
- I422ToYUY2Row(src_y, src_u, src_v, dst_yuy2, width);
476
- }
477
- return 0;
478
- }
479
-
480
- LIBYUV_API
481
- int I422ToUYVY(const uint8_t* src_y,
482
- int src_stride_y,
483
- const uint8_t* src_u,
484
- int src_stride_u,
485
- const uint8_t* src_v,
486
- int src_stride_v,
487
- uint8_t* dst_uyvy,
488
- int dst_stride_uyvy,
489
- int width,
490
- int height) {
491
- int y;
492
- void (*I422ToUYVYRow)(const uint8_t* src_y, const uint8_t* src_u,
493
- const uint8_t* src_v, uint8_t* dst_uyvy, int width) =
494
- I422ToUYVYRow_C;
495
- if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0) {
496
- return -1;
497
- }
498
- // Negative height means invert the image.
499
- if (height < 0) {
500
- height = -height;
501
- dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy;
502
- dst_stride_uyvy = -dst_stride_uyvy;
503
- }
504
- // Coalesce rows.
505
- if (src_stride_y == width && src_stride_u * 2 == width &&
506
- src_stride_v * 2 == width && dst_stride_uyvy == width * 2) {
507
- width *= height;
508
- height = 1;
509
- src_stride_y = src_stride_u = src_stride_v = dst_stride_uyvy = 0;
510
- }
511
- #if defined(HAS_I422TOUYVYROW_SSE2)
512
- if (TestCpuFlag(kCpuHasSSE2)) {
513
- I422ToUYVYRow = I422ToUYVYRow_Any_SSE2;
514
- if (IS_ALIGNED(width, 16)) {
515
- I422ToUYVYRow = I422ToUYVYRow_SSE2;
516
- }
517
- }
518
- #endif
519
- #if defined(HAS_I422TOUYVYROW_AVX2)
520
- if (TestCpuFlag(kCpuHasAVX2)) {
521
- I422ToUYVYRow = I422ToUYVYRow_Any_AVX2;
522
- if (IS_ALIGNED(width, 32)) {
523
- I422ToUYVYRow = I422ToUYVYRow_AVX2;
524
- }
525
- }
526
- #endif
527
- #if defined(HAS_I422TOUYVYROW_NEON)
528
- if (TestCpuFlag(kCpuHasNEON)) {
529
- I422ToUYVYRow = I422ToUYVYRow_Any_NEON;
530
- if (IS_ALIGNED(width, 16)) {
531
- I422ToUYVYRow = I422ToUYVYRow_NEON;
532
- }
533
- }
534
- #endif
535
- #if defined(HAS_I422TOUYVYROW_LSX)
536
- if (TestCpuFlag(kCpuHasLSX)) {
537
- I422ToUYVYRow = I422ToUYVYRow_Any_LSX;
538
- if (IS_ALIGNED(width, 16)) {
539
- I422ToUYVYRow = I422ToUYVYRow_LSX;
540
- }
541
- }
542
- #endif
543
- #if defined(HAS_I422TOUYVYROW_LASX)
544
- if (TestCpuFlag(kCpuHasLASX)) {
545
- I422ToUYVYRow = I422ToUYVYRow_Any_LASX;
546
- if (IS_ALIGNED(width, 32)) {
547
- I422ToUYVYRow = I422ToUYVYRow_LASX;
548
- }
549
- }
550
- #endif
551
-
552
- for (y = 0; y < height; ++y) {
553
- I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width);
554
- src_y += src_stride_y;
555
- src_u += src_stride_u;
556
- src_v += src_stride_v;
557
- dst_uyvy += dst_stride_uyvy;
558
- }
559
- return 0;
560
- }
561
-
562
- LIBYUV_API
563
- int I420ToUYVY(const uint8_t* src_y,
564
- int src_stride_y,
565
- const uint8_t* src_u,
566
- int src_stride_u,
567
- const uint8_t* src_v,
568
- int src_stride_v,
569
- uint8_t* dst_uyvy,
570
- int dst_stride_uyvy,
571
- int width,
572
- int height) {
573
- int y;
574
- void (*I422ToUYVYRow)(const uint8_t* src_y, const uint8_t* src_u,
575
- const uint8_t* src_v, uint8_t* dst_uyvy, int width) =
576
- I422ToUYVYRow_C;
577
- if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0) {
578
- return -1;
579
- }
580
- // Negative height means invert the image.
581
- if (height < 0) {
582
- height = -height;
583
- dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy;
584
- dst_stride_uyvy = -dst_stride_uyvy;
585
- }
586
- #if defined(HAS_I422TOUYVYROW_SSE2)
587
- if (TestCpuFlag(kCpuHasSSE2)) {
588
- I422ToUYVYRow = I422ToUYVYRow_Any_SSE2;
589
- if (IS_ALIGNED(width, 16)) {
590
- I422ToUYVYRow = I422ToUYVYRow_SSE2;
591
- }
592
- }
593
- #endif
594
- #if defined(HAS_I422TOUYVYROW_AVX2)
595
- if (TestCpuFlag(kCpuHasAVX2)) {
596
- I422ToUYVYRow = I422ToUYVYRow_Any_AVX2;
597
- if (IS_ALIGNED(width, 32)) {
598
- I422ToUYVYRow = I422ToUYVYRow_AVX2;
599
- }
600
- }
601
- #endif
602
- #if defined(HAS_I422TOUYVYROW_NEON)
603
- if (TestCpuFlag(kCpuHasNEON)) {
604
- I422ToUYVYRow = I422ToUYVYRow_Any_NEON;
605
- if (IS_ALIGNED(width, 16)) {
606
- I422ToUYVYRow = I422ToUYVYRow_NEON;
607
- }
608
- }
609
- #endif
610
- #if defined(HAS_I422TOUYVYROW_LSX)
611
- if (TestCpuFlag(kCpuHasLSX)) {
612
- I422ToUYVYRow = I422ToUYVYRow_Any_LSX;
613
- if (IS_ALIGNED(width, 16)) {
614
- I422ToUYVYRow = I422ToUYVYRow_LSX;
615
- }
616
- }
617
- #endif
618
- #if defined(HAS_I422TOUYVYROW_LASX)
619
- if (TestCpuFlag(kCpuHasLASX)) {
620
- I422ToUYVYRow = I422ToUYVYRow_Any_LASX;
621
- if (IS_ALIGNED(width, 32)) {
622
- I422ToUYVYRow = I422ToUYVYRow_LASX;
623
- }
624
- }
625
- #endif
626
-
627
- for (y = 0; y < height - 1; y += 2) {
628
- I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width);
629
- I422ToUYVYRow(src_y + src_stride_y, src_u, src_v,
630
- dst_uyvy + dst_stride_uyvy, width);
631
- src_y += src_stride_y * 2;
632
- src_u += src_stride_u;
633
- src_v += src_stride_v;
634
- dst_uyvy += dst_stride_uyvy * 2;
635
- }
636
- if (height & 1) {
637
- I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width);
638
- }
639
- return 0;
640
- }
641
-
642
- LIBYUV_API
643
- int I420ToNV12(const uint8_t* src_y,
644
- int src_stride_y,
645
- const uint8_t* src_u,
646
- int src_stride_u,
647
- const uint8_t* src_v,
648
- int src_stride_v,
649
- uint8_t* dst_y,
650
- int dst_stride_y,
651
- uint8_t* dst_uv,
652
- int dst_stride_uv,
653
- int width,
654
- int height) {
655
- int halfwidth = (width + 1) / 2;
656
- int halfheight = (height + 1) / 2;
657
- if ((!src_y && dst_y) || !src_u || !src_v || !dst_uv || width <= 0 ||
658
- height == 0) {
659
- return -1;
660
- }
661
- // Negative height means invert the image.
662
- if (height < 0) {
663
- height = -height;
664
- halfheight = (height + 1) >> 1;
665
- src_y = src_y + (height - 1) * src_stride_y;
666
- src_u = src_u + (halfheight - 1) * src_stride_u;
667
- src_v = src_v + (halfheight - 1) * src_stride_v;
668
- src_stride_y = -src_stride_y;
669
- src_stride_u = -src_stride_u;
670
- src_stride_v = -src_stride_v;
671
- }
672
- if (dst_y) {
673
- CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
674
- }
675
- MergeUVPlane(src_u, src_stride_u, src_v, src_stride_v, dst_uv, dst_stride_uv,
676
- halfwidth, halfheight);
677
- return 0;
678
- }
679
-
680
- LIBYUV_API
681
- int I420ToNV21(const uint8_t* src_y,
682
- int src_stride_y,
683
- const uint8_t* src_u,
684
- int src_stride_u,
685
- const uint8_t* src_v,
686
- int src_stride_v,
687
- uint8_t* dst_y,
688
- int dst_stride_y,
689
- uint8_t* dst_vu,
690
- int dst_stride_vu,
691
- int width,
692
- int height) {
693
- return I420ToNV12(src_y, src_stride_y, src_v, src_stride_v, src_u,
694
- src_stride_u, dst_y, dst_stride_y, dst_vu, dst_stride_vu,
695
- width, height);
696
- }
697
-
698
- // Convert I420 to specified format
699
- LIBYUV_API
700
- int ConvertFromI420(const uint8_t* y,
701
- int y_stride,
702
- const uint8_t* u,
703
- int u_stride,
704
- const uint8_t* v,
705
- int v_stride,
706
- uint8_t* dst_sample,
707
- int dst_sample_stride,
708
- int width,
709
- int height,
710
- uint32_t fourcc) {
711
- uint32_t format = CanonicalFourCC(fourcc);
712
- int r = 0;
713
- if (!y || !u || !v || !dst_sample || width <= 0 || height == 0) {
714
- return -1;
715
- }
716
- switch (format) {
717
- // Single plane formats
718
- case FOURCC_YUY2:
719
- r = I420ToYUY2(y, y_stride, u, u_stride, v, v_stride, dst_sample,
720
- dst_sample_stride ? dst_sample_stride : width * 2, width,
721
- height);
722
- break;
723
- case FOURCC_UYVY:
724
- r = I420ToUYVY(y, y_stride, u, u_stride, v, v_stride, dst_sample,
725
- dst_sample_stride ? dst_sample_stride : width * 2, width,
726
- height);
727
- break;
728
- case FOURCC_RGBP:
729
- r = I420ToRGB565(y, y_stride, u, u_stride, v, v_stride, dst_sample,
730
- dst_sample_stride ? dst_sample_stride : width * 2, width,
731
- height);
732
- break;
733
- case FOURCC_RGBO:
734
- r = I420ToARGB1555(y, y_stride, u, u_stride, v, v_stride, dst_sample,
735
- dst_sample_stride ? dst_sample_stride : width * 2,
736
- width, height);
737
- break;
738
- case FOURCC_R444:
739
- r = I420ToARGB4444(y, y_stride, u, u_stride, v, v_stride, dst_sample,
740
- dst_sample_stride ? dst_sample_stride : width * 2,
741
- width, height);
742
- break;
743
- case FOURCC_24BG:
744
- r = I420ToRGB24(y, y_stride, u, u_stride, v, v_stride, dst_sample,
745
- dst_sample_stride ? dst_sample_stride : width * 3, width,
746
- height);
747
- break;
748
- case FOURCC_RAW:
749
- r = I420ToRAW(y, y_stride, u, u_stride, v, v_stride, dst_sample,
750
- dst_sample_stride ? dst_sample_stride : width * 3, width,
751
- height);
752
- break;
753
- case FOURCC_ARGB:
754
- r = I420ToARGB(y, y_stride, u, u_stride, v, v_stride, dst_sample,
755
- dst_sample_stride ? dst_sample_stride : width * 4, width,
756
- height);
757
- break;
758
- case FOURCC_BGRA:
759
- r = I420ToBGRA(y, y_stride, u, u_stride, v, v_stride, dst_sample,
760
- dst_sample_stride ? dst_sample_stride : width * 4, width,
761
- height);
762
- break;
763
- case FOURCC_ABGR:
764
- r = I420ToABGR(y, y_stride, u, u_stride, v, v_stride, dst_sample,
765
- dst_sample_stride ? dst_sample_stride : width * 4, width,
766
- height);
767
- break;
768
- case FOURCC_RGBA:
769
- r = I420ToRGBA(y, y_stride, u, u_stride, v, v_stride, dst_sample,
770
- dst_sample_stride ? dst_sample_stride : width * 4, width,
771
- height);
772
- break;
773
- case FOURCC_AR30:
774
- r = I420ToAR30(y, y_stride, u, u_stride, v, v_stride, dst_sample,
775
- dst_sample_stride ? dst_sample_stride : width * 4, width,
776
- height);
777
- break;
778
- case FOURCC_I400:
779
- r = I400Copy(y, y_stride, dst_sample,
780
- dst_sample_stride ? dst_sample_stride : width, width,
781
- height);
782
- break;
783
- case FOURCC_NV12: {
784
- int dst_y_stride = dst_sample_stride ? dst_sample_stride : width;
785
- uint8_t* dst_uv = dst_sample + dst_y_stride * height;
786
- r = I420ToNV12(y, y_stride, u, u_stride, v, v_stride, dst_sample,
787
- dst_sample_stride ? dst_sample_stride : width, dst_uv,
788
- dst_sample_stride ? dst_sample_stride : width, width,
789
- height);
790
- break;
791
- }
792
- case FOURCC_NV21: {
793
- int dst_y_stride = dst_sample_stride ? dst_sample_stride : width;
794
- uint8_t* dst_vu = dst_sample + dst_y_stride * height;
795
- r = I420ToNV21(y, y_stride, u, u_stride, v, v_stride, dst_sample,
796
- dst_sample_stride ? dst_sample_stride : width, dst_vu,
797
- dst_sample_stride ? dst_sample_stride : width, width,
798
- height);
799
- break;
800
- }
801
- // Triplanar formats
802
- case FOURCC_I420:
803
- case FOURCC_YV12: {
804
- dst_sample_stride = dst_sample_stride ? dst_sample_stride : width;
805
- int halfstride = (dst_sample_stride + 1) / 2;
806
- int halfheight = (height + 1) / 2;
807
- uint8_t* dst_u;
808
- uint8_t* dst_v;
809
- if (format == FOURCC_YV12) {
810
- dst_v = dst_sample + dst_sample_stride * height;
811
- dst_u = dst_v + halfstride * halfheight;
812
- } else {
813
- dst_u = dst_sample + dst_sample_stride * height;
814
- dst_v = dst_u + halfstride * halfheight;
815
- }
816
- r = I420Copy(y, y_stride, u, u_stride, v, v_stride, dst_sample,
817
- dst_sample_stride, dst_u, halfstride, dst_v, halfstride,
818
- width, height);
819
- break;
820
- }
821
- case FOURCC_I422:
822
- case FOURCC_YV16: {
823
- dst_sample_stride = dst_sample_stride ? dst_sample_stride : width;
824
- int halfstride = (dst_sample_stride + 1) / 2;
825
- uint8_t* dst_u;
826
- uint8_t* dst_v;
827
- if (format == FOURCC_YV16) {
828
- dst_v = dst_sample + dst_sample_stride * height;
829
- dst_u = dst_v + halfstride * height;
830
- } else {
831
- dst_u = dst_sample + dst_sample_stride * height;
832
- dst_v = dst_u + halfstride * height;
833
- }
834
- r = I420ToI422(y, y_stride, u, u_stride, v, v_stride, dst_sample,
835
- dst_sample_stride, dst_u, halfstride, dst_v, halfstride,
836
- width, height);
837
- break;
838
- }
839
- case FOURCC_I444:
840
- case FOURCC_YV24: {
841
- dst_sample_stride = dst_sample_stride ? dst_sample_stride : width;
842
- uint8_t* dst_u;
843
- uint8_t* dst_v;
844
- if (format == FOURCC_YV24) {
845
- dst_v = dst_sample + dst_sample_stride * height;
846
- dst_u = dst_v + dst_sample_stride * height;
847
- } else {
848
- dst_u = dst_sample + dst_sample_stride * height;
849
- dst_v = dst_u + dst_sample_stride * height;
850
- }
851
- r = I420ToI444(y, y_stride, u, u_stride, v, v_stride, dst_sample,
852
- dst_sample_stride, dst_u, dst_sample_stride, dst_v,
853
- dst_sample_stride, width, height);
854
- break;
855
- }
856
- // Formats not supported - MJPG, biplanar, some rgb formats.
857
- default:
858
- return -1; // unknown fourcc - return failure code.
859
- }
860
- return r;
861
- }
862
-
863
- #ifdef __cplusplus
864
- } // extern "C"
865
- } // namespace libyuv
866
- #endif
1
+ /*
2
+ * Copyright 2012 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/convert_from.h"
12
+
13
+ #include "libyuv/basic_types.h"
14
+ #include "libyuv/convert.h" // For I420Copy
15
+ #include "libyuv/cpu_id.h"
16
+ #include "libyuv/planar_functions.h"
17
+ #include "libyuv/rotate.h"
18
+ #include "libyuv/row.h"
19
+ #include "libyuv/scale.h" // For ScalePlane()
20
+ #include "libyuv/video_common.h"
21
+
22
+ #ifdef __cplusplus
23
+ namespace libyuv {
24
+ extern "C" {
25
+ #endif
26
+
27
+ #define SUBSAMPLE(v, a, s) (v < 0) ? (-((-v + a) >> s)) : ((v + a) >> s)
28
+ static __inline int Abs(int v) {
29
+ return v >= 0 ? v : -v;
30
+ }
31
+
32
+ // I420 To any I4xx YUV format with mirroring.
33
+ static int I420ToI4xx(const uint8_t* src_y,
34
+ int src_stride_y,
35
+ const uint8_t* src_u,
36
+ int src_stride_u,
37
+ const uint8_t* src_v,
38
+ int src_stride_v,
39
+ uint8_t* dst_y,
40
+ int dst_stride_y,
41
+ uint8_t* dst_u,
42
+ int dst_stride_u,
43
+ uint8_t* dst_v,
44
+ int dst_stride_v,
45
+ int src_y_width,
46
+ int src_y_height,
47
+ int dst_uv_width,
48
+ int dst_uv_height) {
49
+ const int src_uv_width = SUBSAMPLE(src_y_width, 1, 1);
50
+ const int src_uv_height = SUBSAMPLE(src_y_height, 1, 1);
51
+ int r;
52
+ if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v ||
53
+ src_y_width <= 0 || src_y_height == 0 || dst_uv_width <= 0 ||
54
+ dst_uv_height <= 0) {
55
+ return -1;
56
+ }
57
+ if (dst_y) {
58
+ CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, src_y_width,
59
+ src_y_height);
60
+ }
61
+ r = ScalePlane(src_u, src_stride_u, src_uv_width, src_uv_height, dst_u,
62
+ dst_stride_u, dst_uv_width, dst_uv_height, kFilterBilinear);
63
+ if (r != 0) {
64
+ return r;
65
+ }
66
+ r = ScalePlane(src_v, src_stride_v, src_uv_width, src_uv_height, dst_v,
67
+ dst_stride_v, dst_uv_width, dst_uv_height, kFilterBilinear);
68
+ return r;
69
+ }
70
+
71
+ // Convert 8 bit YUV to 10 bit.
72
+ LIBYUV_API
73
+ int I420ToI010(const uint8_t* src_y,
74
+ int src_stride_y,
75
+ const uint8_t* src_u,
76
+ int src_stride_u,
77
+ const uint8_t* src_v,
78
+ int src_stride_v,
79
+ uint16_t* dst_y,
80
+ int dst_stride_y,
81
+ uint16_t* dst_u,
82
+ int dst_stride_u,
83
+ uint16_t* dst_v,
84
+ int dst_stride_v,
85
+ int width,
86
+ int height) {
87
+ int halfwidth = (width + 1) >> 1;
88
+ int halfheight = (height + 1) >> 1;
89
+ if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 ||
90
+ height == 0) {
91
+ return -1;
92
+ }
93
+ // Negative height means invert the image.
94
+ if (height < 0) {
95
+ height = -height;
96
+ halfheight = (height + 1) >> 1;
97
+ src_y = src_y + (height - 1) * src_stride_y;
98
+ src_u = src_u + (halfheight - 1) * src_stride_u;
99
+ src_v = src_v + (halfheight - 1) * src_stride_v;
100
+ src_stride_y = -src_stride_y;
101
+ src_stride_u = -src_stride_u;
102
+ src_stride_v = -src_stride_v;
103
+ }
104
+
105
+ // Convert Y plane.
106
+ Convert8To16Plane(src_y, src_stride_y, dst_y, dst_stride_y, 1024, width,
107
+ height);
108
+ // Convert UV planes.
109
+ Convert8To16Plane(src_u, src_stride_u, dst_u, dst_stride_u, 1024, halfwidth,
110
+ halfheight);
111
+ Convert8To16Plane(src_v, src_stride_v, dst_v, dst_stride_v, 1024, halfwidth,
112
+ halfheight);
113
+ return 0;
114
+ }
115
+
116
+ // Convert 8 bit YUV to 12 bit.
117
+ LIBYUV_API
118
+ int I420ToI012(const uint8_t* src_y,
119
+ int src_stride_y,
120
+ const uint8_t* src_u,
121
+ int src_stride_u,
122
+ const uint8_t* src_v,
123
+ int src_stride_v,
124
+ uint16_t* dst_y,
125
+ int dst_stride_y,
126
+ uint16_t* dst_u,
127
+ int dst_stride_u,
128
+ uint16_t* dst_v,
129
+ int dst_stride_v,
130
+ int width,
131
+ int height) {
132
+ int halfwidth = (width + 1) >> 1;
133
+ int halfheight = (height + 1) >> 1;
134
+ if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 ||
135
+ height == 0) {
136
+ return -1;
137
+ }
138
+ // Negative height means invert the image.
139
+ if (height < 0) {
140
+ height = -height;
141
+ halfheight = (height + 1) >> 1;
142
+ src_y = src_y + (height - 1) * src_stride_y;
143
+ src_u = src_u + (halfheight - 1) * src_stride_u;
144
+ src_v = src_v + (halfheight - 1) * src_stride_v;
145
+ src_stride_y = -src_stride_y;
146
+ src_stride_u = -src_stride_u;
147
+ src_stride_v = -src_stride_v;
148
+ }
149
+
150
+ // Convert Y plane.
151
+ Convert8To16Plane(src_y, src_stride_y, dst_y, dst_stride_y, 4096, width,
152
+ height);
153
+ // Convert UV planes.
154
+ Convert8To16Plane(src_u, src_stride_u, dst_u, dst_stride_u, 4096, halfwidth,
155
+ halfheight);
156
+ Convert8To16Plane(src_v, src_stride_v, dst_v, dst_stride_v, 4096, halfwidth,
157
+ halfheight);
158
+ return 0;
159
+ }
160
+
161
+ // 420 chroma is 1/2 width, 1/2 height
162
+ // 422 chroma is 1/2 width, 1x height
163
+ LIBYUV_API
164
+ int I420ToI422(const uint8_t* src_y,
165
+ int src_stride_y,
166
+ const uint8_t* src_u,
167
+ int src_stride_u,
168
+ const uint8_t* src_v,
169
+ int src_stride_v,
170
+ uint8_t* dst_y,
171
+ int dst_stride_y,
172
+ uint8_t* dst_u,
173
+ int dst_stride_u,
174
+ uint8_t* dst_v,
175
+ int dst_stride_v,
176
+ int width,
177
+ int height) {
178
+ const int dst_uv_width = (Abs(width) + 1) >> 1;
179
+ const int dst_uv_height = Abs(height);
180
+ return I420ToI4xx(src_y, src_stride_y, src_u, src_stride_u, src_v,
181
+ src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u,
182
+ dst_v, dst_stride_v, width, height, dst_uv_width,
183
+ dst_uv_height);
184
+ }
185
+
186
+ // 420 chroma is 1/2 width, 1/2 height
187
+ // 444 chroma is 1x width, 1x height
188
+ LIBYUV_API
189
+ int I420ToI444(const uint8_t* src_y,
190
+ int src_stride_y,
191
+ const uint8_t* src_u,
192
+ int src_stride_u,
193
+ const uint8_t* src_v,
194
+ int src_stride_v,
195
+ uint8_t* dst_y,
196
+ int dst_stride_y,
197
+ uint8_t* dst_u,
198
+ int dst_stride_u,
199
+ uint8_t* dst_v,
200
+ int dst_stride_v,
201
+ int width,
202
+ int height) {
203
+ const int dst_uv_width = Abs(width);
204
+ const int dst_uv_height = Abs(height);
205
+ return I420ToI4xx(src_y, src_stride_y, src_u, src_stride_u, src_v,
206
+ src_stride_v, dst_y, dst_stride_y, dst_u, dst_stride_u,
207
+ dst_v, dst_stride_v, width, height, dst_uv_width,
208
+ dst_uv_height);
209
+ }
210
+
211
+ // 420 chroma to 444 chroma, 10/12 bit version
212
+ LIBYUV_API
213
+ int I010ToI410(const uint16_t* src_y,
214
+ int src_stride_y,
215
+ const uint16_t* src_u,
216
+ int src_stride_u,
217
+ const uint16_t* src_v,
218
+ int src_stride_v,
219
+ uint16_t* dst_y,
220
+ int dst_stride_y,
221
+ uint16_t* dst_u,
222
+ int dst_stride_u,
223
+ uint16_t* dst_v,
224
+ int dst_stride_v,
225
+ int width,
226
+ int height) {
227
+ int r;
228
+ if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 ||
229
+ height == 0) {
230
+ return -1;
231
+ }
232
+
233
+ if (dst_y) {
234
+ CopyPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
235
+ }
236
+ r = ScalePlane_12(src_u, src_stride_u, SUBSAMPLE(width, 1, 1),
237
+ SUBSAMPLE(height, 1, 1), dst_u, dst_stride_u, width,
238
+ Abs(height), kFilterBilinear);
239
+ if (r != 0) {
240
+ return r;
241
+ }
242
+ r = ScalePlane_12(src_v, src_stride_v, SUBSAMPLE(width, 1, 1),
243
+ SUBSAMPLE(height, 1, 1), dst_v, dst_stride_v, width,
244
+ Abs(height), kFilterBilinear);
245
+ return r;
246
+ }
247
+
248
+ // 422 chroma to 444 chroma, 10/12 bit version
249
+ LIBYUV_API
250
+ int I210ToI410(const uint16_t* src_y,
251
+ int src_stride_y,
252
+ const uint16_t* src_u,
253
+ int src_stride_u,
254
+ const uint16_t* src_v,
255
+ int src_stride_v,
256
+ uint16_t* dst_y,
257
+ int dst_stride_y,
258
+ uint16_t* dst_u,
259
+ int dst_stride_u,
260
+ uint16_t* dst_v,
261
+ int dst_stride_v,
262
+ int width,
263
+ int height) {
264
+ int r;
265
+ if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 ||
266
+ height == 0) {
267
+ return -1;
268
+ }
269
+
270
+ if (dst_y) {
271
+ CopyPlane_16(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
272
+ }
273
+ r = ScalePlane_12(src_u, src_stride_u, SUBSAMPLE(width, 1, 1), height, dst_u,
274
+ dst_stride_u, width, Abs(height), kFilterBilinear);
275
+ if (r != 0) {
276
+ return r;
277
+ }
278
+ r = ScalePlane_12(src_v, src_stride_v, SUBSAMPLE(width, 1, 1), height, dst_v,
279
+ dst_stride_v, width, Abs(height), kFilterBilinear);
280
+ return r;
281
+ }
282
+
283
+ // 422 chroma is 1/2 width, 1x height
284
+ // 444 chroma is 1x width, 1x height
285
+ LIBYUV_API
286
+ int I422ToI444(const uint8_t* src_y,
287
+ int src_stride_y,
288
+ const uint8_t* src_u,
289
+ int src_stride_u,
290
+ const uint8_t* src_v,
291
+ int src_stride_v,
292
+ uint8_t* dst_y,
293
+ int dst_stride_y,
294
+ uint8_t* dst_u,
295
+ int dst_stride_u,
296
+ uint8_t* dst_v,
297
+ int dst_stride_v,
298
+ int width,
299
+ int height) {
300
+ int r;
301
+ if ((!src_y && dst_y) || !src_u || !src_v || !dst_u || !dst_v || width <= 0 ||
302
+ height == 0) {
303
+ return -1;
304
+ }
305
+
306
+ if (dst_y) {
307
+ CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
308
+ }
309
+ r = ScalePlane(src_u, src_stride_u, SUBSAMPLE(width, 1, 1), height, dst_u,
310
+ dst_stride_u, width, Abs(height), kFilterBilinear);
311
+ if (r != 0) {
312
+ return r;
313
+ }
314
+ r = ScalePlane(src_v, src_stride_v, SUBSAMPLE(width, 1, 1), height, dst_v,
315
+ dst_stride_v, width, Abs(height), kFilterBilinear);
316
+ return r;
317
+ }
318
+
319
+ // Copy to I400. Source can be I420,422,444,400,NV12,NV21
320
+ LIBYUV_API
321
+ int I400Copy(const uint8_t* src_y,
322
+ int src_stride_y,
323
+ uint8_t* dst_y,
324
+ int dst_stride_y,
325
+ int width,
326
+ int height) {
327
+ if (!src_y || !dst_y || width <= 0 || height == 0) {
328
+ return -1;
329
+ }
330
+ CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
331
+ return 0;
332
+ }
333
+
334
+ LIBYUV_API
335
+ int I422ToYUY2(const uint8_t* src_y,
336
+ int src_stride_y,
337
+ const uint8_t* src_u,
338
+ int src_stride_u,
339
+ const uint8_t* src_v,
340
+ int src_stride_v,
341
+ uint8_t* dst_yuy2,
342
+ int dst_stride_yuy2,
343
+ int width,
344
+ int height) {
345
+ int y;
346
+ void (*I422ToYUY2Row)(const uint8_t* src_y, const uint8_t* src_u,
347
+ const uint8_t* src_v, uint8_t* dst_yuy2, int width) =
348
+ I422ToYUY2Row_C;
349
+ if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0) {
350
+ return -1;
351
+ }
352
+ // Negative height means invert the image.
353
+ if (height < 0) {
354
+ height = -height;
355
+ dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2;
356
+ dst_stride_yuy2 = -dst_stride_yuy2;
357
+ }
358
+ // Coalesce rows.
359
+ if (src_stride_y == width && src_stride_u * 2 == width &&
360
+ src_stride_v * 2 == width && dst_stride_yuy2 == width * 2) {
361
+ width *= height;
362
+ height = 1;
363
+ src_stride_y = src_stride_u = src_stride_v = dst_stride_yuy2 = 0;
364
+ }
365
+ #if defined(HAS_I422TOYUY2ROW_SSE2)
366
+ if (TestCpuFlag(kCpuHasSSE2)) {
367
+ I422ToYUY2Row = I422ToYUY2Row_Any_SSE2;
368
+ if (IS_ALIGNED(width, 16)) {
369
+ I422ToYUY2Row = I422ToYUY2Row_SSE2;
370
+ }
371
+ }
372
+ #endif
373
+ #if defined(HAS_I422TOYUY2ROW_AVX2)
374
+ if (TestCpuFlag(kCpuHasAVX2)) {
375
+ I422ToYUY2Row = I422ToYUY2Row_Any_AVX2;
376
+ if (IS_ALIGNED(width, 32)) {
377
+ I422ToYUY2Row = I422ToYUY2Row_AVX2;
378
+ }
379
+ }
380
+ #endif
381
+ #if defined(HAS_I422TOYUY2ROW_NEON)
382
+ if (TestCpuFlag(kCpuHasNEON)) {
383
+ I422ToYUY2Row = I422ToYUY2Row_Any_NEON;
384
+ if (IS_ALIGNED(width, 16)) {
385
+ I422ToYUY2Row = I422ToYUY2Row_NEON;
386
+ }
387
+ }
388
+ #endif
389
+
390
+ for (y = 0; y < height; ++y) {
391
+ I422ToYUY2Row(src_y, src_u, src_v, dst_yuy2, width);
392
+ src_y += src_stride_y;
393
+ src_u += src_stride_u;
394
+ src_v += src_stride_v;
395
+ dst_yuy2 += dst_stride_yuy2;
396
+ }
397
+ return 0;
398
+ }
399
+
400
+ LIBYUV_API
401
+ int I420ToYUY2(const uint8_t* src_y,
402
+ int src_stride_y,
403
+ const uint8_t* src_u,
404
+ int src_stride_u,
405
+ const uint8_t* src_v,
406
+ int src_stride_v,
407
+ uint8_t* dst_yuy2,
408
+ int dst_stride_yuy2,
409
+ int width,
410
+ int height) {
411
+ int y;
412
+ void (*I422ToYUY2Row)(const uint8_t* src_y, const uint8_t* src_u,
413
+ const uint8_t* src_v, uint8_t* dst_yuy2, int width) =
414
+ I422ToYUY2Row_C;
415
+ if (!src_y || !src_u || !src_v || !dst_yuy2 || width <= 0 || height == 0) {
416
+ return -1;
417
+ }
418
+ // Negative height means invert the image.
419
+ if (height < 0) {
420
+ height = -height;
421
+ dst_yuy2 = dst_yuy2 + (height - 1) * dst_stride_yuy2;
422
+ dst_stride_yuy2 = -dst_stride_yuy2;
423
+ }
424
+ #if defined(HAS_I422TOYUY2ROW_SSE2)
425
+ if (TestCpuFlag(kCpuHasSSE2)) {
426
+ I422ToYUY2Row = I422ToYUY2Row_Any_SSE2;
427
+ if (IS_ALIGNED(width, 16)) {
428
+ I422ToYUY2Row = I422ToYUY2Row_SSE2;
429
+ }
430
+ }
431
+ #endif
432
+ #if defined(HAS_I422TOYUY2ROW_AVX2)
433
+ if (TestCpuFlag(kCpuHasAVX2)) {
434
+ I422ToYUY2Row = I422ToYUY2Row_Any_AVX2;
435
+ if (IS_ALIGNED(width, 32)) {
436
+ I422ToYUY2Row = I422ToYUY2Row_AVX2;
437
+ }
438
+ }
439
+ #endif
440
+ #if defined(HAS_I422TOYUY2ROW_NEON)
441
+ if (TestCpuFlag(kCpuHasNEON)) {
442
+ I422ToYUY2Row = I422ToYUY2Row_Any_NEON;
443
+ if (IS_ALIGNED(width, 16)) {
444
+ I422ToYUY2Row = I422ToYUY2Row_NEON;
445
+ }
446
+ }
447
+ #endif
448
+ #if defined(HAS_I422TOYUY2ROW_LSX)
449
+ if (TestCpuFlag(kCpuHasLSX)) {
450
+ I422ToYUY2Row = I422ToYUY2Row_Any_LSX;
451
+ if (IS_ALIGNED(width, 16)) {
452
+ I422ToYUY2Row = I422ToYUY2Row_LSX;
453
+ }
454
+ }
455
+ #endif
456
+ #if defined(HAS_I422TOYUY2ROW_LASX)
457
+ if (TestCpuFlag(kCpuHasLASX)) {
458
+ I422ToYUY2Row = I422ToYUY2Row_Any_LASX;
459
+ if (IS_ALIGNED(width, 32)) {
460
+ I422ToYUY2Row = I422ToYUY2Row_LASX;
461
+ }
462
+ }
463
+ #endif
464
+
465
+ for (y = 0; y < height - 1; y += 2) {
466
+ I422ToYUY2Row(src_y, src_u, src_v, dst_yuy2, width);
467
+ I422ToYUY2Row(src_y + src_stride_y, src_u, src_v,
468
+ dst_yuy2 + dst_stride_yuy2, width);
469
+ src_y += src_stride_y * 2;
470
+ src_u += src_stride_u;
471
+ src_v += src_stride_v;
472
+ dst_yuy2 += dst_stride_yuy2 * 2;
473
+ }
474
+ if (height & 1) {
475
+ I422ToYUY2Row(src_y, src_u, src_v, dst_yuy2, width);
476
+ }
477
+ return 0;
478
+ }
479
+
480
+ LIBYUV_API
481
+ int I422ToUYVY(const uint8_t* src_y,
482
+ int src_stride_y,
483
+ const uint8_t* src_u,
484
+ int src_stride_u,
485
+ const uint8_t* src_v,
486
+ int src_stride_v,
487
+ uint8_t* dst_uyvy,
488
+ int dst_stride_uyvy,
489
+ int width,
490
+ int height) {
491
+ int y;
492
+ void (*I422ToUYVYRow)(const uint8_t* src_y, const uint8_t* src_u,
493
+ const uint8_t* src_v, uint8_t* dst_uyvy, int width) =
494
+ I422ToUYVYRow_C;
495
+ if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0) {
496
+ return -1;
497
+ }
498
+ // Negative height means invert the image.
499
+ if (height < 0) {
500
+ height = -height;
501
+ dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy;
502
+ dst_stride_uyvy = -dst_stride_uyvy;
503
+ }
504
+ // Coalesce rows.
505
+ if (src_stride_y == width && src_stride_u * 2 == width &&
506
+ src_stride_v * 2 == width && dst_stride_uyvy == width * 2) {
507
+ width *= height;
508
+ height = 1;
509
+ src_stride_y = src_stride_u = src_stride_v = dst_stride_uyvy = 0;
510
+ }
511
+ #if defined(HAS_I422TOUYVYROW_SSE2)
512
+ if (TestCpuFlag(kCpuHasSSE2)) {
513
+ I422ToUYVYRow = I422ToUYVYRow_Any_SSE2;
514
+ if (IS_ALIGNED(width, 16)) {
515
+ I422ToUYVYRow = I422ToUYVYRow_SSE2;
516
+ }
517
+ }
518
+ #endif
519
+ #if defined(HAS_I422TOUYVYROW_AVX2)
520
+ if (TestCpuFlag(kCpuHasAVX2)) {
521
+ I422ToUYVYRow = I422ToUYVYRow_Any_AVX2;
522
+ if (IS_ALIGNED(width, 32)) {
523
+ I422ToUYVYRow = I422ToUYVYRow_AVX2;
524
+ }
525
+ }
526
+ #endif
527
+ #if defined(HAS_I422TOUYVYROW_NEON)
528
+ if (TestCpuFlag(kCpuHasNEON)) {
529
+ I422ToUYVYRow = I422ToUYVYRow_Any_NEON;
530
+ if (IS_ALIGNED(width, 16)) {
531
+ I422ToUYVYRow = I422ToUYVYRow_NEON;
532
+ }
533
+ }
534
+ #endif
535
+ #if defined(HAS_I422TOUYVYROW_LSX)
536
+ if (TestCpuFlag(kCpuHasLSX)) {
537
+ I422ToUYVYRow = I422ToUYVYRow_Any_LSX;
538
+ if (IS_ALIGNED(width, 16)) {
539
+ I422ToUYVYRow = I422ToUYVYRow_LSX;
540
+ }
541
+ }
542
+ #endif
543
+ #if defined(HAS_I422TOUYVYROW_LASX)
544
+ if (TestCpuFlag(kCpuHasLASX)) {
545
+ I422ToUYVYRow = I422ToUYVYRow_Any_LASX;
546
+ if (IS_ALIGNED(width, 32)) {
547
+ I422ToUYVYRow = I422ToUYVYRow_LASX;
548
+ }
549
+ }
550
+ #endif
551
+
552
+ for (y = 0; y < height; ++y) {
553
+ I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width);
554
+ src_y += src_stride_y;
555
+ src_u += src_stride_u;
556
+ src_v += src_stride_v;
557
+ dst_uyvy += dst_stride_uyvy;
558
+ }
559
+ return 0;
560
+ }
561
+
562
+ LIBYUV_API
563
+ int I420ToUYVY(const uint8_t* src_y,
564
+ int src_stride_y,
565
+ const uint8_t* src_u,
566
+ int src_stride_u,
567
+ const uint8_t* src_v,
568
+ int src_stride_v,
569
+ uint8_t* dst_uyvy,
570
+ int dst_stride_uyvy,
571
+ int width,
572
+ int height) {
573
+ int y;
574
+ void (*I422ToUYVYRow)(const uint8_t* src_y, const uint8_t* src_u,
575
+ const uint8_t* src_v, uint8_t* dst_uyvy, int width) =
576
+ I422ToUYVYRow_C;
577
+ if (!src_y || !src_u || !src_v || !dst_uyvy || width <= 0 || height == 0) {
578
+ return -1;
579
+ }
580
+ // Negative height means invert the image.
581
+ if (height < 0) {
582
+ height = -height;
583
+ dst_uyvy = dst_uyvy + (height - 1) * dst_stride_uyvy;
584
+ dst_stride_uyvy = -dst_stride_uyvy;
585
+ }
586
+ #if defined(HAS_I422TOUYVYROW_SSE2)
587
+ if (TestCpuFlag(kCpuHasSSE2)) {
588
+ I422ToUYVYRow = I422ToUYVYRow_Any_SSE2;
589
+ if (IS_ALIGNED(width, 16)) {
590
+ I422ToUYVYRow = I422ToUYVYRow_SSE2;
591
+ }
592
+ }
593
+ #endif
594
+ #if defined(HAS_I422TOUYVYROW_AVX2)
595
+ if (TestCpuFlag(kCpuHasAVX2)) {
596
+ I422ToUYVYRow = I422ToUYVYRow_Any_AVX2;
597
+ if (IS_ALIGNED(width, 32)) {
598
+ I422ToUYVYRow = I422ToUYVYRow_AVX2;
599
+ }
600
+ }
601
+ #endif
602
+ #if defined(HAS_I422TOUYVYROW_NEON)
603
+ if (TestCpuFlag(kCpuHasNEON)) {
604
+ I422ToUYVYRow = I422ToUYVYRow_Any_NEON;
605
+ if (IS_ALIGNED(width, 16)) {
606
+ I422ToUYVYRow = I422ToUYVYRow_NEON;
607
+ }
608
+ }
609
+ #endif
610
+ #if defined(HAS_I422TOUYVYROW_LSX)
611
+ if (TestCpuFlag(kCpuHasLSX)) {
612
+ I422ToUYVYRow = I422ToUYVYRow_Any_LSX;
613
+ if (IS_ALIGNED(width, 16)) {
614
+ I422ToUYVYRow = I422ToUYVYRow_LSX;
615
+ }
616
+ }
617
+ #endif
618
+ #if defined(HAS_I422TOUYVYROW_LASX)
619
+ if (TestCpuFlag(kCpuHasLASX)) {
620
+ I422ToUYVYRow = I422ToUYVYRow_Any_LASX;
621
+ if (IS_ALIGNED(width, 32)) {
622
+ I422ToUYVYRow = I422ToUYVYRow_LASX;
623
+ }
624
+ }
625
+ #endif
626
+
627
+ for (y = 0; y < height - 1; y += 2) {
628
+ I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width);
629
+ I422ToUYVYRow(src_y + src_stride_y, src_u, src_v,
630
+ dst_uyvy + dst_stride_uyvy, width);
631
+ src_y += src_stride_y * 2;
632
+ src_u += src_stride_u;
633
+ src_v += src_stride_v;
634
+ dst_uyvy += dst_stride_uyvy * 2;
635
+ }
636
+ if (height & 1) {
637
+ I422ToUYVYRow(src_y, src_u, src_v, dst_uyvy, width);
638
+ }
639
+ return 0;
640
+ }
641
+
642
+ LIBYUV_API
643
+ int I420ToNV12(const uint8_t* src_y,
644
+ int src_stride_y,
645
+ const uint8_t* src_u,
646
+ int src_stride_u,
647
+ const uint8_t* src_v,
648
+ int src_stride_v,
649
+ uint8_t* dst_y,
650
+ int dst_stride_y,
651
+ uint8_t* dst_uv,
652
+ int dst_stride_uv,
653
+ int width,
654
+ int height) {
655
+ int halfwidth = (width + 1) / 2;
656
+ int halfheight = (height + 1) / 2;
657
+ if ((!src_y && dst_y) || !src_u || !src_v || !dst_uv || width <= 0 ||
658
+ height == 0) {
659
+ return -1;
660
+ }
661
+ // Negative height means invert the image.
662
+ if (height < 0) {
663
+ height = -height;
664
+ halfheight = (height + 1) >> 1;
665
+ src_y = src_y + (height - 1) * src_stride_y;
666
+ src_u = src_u + (halfheight - 1) * src_stride_u;
667
+ src_v = src_v + (halfheight - 1) * src_stride_v;
668
+ src_stride_y = -src_stride_y;
669
+ src_stride_u = -src_stride_u;
670
+ src_stride_v = -src_stride_v;
671
+ }
672
+ if (dst_y) {
673
+ CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, width, height);
674
+ }
675
+ MergeUVPlane(src_u, src_stride_u, src_v, src_stride_v, dst_uv, dst_stride_uv,
676
+ halfwidth, halfheight);
677
+ return 0;
678
+ }
679
+
680
+ LIBYUV_API
681
+ int I420ToNV21(const uint8_t* src_y,
682
+ int src_stride_y,
683
+ const uint8_t* src_u,
684
+ int src_stride_u,
685
+ const uint8_t* src_v,
686
+ int src_stride_v,
687
+ uint8_t* dst_y,
688
+ int dst_stride_y,
689
+ uint8_t* dst_vu,
690
+ int dst_stride_vu,
691
+ int width,
692
+ int height) {
693
+ return I420ToNV12(src_y, src_stride_y, src_v, src_stride_v, src_u,
694
+ src_stride_u, dst_y, dst_stride_y, dst_vu, dst_stride_vu,
695
+ width, height);
696
+ }
697
+
698
+ // Convert I420 to specified format
699
+ LIBYUV_API
700
+ int ConvertFromI420(const uint8_t* y,
701
+ int y_stride,
702
+ const uint8_t* u,
703
+ int u_stride,
704
+ const uint8_t* v,
705
+ int v_stride,
706
+ uint8_t* dst_sample,
707
+ int dst_sample_stride,
708
+ int width,
709
+ int height,
710
+ uint32_t fourcc) {
711
+ uint32_t format = CanonicalFourCC(fourcc);
712
+ int r = 0;
713
+ if (!y || !u || !v || !dst_sample || width <= 0 || height == 0) {
714
+ return -1;
715
+ }
716
+ switch (format) {
717
+ // Single plane formats
718
+ case FOURCC_YUY2:
719
+ r = I420ToYUY2(y, y_stride, u, u_stride, v, v_stride, dst_sample,
720
+ dst_sample_stride ? dst_sample_stride : width * 2, width,
721
+ height);
722
+ break;
723
+ case FOURCC_UYVY:
724
+ r = I420ToUYVY(y, y_stride, u, u_stride, v, v_stride, dst_sample,
725
+ dst_sample_stride ? dst_sample_stride : width * 2, width,
726
+ height);
727
+ break;
728
+ case FOURCC_RGBP:
729
+ r = I420ToRGB565(y, y_stride, u, u_stride, v, v_stride, dst_sample,
730
+ dst_sample_stride ? dst_sample_stride : width * 2, width,
731
+ height);
732
+ break;
733
+ case FOURCC_RGBO:
734
+ r = I420ToARGB1555(y, y_stride, u, u_stride, v, v_stride, dst_sample,
735
+ dst_sample_stride ? dst_sample_stride : width * 2,
736
+ width, height);
737
+ break;
738
+ case FOURCC_R444:
739
+ r = I420ToARGB4444(y, y_stride, u, u_stride, v, v_stride, dst_sample,
740
+ dst_sample_stride ? dst_sample_stride : width * 2,
741
+ width, height);
742
+ break;
743
+ case FOURCC_24BG:
744
+ r = I420ToRGB24(y, y_stride, u, u_stride, v, v_stride, dst_sample,
745
+ dst_sample_stride ? dst_sample_stride : width * 3, width,
746
+ height);
747
+ break;
748
+ case FOURCC_RAW:
749
+ r = I420ToRAW(y, y_stride, u, u_stride, v, v_stride, dst_sample,
750
+ dst_sample_stride ? dst_sample_stride : width * 3, width,
751
+ height);
752
+ break;
753
+ case FOURCC_ARGB:
754
+ r = I420ToARGB(y, y_stride, u, u_stride, v, v_stride, dst_sample,
755
+ dst_sample_stride ? dst_sample_stride : width * 4, width,
756
+ height);
757
+ break;
758
+ case FOURCC_BGRA:
759
+ r = I420ToBGRA(y, y_stride, u, u_stride, v, v_stride, dst_sample,
760
+ dst_sample_stride ? dst_sample_stride : width * 4, width,
761
+ height);
762
+ break;
763
+ case FOURCC_ABGR:
764
+ r = I420ToABGR(y, y_stride, u, u_stride, v, v_stride, dst_sample,
765
+ dst_sample_stride ? dst_sample_stride : width * 4, width,
766
+ height);
767
+ break;
768
+ case FOURCC_RGBA:
769
+ r = I420ToRGBA(y, y_stride, u, u_stride, v, v_stride, dst_sample,
770
+ dst_sample_stride ? dst_sample_stride : width * 4, width,
771
+ height);
772
+ break;
773
+ case FOURCC_AR30:
774
+ r = I420ToAR30(y, y_stride, u, u_stride, v, v_stride, dst_sample,
775
+ dst_sample_stride ? dst_sample_stride : width * 4, width,
776
+ height);
777
+ break;
778
+ case FOURCC_I400:
779
+ r = I400Copy(y, y_stride, dst_sample,
780
+ dst_sample_stride ? dst_sample_stride : width, width,
781
+ height);
782
+ break;
783
+ case FOURCC_NV12: {
784
+ int dst_y_stride = dst_sample_stride ? dst_sample_stride : width;
785
+ uint8_t* dst_uv = dst_sample + dst_y_stride * height;
786
+ r = I420ToNV12(y, y_stride, u, u_stride, v, v_stride, dst_sample,
787
+ dst_sample_stride ? dst_sample_stride : width, dst_uv,
788
+ dst_sample_stride ? dst_sample_stride : width, width,
789
+ height);
790
+ break;
791
+ }
792
+ case FOURCC_NV21: {
793
+ int dst_y_stride = dst_sample_stride ? dst_sample_stride : width;
794
+ uint8_t* dst_vu = dst_sample + dst_y_stride * height;
795
+ r = I420ToNV21(y, y_stride, u, u_stride, v, v_stride, dst_sample,
796
+ dst_sample_stride ? dst_sample_stride : width, dst_vu,
797
+ dst_sample_stride ? dst_sample_stride : width, width,
798
+ height);
799
+ break;
800
+ }
801
+ // Triplanar formats
802
+ case FOURCC_I420:
803
+ case FOURCC_YV12: {
804
+ dst_sample_stride = dst_sample_stride ? dst_sample_stride : width;
805
+ int halfstride = (dst_sample_stride + 1) / 2;
806
+ int halfheight = (height + 1) / 2;
807
+ uint8_t* dst_u;
808
+ uint8_t* dst_v;
809
+ if (format == FOURCC_YV12) {
810
+ dst_v = dst_sample + dst_sample_stride * height;
811
+ dst_u = dst_v + halfstride * halfheight;
812
+ } else {
813
+ dst_u = dst_sample + dst_sample_stride * height;
814
+ dst_v = dst_u + halfstride * halfheight;
815
+ }
816
+ r = I420Copy(y, y_stride, u, u_stride, v, v_stride, dst_sample,
817
+ dst_sample_stride, dst_u, halfstride, dst_v, halfstride,
818
+ width, height);
819
+ break;
820
+ }
821
+ case FOURCC_I422:
822
+ case FOURCC_YV16: {
823
+ dst_sample_stride = dst_sample_stride ? dst_sample_stride : width;
824
+ int halfstride = (dst_sample_stride + 1) / 2;
825
+ uint8_t* dst_u;
826
+ uint8_t* dst_v;
827
+ if (format == FOURCC_YV16) {
828
+ dst_v = dst_sample + dst_sample_stride * height;
829
+ dst_u = dst_v + halfstride * height;
830
+ } else {
831
+ dst_u = dst_sample + dst_sample_stride * height;
832
+ dst_v = dst_u + halfstride * height;
833
+ }
834
+ r = I420ToI422(y, y_stride, u, u_stride, v, v_stride, dst_sample,
835
+ dst_sample_stride, dst_u, halfstride, dst_v, halfstride,
836
+ width, height);
837
+ break;
838
+ }
839
+ case FOURCC_I444:
840
+ case FOURCC_YV24: {
841
+ dst_sample_stride = dst_sample_stride ? dst_sample_stride : width;
842
+ uint8_t* dst_u;
843
+ uint8_t* dst_v;
844
+ if (format == FOURCC_YV24) {
845
+ dst_v = dst_sample + dst_sample_stride * height;
846
+ dst_u = dst_v + dst_sample_stride * height;
847
+ } else {
848
+ dst_u = dst_sample + dst_sample_stride * height;
849
+ dst_v = dst_u + dst_sample_stride * height;
850
+ }
851
+ r = I420ToI444(y, y_stride, u, u_stride, v, v_stride, dst_sample,
852
+ dst_sample_stride, dst_u, dst_sample_stride, dst_v,
853
+ dst_sample_stride, width, height);
854
+ break;
855
+ }
856
+ // Formats not supported - MJPG, biplanar, some rgb formats.
857
+ default:
858
+ return -1; // unknown fourcc - return failure code.
859
+ }
860
+ return r;
861
+ }
862
+
863
+ #ifdef __cplusplus
864
+ } // extern "C"
865
+ } // namespace libyuv
866
+ #endif