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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/README.md +442 -442
  2. package/android/.gradle/9.2.0/checksums/checksums.lock +0 -0
  3. package/android/.gradle/9.2.0/fileHashes/fileHashes.bin +0 -0
  4. package/android/.gradle/9.2.0/fileHashes/fileHashes.lock +0 -0
  5. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  6. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  7. package/android/build/reports/problems/problems-report.html +659 -0
  8. package/android/build.gradle +12 -4
  9. package/android/src/main/cpp/CMakeLists.txt +101 -94
  10. package/android/src/main/cpp/libyuv/.clang-format +6 -6
  11. package/android/src/main/cpp/libyuv/.gn +40 -40
  12. package/android/src/main/cpp/libyuv/.vpython3 +410 -410
  13. package/android/src/main/cpp/libyuv/AUTHORS +7 -7
  14. package/android/src/main/cpp/libyuv/Android.bp +202 -202
  15. package/android/src/main/cpp/libyuv/Android.mk +106 -106
  16. package/android/src/main/cpp/libyuv/BUILD.gn +490 -490
  17. package/android/src/main/cpp/libyuv/CM_linux_packages.cmake +70 -70
  18. package/android/src/main/cpp/libyuv/CMakeLists.txt +259 -252
  19. package/android/src/main/cpp/libyuv/DEPS +935 -935
  20. package/android/src/main/cpp/libyuv/DIR_METADATA +3 -3
  21. package/android/src/main/cpp/libyuv/LICENSE +29 -29
  22. package/android/src/main/cpp/libyuv/OWNERS +11 -11
  23. package/android/src/main/cpp/libyuv/PATENTS +23 -23
  24. package/android/src/main/cpp/libyuv/PRESUBMIT.py +65 -65
  25. package/android/src/main/cpp/libyuv/README.chromium +11 -11
  26. package/android/src/main/cpp/libyuv/README.md +19 -19
  27. package/android/src/main/cpp/libyuv/build_overrides/build.gni +60 -60
  28. package/android/src/main/cpp/libyuv/build_overrides/gtest.gni +19 -19
  29. package/android/src/main/cpp/libyuv/build_overrides/partition_alloc.gni +17 -17
  30. package/android/src/main/cpp/libyuv/codereview.settings +5 -5
  31. package/android/src/main/cpp/libyuv/docs/deprecated_builds.md +409 -409
  32. package/android/src/main/cpp/libyuv/docs/environment_variables.md +64 -64
  33. package/android/src/main/cpp/libyuv/docs/feature_detection.md +108 -108
  34. package/android/src/main/cpp/libyuv/docs/filtering.md +196 -196
  35. package/android/src/main/cpp/libyuv/docs/formats.md +208 -208
  36. package/android/src/main/cpp/libyuv/docs/getting_started.md +296 -296
  37. package/android/src/main/cpp/libyuv/docs/rotation.md +107 -107
  38. package/android/src/main/cpp/libyuv/download_vs_toolchain.py +29 -29
  39. package/android/src/main/cpp/libyuv/include/libyuv/basic_types.h +68 -68
  40. package/android/src/main/cpp/libyuv/include/libyuv/compare.h +111 -111
  41. package/android/src/main/cpp/libyuv/include/libyuv/compare_row.h +112 -112
  42. package/android/src/main/cpp/libyuv/include/libyuv/convert.h +1117 -1117
  43. package/android/src/main/cpp/libyuv/include/libyuv/convert_argb.h +2335 -2335
  44. package/android/src/main/cpp/libyuv/include/libyuv/convert_from.h +203 -203
  45. package/android/src/main/cpp/libyuv/include/libyuv/convert_from_argb.h +394 -394
  46. package/android/src/main/cpp/libyuv/include/libyuv/cpu_id.h +147 -147
  47. package/android/src/main/cpp/libyuv/include/libyuv/cpu_support.h +99 -99
  48. package/android/src/main/cpp/libyuv/include/libyuv/loongson_intrinsics.h +1949 -1949
  49. package/android/src/main/cpp/libyuv/include/libyuv/mjpeg_decoder.h +195 -195
  50. package/android/src/main/cpp/libyuv/include/libyuv/planar_functions.h +1131 -1131
  51. package/android/src/main/cpp/libyuv/include/libyuv/rotate.h +296 -296
  52. package/android/src/main/cpp/libyuv/include/libyuv/rotate_argb.h +37 -37
  53. package/android/src/main/cpp/libyuv/include/libyuv/rotate_row.h +265 -265
  54. package/android/src/main/cpp/libyuv/include/libyuv/row.h +6738 -6738
  55. package/android/src/main/cpp/libyuv/include/libyuv/row_sve.h +2154 -2154
  56. package/android/src/main/cpp/libyuv/include/libyuv/scale.h +336 -336
  57. package/android/src/main/cpp/libyuv/include/libyuv/scale_argb.h +76 -76
  58. package/android/src/main/cpp/libyuv/include/libyuv/scale_rgb.h +42 -42
  59. package/android/src/main/cpp/libyuv/include/libyuv/scale_row.h +1726 -1726
  60. package/android/src/main/cpp/libyuv/include/libyuv/scale_uv.h +51 -51
  61. package/android/src/main/cpp/libyuv/include/libyuv/version.h +16 -16
  62. package/android/src/main/cpp/libyuv/include/libyuv/video_common.h +222 -222
  63. package/android/src/main/cpp/libyuv/include/libyuv.h +33 -33
  64. package/android/src/main/cpp/libyuv/infra/config/OWNERS +3 -3
  65. package/android/src/main/cpp/libyuv/infra/config/PRESUBMIT.py +17 -17
  66. package/android/src/main/cpp/libyuv/infra/config/README.md +2 -2
  67. package/android/src/main/cpp/libyuv/infra/config/codereview.settings +6 -6
  68. package/android/src/main/cpp/libyuv/infra/config/commit-queue.cfg +144 -144
  69. package/android/src/main/cpp/libyuv/infra/config/cr-buildbucket.cfg +1185 -1185
  70. package/android/src/main/cpp/libyuv/infra/config/luci-logdog.cfg +9 -9
  71. package/android/src/main/cpp/libyuv/infra/config/luci-milo.cfg +246 -246
  72. package/android/src/main/cpp/libyuv/infra/config/luci-scheduler.cfg +385 -385
  73. package/android/src/main/cpp/libyuv/infra/config/main.star +402 -402
  74. package/android/src/main/cpp/libyuv/infra/config/project.cfg +16 -16
  75. package/android/src/main/cpp/libyuv/infra/config/realms.cfg +111 -111
  76. package/android/src/main/cpp/libyuv/libyuv.gni +34 -34
  77. package/android/src/main/cpp/libyuv/libyuv.gyp +149 -149
  78. package/android/src/main/cpp/libyuv/libyuv.gypi +87 -87
  79. package/android/src/main/cpp/libyuv/linux.mk +96 -96
  80. package/android/src/main/cpp/libyuv/public.mk +13 -13
  81. package/android/src/main/cpp/libyuv/pylintrc +49 -49
  82. package/android/src/main/cpp/libyuv/riscv_script/prepare_toolchain_qemu.sh +74 -74
  83. package/android/src/main/cpp/libyuv/riscv_script/riscv-clang.cmake +56 -56
  84. package/android/src/main/cpp/libyuv/riscv_script/run_qemu.sh +15 -15
  85. package/android/src/main/cpp/libyuv/source/compare.cc +435 -435
  86. package/android/src/main/cpp/libyuv/source/compare_common.cc +74 -74
  87. package/android/src/main/cpp/libyuv/source/compare_gcc.cc +362 -362
  88. package/android/src/main/cpp/libyuv/source/compare_neon.cc +96 -96
  89. package/android/src/main/cpp/libyuv/source/compare_neon64.cc +223 -223
  90. package/android/src/main/cpp/libyuv/source/compare_win.cc +241 -241
  91. package/android/src/main/cpp/libyuv/source/convert.cc +4746 -4746
  92. package/android/src/main/cpp/libyuv/source/convert_argb.cc +9179 -9179
  93. package/android/src/main/cpp/libyuv/source/convert_from.cc +866 -866
  94. package/android/src/main/cpp/libyuv/source/convert_from_argb.cc +3671 -3671
  95. package/android/src/main/cpp/libyuv/source/convert_jpeg.cc +602 -602
  96. package/android/src/main/cpp/libyuv/source/convert_to_argb.cc +391 -391
  97. package/android/src/main/cpp/libyuv/source/convert_to_i420.cc +288 -288
  98. package/android/src/main/cpp/libyuv/source/cpu_id.cc +496 -496
  99. package/android/src/main/cpp/libyuv/source/mjpeg_decoder.cc +580 -580
  100. package/android/src/main/cpp/libyuv/source/mjpeg_validate.cc +71 -71
  101. package/android/src/main/cpp/libyuv/source/planar_functions.cc +5663 -5663
  102. package/android/src/main/cpp/libyuv/source/rotate.cc +1241 -1241
  103. package/android/src/main/cpp/libyuv/source/rotate_any.cc +76 -76
  104. package/android/src/main/cpp/libyuv/source/rotate_argb.cc +259 -259
  105. package/android/src/main/cpp/libyuv/source/rotate_common.cc +208 -208
  106. package/android/src/main/cpp/libyuv/source/rotate_gcc.cc +505 -505
  107. package/android/src/main/cpp/libyuv/source/rotate_lsx.cc +233 -233
  108. package/android/src/main/cpp/libyuv/source/rotate_neon.cc +219 -219
  109. package/android/src/main/cpp/libyuv/source/rotate_neon64.cc +273 -273
  110. package/android/src/main/cpp/libyuv/source/rotate_sme.cc +174 -174
  111. package/android/src/main/cpp/libyuv/source/rotate_win.cc +253 -253
  112. package/android/src/main/cpp/libyuv/source/row_any.cc +2519 -2519
  113. package/android/src/main/cpp/libyuv/source/row_common.cc +4461 -4461
  114. package/android/src/main/cpp/libyuv/source/row_gcc.cc +9570 -9570
  115. package/android/src/main/cpp/libyuv/source/row_lasx.cc +2343 -2343
  116. package/android/src/main/cpp/libyuv/source/row_lsx.cc +3030 -3030
  117. package/android/src/main/cpp/libyuv/source/row_neon.cc +4026 -4026
  118. package/android/src/main/cpp/libyuv/source/row_neon64.cc +5617 -5617
  119. package/android/src/main/cpp/libyuv/source/row_rvv.cc +2599 -2599
  120. package/android/src/main/cpp/libyuv/source/row_sme.cc +1183 -1183
  121. package/android/src/main/cpp/libyuv/source/row_sve.cc +1088 -1088
  122. package/android/src/main/cpp/libyuv/source/row_win.cc +6453 -6453
  123. package/android/src/main/cpp/libyuv/source/scale.cc +2710 -2710
  124. package/android/src/main/cpp/libyuv/source/scale_any.cc +991 -991
  125. package/android/src/main/cpp/libyuv/source/scale_argb.cc +1158 -1158
  126. package/android/src/main/cpp/libyuv/source/scale_common.cc +1977 -1977
  127. package/android/src/main/cpp/libyuv/source/scale_gcc.cc +2947 -2947
  128. package/android/src/main/cpp/libyuv/source/scale_lsx.cc +739 -739
  129. package/android/src/main/cpp/libyuv/source/scale_neon.cc +1449 -1449
  130. package/android/src/main/cpp/libyuv/source/scale_neon64.cc +1552 -1552
  131. package/android/src/main/cpp/libyuv/source/scale_rgb.cc +82 -82
  132. package/android/src/main/cpp/libyuv/source/scale_rvv.cc +1971 -1971
  133. package/android/src/main/cpp/libyuv/source/scale_sme.cc +555 -555
  134. package/android/src/main/cpp/libyuv/source/scale_uv.cc +1159 -1159
  135. package/android/src/main/cpp/libyuv/source/scale_win.cc +1392 -1392
  136. package/android/src/main/cpp/libyuv/source/test.sh +35 -35
  137. package/android/src/main/cpp/libyuv/source/video_common.cc +62 -62
  138. package/android/src/main/cpp/libyuv/tools_libyuv/OWNERS +4 -4
  139. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/roll_deps.py +931 -931
  140. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py +164 -164
  141. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS +21 -21
  142. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.new +13 -13
  143. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old +13 -13
  144. package/android/src/main/cpp/libyuv/tools_libyuv/get_landmines.py +38 -38
  145. package/android/src/main/cpp/libyuv/tools_libyuv/msan/OWNERS +3 -3
  146. package/android/src/main/cpp/libyuv/tools_libyuv/msan/blacklist.txt +9 -9
  147. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/OWNERS +3 -3
  148. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/blacklist.txt +15 -15
  149. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/vptr_blacklist.txt +25 -25
  150. package/android/src/main/cpp/libyuv/unit_test/basictypes_test.cc +43 -43
  151. package/android/src/main/cpp/libyuv/unit_test/color_test.cc +848 -848
  152. package/android/src/main/cpp/libyuv/unit_test/compare_test.cc +739 -739
  153. package/android/src/main/cpp/libyuv/unit_test/convert_argb_test.cc +2867 -2867
  154. package/android/src/main/cpp/libyuv/unit_test/convert_test.cc +2133 -2133
  155. package/android/src/main/cpp/libyuv/unit_test/cpu_test.cc +427 -427
  156. package/android/src/main/cpp/libyuv/unit_test/cpu_thread_test.cc +63 -63
  157. package/android/src/main/cpp/libyuv/unit_test/math_test.cc +160 -160
  158. package/android/src/main/cpp/libyuv/unit_test/planar_test.cc +4731 -4731
  159. package/android/src/main/cpp/libyuv/unit_test/rotate_argb_test.cc +334 -334
  160. package/android/src/main/cpp/libyuv/unit_test/rotate_test.cc +962 -962
  161. package/android/src/main/cpp/libyuv/unit_test/scale_argb_test.cc +590 -590
  162. package/android/src/main/cpp/libyuv/unit_test/scale_plane_test.cc +465 -465
  163. package/android/src/main/cpp/libyuv/unit_test/scale_rgb_test.cc +280 -280
  164. package/android/src/main/cpp/libyuv/unit_test/scale_test.cc +1135 -1135
  165. package/android/src/main/cpp/libyuv/unit_test/scale_uv_test.cc +249 -249
  166. package/android/src/main/cpp/libyuv/unit_test/testdata/arm_v7.txt +12 -12
  167. package/android/src/main/cpp/libyuv/unit_test/testdata/mips.txt +7 -7
  168. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson2k.txt +5 -5
  169. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson3.txt +10 -10
  170. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson_mmi.txt +7 -7
  171. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64.txt +3 -3
  172. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv.txt +3 -3
  173. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv_zvfh.txt +3 -3
  174. package/android/src/main/cpp/libyuv/unit_test/testdata/tegra3.txt +23 -23
  175. package/android/src/main/cpp/libyuv/unit_test/unit_test.cc +581 -581
  176. package/android/src/main/cpp/libyuv/unit_test/unit_test.h +232 -232
  177. package/android/src/main/cpp/libyuv/unit_test/video_common_test.cc +112 -112
  178. package/android/src/main/cpp/libyuv/util/Makefile +9 -9
  179. package/android/src/main/cpp/libyuv/util/color.cc +120 -120
  180. package/android/src/main/cpp/libyuv/util/compare.cc +67 -67
  181. package/android/src/main/cpp/libyuv/util/cpuid.c +211 -211
  182. package/android/src/main/cpp/libyuv/util/i444tonv12_eg.cc +27 -27
  183. package/android/src/main/cpp/libyuv/util/psnr.cc +291 -291
  184. package/android/src/main/cpp/libyuv/util/psnr.h +47 -47
  185. package/android/src/main/cpp/libyuv/util/psnr_main.cc +620 -620
  186. package/android/src/main/cpp/libyuv/util/ssim.cc +364 -364
  187. package/android/src/main/cpp/libyuv/util/ssim.h +38 -38
  188. package/android/src/main/cpp/libyuv/util/yuvconstants.c +114 -114
  189. package/android/src/main/cpp/libyuv/util/yuvconvert.cc +367 -367
  190. package/android/src/main/cpp/libyuv/winarm.mk +47 -47
  191. package/index.js +17 -1
  192. package/ios/FaceAntiSpoofFrameProcessor.swift +283 -0
  193. package/ios/FaceAntiSpoofJSI.h +12 -0
  194. package/ios/FaceAntiSpoofJSI.mm +92 -0
  195. package/ios/FaceAntiSpoofManager.swift +63 -0
  196. package/ios/FaceAntiSpoofModule.m +191 -0
  197. package/ios/FaceAntiSpoofPluginRegister.m +42 -0
  198. package/ios/models/FaceAntiSpoofing.tflite +0 -0
  199. package/ios/models/model_spec.json +16 -0
  200. package/package.json +87 -86
  201. package/.gitignore +0 -27
  202. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  203. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  204. package/android/.gradle/8.9/gc.properties +0 -0
  205. /package/android/.gradle/{8.9 → 9.2.0}/fileChanges/last-build.bin +0 -0
  206. /package/android/.gradle/{8.9/dependencies-accessors → 9.2.0}/gc.properties +0 -0
@@ -1,1977 +1,1977 @@
1
- /*
2
- * Copyright 2013 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 <string.h>
15
-
16
- #include "libyuv/cpu_id.h"
17
- #include "libyuv/planar_functions.h" // For CopyARGB
18
- #include "libyuv/row.h"
19
- #include "libyuv/scale_row.h"
20
-
21
- #ifdef __cplusplus
22
- namespace libyuv {
23
- extern "C" {
24
- #endif
25
-
26
- #ifdef __cplusplus
27
- #define STATIC_CAST(type, expr) static_cast<type>(expr)
28
- #else
29
- #define STATIC_CAST(type, expr) (type)(expr)
30
- #endif
31
-
32
- // TODO(fbarchard): make clamp255 preserve negative values.
33
- static __inline int32_t clamp255(int32_t v) {
34
- return (-(v >= 255) | v) & 255;
35
- }
36
-
37
- // Use scale to convert lsb formats to msb, depending how many bits there are:
38
- // 32768 = 9 bits
39
- // 16384 = 10 bits
40
- // 4096 = 12 bits
41
- // 256 = 16 bits
42
- // TODO(fbarchard): change scale to bits
43
- #define C16TO8(v, scale) clamp255(((v) * (scale)) >> 16)
44
-
45
- static __inline int Abs(int v) {
46
- return v >= 0 ? v : -v;
47
- }
48
-
49
- // CPU agnostic row functions
50
- void ScaleRowDown2_C(const uint8_t* src_ptr,
51
- ptrdiff_t src_stride,
52
- uint8_t* dst,
53
- int dst_width) {
54
- int x;
55
- (void)src_stride;
56
- for (x = 0; x < dst_width - 1; x += 2) {
57
- dst[0] = src_ptr[1];
58
- dst[1] = src_ptr[3];
59
- dst += 2;
60
- src_ptr += 4;
61
- }
62
- if (dst_width & 1) {
63
- dst[0] = src_ptr[1];
64
- }
65
- }
66
-
67
- void ScaleRowDown2_16_C(const uint16_t* src_ptr,
68
- ptrdiff_t src_stride,
69
- uint16_t* dst,
70
- int dst_width) {
71
- int x;
72
- (void)src_stride;
73
- for (x = 0; x < dst_width - 1; x += 2) {
74
- dst[0] = src_ptr[1];
75
- dst[1] = src_ptr[3];
76
- dst += 2;
77
- src_ptr += 4;
78
- }
79
- if (dst_width & 1) {
80
- dst[0] = src_ptr[1];
81
- }
82
- }
83
-
84
- void ScaleRowDown2_16To8_C(const uint16_t* src_ptr,
85
- ptrdiff_t src_stride,
86
- uint8_t* dst,
87
- int dst_width,
88
- int scale) {
89
- int x;
90
- (void)src_stride;
91
- assert(scale >= 256);
92
- assert(scale <= 32768);
93
- for (x = 0; x < dst_width - 1; x += 2) {
94
- dst[0] = STATIC_CAST(uint8_t, C16TO8(src_ptr[1], scale));
95
- dst[1] = STATIC_CAST(uint8_t, C16TO8(src_ptr[3], scale));
96
- dst += 2;
97
- src_ptr += 4;
98
- }
99
- if (dst_width & 1) {
100
- dst[0] = STATIC_CAST(uint8_t, C16TO8(src_ptr[1], scale));
101
- }
102
- }
103
-
104
- void ScaleRowDown2_16To8_Odd_C(const uint16_t* src_ptr,
105
- ptrdiff_t src_stride,
106
- uint8_t* dst,
107
- int dst_width,
108
- int scale) {
109
- int x;
110
- (void)src_stride;
111
- assert(scale >= 256);
112
- assert(scale <= 32768);
113
- dst_width -= 1;
114
- for (x = 0; x < dst_width - 1; x += 2) {
115
- dst[0] = STATIC_CAST(uint8_t, C16TO8(src_ptr[1], scale));
116
- dst[1] = STATIC_CAST(uint8_t, C16TO8(src_ptr[3], scale));
117
- dst += 2;
118
- src_ptr += 4;
119
- }
120
- if (dst_width & 1) {
121
- dst[0] = STATIC_CAST(uint8_t, C16TO8(src_ptr[1], scale));
122
- dst += 1;
123
- src_ptr += 2;
124
- }
125
- dst[0] = STATIC_CAST(uint8_t, C16TO8(src_ptr[0], scale));
126
- }
127
-
128
- void ScaleRowDown2Linear_C(const uint8_t* src_ptr,
129
- ptrdiff_t src_stride,
130
- uint8_t* dst,
131
- int dst_width) {
132
- const uint8_t* s = src_ptr;
133
- int x;
134
- (void)src_stride;
135
- for (x = 0; x < dst_width - 1; x += 2) {
136
- dst[0] = (s[0] + s[1] + 1) >> 1;
137
- dst[1] = (s[2] + s[3] + 1) >> 1;
138
- dst += 2;
139
- s += 4;
140
- }
141
- if (dst_width & 1) {
142
- dst[0] = (s[0] + s[1] + 1) >> 1;
143
- }
144
- }
145
-
146
- void ScaleRowDown2Linear_16_C(const uint16_t* src_ptr,
147
- ptrdiff_t src_stride,
148
- uint16_t* dst,
149
- int dst_width) {
150
- const uint16_t* s = src_ptr;
151
- int x;
152
- (void)src_stride;
153
- for (x = 0; x < dst_width - 1; x += 2) {
154
- dst[0] = (s[0] + s[1] + 1) >> 1;
155
- dst[1] = (s[2] + s[3] + 1) >> 1;
156
- dst += 2;
157
- s += 4;
158
- }
159
- if (dst_width & 1) {
160
- dst[0] = (s[0] + s[1] + 1) >> 1;
161
- }
162
- }
163
-
164
- void ScaleRowDown2Linear_16To8_C(const uint16_t* src_ptr,
165
- ptrdiff_t src_stride,
166
- uint8_t* dst,
167
- int dst_width,
168
- int scale) {
169
- const uint16_t* s = src_ptr;
170
- int x;
171
- (void)src_stride;
172
- assert(scale >= 256);
173
- assert(scale <= 32768);
174
- for (x = 0; x < dst_width - 1; x += 2) {
175
- dst[0] = STATIC_CAST(uint8_t, C16TO8((s[0] + s[1] + 1) >> 1, scale));
176
- dst[1] = STATIC_CAST(uint8_t, C16TO8((s[2] + s[3] + 1) >> 1, scale));
177
- dst += 2;
178
- s += 4;
179
- }
180
- if (dst_width & 1) {
181
- dst[0] = STATIC_CAST(uint8_t, C16TO8((s[0] + s[1] + 1) >> 1, scale));
182
- }
183
- }
184
-
185
- void ScaleRowDown2Linear_16To8_Odd_C(const uint16_t* src_ptr,
186
- ptrdiff_t src_stride,
187
- uint8_t* dst,
188
- int dst_width,
189
- int scale) {
190
- const uint16_t* s = src_ptr;
191
- int x;
192
- (void)src_stride;
193
- assert(scale >= 256);
194
- assert(scale <= 32768);
195
- dst_width -= 1;
196
- for (x = 0; x < dst_width - 1; x += 2) {
197
- dst[0] = STATIC_CAST(uint8_t, C16TO8((s[0] + s[1] + 1) >> 1, scale));
198
- dst[1] = STATIC_CAST(uint8_t, C16TO8((s[2] + s[3] + 1) >> 1, scale));
199
- dst += 2;
200
- s += 4;
201
- }
202
- if (dst_width & 1) {
203
- dst[0] = STATIC_CAST(uint8_t, C16TO8((s[0] + s[1] + 1) >> 1, scale));
204
- dst += 1;
205
- s += 2;
206
- }
207
- dst[0] = STATIC_CAST(uint8_t, C16TO8(s[0], scale));
208
- }
209
-
210
- void ScaleRowDown2Box_C(const uint8_t* src_ptr,
211
- ptrdiff_t src_stride,
212
- uint8_t* dst,
213
- int dst_width) {
214
- const uint8_t* s = src_ptr;
215
- const uint8_t* t = src_ptr + src_stride;
216
- int x;
217
- for (x = 0; x < dst_width - 1; x += 2) {
218
- dst[0] = (s[0] + s[1] + t[0] + t[1] + 2) >> 2;
219
- dst[1] = (s[2] + s[3] + t[2] + t[3] + 2) >> 2;
220
- dst += 2;
221
- s += 4;
222
- t += 4;
223
- }
224
- if (dst_width & 1) {
225
- dst[0] = (s[0] + s[1] + t[0] + t[1] + 2) >> 2;
226
- }
227
- }
228
-
229
- void ScaleRowDown2Box_Odd_C(const uint8_t* src_ptr,
230
- ptrdiff_t src_stride,
231
- uint8_t* dst,
232
- int dst_width) {
233
- const uint8_t* s = src_ptr;
234
- const uint8_t* t = src_ptr + src_stride;
235
- int x;
236
- dst_width -= 1;
237
- for (x = 0; x < dst_width - 1; x += 2) {
238
- dst[0] = (s[0] + s[1] + t[0] + t[1] + 2) >> 2;
239
- dst[1] = (s[2] + s[3] + t[2] + t[3] + 2) >> 2;
240
- dst += 2;
241
- s += 4;
242
- t += 4;
243
- }
244
- if (dst_width & 1) {
245
- dst[0] = (s[0] + s[1] + t[0] + t[1] + 2) >> 2;
246
- dst += 1;
247
- s += 2;
248
- t += 2;
249
- }
250
- dst[0] = (s[0] + t[0] + 1) >> 1;
251
- }
252
-
253
- void ScaleRowDown2Box_16_C(const uint16_t* src_ptr,
254
- ptrdiff_t src_stride,
255
- uint16_t* dst,
256
- int dst_width) {
257
- const uint16_t* s = src_ptr;
258
- const uint16_t* t = src_ptr + src_stride;
259
- int x;
260
- for (x = 0; x < dst_width - 1; x += 2) {
261
- dst[0] = (s[0] + s[1] + t[0] + t[1] + 2) >> 2;
262
- dst[1] = (s[2] + s[3] + t[2] + t[3] + 2) >> 2;
263
- dst += 2;
264
- s += 4;
265
- t += 4;
266
- }
267
- if (dst_width & 1) {
268
- dst[0] = (s[0] + s[1] + t[0] + t[1] + 2) >> 2;
269
- }
270
- }
271
-
272
- void ScaleRowDown2Box_16To8_C(const uint16_t* src_ptr,
273
- ptrdiff_t src_stride,
274
- uint8_t* dst,
275
- int dst_width,
276
- int scale) {
277
- const uint16_t* s = src_ptr;
278
- const uint16_t* t = src_ptr + src_stride;
279
- int x;
280
- assert(scale >= 256);
281
- assert(scale <= 32768);
282
- for (x = 0; x < dst_width - 1; x += 2) {
283
- dst[0] = STATIC_CAST(uint8_t,
284
- C16TO8((s[0] + s[1] + t[0] + t[1] + 2) >> 2, scale));
285
- dst[1] = STATIC_CAST(uint8_t,
286
- C16TO8((s[2] + s[3] + t[2] + t[3] + 2) >> 2, scale));
287
- dst += 2;
288
- s += 4;
289
- t += 4;
290
- }
291
- if (dst_width & 1) {
292
- dst[0] = STATIC_CAST(uint8_t,
293
- C16TO8((s[0] + s[1] + t[0] + t[1] + 2) >> 2, scale));
294
- }
295
- }
296
-
297
- void ScaleRowDown2Box_16To8_Odd_C(const uint16_t* src_ptr,
298
- ptrdiff_t src_stride,
299
- uint8_t* dst,
300
- int dst_width,
301
- int scale) {
302
- const uint16_t* s = src_ptr;
303
- const uint16_t* t = src_ptr + src_stride;
304
- int x;
305
- assert(scale >= 256);
306
- assert(scale <= 32768);
307
- dst_width -= 1;
308
- for (x = 0; x < dst_width - 1; x += 2) {
309
- dst[0] = STATIC_CAST(uint8_t,
310
- C16TO8((s[0] + s[1] + t[0] + t[1] + 2) >> 2, scale));
311
- dst[1] = STATIC_CAST(uint8_t,
312
- C16TO8((s[2] + s[3] + t[2] + t[3] + 2) >> 2, scale));
313
- dst += 2;
314
- s += 4;
315
- t += 4;
316
- }
317
- if (dst_width & 1) {
318
- dst[0] = STATIC_CAST(uint8_t,
319
- C16TO8((s[0] + s[1] + t[0] + t[1] + 2) >> 2, scale));
320
- dst += 1;
321
- s += 2;
322
- t += 2;
323
- }
324
- dst[0] = STATIC_CAST(uint8_t, C16TO8((s[0] + t[0] + 1) >> 1, scale));
325
- }
326
-
327
- void ScaleRowDown4_C(const uint8_t* src_ptr,
328
- ptrdiff_t src_stride,
329
- uint8_t* dst,
330
- int dst_width) {
331
- int x;
332
- (void)src_stride;
333
- for (x = 0; x < dst_width - 1; x += 2) {
334
- dst[0] = src_ptr[2];
335
- dst[1] = src_ptr[6];
336
- dst += 2;
337
- src_ptr += 8;
338
- }
339
- if (dst_width & 1) {
340
- dst[0] = src_ptr[2];
341
- }
342
- }
343
-
344
- void ScaleRowDown4_16_C(const uint16_t* src_ptr,
345
- ptrdiff_t src_stride,
346
- uint16_t* dst,
347
- int dst_width) {
348
- int x;
349
- (void)src_stride;
350
- for (x = 0; x < dst_width - 1; x += 2) {
351
- dst[0] = src_ptr[2];
352
- dst[1] = src_ptr[6];
353
- dst += 2;
354
- src_ptr += 8;
355
- }
356
- if (dst_width & 1) {
357
- dst[0] = src_ptr[2];
358
- }
359
- }
360
-
361
- void ScaleRowDown4Box_C(const uint8_t* src_ptr,
362
- ptrdiff_t src_stride,
363
- uint8_t* dst,
364
- int dst_width) {
365
- intptr_t stride = src_stride;
366
- int x;
367
- for (x = 0; x < dst_width - 1; x += 2) {
368
- dst[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[3] +
369
- src_ptr[stride + 0] + src_ptr[stride + 1] + src_ptr[stride + 2] +
370
- src_ptr[stride + 3] + src_ptr[stride * 2 + 0] +
371
- src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2] +
372
- src_ptr[stride * 2 + 3] + src_ptr[stride * 3 + 0] +
373
- src_ptr[stride * 3 + 1] + src_ptr[stride * 3 + 2] +
374
- src_ptr[stride * 3 + 3] + 8) >>
375
- 4;
376
- dst[1] = (src_ptr[4] + src_ptr[5] + src_ptr[6] + src_ptr[7] +
377
- src_ptr[stride + 4] + src_ptr[stride + 5] + src_ptr[stride + 6] +
378
- src_ptr[stride + 7] + src_ptr[stride * 2 + 4] +
379
- src_ptr[stride * 2 + 5] + src_ptr[stride * 2 + 6] +
380
- src_ptr[stride * 2 + 7] + src_ptr[stride * 3 + 4] +
381
- src_ptr[stride * 3 + 5] + src_ptr[stride * 3 + 6] +
382
- src_ptr[stride * 3 + 7] + 8) >>
383
- 4;
384
- dst += 2;
385
- src_ptr += 8;
386
- }
387
- if (dst_width & 1) {
388
- dst[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[3] +
389
- src_ptr[stride + 0] + src_ptr[stride + 1] + src_ptr[stride + 2] +
390
- src_ptr[stride + 3] + src_ptr[stride * 2 + 0] +
391
- src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2] +
392
- src_ptr[stride * 2 + 3] + src_ptr[stride * 3 + 0] +
393
- src_ptr[stride * 3 + 1] + src_ptr[stride * 3 + 2] +
394
- src_ptr[stride * 3 + 3] + 8) >>
395
- 4;
396
- }
397
- }
398
-
399
- void ScaleRowDown4Box_16_C(const uint16_t* src_ptr,
400
- ptrdiff_t src_stride,
401
- uint16_t* dst,
402
- int dst_width) {
403
- intptr_t stride = src_stride;
404
- int x;
405
- for (x = 0; x < dst_width - 1; x += 2) {
406
- dst[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[3] +
407
- src_ptr[stride + 0] + src_ptr[stride + 1] + src_ptr[stride + 2] +
408
- src_ptr[stride + 3] + src_ptr[stride * 2 + 0] +
409
- src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2] +
410
- src_ptr[stride * 2 + 3] + src_ptr[stride * 3 + 0] +
411
- src_ptr[stride * 3 + 1] + src_ptr[stride * 3 + 2] +
412
- src_ptr[stride * 3 + 3] + 8) >>
413
- 4;
414
- dst[1] = (src_ptr[4] + src_ptr[5] + src_ptr[6] + src_ptr[7] +
415
- src_ptr[stride + 4] + src_ptr[stride + 5] + src_ptr[stride + 6] +
416
- src_ptr[stride + 7] + src_ptr[stride * 2 + 4] +
417
- src_ptr[stride * 2 + 5] + src_ptr[stride * 2 + 6] +
418
- src_ptr[stride * 2 + 7] + src_ptr[stride * 3 + 4] +
419
- src_ptr[stride * 3 + 5] + src_ptr[stride * 3 + 6] +
420
- src_ptr[stride * 3 + 7] + 8) >>
421
- 4;
422
- dst += 2;
423
- src_ptr += 8;
424
- }
425
- if (dst_width & 1) {
426
- dst[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[3] +
427
- src_ptr[stride + 0] + src_ptr[stride + 1] + src_ptr[stride + 2] +
428
- src_ptr[stride + 3] + src_ptr[stride * 2 + 0] +
429
- src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2] +
430
- src_ptr[stride * 2 + 3] + src_ptr[stride * 3 + 0] +
431
- src_ptr[stride * 3 + 1] + src_ptr[stride * 3 + 2] +
432
- src_ptr[stride * 3 + 3] + 8) >>
433
- 4;
434
- }
435
- }
436
-
437
- void ScaleRowDown34_C(const uint8_t* src_ptr,
438
- ptrdiff_t src_stride,
439
- uint8_t* dst,
440
- int dst_width) {
441
- int x;
442
- (void)src_stride;
443
- assert((dst_width % 3 == 0) && (dst_width > 0));
444
- for (x = 0; x < dst_width; x += 3) {
445
- dst[0] = src_ptr[0];
446
- dst[1] = src_ptr[1];
447
- dst[2] = src_ptr[3];
448
- dst += 3;
449
- src_ptr += 4;
450
- }
451
- }
452
-
453
- void ScaleRowDown34_16_C(const uint16_t* src_ptr,
454
- ptrdiff_t src_stride,
455
- uint16_t* dst,
456
- int dst_width) {
457
- int x;
458
- (void)src_stride;
459
- assert((dst_width % 3 == 0) && (dst_width > 0));
460
- for (x = 0; x < dst_width; x += 3) {
461
- dst[0] = src_ptr[0];
462
- dst[1] = src_ptr[1];
463
- dst[2] = src_ptr[3];
464
- dst += 3;
465
- src_ptr += 4;
466
- }
467
- }
468
-
469
- // Filter rows 0 and 1 together, 3 : 1
470
- void ScaleRowDown34_0_Box_C(const uint8_t* src_ptr,
471
- ptrdiff_t src_stride,
472
- uint8_t* d,
473
- int dst_width) {
474
- const uint8_t* s = src_ptr;
475
- const uint8_t* t = src_ptr + src_stride;
476
- int x;
477
- assert((dst_width % 3 == 0) && (dst_width > 0));
478
- for (x = 0; x < dst_width; x += 3) {
479
- uint8_t a0 = (s[0] * 3 + s[1] * 1 + 2) >> 2;
480
- uint8_t a1 = (s[1] * 1 + s[2] * 1 + 1) >> 1;
481
- uint8_t a2 = (s[2] * 1 + s[3] * 3 + 2) >> 2;
482
- uint8_t b0 = (t[0] * 3 + t[1] * 1 + 2) >> 2;
483
- uint8_t b1 = (t[1] * 1 + t[2] * 1 + 1) >> 1;
484
- uint8_t b2 = (t[2] * 1 + t[3] * 3 + 2) >> 2;
485
- d[0] = (a0 * 3 + b0 + 2) >> 2;
486
- d[1] = (a1 * 3 + b1 + 2) >> 2;
487
- d[2] = (a2 * 3 + b2 + 2) >> 2;
488
- d += 3;
489
- s += 4;
490
- t += 4;
491
- }
492
- }
493
-
494
- void ScaleRowDown34_0_Box_16_C(const uint16_t* src_ptr,
495
- ptrdiff_t src_stride,
496
- uint16_t* d,
497
- int dst_width) {
498
- const uint16_t* s = src_ptr;
499
- const uint16_t* t = src_ptr + src_stride;
500
- int x;
501
- assert((dst_width % 3 == 0) && (dst_width > 0));
502
- for (x = 0; x < dst_width; x += 3) {
503
- uint16_t a0 = (s[0] * 3 + s[1] * 1 + 2) >> 2;
504
- uint16_t a1 = (s[1] * 1 + s[2] * 1 + 1) >> 1;
505
- uint16_t a2 = (s[2] * 1 + s[3] * 3 + 2) >> 2;
506
- uint16_t b0 = (t[0] * 3 + t[1] * 1 + 2) >> 2;
507
- uint16_t b1 = (t[1] * 1 + t[2] * 1 + 1) >> 1;
508
- uint16_t b2 = (t[2] * 1 + t[3] * 3 + 2) >> 2;
509
- d[0] = (a0 * 3 + b0 + 2) >> 2;
510
- d[1] = (a1 * 3 + b1 + 2) >> 2;
511
- d[2] = (a2 * 3 + b2 + 2) >> 2;
512
- d += 3;
513
- s += 4;
514
- t += 4;
515
- }
516
- }
517
-
518
- // Filter rows 1 and 2 together, 1 : 1
519
- void ScaleRowDown34_1_Box_C(const uint8_t* src_ptr,
520
- ptrdiff_t src_stride,
521
- uint8_t* d,
522
- int dst_width) {
523
- const uint8_t* s = src_ptr;
524
- const uint8_t* t = src_ptr + src_stride;
525
- int x;
526
- assert((dst_width % 3 == 0) && (dst_width > 0));
527
- for (x = 0; x < dst_width; x += 3) {
528
- uint8_t a0 = (s[0] * 3 + s[1] * 1 + 2) >> 2;
529
- uint8_t a1 = (s[1] * 1 + s[2] * 1 + 1) >> 1;
530
- uint8_t a2 = (s[2] * 1 + s[3] * 3 + 2) >> 2;
531
- uint8_t b0 = (t[0] * 3 + t[1] * 1 + 2) >> 2;
532
- uint8_t b1 = (t[1] * 1 + t[2] * 1 + 1) >> 1;
533
- uint8_t b2 = (t[2] * 1 + t[3] * 3 + 2) >> 2;
534
- d[0] = (a0 + b0 + 1) >> 1;
535
- d[1] = (a1 + b1 + 1) >> 1;
536
- d[2] = (a2 + b2 + 1) >> 1;
537
- d += 3;
538
- s += 4;
539
- t += 4;
540
- }
541
- }
542
-
543
- void ScaleRowDown34_1_Box_16_C(const uint16_t* src_ptr,
544
- ptrdiff_t src_stride,
545
- uint16_t* d,
546
- int dst_width) {
547
- const uint16_t* s = src_ptr;
548
- const uint16_t* t = src_ptr + src_stride;
549
- int x;
550
- assert((dst_width % 3 == 0) && (dst_width > 0));
551
- for (x = 0; x < dst_width; x += 3) {
552
- uint16_t a0 = (s[0] * 3 + s[1] * 1 + 2) >> 2;
553
- uint16_t a1 = (s[1] * 1 + s[2] * 1 + 1) >> 1;
554
- uint16_t a2 = (s[2] * 1 + s[3] * 3 + 2) >> 2;
555
- uint16_t b0 = (t[0] * 3 + t[1] * 1 + 2) >> 2;
556
- uint16_t b1 = (t[1] * 1 + t[2] * 1 + 1) >> 1;
557
- uint16_t b2 = (t[2] * 1 + t[3] * 3 + 2) >> 2;
558
- d[0] = (a0 + b0 + 1) >> 1;
559
- d[1] = (a1 + b1 + 1) >> 1;
560
- d[2] = (a2 + b2 + 1) >> 1;
561
- d += 3;
562
- s += 4;
563
- t += 4;
564
- }
565
- }
566
-
567
- // Sample position: (O is src sample position, X is dst sample position)
568
- //
569
- // v dst_ptr at here v stop at here
570
- // X O X X O X X O X X O X X O X
571
- // ^ src_ptr at here
572
- void ScaleRowUp2_Linear_C(const uint8_t* src_ptr,
573
- uint8_t* dst_ptr,
574
- int dst_width) {
575
- int src_width = dst_width >> 1;
576
- int x;
577
- assert((dst_width % 2 == 0) && (dst_width >= 0));
578
- for (x = 0; x < src_width; ++x) {
579
- dst_ptr[2 * x + 0] = (src_ptr[x + 0] * 3 + src_ptr[x + 1] * 1 + 2) >> 2;
580
- dst_ptr[2 * x + 1] = (src_ptr[x + 0] * 1 + src_ptr[x + 1] * 3 + 2) >> 2;
581
- }
582
- }
583
-
584
- // Sample position: (O is src sample position, X is dst sample position)
585
- //
586
- // src_ptr at here
587
- // X v X X X X X X X X X
588
- // O O O O O
589
- // X X X X X X X X X X
590
- // ^ dst_ptr at here ^ stop at here
591
- // X X X X X X X X X X
592
- // O O O O O
593
- // X X X X X X X X X X
594
- void ScaleRowUp2_Bilinear_C(const uint8_t* src_ptr,
595
- ptrdiff_t src_stride,
596
- uint8_t* dst_ptr,
597
- ptrdiff_t dst_stride,
598
- int dst_width) {
599
- const uint8_t* s = src_ptr;
600
- const uint8_t* t = src_ptr + src_stride;
601
- uint8_t* d = dst_ptr;
602
- uint8_t* e = dst_ptr + dst_stride;
603
- int src_width = dst_width >> 1;
604
- int x;
605
- assert((dst_width % 2 == 0) && (dst_width >= 0));
606
- for (x = 0; x < src_width; ++x) {
607
- d[2 * x + 0] =
608
- (s[x + 0] * 9 + s[x + 1] * 3 + t[x + 0] * 3 + t[x + 1] * 1 + 8) >> 4;
609
- d[2 * x + 1] =
610
- (s[x + 0] * 3 + s[x + 1] * 9 + t[x + 0] * 1 + t[x + 1] * 3 + 8) >> 4;
611
- e[2 * x + 0] =
612
- (s[x + 0] * 3 + s[x + 1] * 1 + t[x + 0] * 9 + t[x + 1] * 3 + 8) >> 4;
613
- e[2 * x + 1] =
614
- (s[x + 0] * 1 + s[x + 1] * 3 + t[x + 0] * 3 + t[x + 1] * 9 + 8) >> 4;
615
- }
616
- }
617
-
618
- // Only suitable for at most 14 bit range.
619
- void ScaleRowUp2_Linear_16_C(const uint16_t* src_ptr,
620
- uint16_t* dst_ptr,
621
- int dst_width) {
622
- int src_width = dst_width >> 1;
623
- int x;
624
- assert((dst_width % 2 == 0) && (dst_width >= 0));
625
- for (x = 0; x < src_width; ++x) {
626
- dst_ptr[2 * x + 0] = (src_ptr[x + 0] * 3 + src_ptr[x + 1] * 1 + 2) >> 2;
627
- dst_ptr[2 * x + 1] = (src_ptr[x + 0] * 1 + src_ptr[x + 1] * 3 + 2) >> 2;
628
- }
629
- }
630
-
631
- // Only suitable for at most 12bit range.
632
- void ScaleRowUp2_Bilinear_16_C(const uint16_t* src_ptr,
633
- ptrdiff_t src_stride,
634
- uint16_t* dst_ptr,
635
- ptrdiff_t dst_stride,
636
- int dst_width) {
637
- const uint16_t* s = src_ptr;
638
- const uint16_t* t = src_ptr + src_stride;
639
- uint16_t* d = dst_ptr;
640
- uint16_t* e = dst_ptr + dst_stride;
641
- int src_width = dst_width >> 1;
642
- int x;
643
- assert((dst_width % 2 == 0) && (dst_width >= 0));
644
- for (x = 0; x < src_width; ++x) {
645
- d[2 * x + 0] =
646
- (s[x + 0] * 9 + s[x + 1] * 3 + t[x + 0] * 3 + t[x + 1] * 1 + 8) >> 4;
647
- d[2 * x + 1] =
648
- (s[x + 0] * 3 + s[x + 1] * 9 + t[x + 0] * 1 + t[x + 1] * 3 + 8) >> 4;
649
- e[2 * x + 0] =
650
- (s[x + 0] * 3 + s[x + 1] * 1 + t[x + 0] * 9 + t[x + 1] * 3 + 8) >> 4;
651
- e[2 * x + 1] =
652
- (s[x + 0] * 1 + s[x + 1] * 3 + t[x + 0] * 3 + t[x + 1] * 9 + 8) >> 4;
653
- }
654
- }
655
-
656
- // Scales a single row of pixels using point sampling.
657
- void ScaleCols_C(uint8_t* dst_ptr,
658
- const uint8_t* src_ptr,
659
- int dst_width,
660
- int x,
661
- int dx) {
662
- int j;
663
- for (j = 0; j < dst_width - 1; j += 2) {
664
- dst_ptr[0] = src_ptr[x >> 16];
665
- x += dx;
666
- dst_ptr[1] = src_ptr[x >> 16];
667
- x += dx;
668
- dst_ptr += 2;
669
- }
670
- if (dst_width & 1) {
671
- dst_ptr[0] = src_ptr[x >> 16];
672
- }
673
- }
674
-
675
- void ScaleCols_16_C(uint16_t* dst_ptr,
676
- const uint16_t* src_ptr,
677
- int dst_width,
678
- int x,
679
- int dx) {
680
- int j;
681
- for (j = 0; j < dst_width - 1; j += 2) {
682
- dst_ptr[0] = src_ptr[x >> 16];
683
- x += dx;
684
- dst_ptr[1] = src_ptr[x >> 16];
685
- x += dx;
686
- dst_ptr += 2;
687
- }
688
- if (dst_width & 1) {
689
- dst_ptr[0] = src_ptr[x >> 16];
690
- }
691
- }
692
-
693
- // Scales a single row of pixels up by 2x using point sampling.
694
- void ScaleColsUp2_C(uint8_t* dst_ptr,
695
- const uint8_t* src_ptr,
696
- int dst_width,
697
- int x,
698
- int dx) {
699
- int j;
700
- (void)x;
701
- (void)dx;
702
- for (j = 0; j < dst_width - 1; j += 2) {
703
- dst_ptr[1] = dst_ptr[0] = src_ptr[0];
704
- src_ptr += 1;
705
- dst_ptr += 2;
706
- }
707
- if (dst_width & 1) {
708
- dst_ptr[0] = src_ptr[0];
709
- }
710
- }
711
-
712
- void ScaleColsUp2_16_C(uint16_t* dst_ptr,
713
- const uint16_t* src_ptr,
714
- int dst_width,
715
- int x,
716
- int dx) {
717
- int j;
718
- (void)x;
719
- (void)dx;
720
- for (j = 0; j < dst_width - 1; j += 2) {
721
- dst_ptr[1] = dst_ptr[0] = src_ptr[0];
722
- src_ptr += 1;
723
- dst_ptr += 2;
724
- }
725
- if (dst_width & 1) {
726
- dst_ptr[0] = src_ptr[0];
727
- }
728
- }
729
-
730
- // (1-f)a + fb can be replaced with a + f(b-a)
731
- #if defined(__arm__) || defined(__aarch64__)
732
- #define BLENDER(a, b, f) \
733
- (uint8_t)((int)(a) + ((((int)((f)) * ((int)(b) - (int)(a))) + 0x8000) >> 16))
734
- #else
735
- // Intel uses 7 bit math with rounding.
736
- #define BLENDER(a, b, f) \
737
- (uint8_t)((int)(a) + (((int)((f) >> 9) * ((int)(b) - (int)(a)) + 0x40) >> 7))
738
- #endif
739
-
740
- void ScaleFilterCols_C(uint8_t* dst_ptr,
741
- const uint8_t* src_ptr,
742
- int dst_width,
743
- int x,
744
- int dx) {
745
- int j;
746
- for (j = 0; j < dst_width - 1; j += 2) {
747
- int xi = x >> 16;
748
- int a = src_ptr[xi];
749
- int b = src_ptr[xi + 1];
750
- dst_ptr[0] = BLENDER(a, b, x & 0xffff);
751
- x += dx;
752
- xi = x >> 16;
753
- a = src_ptr[xi];
754
- b = src_ptr[xi + 1];
755
- dst_ptr[1] = BLENDER(a, b, x & 0xffff);
756
- x += dx;
757
- dst_ptr += 2;
758
- }
759
- if (dst_width & 1) {
760
- int xi = x >> 16;
761
- int a = src_ptr[xi];
762
- int b = src_ptr[xi + 1];
763
- dst_ptr[0] = BLENDER(a, b, x & 0xffff);
764
- }
765
- }
766
-
767
- void ScaleFilterCols64_C(uint8_t* dst_ptr,
768
- const uint8_t* src_ptr,
769
- int dst_width,
770
- int x32,
771
- int dx) {
772
- int64_t x = (int64_t)(x32);
773
- int j;
774
- for (j = 0; j < dst_width - 1; j += 2) {
775
- int64_t xi = x >> 16;
776
- int a = src_ptr[xi];
777
- int b = src_ptr[xi + 1];
778
- dst_ptr[0] = BLENDER(a, b, x & 0xffff);
779
- x += dx;
780
- xi = x >> 16;
781
- a = src_ptr[xi];
782
- b = src_ptr[xi + 1];
783
- dst_ptr[1] = BLENDER(a, b, x & 0xffff);
784
- x += dx;
785
- dst_ptr += 2;
786
- }
787
- if (dst_width & 1) {
788
- int64_t xi = x >> 16;
789
- int a = src_ptr[xi];
790
- int b = src_ptr[xi + 1];
791
- dst_ptr[0] = BLENDER(a, b, x & 0xffff);
792
- }
793
- }
794
- #undef BLENDER
795
-
796
- // Same as 8 bit arm blender but return is cast to uint16_t
797
- #define BLENDER(a, b, f) \
798
- (uint16_t)( \
799
- (int)(a) + \
800
- (int)((((int64_t)((f)) * ((int64_t)(b) - (int)(a))) + 0x8000) >> 16))
801
-
802
- void ScaleFilterCols_16_C(uint16_t* dst_ptr,
803
- const uint16_t* src_ptr,
804
- int dst_width,
805
- int x,
806
- int dx) {
807
- int j;
808
- for (j = 0; j < dst_width - 1; j += 2) {
809
- int xi = x >> 16;
810
- int a = src_ptr[xi];
811
- int b = src_ptr[xi + 1];
812
- dst_ptr[0] = BLENDER(a, b, x & 0xffff);
813
- x += dx;
814
- xi = x >> 16;
815
- a = src_ptr[xi];
816
- b = src_ptr[xi + 1];
817
- dst_ptr[1] = BLENDER(a, b, x & 0xffff);
818
- x += dx;
819
- dst_ptr += 2;
820
- }
821
- if (dst_width & 1) {
822
- int xi = x >> 16;
823
- int a = src_ptr[xi];
824
- int b = src_ptr[xi + 1];
825
- dst_ptr[0] = BLENDER(a, b, x & 0xffff);
826
- }
827
- }
828
-
829
- void ScaleFilterCols64_16_C(uint16_t* dst_ptr,
830
- const uint16_t* src_ptr,
831
- int dst_width,
832
- int x32,
833
- int dx) {
834
- int64_t x = (int64_t)(x32);
835
- int j;
836
- for (j = 0; j < dst_width - 1; j += 2) {
837
- int64_t xi = x >> 16;
838
- int a = src_ptr[xi];
839
- int b = src_ptr[xi + 1];
840
- dst_ptr[0] = BLENDER(a, b, x & 0xffff);
841
- x += dx;
842
- xi = x >> 16;
843
- a = src_ptr[xi];
844
- b = src_ptr[xi + 1];
845
- dst_ptr[1] = BLENDER(a, b, x & 0xffff);
846
- x += dx;
847
- dst_ptr += 2;
848
- }
849
- if (dst_width & 1) {
850
- int64_t xi = x >> 16;
851
- int a = src_ptr[xi];
852
- int b = src_ptr[xi + 1];
853
- dst_ptr[0] = BLENDER(a, b, x & 0xffff);
854
- }
855
- }
856
- #undef BLENDER
857
-
858
- void ScaleRowDown38_C(const uint8_t* src_ptr,
859
- ptrdiff_t src_stride,
860
- uint8_t* dst,
861
- int dst_width) {
862
- int x;
863
- (void)src_stride;
864
- assert(dst_width % 3 == 0);
865
- for (x = 0; x < dst_width; x += 3) {
866
- dst[0] = src_ptr[0];
867
- dst[1] = src_ptr[3];
868
- dst[2] = src_ptr[6];
869
- dst += 3;
870
- src_ptr += 8;
871
- }
872
- }
873
-
874
- void ScaleRowDown38_16_C(const uint16_t* src_ptr,
875
- ptrdiff_t src_stride,
876
- uint16_t* dst,
877
- int dst_width) {
878
- int x;
879
- (void)src_stride;
880
- assert(dst_width % 3 == 0);
881
- for (x = 0; x < dst_width; x += 3) {
882
- dst[0] = src_ptr[0];
883
- dst[1] = src_ptr[3];
884
- dst[2] = src_ptr[6];
885
- dst += 3;
886
- src_ptr += 8;
887
- }
888
- }
889
-
890
- // 8x3 -> 3x1
891
- void ScaleRowDown38_3_Box_C(const uint8_t* src_ptr,
892
- ptrdiff_t src_stride,
893
- uint8_t* dst_ptr,
894
- int dst_width) {
895
- intptr_t stride = src_stride;
896
- int i;
897
- assert((dst_width % 3 == 0) && (dst_width > 0));
898
- for (i = 0; i < dst_width; i += 3) {
899
- dst_ptr[0] =
900
- (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[stride + 0] +
901
- src_ptr[stride + 1] + src_ptr[stride + 2] + src_ptr[stride * 2 + 0] +
902
- src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2]) *
903
- (65536 / 9) >>
904
- 16;
905
- dst_ptr[1] =
906
- (src_ptr[3] + src_ptr[4] + src_ptr[5] + src_ptr[stride + 3] +
907
- src_ptr[stride + 4] + src_ptr[stride + 5] + src_ptr[stride * 2 + 3] +
908
- src_ptr[stride * 2 + 4] + src_ptr[stride * 2 + 5]) *
909
- (65536 / 9) >>
910
- 16;
911
- dst_ptr[2] =
912
- (src_ptr[6] + src_ptr[7] + src_ptr[stride + 6] + src_ptr[stride + 7] +
913
- src_ptr[stride * 2 + 6] + src_ptr[stride * 2 + 7]) *
914
- (65536 / 6) >>
915
- 16;
916
- src_ptr += 8;
917
- dst_ptr += 3;
918
- }
919
- }
920
-
921
- void ScaleRowDown38_3_Box_16_C(const uint16_t* src_ptr,
922
- ptrdiff_t src_stride,
923
- uint16_t* dst_ptr,
924
- int dst_width) {
925
- intptr_t stride = src_stride;
926
- int i;
927
- assert((dst_width % 3 == 0) && (dst_width > 0));
928
- for (i = 0; i < dst_width; i += 3) {
929
- dst_ptr[0] =
930
- (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[stride + 0] +
931
- src_ptr[stride + 1] + src_ptr[stride + 2] + src_ptr[stride * 2 + 0] +
932
- src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2]) *
933
- (65536u / 9u) >>
934
- 16;
935
- dst_ptr[1] =
936
- (src_ptr[3] + src_ptr[4] + src_ptr[5] + src_ptr[stride + 3] +
937
- src_ptr[stride + 4] + src_ptr[stride + 5] + src_ptr[stride * 2 + 3] +
938
- src_ptr[stride * 2 + 4] + src_ptr[stride * 2 + 5]) *
939
- (65536u / 9u) >>
940
- 16;
941
- dst_ptr[2] =
942
- (src_ptr[6] + src_ptr[7] + src_ptr[stride + 6] + src_ptr[stride + 7] +
943
- src_ptr[stride * 2 + 6] + src_ptr[stride * 2 + 7]) *
944
- (65536u / 6u) >>
945
- 16;
946
- src_ptr += 8;
947
- dst_ptr += 3;
948
- }
949
- }
950
-
951
- // 8x2 -> 3x1
952
- void ScaleRowDown38_2_Box_C(const uint8_t* src_ptr,
953
- ptrdiff_t src_stride,
954
- uint8_t* dst_ptr,
955
- int dst_width) {
956
- intptr_t stride = src_stride;
957
- int i;
958
- assert((dst_width % 3 == 0) && (dst_width > 0));
959
- for (i = 0; i < dst_width; i += 3) {
960
- dst_ptr[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[stride + 0] +
961
- src_ptr[stride + 1] + src_ptr[stride + 2]) *
962
- (65536 / 6) >>
963
- 16;
964
- dst_ptr[1] = (src_ptr[3] + src_ptr[4] + src_ptr[5] + src_ptr[stride + 3] +
965
- src_ptr[stride + 4] + src_ptr[stride + 5]) *
966
- (65536 / 6) >>
967
- 16;
968
- dst_ptr[2] =
969
- (src_ptr[6] + src_ptr[7] + src_ptr[stride + 6] + src_ptr[stride + 7]) *
970
- (65536 / 4) >>
971
- 16;
972
- src_ptr += 8;
973
- dst_ptr += 3;
974
- }
975
- }
976
-
977
- void ScaleRowDown38_2_Box_16_C(const uint16_t* src_ptr,
978
- ptrdiff_t src_stride,
979
- uint16_t* dst_ptr,
980
- int dst_width) {
981
- intptr_t stride = src_stride;
982
- int i;
983
- assert((dst_width % 3 == 0) && (dst_width > 0));
984
- for (i = 0; i < dst_width; i += 3) {
985
- dst_ptr[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[stride + 0] +
986
- src_ptr[stride + 1] + src_ptr[stride + 2]) *
987
- (65536u / 6u) >>
988
- 16;
989
- dst_ptr[1] = (src_ptr[3] + src_ptr[4] + src_ptr[5] + src_ptr[stride + 3] +
990
- src_ptr[stride + 4] + src_ptr[stride + 5]) *
991
- (65536u / 6u) >>
992
- 16;
993
- dst_ptr[2] =
994
- (src_ptr[6] + src_ptr[7] + src_ptr[stride + 6] + src_ptr[stride + 7]) *
995
- (65536u / 4u) >>
996
- 16;
997
- src_ptr += 8;
998
- dst_ptr += 3;
999
- }
1000
- }
1001
-
1002
- void ScaleAddRow_C(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width) {
1003
- int x;
1004
- assert(src_width > 0);
1005
- for (x = 0; x < src_width - 1; x += 2) {
1006
- dst_ptr[0] += src_ptr[0];
1007
- dst_ptr[1] += src_ptr[1];
1008
- src_ptr += 2;
1009
- dst_ptr += 2;
1010
- }
1011
- if (src_width & 1) {
1012
- dst_ptr[0] += src_ptr[0];
1013
- }
1014
- }
1015
-
1016
- void ScaleAddRow_16_C(const uint16_t* src_ptr,
1017
- uint32_t* dst_ptr,
1018
- int src_width) {
1019
- int x;
1020
- assert(src_width > 0);
1021
- for (x = 0; x < src_width - 1; x += 2) {
1022
- dst_ptr[0] += src_ptr[0];
1023
- dst_ptr[1] += src_ptr[1];
1024
- src_ptr += 2;
1025
- dst_ptr += 2;
1026
- }
1027
- if (src_width & 1) {
1028
- dst_ptr[0] += src_ptr[0];
1029
- }
1030
- }
1031
-
1032
- // ARGB scale row functions
1033
-
1034
- void ScaleARGBRowDown2_C(const uint8_t* src_argb,
1035
- ptrdiff_t src_stride,
1036
- uint8_t* dst_argb,
1037
- int dst_width) {
1038
- const uint32_t* src = (const uint32_t*)(src_argb);
1039
- uint32_t* dst = (uint32_t*)(dst_argb);
1040
- int x;
1041
- (void)src_stride;
1042
- for (x = 0; x < dst_width - 1; x += 2) {
1043
- dst[0] = src[1];
1044
- dst[1] = src[3];
1045
- src += 4;
1046
- dst += 2;
1047
- }
1048
- if (dst_width & 1) {
1049
- dst[0] = src[1];
1050
- }
1051
- }
1052
-
1053
- void ScaleARGBRowDown2Linear_C(const uint8_t* src_argb,
1054
- ptrdiff_t src_stride,
1055
- uint8_t* dst_argb,
1056
- int dst_width) {
1057
- int x;
1058
- (void)src_stride;
1059
- for (x = 0; x < dst_width; ++x) {
1060
- dst_argb[0] = (src_argb[0] + src_argb[4] + 1) >> 1;
1061
- dst_argb[1] = (src_argb[1] + src_argb[5] + 1) >> 1;
1062
- dst_argb[2] = (src_argb[2] + src_argb[6] + 1) >> 1;
1063
- dst_argb[3] = (src_argb[3] + src_argb[7] + 1) >> 1;
1064
- src_argb += 8;
1065
- dst_argb += 4;
1066
- }
1067
- }
1068
-
1069
- void ScaleARGBRowDown2Box_C(const uint8_t* src_argb,
1070
- ptrdiff_t src_stride,
1071
- uint8_t* dst_argb,
1072
- int dst_width) {
1073
- int x;
1074
- for (x = 0; x < dst_width; ++x) {
1075
- dst_argb[0] = (src_argb[0] + src_argb[4] + src_argb[src_stride] +
1076
- src_argb[src_stride + 4] + 2) >>
1077
- 2;
1078
- dst_argb[1] = (src_argb[1] + src_argb[5] + src_argb[src_stride + 1] +
1079
- src_argb[src_stride + 5] + 2) >>
1080
- 2;
1081
- dst_argb[2] = (src_argb[2] + src_argb[6] + src_argb[src_stride + 2] +
1082
- src_argb[src_stride + 6] + 2) >>
1083
- 2;
1084
- dst_argb[3] = (src_argb[3] + src_argb[7] + src_argb[src_stride + 3] +
1085
- src_argb[src_stride + 7] + 2) >>
1086
- 2;
1087
- src_argb += 8;
1088
- dst_argb += 4;
1089
- }
1090
- }
1091
-
1092
- void ScaleARGBRowDownEven_C(const uint8_t* src_argb,
1093
- ptrdiff_t src_stride,
1094
- int src_stepx,
1095
- uint8_t* dst_argb,
1096
- int dst_width) {
1097
- const uint32_t* src = (const uint32_t*)(src_argb);
1098
- uint32_t* dst = (uint32_t*)(dst_argb);
1099
- (void)src_stride;
1100
- int x;
1101
- for (x = 0; x < dst_width - 1; x += 2) {
1102
- dst[0] = src[0];
1103
- dst[1] = src[src_stepx];
1104
- src += src_stepx * 2;
1105
- dst += 2;
1106
- }
1107
- if (dst_width & 1) {
1108
- dst[0] = src[0];
1109
- }
1110
- }
1111
-
1112
- void ScaleARGBRowDownEvenBox_C(const uint8_t* src_argb,
1113
- ptrdiff_t src_stride,
1114
- int src_stepx,
1115
- uint8_t* dst_argb,
1116
- int dst_width) {
1117
- int x;
1118
- for (x = 0; x < dst_width; ++x) {
1119
- dst_argb[0] = (src_argb[0] + src_argb[4] + src_argb[src_stride] +
1120
- src_argb[src_stride + 4] + 2) >>
1121
- 2;
1122
- dst_argb[1] = (src_argb[1] + src_argb[5] + src_argb[src_stride + 1] +
1123
- src_argb[src_stride + 5] + 2) >>
1124
- 2;
1125
- dst_argb[2] = (src_argb[2] + src_argb[6] + src_argb[src_stride + 2] +
1126
- src_argb[src_stride + 6] + 2) >>
1127
- 2;
1128
- dst_argb[3] = (src_argb[3] + src_argb[7] + src_argb[src_stride + 3] +
1129
- src_argb[src_stride + 7] + 2) >>
1130
- 2;
1131
- src_argb += src_stepx * 4;
1132
- dst_argb += 4;
1133
- }
1134
- }
1135
-
1136
- // Scales a single row of pixels using point sampling.
1137
- void ScaleARGBCols_C(uint8_t* dst_argb,
1138
- const uint8_t* src_argb,
1139
- int dst_width,
1140
- int x,
1141
- int dx) {
1142
- const uint32_t* src = (const uint32_t*)(src_argb);
1143
- uint32_t* dst = (uint32_t*)(dst_argb);
1144
- int j;
1145
- for (j = 0; j < dst_width - 1; j += 2) {
1146
- dst[0] = src[x >> 16];
1147
- x += dx;
1148
- dst[1] = src[x >> 16];
1149
- x += dx;
1150
- dst += 2;
1151
- }
1152
- if (dst_width & 1) {
1153
- dst[0] = src[x >> 16];
1154
- }
1155
- }
1156
-
1157
- void ScaleARGBCols64_C(uint8_t* dst_argb,
1158
- const uint8_t* src_argb,
1159
- int dst_width,
1160
- int x32,
1161
- int dx) {
1162
- int64_t x = (int64_t)(x32);
1163
- const uint32_t* src = (const uint32_t*)(src_argb);
1164
- uint32_t* dst = (uint32_t*)(dst_argb);
1165
- int j;
1166
- for (j = 0; j < dst_width - 1; j += 2) {
1167
- dst[0] = src[x >> 16];
1168
- x += dx;
1169
- dst[1] = src[x >> 16];
1170
- x += dx;
1171
- dst += 2;
1172
- }
1173
- if (dst_width & 1) {
1174
- dst[0] = src[x >> 16];
1175
- }
1176
- }
1177
-
1178
- // Scales a single row of pixels up by 2x using point sampling.
1179
- void ScaleARGBColsUp2_C(uint8_t* dst_argb,
1180
- const uint8_t* src_argb,
1181
- int dst_width,
1182
- int x,
1183
- int dx) {
1184
- const uint32_t* src = (const uint32_t*)(src_argb);
1185
- uint32_t* dst = (uint32_t*)(dst_argb);
1186
- int j;
1187
- (void)x;
1188
- (void)dx;
1189
- for (j = 0; j < dst_width - 1; j += 2) {
1190
- dst[1] = dst[0] = src[0];
1191
- src += 1;
1192
- dst += 2;
1193
- }
1194
- if (dst_width & 1) {
1195
- dst[0] = src[0];
1196
- }
1197
- }
1198
-
1199
- // TODO(fbarchard): Replace 0x7f ^ f with 128-f. bug=607.
1200
- // Mimics SSSE3 blender
1201
- #define BLENDER1(a, b, f) ((a) * (0x7f ^ f) + (b)*f) >> 7
1202
- #define BLENDERC(a, b, f, s) \
1203
- (uint32_t)(BLENDER1(((a) >> s) & 255, ((b) >> s) & 255, f) << s)
1204
- #define BLENDER(a, b, f) \
1205
- BLENDERC(a, b, f, 24) | BLENDERC(a, b, f, 16) | BLENDERC(a, b, f, 8) | \
1206
- BLENDERC(a, b, f, 0)
1207
-
1208
- void ScaleARGBFilterCols_C(uint8_t* dst_argb,
1209
- const uint8_t* src_argb,
1210
- int dst_width,
1211
- int x,
1212
- int dx) {
1213
- const uint32_t* src = (const uint32_t*)(src_argb);
1214
- uint32_t* dst = (uint32_t*)(dst_argb);
1215
- int j;
1216
- for (j = 0; j < dst_width - 1; j += 2) {
1217
- int xi = x >> 16;
1218
- int xf = (x >> 9) & 0x7f;
1219
- uint32_t a = src[xi];
1220
- uint32_t b = src[xi + 1];
1221
- dst[0] = BLENDER(a, b, xf);
1222
- x += dx;
1223
- xi = x >> 16;
1224
- xf = (x >> 9) & 0x7f;
1225
- a = src[xi];
1226
- b = src[xi + 1];
1227
- dst[1] = BLENDER(a, b, xf);
1228
- x += dx;
1229
- dst += 2;
1230
- }
1231
- if (dst_width & 1) {
1232
- int xi = x >> 16;
1233
- int xf = (x >> 9) & 0x7f;
1234
- uint32_t a = src[xi];
1235
- uint32_t b = src[xi + 1];
1236
- dst[0] = BLENDER(a, b, xf);
1237
- }
1238
- }
1239
-
1240
- void ScaleARGBFilterCols64_C(uint8_t* dst_argb,
1241
- const uint8_t* src_argb,
1242
- int dst_width,
1243
- int x32,
1244
- int dx) {
1245
- int64_t x = (int64_t)(x32);
1246
- const uint32_t* src = (const uint32_t*)(src_argb);
1247
- uint32_t* dst = (uint32_t*)(dst_argb);
1248
- int j;
1249
- for (j = 0; j < dst_width - 1; j += 2) {
1250
- int64_t xi = x >> 16;
1251
- int xf = (x >> 9) & 0x7f;
1252
- uint32_t a = src[xi];
1253
- uint32_t b = src[xi + 1];
1254
- dst[0] = BLENDER(a, b, xf);
1255
- x += dx;
1256
- xi = x >> 16;
1257
- xf = (x >> 9) & 0x7f;
1258
- a = src[xi];
1259
- b = src[xi + 1];
1260
- dst[1] = BLENDER(a, b, xf);
1261
- x += dx;
1262
- dst += 2;
1263
- }
1264
- if (dst_width & 1) {
1265
- int64_t xi = x >> 16;
1266
- int xf = (x >> 9) & 0x7f;
1267
- uint32_t a = src[xi];
1268
- uint32_t b = src[xi + 1];
1269
- dst[0] = BLENDER(a, b, xf);
1270
- }
1271
- }
1272
- #undef BLENDER1
1273
- #undef BLENDERC
1274
- #undef BLENDER
1275
-
1276
- // UV scale row functions
1277
- // same as ARGB but 2 channels
1278
-
1279
- void ScaleUVRowDown2_C(const uint8_t* src_uv,
1280
- ptrdiff_t src_stride,
1281
- uint8_t* dst_uv,
1282
- int dst_width) {
1283
- int x;
1284
- (void)src_stride;
1285
- for (x = 0; x < dst_width; ++x) {
1286
- dst_uv[0] = src_uv[2]; // Store the 2nd UV
1287
- dst_uv[1] = src_uv[3];
1288
- src_uv += 4;
1289
- dst_uv += 2;
1290
- }
1291
- }
1292
-
1293
- void ScaleUVRowDown2Linear_C(const uint8_t* src_uv,
1294
- ptrdiff_t src_stride,
1295
- uint8_t* dst_uv,
1296
- int dst_width) {
1297
- int x;
1298
- (void)src_stride;
1299
- for (x = 0; x < dst_width; ++x) {
1300
- dst_uv[0] = (src_uv[0] + src_uv[2] + 1) >> 1;
1301
- dst_uv[1] = (src_uv[1] + src_uv[3] + 1) >> 1;
1302
- src_uv += 4;
1303
- dst_uv += 2;
1304
- }
1305
- }
1306
-
1307
- void ScaleUVRowDown2Box_C(const uint8_t* src_uv,
1308
- ptrdiff_t src_stride,
1309
- uint8_t* dst_uv,
1310
- int dst_width) {
1311
- int x;
1312
- for (x = 0; x < dst_width; ++x) {
1313
- dst_uv[0] = (src_uv[0] + src_uv[2] + src_uv[src_stride] +
1314
- src_uv[src_stride + 2] + 2) >>
1315
- 2;
1316
- dst_uv[1] = (src_uv[1] + src_uv[3] + src_uv[src_stride + 1] +
1317
- src_uv[src_stride + 3] + 2) >>
1318
- 2;
1319
- src_uv += 4;
1320
- dst_uv += 2;
1321
- }
1322
- }
1323
-
1324
- void ScaleUVRowDownEven_C(const uint8_t* src_uv,
1325
- ptrdiff_t src_stride,
1326
- int src_stepx,
1327
- uint8_t* dst_uv,
1328
- int dst_width) {
1329
- const uint16_t* src = (const uint16_t*)(src_uv);
1330
- uint16_t* dst = (uint16_t*)(dst_uv);
1331
- (void)src_stride;
1332
- int x;
1333
- for (x = 0; x < dst_width - 1; x += 2) {
1334
- dst[0] = src[0];
1335
- dst[1] = src[src_stepx];
1336
- src += src_stepx * 2;
1337
- dst += 2;
1338
- }
1339
- if (dst_width & 1) {
1340
- dst[0] = src[0];
1341
- }
1342
- }
1343
-
1344
- void ScaleUVRowDownEvenBox_C(const uint8_t* src_uv,
1345
- ptrdiff_t src_stride,
1346
- int src_stepx,
1347
- uint8_t* dst_uv,
1348
- int dst_width) {
1349
- int x;
1350
- for (x = 0; x < dst_width; ++x) {
1351
- dst_uv[0] = (src_uv[0] + src_uv[2] + src_uv[src_stride] +
1352
- src_uv[src_stride + 2] + 2) >>
1353
- 2;
1354
- dst_uv[1] = (src_uv[1] + src_uv[3] + src_uv[src_stride + 1] +
1355
- src_uv[src_stride + 3] + 2) >>
1356
- 2;
1357
- src_uv += src_stepx * 2;
1358
- dst_uv += 2;
1359
- }
1360
- }
1361
-
1362
- void ScaleUVRowUp2_Linear_C(const uint8_t* src_ptr,
1363
- uint8_t* dst_ptr,
1364
- int dst_width) {
1365
- int src_width = dst_width >> 1;
1366
- int x;
1367
- assert((dst_width % 2 == 0) && (dst_width >= 0));
1368
- for (x = 0; x < src_width; ++x) {
1369
- dst_ptr[4 * x + 0] =
1370
- (src_ptr[2 * x + 0] * 3 + src_ptr[2 * x + 2] * 1 + 2) >> 2;
1371
- dst_ptr[4 * x + 1] =
1372
- (src_ptr[2 * x + 1] * 3 + src_ptr[2 * x + 3] * 1 + 2) >> 2;
1373
- dst_ptr[4 * x + 2] =
1374
- (src_ptr[2 * x + 0] * 1 + src_ptr[2 * x + 2] * 3 + 2) >> 2;
1375
- dst_ptr[4 * x + 3] =
1376
- (src_ptr[2 * x + 1] * 1 + src_ptr[2 * x + 3] * 3 + 2) >> 2;
1377
- }
1378
- }
1379
-
1380
- void ScaleUVRowUp2_Bilinear_C(const uint8_t* src_ptr,
1381
- ptrdiff_t src_stride,
1382
- uint8_t* dst_ptr,
1383
- ptrdiff_t dst_stride,
1384
- int dst_width) {
1385
- const uint8_t* s = src_ptr;
1386
- const uint8_t* t = src_ptr + src_stride;
1387
- uint8_t* d = dst_ptr;
1388
- uint8_t* e = dst_ptr + dst_stride;
1389
- int src_width = dst_width >> 1;
1390
- int x;
1391
- assert((dst_width % 2 == 0) && (dst_width >= 0));
1392
- for (x = 0; x < src_width; ++x) {
1393
- d[4 * x + 0] = (s[2 * x + 0] * 9 + s[2 * x + 2] * 3 + t[2 * x + 0] * 3 +
1394
- t[2 * x + 2] * 1 + 8) >>
1395
- 4;
1396
- d[4 * x + 1] = (s[2 * x + 1] * 9 + s[2 * x + 3] * 3 + t[2 * x + 1] * 3 +
1397
- t[2 * x + 3] * 1 + 8) >>
1398
- 4;
1399
- d[4 * x + 2] = (s[2 * x + 0] * 3 + s[2 * x + 2] * 9 + t[2 * x + 0] * 1 +
1400
- t[2 * x + 2] * 3 + 8) >>
1401
- 4;
1402
- d[4 * x + 3] = (s[2 * x + 1] * 3 + s[2 * x + 3] * 9 + t[2 * x + 1] * 1 +
1403
- t[2 * x + 3] * 3 + 8) >>
1404
- 4;
1405
- e[4 * x + 0] = (s[2 * x + 0] * 3 + s[2 * x + 2] * 1 + t[2 * x + 0] * 9 +
1406
- t[2 * x + 2] * 3 + 8) >>
1407
- 4;
1408
- e[4 * x + 1] = (s[2 * x + 1] * 3 + s[2 * x + 3] * 1 + t[2 * x + 1] * 9 +
1409
- t[2 * x + 3] * 3 + 8) >>
1410
- 4;
1411
- e[4 * x + 2] = (s[2 * x + 0] * 1 + s[2 * x + 2] * 3 + t[2 * x + 0] * 3 +
1412
- t[2 * x + 2] * 9 + 8) >>
1413
- 4;
1414
- e[4 * x + 3] = (s[2 * x + 1] * 1 + s[2 * x + 3] * 3 + t[2 * x + 1] * 3 +
1415
- t[2 * x + 3] * 9 + 8) >>
1416
- 4;
1417
- }
1418
- }
1419
-
1420
- void ScaleUVRowUp2_Linear_16_C(const uint16_t* src_ptr,
1421
- uint16_t* dst_ptr,
1422
- int dst_width) {
1423
- int src_width = dst_width >> 1;
1424
- int x;
1425
- assert((dst_width % 2 == 0) && (dst_width >= 0));
1426
- for (x = 0; x < src_width; ++x) {
1427
- dst_ptr[4 * x + 0] =
1428
- (src_ptr[2 * x + 0] * 3 + src_ptr[2 * x + 2] * 1 + 2) >> 2;
1429
- dst_ptr[4 * x + 1] =
1430
- (src_ptr[2 * x + 1] * 3 + src_ptr[2 * x + 3] * 1 + 2) >> 2;
1431
- dst_ptr[4 * x + 2] =
1432
- (src_ptr[2 * x + 0] * 1 + src_ptr[2 * x + 2] * 3 + 2) >> 2;
1433
- dst_ptr[4 * x + 3] =
1434
- (src_ptr[2 * x + 1] * 1 + src_ptr[2 * x + 3] * 3 + 2) >> 2;
1435
- }
1436
- }
1437
-
1438
- void ScaleUVRowUp2_Bilinear_16_C(const uint16_t* src_ptr,
1439
- ptrdiff_t src_stride,
1440
- uint16_t* dst_ptr,
1441
- ptrdiff_t dst_stride,
1442
- int dst_width) {
1443
- const uint16_t* s = src_ptr;
1444
- const uint16_t* t = src_ptr + src_stride;
1445
- uint16_t* d = dst_ptr;
1446
- uint16_t* e = dst_ptr + dst_stride;
1447
- int src_width = dst_width >> 1;
1448
- int x;
1449
- assert((dst_width % 2 == 0) && (dst_width >= 0));
1450
- for (x = 0; x < src_width; ++x) {
1451
- d[4 * x + 0] = (s[2 * x + 0] * 9 + s[2 * x + 2] * 3 + t[2 * x + 0] * 3 +
1452
- t[2 * x + 2] * 1 + 8) >>
1453
- 4;
1454
- d[4 * x + 1] = (s[2 * x + 1] * 9 + s[2 * x + 3] * 3 + t[2 * x + 1] * 3 +
1455
- t[2 * x + 3] * 1 + 8) >>
1456
- 4;
1457
- d[4 * x + 2] = (s[2 * x + 0] * 3 + s[2 * x + 2] * 9 + t[2 * x + 0] * 1 +
1458
- t[2 * x + 2] * 3 + 8) >>
1459
- 4;
1460
- d[4 * x + 3] = (s[2 * x + 1] * 3 + s[2 * x + 3] * 9 + t[2 * x + 1] * 1 +
1461
- t[2 * x + 3] * 3 + 8) >>
1462
- 4;
1463
- e[4 * x + 0] = (s[2 * x + 0] * 3 + s[2 * x + 2] * 1 + t[2 * x + 0] * 9 +
1464
- t[2 * x + 2] * 3 + 8) >>
1465
- 4;
1466
- e[4 * x + 1] = (s[2 * x + 1] * 3 + s[2 * x + 3] * 1 + t[2 * x + 1] * 9 +
1467
- t[2 * x + 3] * 3 + 8) >>
1468
- 4;
1469
- e[4 * x + 2] = (s[2 * x + 0] * 1 + s[2 * x + 2] * 3 + t[2 * x + 0] * 3 +
1470
- t[2 * x + 2] * 9 + 8) >>
1471
- 4;
1472
- e[4 * x + 3] = (s[2 * x + 1] * 1 + s[2 * x + 3] * 3 + t[2 * x + 1] * 3 +
1473
- t[2 * x + 3] * 9 + 8) >>
1474
- 4;
1475
- }
1476
- }
1477
-
1478
- // Scales a single row of pixels using point sampling.
1479
- void ScaleUVCols_C(uint8_t* dst_uv,
1480
- const uint8_t* src_uv,
1481
- int dst_width,
1482
- int x,
1483
- int dx) {
1484
- const uint16_t* src = (const uint16_t*)(src_uv);
1485
- uint16_t* dst = (uint16_t*)(dst_uv);
1486
- int j;
1487
- for (j = 0; j < dst_width - 1; j += 2) {
1488
- dst[0] = src[x >> 16];
1489
- x += dx;
1490
- dst[1] = src[x >> 16];
1491
- x += dx;
1492
- dst += 2;
1493
- }
1494
- if (dst_width & 1) {
1495
- dst[0] = src[x >> 16];
1496
- }
1497
- }
1498
-
1499
- void ScaleUVCols64_C(uint8_t* dst_uv,
1500
- const uint8_t* src_uv,
1501
- int dst_width,
1502
- int x32,
1503
- int dx) {
1504
- int64_t x = (int64_t)(x32);
1505
- const uint16_t* src = (const uint16_t*)(src_uv);
1506
- uint16_t* dst = (uint16_t*)(dst_uv);
1507
- int j;
1508
- for (j = 0; j < dst_width - 1; j += 2) {
1509
- dst[0] = src[x >> 16];
1510
- x += dx;
1511
- dst[1] = src[x >> 16];
1512
- x += dx;
1513
- dst += 2;
1514
- }
1515
- if (dst_width & 1) {
1516
- dst[0] = src[x >> 16];
1517
- }
1518
- }
1519
-
1520
- // Scales a single row of pixels up by 2x using point sampling.
1521
- void ScaleUVColsUp2_C(uint8_t* dst_uv,
1522
- const uint8_t* src_uv,
1523
- int dst_width,
1524
- int x,
1525
- int dx) {
1526
- const uint16_t* src = (const uint16_t*)(src_uv);
1527
- uint16_t* dst = (uint16_t*)(dst_uv);
1528
- int j;
1529
- (void)x;
1530
- (void)dx;
1531
- for (j = 0; j < dst_width - 1; j += 2) {
1532
- dst[1] = dst[0] = src[0];
1533
- src += 1;
1534
- dst += 2;
1535
- }
1536
- if (dst_width & 1) {
1537
- dst[0] = src[0];
1538
- }
1539
- }
1540
-
1541
- // TODO(fbarchard): Replace 0x7f ^ f with 128-f. bug=607.
1542
- // Mimics SSSE3 blender
1543
- #define BLENDER1(a, b, f) ((a) * (0x7f ^ f) + (b)*f) >> 7
1544
- #define BLENDERC(a, b, f, s) \
1545
- (uint16_t)(BLENDER1(((a) >> s) & 255, ((b) >> s) & 255, f) << s)
1546
- #define BLENDER(a, b, f) BLENDERC(a, b, f, 8) | BLENDERC(a, b, f, 0)
1547
-
1548
- void ScaleUVFilterCols_C(uint8_t* dst_uv,
1549
- const uint8_t* src_uv,
1550
- int dst_width,
1551
- int x,
1552
- int dx) {
1553
- const uint16_t* src = (const uint16_t*)(src_uv);
1554
- uint16_t* dst = (uint16_t*)(dst_uv);
1555
- int j;
1556
- for (j = 0; j < dst_width - 1; j += 2) {
1557
- int xi = x >> 16;
1558
- int xf = (x >> 9) & 0x7f;
1559
- uint16_t a = src[xi];
1560
- uint16_t b = src[xi + 1];
1561
- dst[0] = BLENDER(a, b, xf);
1562
- x += dx;
1563
- xi = x >> 16;
1564
- xf = (x >> 9) & 0x7f;
1565
- a = src[xi];
1566
- b = src[xi + 1];
1567
- dst[1] = BLENDER(a, b, xf);
1568
- x += dx;
1569
- dst += 2;
1570
- }
1571
- if (dst_width & 1) {
1572
- int xi = x >> 16;
1573
- int xf = (x >> 9) & 0x7f;
1574
- uint16_t a = src[xi];
1575
- uint16_t b = src[xi + 1];
1576
- dst[0] = BLENDER(a, b, xf);
1577
- }
1578
- }
1579
-
1580
- void ScaleUVFilterCols64_C(uint8_t* dst_uv,
1581
- const uint8_t* src_uv,
1582
- int dst_width,
1583
- int x32,
1584
- int dx) {
1585
- int64_t x = (int64_t)(x32);
1586
- const uint16_t* src = (const uint16_t*)(src_uv);
1587
- uint16_t* dst = (uint16_t*)(dst_uv);
1588
- int j;
1589
- for (j = 0; j < dst_width - 1; j += 2) {
1590
- int64_t xi = x >> 16;
1591
- int xf = (x >> 9) & 0x7f;
1592
- uint16_t a = src[xi];
1593
- uint16_t b = src[xi + 1];
1594
- dst[0] = BLENDER(a, b, xf);
1595
- x += dx;
1596
- xi = x >> 16;
1597
- xf = (x >> 9) & 0x7f;
1598
- a = src[xi];
1599
- b = src[xi + 1];
1600
- dst[1] = BLENDER(a, b, xf);
1601
- x += dx;
1602
- dst += 2;
1603
- }
1604
- if (dst_width & 1) {
1605
- int64_t xi = x >> 16;
1606
- int xf = (x >> 9) & 0x7f;
1607
- uint16_t a = src[xi];
1608
- uint16_t b = src[xi + 1];
1609
- dst[0] = BLENDER(a, b, xf);
1610
- }
1611
- }
1612
- #undef BLENDER1
1613
- #undef BLENDERC
1614
- #undef BLENDER
1615
-
1616
- // Scale plane vertically with bilinear interpolation.
1617
- void ScalePlaneVertical(int src_height,
1618
- int dst_width,
1619
- int dst_height,
1620
- int src_stride,
1621
- int dst_stride,
1622
- const uint8_t* src_argb,
1623
- uint8_t* dst_argb,
1624
- int x,
1625
- int y,
1626
- int dy,
1627
- int bpp, // bytes per pixel. 4 for ARGB.
1628
- enum FilterMode filtering) {
1629
- // TODO(fbarchard): Allow higher bpp.
1630
- int dst_width_bytes = dst_width * bpp;
1631
- void (*InterpolateRow)(uint8_t* dst_argb, const uint8_t* src_argb,
1632
- ptrdiff_t src_stride, int dst_width,
1633
- int source_y_fraction) = InterpolateRow_C;
1634
- const int max_y = (src_height > 1) ? ((src_height - 1) << 16) - 1 : 0;
1635
- int j;
1636
- assert(bpp >= 1 && bpp <= 4);
1637
- assert(src_height != 0);
1638
- assert(dst_width > 0);
1639
- assert(dst_height > 0);
1640
- src_argb += (x >> 16) * bpp;
1641
- #if defined(HAS_INTERPOLATEROW_SSSE3)
1642
- if (TestCpuFlag(kCpuHasSSSE3)) {
1643
- InterpolateRow = InterpolateRow_Any_SSSE3;
1644
- if (IS_ALIGNED(dst_width_bytes, 16)) {
1645
- InterpolateRow = InterpolateRow_SSSE3;
1646
- }
1647
- }
1648
- #endif
1649
- #if defined(HAS_INTERPOLATEROW_AVX2)
1650
- if (TestCpuFlag(kCpuHasAVX2)) {
1651
- InterpolateRow = InterpolateRow_Any_AVX2;
1652
- if (IS_ALIGNED(dst_width_bytes, 32)) {
1653
- InterpolateRow = InterpolateRow_AVX2;
1654
- }
1655
- }
1656
- #endif
1657
- #if defined(HAS_INTERPOLATEROW_NEON)
1658
- if (TestCpuFlag(kCpuHasNEON)) {
1659
- InterpolateRow = InterpolateRow_Any_NEON;
1660
- if (IS_ALIGNED(dst_width_bytes, 16)) {
1661
- InterpolateRow = InterpolateRow_NEON;
1662
- }
1663
- }
1664
- #endif
1665
- #if defined(HAS_INTERPOLATEROW_SME)
1666
- if (TestCpuFlag(kCpuHasSME)) {
1667
- InterpolateRow = InterpolateRow_SME;
1668
- }
1669
- #endif
1670
- #if defined(HAS_INTERPOLATEROW_LSX)
1671
- if (TestCpuFlag(kCpuHasLSX)) {
1672
- InterpolateRow = InterpolateRow_Any_LSX;
1673
- if (IS_ALIGNED(dst_width_bytes, 32)) {
1674
- InterpolateRow = InterpolateRow_LSX;
1675
- }
1676
- }
1677
- #endif
1678
- #if defined(HAS_INTERPOLATEROW_RVV)
1679
- if (TestCpuFlag(kCpuHasRVV)) {
1680
- InterpolateRow = InterpolateRow_RVV;
1681
- }
1682
- #endif
1683
-
1684
- for (j = 0; j < dst_height; ++j) {
1685
- int yi;
1686
- int yf;
1687
- if (y > max_y) {
1688
- y = max_y;
1689
- }
1690
- yi = y >> 16;
1691
- yf = filtering ? ((y >> 8) & 255) : 0;
1692
- InterpolateRow(dst_argb, src_argb + yi * src_stride, src_stride,
1693
- dst_width_bytes, yf);
1694
- dst_argb += dst_stride;
1695
- y += dy;
1696
- }
1697
- }
1698
-
1699
- void ScalePlaneVertical_16(int src_height,
1700
- int dst_width,
1701
- int dst_height,
1702
- int src_stride,
1703
- int dst_stride,
1704
- const uint16_t* src_argb,
1705
- uint16_t* dst_argb,
1706
- int x,
1707
- int y,
1708
- int dy,
1709
- int wpp, /* words per pixel. normally 1 */
1710
- enum FilterMode filtering) {
1711
- // TODO(fbarchard): Allow higher wpp.
1712
- int dst_width_words = dst_width * wpp;
1713
- void (*InterpolateRow)(uint16_t* dst_argb, const uint16_t* src_argb,
1714
- ptrdiff_t src_stride, int dst_width,
1715
- int source_y_fraction) = InterpolateRow_16_C;
1716
- const int max_y = (src_height > 1) ? ((src_height - 1) << 16) - 1 : 0;
1717
- int j;
1718
- assert(wpp >= 1 && wpp <= 2);
1719
- assert(src_height != 0);
1720
- assert(dst_width > 0);
1721
- assert(dst_height > 0);
1722
- src_argb += (x >> 16) * wpp;
1723
- #if defined(HAS_INTERPOLATEROW_16_SSE2)
1724
- if (TestCpuFlag(kCpuHasSSE2)) {
1725
- InterpolateRow = InterpolateRow_16_Any_SSE2;
1726
- if (IS_ALIGNED(dst_width_words, 16)) {
1727
- InterpolateRow = InterpolateRow_16_SSE2;
1728
- }
1729
- }
1730
- #endif
1731
- #if defined(HAS_INTERPOLATEROW_16_SSSE3)
1732
- if (TestCpuFlag(kCpuHasSSSE3)) {
1733
- InterpolateRow = InterpolateRow_16_Any_SSSE3;
1734
- if (IS_ALIGNED(dst_width_words, 16)) {
1735
- InterpolateRow = InterpolateRow_16_SSSE3;
1736
- }
1737
- }
1738
- #endif
1739
- #if defined(HAS_INTERPOLATEROW_16_AVX2)
1740
- if (TestCpuFlag(kCpuHasAVX2)) {
1741
- InterpolateRow = InterpolateRow_16_Any_AVX2;
1742
- if (IS_ALIGNED(dst_width_words, 32)) {
1743
- InterpolateRow = InterpolateRow_16_AVX2;
1744
- }
1745
- }
1746
- #endif
1747
- #if defined(HAS_INTERPOLATEROW_16_NEON)
1748
- if (TestCpuFlag(kCpuHasNEON)) {
1749
- InterpolateRow = InterpolateRow_16_Any_NEON;
1750
- if (IS_ALIGNED(dst_width_words, 8)) {
1751
- InterpolateRow = InterpolateRow_16_NEON;
1752
- }
1753
- }
1754
- #endif
1755
- #if defined(HAS_INTERPOLATEROW_16_SME)
1756
- if (TestCpuFlag(kCpuHasSME)) {
1757
- InterpolateRow = InterpolateRow_16_SME;
1758
- }
1759
- #endif
1760
- for (j = 0; j < dst_height; ++j) {
1761
- int yi;
1762
- int yf;
1763
- if (y > max_y) {
1764
- y = max_y;
1765
- }
1766
- yi = y >> 16;
1767
- yf = filtering ? ((y >> 8) & 255) : 0;
1768
- InterpolateRow(dst_argb, src_argb + yi * src_stride, src_stride,
1769
- dst_width_words, yf);
1770
- dst_argb += dst_stride;
1771
- y += dy;
1772
- }
1773
- }
1774
-
1775
- // Use scale to convert lsb formats to msb, depending how many bits there are:
1776
- // 32768 = 9 bits
1777
- // 16384 = 10 bits
1778
- // 4096 = 12 bits
1779
- // 256 = 16 bits
1780
- // TODO(fbarchard): change scale to bits
1781
- void ScalePlaneVertical_16To8(int src_height,
1782
- int dst_width,
1783
- int dst_height,
1784
- int src_stride,
1785
- int dst_stride,
1786
- const uint16_t* src_argb,
1787
- uint8_t* dst_argb,
1788
- int x,
1789
- int y,
1790
- int dy,
1791
- int wpp, /* words per pixel. normally 1 */
1792
- int scale,
1793
- enum FilterMode filtering) {
1794
- // TODO(fbarchard): Allow higher wpp.
1795
- int dst_width_words = dst_width * wpp;
1796
- // TODO(https://crbug.com/libyuv/931): Add NEON 32 bit and AVX2 versions.
1797
- void (*InterpolateRow_16To8)(uint8_t* dst_argb, const uint16_t* src_argb,
1798
- ptrdiff_t src_stride, int scale, int dst_width,
1799
- int source_y_fraction) = InterpolateRow_16To8_C;
1800
- const int max_y = (src_height > 1) ? ((src_height - 1) << 16) - 1 : 0;
1801
- int j;
1802
- assert(wpp >= 1 && wpp <= 2);
1803
- assert(src_height != 0);
1804
- assert(dst_width > 0);
1805
- assert(dst_height > 0);
1806
- src_argb += (x >> 16) * wpp;
1807
-
1808
- #if defined(HAS_INTERPOLATEROW_16TO8_NEON)
1809
- if (TestCpuFlag(kCpuHasNEON)) {
1810
- InterpolateRow_16To8 = InterpolateRow_16To8_Any_NEON;
1811
- if (IS_ALIGNED(dst_width, 8)) {
1812
- InterpolateRow_16To8 = InterpolateRow_16To8_NEON;
1813
- }
1814
- }
1815
- #endif
1816
- #if defined(HAS_INTERPOLATEROW_16TO8_SME)
1817
- if (TestCpuFlag(kCpuHasSME)) {
1818
- InterpolateRow_16To8 = InterpolateRow_16To8_SME;
1819
- }
1820
- #endif
1821
- #if defined(HAS_INTERPOLATEROW_16TO8_AVX2)
1822
- if (TestCpuFlag(kCpuHasAVX2)) {
1823
- InterpolateRow_16To8 = InterpolateRow_16To8_Any_AVX2;
1824
- if (IS_ALIGNED(dst_width, 32)) {
1825
- InterpolateRow_16To8 = InterpolateRow_16To8_AVX2;
1826
- }
1827
- }
1828
- #endif
1829
- for (j = 0; j < dst_height; ++j) {
1830
- int yi;
1831
- int yf;
1832
- if (y > max_y) {
1833
- y = max_y;
1834
- }
1835
- yi = y >> 16;
1836
- yf = filtering ? ((y >> 8) & 255) : 0;
1837
- InterpolateRow_16To8(dst_argb, src_argb + yi * src_stride, src_stride,
1838
- scale, dst_width_words, yf);
1839
- dst_argb += dst_stride;
1840
- y += dy;
1841
- }
1842
- }
1843
-
1844
- // Simplify the filtering based on scale factors.
1845
- enum FilterMode ScaleFilterReduce(int src_width,
1846
- int src_height,
1847
- int dst_width,
1848
- int dst_height,
1849
- enum FilterMode filtering) {
1850
- if (src_width < 0) {
1851
- src_width = -src_width;
1852
- }
1853
- if (src_height < 0) {
1854
- src_height = -src_height;
1855
- }
1856
- if (filtering == kFilterBox) {
1857
- // If scaling either axis to 0.5 or larger, switch from Box to Bilinear.
1858
- if (dst_width * 2 >= src_width || dst_height * 2 >= src_height) {
1859
- filtering = kFilterBilinear;
1860
- }
1861
- }
1862
- if (filtering == kFilterBilinear) {
1863
- if (src_height == 1) {
1864
- filtering = kFilterLinear;
1865
- }
1866
- // TODO(fbarchard): Detect any odd scale factor and reduce to Linear.
1867
- if (dst_height == src_height || dst_height * 3 == src_height) {
1868
- filtering = kFilterLinear;
1869
- }
1870
- // TODO(fbarchard): Remove 1 pixel wide filter restriction, which is to
1871
- // avoid reading 2 pixels horizontally that causes memory exception.
1872
- if (src_width == 1) {
1873
- filtering = kFilterNone;
1874
- }
1875
- }
1876
- if (filtering == kFilterLinear) {
1877
- if (src_width == 1) {
1878
- filtering = kFilterNone;
1879
- }
1880
- // TODO(fbarchard): Detect any odd scale factor and reduce to None.
1881
- if (dst_width == src_width || dst_width * 3 == src_width) {
1882
- filtering = kFilterNone;
1883
- }
1884
- }
1885
- return filtering;
1886
- }
1887
-
1888
- // Divide num by div and return as 16.16 fixed point result.
1889
- int FixedDiv_C(int num, int div) {
1890
- return (int)(((int64_t)(num) << 16) / div);
1891
- }
1892
-
1893
- // Divide num - 1 by div - 1 and return as 16.16 fixed point result.
1894
- int FixedDiv1_C(int num, int div) {
1895
- return (int)((((int64_t)(num) << 16) - 0x00010001) / (div - 1));
1896
- }
1897
-
1898
- #define CENTERSTART(dx, s) (dx < 0) ? -((-dx >> 1) + s) : ((dx >> 1) + s)
1899
-
1900
- // Compute slope values for stepping.
1901
- void ScaleSlope(int src_width,
1902
- int src_height,
1903
- int dst_width,
1904
- int dst_height,
1905
- enum FilterMode filtering,
1906
- int* x,
1907
- int* y,
1908
- int* dx,
1909
- int* dy) {
1910
- assert(x != NULL);
1911
- assert(y != NULL);
1912
- assert(dx != NULL);
1913
- assert(dy != NULL);
1914
- assert(src_width != 0);
1915
- assert(src_height != 0);
1916
- assert(dst_width > 0);
1917
- assert(dst_height > 0);
1918
- // Check for 1 pixel and avoid FixedDiv overflow.
1919
- if (dst_width == 1 && src_width >= 32768) {
1920
- dst_width = src_width;
1921
- }
1922
- if (dst_height == 1 && src_height >= 32768) {
1923
- dst_height = src_height;
1924
- }
1925
- if (filtering == kFilterBox) {
1926
- // Scale step for point sampling duplicates all pixels equally.
1927
- *dx = FixedDiv(Abs(src_width), dst_width);
1928
- *dy = FixedDiv(src_height, dst_height);
1929
- *x = 0;
1930
- *y = 0;
1931
- } else if (filtering == kFilterBilinear) {
1932
- // Scale step for bilinear sampling renders last pixel once for upsample.
1933
- if (dst_width <= Abs(src_width)) {
1934
- *dx = FixedDiv(Abs(src_width), dst_width);
1935
- *x = CENTERSTART(*dx, -32768); // Subtract 0.5 (32768) to center filter.
1936
- } else if (src_width > 1 && dst_width > 1) {
1937
- *dx = FixedDiv1(Abs(src_width), dst_width);
1938
- *x = 0;
1939
- }
1940
- if (dst_height <= src_height) {
1941
- *dy = FixedDiv(src_height, dst_height);
1942
- *y = CENTERSTART(*dy, -32768); // Subtract 0.5 (32768) to center filter.
1943
- } else if (src_height > 1 && dst_height > 1) {
1944
- *dy = FixedDiv1(src_height, dst_height);
1945
- *y = 0;
1946
- }
1947
- } else if (filtering == kFilterLinear) {
1948
- // Scale step for bilinear sampling renders last pixel once for upsample.
1949
- if (dst_width <= Abs(src_width)) {
1950
- *dx = FixedDiv(Abs(src_width), dst_width);
1951
- *x = CENTERSTART(*dx, -32768); // Subtract 0.5 (32768) to center filter.
1952
- } else if (src_width > 1 && dst_width > 1) {
1953
- *dx = FixedDiv1(Abs(src_width), dst_width);
1954
- *x = 0;
1955
- }
1956
- *dy = FixedDiv(src_height, dst_height);
1957
- *y = *dy >> 1;
1958
- } else {
1959
- // Scale step for point sampling duplicates all pixels equally.
1960
- *dx = FixedDiv(Abs(src_width), dst_width);
1961
- *dy = FixedDiv(src_height, dst_height);
1962
- *x = CENTERSTART(*dx, 0);
1963
- *y = CENTERSTART(*dy, 0);
1964
- }
1965
- // Negative src_width means horizontally mirror.
1966
- if (src_width < 0) {
1967
- *x += (dst_width - 1) * *dx;
1968
- *dx = -*dx;
1969
- // src_width = -src_width; // Caller must do this.
1970
- }
1971
- }
1972
- #undef CENTERSTART
1973
-
1974
- #ifdef __cplusplus
1975
- } // extern "C"
1976
- } // namespace libyuv
1977
- #endif
1
+ /*
2
+ * Copyright 2013 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 <string.h>
15
+
16
+ #include "libyuv/cpu_id.h"
17
+ #include "libyuv/planar_functions.h" // For CopyARGB
18
+ #include "libyuv/row.h"
19
+ #include "libyuv/scale_row.h"
20
+
21
+ #ifdef __cplusplus
22
+ namespace libyuv {
23
+ extern "C" {
24
+ #endif
25
+
26
+ #ifdef __cplusplus
27
+ #define STATIC_CAST(type, expr) static_cast<type>(expr)
28
+ #else
29
+ #define STATIC_CAST(type, expr) (type)(expr)
30
+ #endif
31
+
32
+ // TODO(fbarchard): make clamp255 preserve negative values.
33
+ static __inline int32_t clamp255(int32_t v) {
34
+ return (-(v >= 255) | v) & 255;
35
+ }
36
+
37
+ // Use scale to convert lsb formats to msb, depending how many bits there are:
38
+ // 32768 = 9 bits
39
+ // 16384 = 10 bits
40
+ // 4096 = 12 bits
41
+ // 256 = 16 bits
42
+ // TODO(fbarchard): change scale to bits
43
+ #define C16TO8(v, scale) clamp255(((v) * (scale)) >> 16)
44
+
45
+ static __inline int Abs(int v) {
46
+ return v >= 0 ? v : -v;
47
+ }
48
+
49
+ // CPU agnostic row functions
50
+ void ScaleRowDown2_C(const uint8_t* src_ptr,
51
+ ptrdiff_t src_stride,
52
+ uint8_t* dst,
53
+ int dst_width) {
54
+ int x;
55
+ (void)src_stride;
56
+ for (x = 0; x < dst_width - 1; x += 2) {
57
+ dst[0] = src_ptr[1];
58
+ dst[1] = src_ptr[3];
59
+ dst += 2;
60
+ src_ptr += 4;
61
+ }
62
+ if (dst_width & 1) {
63
+ dst[0] = src_ptr[1];
64
+ }
65
+ }
66
+
67
+ void ScaleRowDown2_16_C(const uint16_t* src_ptr,
68
+ ptrdiff_t src_stride,
69
+ uint16_t* dst,
70
+ int dst_width) {
71
+ int x;
72
+ (void)src_stride;
73
+ for (x = 0; x < dst_width - 1; x += 2) {
74
+ dst[0] = src_ptr[1];
75
+ dst[1] = src_ptr[3];
76
+ dst += 2;
77
+ src_ptr += 4;
78
+ }
79
+ if (dst_width & 1) {
80
+ dst[0] = src_ptr[1];
81
+ }
82
+ }
83
+
84
+ void ScaleRowDown2_16To8_C(const uint16_t* src_ptr,
85
+ ptrdiff_t src_stride,
86
+ uint8_t* dst,
87
+ int dst_width,
88
+ int scale) {
89
+ int x;
90
+ (void)src_stride;
91
+ assert(scale >= 256);
92
+ assert(scale <= 32768);
93
+ for (x = 0; x < dst_width - 1; x += 2) {
94
+ dst[0] = STATIC_CAST(uint8_t, C16TO8(src_ptr[1], scale));
95
+ dst[1] = STATIC_CAST(uint8_t, C16TO8(src_ptr[3], scale));
96
+ dst += 2;
97
+ src_ptr += 4;
98
+ }
99
+ if (dst_width & 1) {
100
+ dst[0] = STATIC_CAST(uint8_t, C16TO8(src_ptr[1], scale));
101
+ }
102
+ }
103
+
104
+ void ScaleRowDown2_16To8_Odd_C(const uint16_t* src_ptr,
105
+ ptrdiff_t src_stride,
106
+ uint8_t* dst,
107
+ int dst_width,
108
+ int scale) {
109
+ int x;
110
+ (void)src_stride;
111
+ assert(scale >= 256);
112
+ assert(scale <= 32768);
113
+ dst_width -= 1;
114
+ for (x = 0; x < dst_width - 1; x += 2) {
115
+ dst[0] = STATIC_CAST(uint8_t, C16TO8(src_ptr[1], scale));
116
+ dst[1] = STATIC_CAST(uint8_t, C16TO8(src_ptr[3], scale));
117
+ dst += 2;
118
+ src_ptr += 4;
119
+ }
120
+ if (dst_width & 1) {
121
+ dst[0] = STATIC_CAST(uint8_t, C16TO8(src_ptr[1], scale));
122
+ dst += 1;
123
+ src_ptr += 2;
124
+ }
125
+ dst[0] = STATIC_CAST(uint8_t, C16TO8(src_ptr[0], scale));
126
+ }
127
+
128
+ void ScaleRowDown2Linear_C(const uint8_t* src_ptr,
129
+ ptrdiff_t src_stride,
130
+ uint8_t* dst,
131
+ int dst_width) {
132
+ const uint8_t* s = src_ptr;
133
+ int x;
134
+ (void)src_stride;
135
+ for (x = 0; x < dst_width - 1; x += 2) {
136
+ dst[0] = (s[0] + s[1] + 1) >> 1;
137
+ dst[1] = (s[2] + s[3] + 1) >> 1;
138
+ dst += 2;
139
+ s += 4;
140
+ }
141
+ if (dst_width & 1) {
142
+ dst[0] = (s[0] + s[1] + 1) >> 1;
143
+ }
144
+ }
145
+
146
+ void ScaleRowDown2Linear_16_C(const uint16_t* src_ptr,
147
+ ptrdiff_t src_stride,
148
+ uint16_t* dst,
149
+ int dst_width) {
150
+ const uint16_t* s = src_ptr;
151
+ int x;
152
+ (void)src_stride;
153
+ for (x = 0; x < dst_width - 1; x += 2) {
154
+ dst[0] = (s[0] + s[1] + 1) >> 1;
155
+ dst[1] = (s[2] + s[3] + 1) >> 1;
156
+ dst += 2;
157
+ s += 4;
158
+ }
159
+ if (dst_width & 1) {
160
+ dst[0] = (s[0] + s[1] + 1) >> 1;
161
+ }
162
+ }
163
+
164
+ void ScaleRowDown2Linear_16To8_C(const uint16_t* src_ptr,
165
+ ptrdiff_t src_stride,
166
+ uint8_t* dst,
167
+ int dst_width,
168
+ int scale) {
169
+ const uint16_t* s = src_ptr;
170
+ int x;
171
+ (void)src_stride;
172
+ assert(scale >= 256);
173
+ assert(scale <= 32768);
174
+ for (x = 0; x < dst_width - 1; x += 2) {
175
+ dst[0] = STATIC_CAST(uint8_t, C16TO8((s[0] + s[1] + 1) >> 1, scale));
176
+ dst[1] = STATIC_CAST(uint8_t, C16TO8((s[2] + s[3] + 1) >> 1, scale));
177
+ dst += 2;
178
+ s += 4;
179
+ }
180
+ if (dst_width & 1) {
181
+ dst[0] = STATIC_CAST(uint8_t, C16TO8((s[0] + s[1] + 1) >> 1, scale));
182
+ }
183
+ }
184
+
185
+ void ScaleRowDown2Linear_16To8_Odd_C(const uint16_t* src_ptr,
186
+ ptrdiff_t src_stride,
187
+ uint8_t* dst,
188
+ int dst_width,
189
+ int scale) {
190
+ const uint16_t* s = src_ptr;
191
+ int x;
192
+ (void)src_stride;
193
+ assert(scale >= 256);
194
+ assert(scale <= 32768);
195
+ dst_width -= 1;
196
+ for (x = 0; x < dst_width - 1; x += 2) {
197
+ dst[0] = STATIC_CAST(uint8_t, C16TO8((s[0] + s[1] + 1) >> 1, scale));
198
+ dst[1] = STATIC_CAST(uint8_t, C16TO8((s[2] + s[3] + 1) >> 1, scale));
199
+ dst += 2;
200
+ s += 4;
201
+ }
202
+ if (dst_width & 1) {
203
+ dst[0] = STATIC_CAST(uint8_t, C16TO8((s[0] + s[1] + 1) >> 1, scale));
204
+ dst += 1;
205
+ s += 2;
206
+ }
207
+ dst[0] = STATIC_CAST(uint8_t, C16TO8(s[0], scale));
208
+ }
209
+
210
+ void ScaleRowDown2Box_C(const uint8_t* src_ptr,
211
+ ptrdiff_t src_stride,
212
+ uint8_t* dst,
213
+ int dst_width) {
214
+ const uint8_t* s = src_ptr;
215
+ const uint8_t* t = src_ptr + src_stride;
216
+ int x;
217
+ for (x = 0; x < dst_width - 1; x += 2) {
218
+ dst[0] = (s[0] + s[1] + t[0] + t[1] + 2) >> 2;
219
+ dst[1] = (s[2] + s[3] + t[2] + t[3] + 2) >> 2;
220
+ dst += 2;
221
+ s += 4;
222
+ t += 4;
223
+ }
224
+ if (dst_width & 1) {
225
+ dst[0] = (s[0] + s[1] + t[0] + t[1] + 2) >> 2;
226
+ }
227
+ }
228
+
229
+ void ScaleRowDown2Box_Odd_C(const uint8_t* src_ptr,
230
+ ptrdiff_t src_stride,
231
+ uint8_t* dst,
232
+ int dst_width) {
233
+ const uint8_t* s = src_ptr;
234
+ const uint8_t* t = src_ptr + src_stride;
235
+ int x;
236
+ dst_width -= 1;
237
+ for (x = 0; x < dst_width - 1; x += 2) {
238
+ dst[0] = (s[0] + s[1] + t[0] + t[1] + 2) >> 2;
239
+ dst[1] = (s[2] + s[3] + t[2] + t[3] + 2) >> 2;
240
+ dst += 2;
241
+ s += 4;
242
+ t += 4;
243
+ }
244
+ if (dst_width & 1) {
245
+ dst[0] = (s[0] + s[1] + t[0] + t[1] + 2) >> 2;
246
+ dst += 1;
247
+ s += 2;
248
+ t += 2;
249
+ }
250
+ dst[0] = (s[0] + t[0] + 1) >> 1;
251
+ }
252
+
253
+ void ScaleRowDown2Box_16_C(const uint16_t* src_ptr,
254
+ ptrdiff_t src_stride,
255
+ uint16_t* dst,
256
+ int dst_width) {
257
+ const uint16_t* s = src_ptr;
258
+ const uint16_t* t = src_ptr + src_stride;
259
+ int x;
260
+ for (x = 0; x < dst_width - 1; x += 2) {
261
+ dst[0] = (s[0] + s[1] + t[0] + t[1] + 2) >> 2;
262
+ dst[1] = (s[2] + s[3] + t[2] + t[3] + 2) >> 2;
263
+ dst += 2;
264
+ s += 4;
265
+ t += 4;
266
+ }
267
+ if (dst_width & 1) {
268
+ dst[0] = (s[0] + s[1] + t[0] + t[1] + 2) >> 2;
269
+ }
270
+ }
271
+
272
+ void ScaleRowDown2Box_16To8_C(const uint16_t* src_ptr,
273
+ ptrdiff_t src_stride,
274
+ uint8_t* dst,
275
+ int dst_width,
276
+ int scale) {
277
+ const uint16_t* s = src_ptr;
278
+ const uint16_t* t = src_ptr + src_stride;
279
+ int x;
280
+ assert(scale >= 256);
281
+ assert(scale <= 32768);
282
+ for (x = 0; x < dst_width - 1; x += 2) {
283
+ dst[0] = STATIC_CAST(uint8_t,
284
+ C16TO8((s[0] + s[1] + t[0] + t[1] + 2) >> 2, scale));
285
+ dst[1] = STATIC_CAST(uint8_t,
286
+ C16TO8((s[2] + s[3] + t[2] + t[3] + 2) >> 2, scale));
287
+ dst += 2;
288
+ s += 4;
289
+ t += 4;
290
+ }
291
+ if (dst_width & 1) {
292
+ dst[0] = STATIC_CAST(uint8_t,
293
+ C16TO8((s[0] + s[1] + t[0] + t[1] + 2) >> 2, scale));
294
+ }
295
+ }
296
+
297
+ void ScaleRowDown2Box_16To8_Odd_C(const uint16_t* src_ptr,
298
+ ptrdiff_t src_stride,
299
+ uint8_t* dst,
300
+ int dst_width,
301
+ int scale) {
302
+ const uint16_t* s = src_ptr;
303
+ const uint16_t* t = src_ptr + src_stride;
304
+ int x;
305
+ assert(scale >= 256);
306
+ assert(scale <= 32768);
307
+ dst_width -= 1;
308
+ for (x = 0; x < dst_width - 1; x += 2) {
309
+ dst[0] = STATIC_CAST(uint8_t,
310
+ C16TO8((s[0] + s[1] + t[0] + t[1] + 2) >> 2, scale));
311
+ dst[1] = STATIC_CAST(uint8_t,
312
+ C16TO8((s[2] + s[3] + t[2] + t[3] + 2) >> 2, scale));
313
+ dst += 2;
314
+ s += 4;
315
+ t += 4;
316
+ }
317
+ if (dst_width & 1) {
318
+ dst[0] = STATIC_CAST(uint8_t,
319
+ C16TO8((s[0] + s[1] + t[0] + t[1] + 2) >> 2, scale));
320
+ dst += 1;
321
+ s += 2;
322
+ t += 2;
323
+ }
324
+ dst[0] = STATIC_CAST(uint8_t, C16TO8((s[0] + t[0] + 1) >> 1, scale));
325
+ }
326
+
327
+ void ScaleRowDown4_C(const uint8_t* src_ptr,
328
+ ptrdiff_t src_stride,
329
+ uint8_t* dst,
330
+ int dst_width) {
331
+ int x;
332
+ (void)src_stride;
333
+ for (x = 0; x < dst_width - 1; x += 2) {
334
+ dst[0] = src_ptr[2];
335
+ dst[1] = src_ptr[6];
336
+ dst += 2;
337
+ src_ptr += 8;
338
+ }
339
+ if (dst_width & 1) {
340
+ dst[0] = src_ptr[2];
341
+ }
342
+ }
343
+
344
+ void ScaleRowDown4_16_C(const uint16_t* src_ptr,
345
+ ptrdiff_t src_stride,
346
+ uint16_t* dst,
347
+ int dst_width) {
348
+ int x;
349
+ (void)src_stride;
350
+ for (x = 0; x < dst_width - 1; x += 2) {
351
+ dst[0] = src_ptr[2];
352
+ dst[1] = src_ptr[6];
353
+ dst += 2;
354
+ src_ptr += 8;
355
+ }
356
+ if (dst_width & 1) {
357
+ dst[0] = src_ptr[2];
358
+ }
359
+ }
360
+
361
+ void ScaleRowDown4Box_C(const uint8_t* src_ptr,
362
+ ptrdiff_t src_stride,
363
+ uint8_t* dst,
364
+ int dst_width) {
365
+ intptr_t stride = src_stride;
366
+ int x;
367
+ for (x = 0; x < dst_width - 1; x += 2) {
368
+ dst[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[3] +
369
+ src_ptr[stride + 0] + src_ptr[stride + 1] + src_ptr[stride + 2] +
370
+ src_ptr[stride + 3] + src_ptr[stride * 2 + 0] +
371
+ src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2] +
372
+ src_ptr[stride * 2 + 3] + src_ptr[stride * 3 + 0] +
373
+ src_ptr[stride * 3 + 1] + src_ptr[stride * 3 + 2] +
374
+ src_ptr[stride * 3 + 3] + 8) >>
375
+ 4;
376
+ dst[1] = (src_ptr[4] + src_ptr[5] + src_ptr[6] + src_ptr[7] +
377
+ src_ptr[stride + 4] + src_ptr[stride + 5] + src_ptr[stride + 6] +
378
+ src_ptr[stride + 7] + src_ptr[stride * 2 + 4] +
379
+ src_ptr[stride * 2 + 5] + src_ptr[stride * 2 + 6] +
380
+ src_ptr[stride * 2 + 7] + src_ptr[stride * 3 + 4] +
381
+ src_ptr[stride * 3 + 5] + src_ptr[stride * 3 + 6] +
382
+ src_ptr[stride * 3 + 7] + 8) >>
383
+ 4;
384
+ dst += 2;
385
+ src_ptr += 8;
386
+ }
387
+ if (dst_width & 1) {
388
+ dst[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[3] +
389
+ src_ptr[stride + 0] + src_ptr[stride + 1] + src_ptr[stride + 2] +
390
+ src_ptr[stride + 3] + src_ptr[stride * 2 + 0] +
391
+ src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2] +
392
+ src_ptr[stride * 2 + 3] + src_ptr[stride * 3 + 0] +
393
+ src_ptr[stride * 3 + 1] + src_ptr[stride * 3 + 2] +
394
+ src_ptr[stride * 3 + 3] + 8) >>
395
+ 4;
396
+ }
397
+ }
398
+
399
+ void ScaleRowDown4Box_16_C(const uint16_t* src_ptr,
400
+ ptrdiff_t src_stride,
401
+ uint16_t* dst,
402
+ int dst_width) {
403
+ intptr_t stride = src_stride;
404
+ int x;
405
+ for (x = 0; x < dst_width - 1; x += 2) {
406
+ dst[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[3] +
407
+ src_ptr[stride + 0] + src_ptr[stride + 1] + src_ptr[stride + 2] +
408
+ src_ptr[stride + 3] + src_ptr[stride * 2 + 0] +
409
+ src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2] +
410
+ src_ptr[stride * 2 + 3] + src_ptr[stride * 3 + 0] +
411
+ src_ptr[stride * 3 + 1] + src_ptr[stride * 3 + 2] +
412
+ src_ptr[stride * 3 + 3] + 8) >>
413
+ 4;
414
+ dst[1] = (src_ptr[4] + src_ptr[5] + src_ptr[6] + src_ptr[7] +
415
+ src_ptr[stride + 4] + src_ptr[stride + 5] + src_ptr[stride + 6] +
416
+ src_ptr[stride + 7] + src_ptr[stride * 2 + 4] +
417
+ src_ptr[stride * 2 + 5] + src_ptr[stride * 2 + 6] +
418
+ src_ptr[stride * 2 + 7] + src_ptr[stride * 3 + 4] +
419
+ src_ptr[stride * 3 + 5] + src_ptr[stride * 3 + 6] +
420
+ src_ptr[stride * 3 + 7] + 8) >>
421
+ 4;
422
+ dst += 2;
423
+ src_ptr += 8;
424
+ }
425
+ if (dst_width & 1) {
426
+ dst[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[3] +
427
+ src_ptr[stride + 0] + src_ptr[stride + 1] + src_ptr[stride + 2] +
428
+ src_ptr[stride + 3] + src_ptr[stride * 2 + 0] +
429
+ src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2] +
430
+ src_ptr[stride * 2 + 3] + src_ptr[stride * 3 + 0] +
431
+ src_ptr[stride * 3 + 1] + src_ptr[stride * 3 + 2] +
432
+ src_ptr[stride * 3 + 3] + 8) >>
433
+ 4;
434
+ }
435
+ }
436
+
437
+ void ScaleRowDown34_C(const uint8_t* src_ptr,
438
+ ptrdiff_t src_stride,
439
+ uint8_t* dst,
440
+ int dst_width) {
441
+ int x;
442
+ (void)src_stride;
443
+ assert((dst_width % 3 == 0) && (dst_width > 0));
444
+ for (x = 0; x < dst_width; x += 3) {
445
+ dst[0] = src_ptr[0];
446
+ dst[1] = src_ptr[1];
447
+ dst[2] = src_ptr[3];
448
+ dst += 3;
449
+ src_ptr += 4;
450
+ }
451
+ }
452
+
453
+ void ScaleRowDown34_16_C(const uint16_t* src_ptr,
454
+ ptrdiff_t src_stride,
455
+ uint16_t* dst,
456
+ int dst_width) {
457
+ int x;
458
+ (void)src_stride;
459
+ assert((dst_width % 3 == 0) && (dst_width > 0));
460
+ for (x = 0; x < dst_width; x += 3) {
461
+ dst[0] = src_ptr[0];
462
+ dst[1] = src_ptr[1];
463
+ dst[2] = src_ptr[3];
464
+ dst += 3;
465
+ src_ptr += 4;
466
+ }
467
+ }
468
+
469
+ // Filter rows 0 and 1 together, 3 : 1
470
+ void ScaleRowDown34_0_Box_C(const uint8_t* src_ptr,
471
+ ptrdiff_t src_stride,
472
+ uint8_t* d,
473
+ int dst_width) {
474
+ const uint8_t* s = src_ptr;
475
+ const uint8_t* t = src_ptr + src_stride;
476
+ int x;
477
+ assert((dst_width % 3 == 0) && (dst_width > 0));
478
+ for (x = 0; x < dst_width; x += 3) {
479
+ uint8_t a0 = (s[0] * 3 + s[1] * 1 + 2) >> 2;
480
+ uint8_t a1 = (s[1] * 1 + s[2] * 1 + 1) >> 1;
481
+ uint8_t a2 = (s[2] * 1 + s[3] * 3 + 2) >> 2;
482
+ uint8_t b0 = (t[0] * 3 + t[1] * 1 + 2) >> 2;
483
+ uint8_t b1 = (t[1] * 1 + t[2] * 1 + 1) >> 1;
484
+ uint8_t b2 = (t[2] * 1 + t[3] * 3 + 2) >> 2;
485
+ d[0] = (a0 * 3 + b0 + 2) >> 2;
486
+ d[1] = (a1 * 3 + b1 + 2) >> 2;
487
+ d[2] = (a2 * 3 + b2 + 2) >> 2;
488
+ d += 3;
489
+ s += 4;
490
+ t += 4;
491
+ }
492
+ }
493
+
494
+ void ScaleRowDown34_0_Box_16_C(const uint16_t* src_ptr,
495
+ ptrdiff_t src_stride,
496
+ uint16_t* d,
497
+ int dst_width) {
498
+ const uint16_t* s = src_ptr;
499
+ const uint16_t* t = src_ptr + src_stride;
500
+ int x;
501
+ assert((dst_width % 3 == 0) && (dst_width > 0));
502
+ for (x = 0; x < dst_width; x += 3) {
503
+ uint16_t a0 = (s[0] * 3 + s[1] * 1 + 2) >> 2;
504
+ uint16_t a1 = (s[1] * 1 + s[2] * 1 + 1) >> 1;
505
+ uint16_t a2 = (s[2] * 1 + s[3] * 3 + 2) >> 2;
506
+ uint16_t b0 = (t[0] * 3 + t[1] * 1 + 2) >> 2;
507
+ uint16_t b1 = (t[1] * 1 + t[2] * 1 + 1) >> 1;
508
+ uint16_t b2 = (t[2] * 1 + t[3] * 3 + 2) >> 2;
509
+ d[0] = (a0 * 3 + b0 + 2) >> 2;
510
+ d[1] = (a1 * 3 + b1 + 2) >> 2;
511
+ d[2] = (a2 * 3 + b2 + 2) >> 2;
512
+ d += 3;
513
+ s += 4;
514
+ t += 4;
515
+ }
516
+ }
517
+
518
+ // Filter rows 1 and 2 together, 1 : 1
519
+ void ScaleRowDown34_1_Box_C(const uint8_t* src_ptr,
520
+ ptrdiff_t src_stride,
521
+ uint8_t* d,
522
+ int dst_width) {
523
+ const uint8_t* s = src_ptr;
524
+ const uint8_t* t = src_ptr + src_stride;
525
+ int x;
526
+ assert((dst_width % 3 == 0) && (dst_width > 0));
527
+ for (x = 0; x < dst_width; x += 3) {
528
+ uint8_t a0 = (s[0] * 3 + s[1] * 1 + 2) >> 2;
529
+ uint8_t a1 = (s[1] * 1 + s[2] * 1 + 1) >> 1;
530
+ uint8_t a2 = (s[2] * 1 + s[3] * 3 + 2) >> 2;
531
+ uint8_t b0 = (t[0] * 3 + t[1] * 1 + 2) >> 2;
532
+ uint8_t b1 = (t[1] * 1 + t[2] * 1 + 1) >> 1;
533
+ uint8_t b2 = (t[2] * 1 + t[3] * 3 + 2) >> 2;
534
+ d[0] = (a0 + b0 + 1) >> 1;
535
+ d[1] = (a1 + b1 + 1) >> 1;
536
+ d[2] = (a2 + b2 + 1) >> 1;
537
+ d += 3;
538
+ s += 4;
539
+ t += 4;
540
+ }
541
+ }
542
+
543
+ void ScaleRowDown34_1_Box_16_C(const uint16_t* src_ptr,
544
+ ptrdiff_t src_stride,
545
+ uint16_t* d,
546
+ int dst_width) {
547
+ const uint16_t* s = src_ptr;
548
+ const uint16_t* t = src_ptr + src_stride;
549
+ int x;
550
+ assert((dst_width % 3 == 0) && (dst_width > 0));
551
+ for (x = 0; x < dst_width; x += 3) {
552
+ uint16_t a0 = (s[0] * 3 + s[1] * 1 + 2) >> 2;
553
+ uint16_t a1 = (s[1] * 1 + s[2] * 1 + 1) >> 1;
554
+ uint16_t a2 = (s[2] * 1 + s[3] * 3 + 2) >> 2;
555
+ uint16_t b0 = (t[0] * 3 + t[1] * 1 + 2) >> 2;
556
+ uint16_t b1 = (t[1] * 1 + t[2] * 1 + 1) >> 1;
557
+ uint16_t b2 = (t[2] * 1 + t[3] * 3 + 2) >> 2;
558
+ d[0] = (a0 + b0 + 1) >> 1;
559
+ d[1] = (a1 + b1 + 1) >> 1;
560
+ d[2] = (a2 + b2 + 1) >> 1;
561
+ d += 3;
562
+ s += 4;
563
+ t += 4;
564
+ }
565
+ }
566
+
567
+ // Sample position: (O is src sample position, X is dst sample position)
568
+ //
569
+ // v dst_ptr at here v stop at here
570
+ // X O X X O X X O X X O X X O X
571
+ // ^ src_ptr at here
572
+ void ScaleRowUp2_Linear_C(const uint8_t* src_ptr,
573
+ uint8_t* dst_ptr,
574
+ int dst_width) {
575
+ int src_width = dst_width >> 1;
576
+ int x;
577
+ assert((dst_width % 2 == 0) && (dst_width >= 0));
578
+ for (x = 0; x < src_width; ++x) {
579
+ dst_ptr[2 * x + 0] = (src_ptr[x + 0] * 3 + src_ptr[x + 1] * 1 + 2) >> 2;
580
+ dst_ptr[2 * x + 1] = (src_ptr[x + 0] * 1 + src_ptr[x + 1] * 3 + 2) >> 2;
581
+ }
582
+ }
583
+
584
+ // Sample position: (O is src sample position, X is dst sample position)
585
+ //
586
+ // src_ptr at here
587
+ // X v X X X X X X X X X
588
+ // O O O O O
589
+ // X X X X X X X X X X
590
+ // ^ dst_ptr at here ^ stop at here
591
+ // X X X X X X X X X X
592
+ // O O O O O
593
+ // X X X X X X X X X X
594
+ void ScaleRowUp2_Bilinear_C(const uint8_t* src_ptr,
595
+ ptrdiff_t src_stride,
596
+ uint8_t* dst_ptr,
597
+ ptrdiff_t dst_stride,
598
+ int dst_width) {
599
+ const uint8_t* s = src_ptr;
600
+ const uint8_t* t = src_ptr + src_stride;
601
+ uint8_t* d = dst_ptr;
602
+ uint8_t* e = dst_ptr + dst_stride;
603
+ int src_width = dst_width >> 1;
604
+ int x;
605
+ assert((dst_width % 2 == 0) && (dst_width >= 0));
606
+ for (x = 0; x < src_width; ++x) {
607
+ d[2 * x + 0] =
608
+ (s[x + 0] * 9 + s[x + 1] * 3 + t[x + 0] * 3 + t[x + 1] * 1 + 8) >> 4;
609
+ d[2 * x + 1] =
610
+ (s[x + 0] * 3 + s[x + 1] * 9 + t[x + 0] * 1 + t[x + 1] * 3 + 8) >> 4;
611
+ e[2 * x + 0] =
612
+ (s[x + 0] * 3 + s[x + 1] * 1 + t[x + 0] * 9 + t[x + 1] * 3 + 8) >> 4;
613
+ e[2 * x + 1] =
614
+ (s[x + 0] * 1 + s[x + 1] * 3 + t[x + 0] * 3 + t[x + 1] * 9 + 8) >> 4;
615
+ }
616
+ }
617
+
618
+ // Only suitable for at most 14 bit range.
619
+ void ScaleRowUp2_Linear_16_C(const uint16_t* src_ptr,
620
+ uint16_t* dst_ptr,
621
+ int dst_width) {
622
+ int src_width = dst_width >> 1;
623
+ int x;
624
+ assert((dst_width % 2 == 0) && (dst_width >= 0));
625
+ for (x = 0; x < src_width; ++x) {
626
+ dst_ptr[2 * x + 0] = (src_ptr[x + 0] * 3 + src_ptr[x + 1] * 1 + 2) >> 2;
627
+ dst_ptr[2 * x + 1] = (src_ptr[x + 0] * 1 + src_ptr[x + 1] * 3 + 2) >> 2;
628
+ }
629
+ }
630
+
631
+ // Only suitable for at most 12bit range.
632
+ void ScaleRowUp2_Bilinear_16_C(const uint16_t* src_ptr,
633
+ ptrdiff_t src_stride,
634
+ uint16_t* dst_ptr,
635
+ ptrdiff_t dst_stride,
636
+ int dst_width) {
637
+ const uint16_t* s = src_ptr;
638
+ const uint16_t* t = src_ptr + src_stride;
639
+ uint16_t* d = dst_ptr;
640
+ uint16_t* e = dst_ptr + dst_stride;
641
+ int src_width = dst_width >> 1;
642
+ int x;
643
+ assert((dst_width % 2 == 0) && (dst_width >= 0));
644
+ for (x = 0; x < src_width; ++x) {
645
+ d[2 * x + 0] =
646
+ (s[x + 0] * 9 + s[x + 1] * 3 + t[x + 0] * 3 + t[x + 1] * 1 + 8) >> 4;
647
+ d[2 * x + 1] =
648
+ (s[x + 0] * 3 + s[x + 1] * 9 + t[x + 0] * 1 + t[x + 1] * 3 + 8) >> 4;
649
+ e[2 * x + 0] =
650
+ (s[x + 0] * 3 + s[x + 1] * 1 + t[x + 0] * 9 + t[x + 1] * 3 + 8) >> 4;
651
+ e[2 * x + 1] =
652
+ (s[x + 0] * 1 + s[x + 1] * 3 + t[x + 0] * 3 + t[x + 1] * 9 + 8) >> 4;
653
+ }
654
+ }
655
+
656
+ // Scales a single row of pixels using point sampling.
657
+ void ScaleCols_C(uint8_t* dst_ptr,
658
+ const uint8_t* src_ptr,
659
+ int dst_width,
660
+ int x,
661
+ int dx) {
662
+ int j;
663
+ for (j = 0; j < dst_width - 1; j += 2) {
664
+ dst_ptr[0] = src_ptr[x >> 16];
665
+ x += dx;
666
+ dst_ptr[1] = src_ptr[x >> 16];
667
+ x += dx;
668
+ dst_ptr += 2;
669
+ }
670
+ if (dst_width & 1) {
671
+ dst_ptr[0] = src_ptr[x >> 16];
672
+ }
673
+ }
674
+
675
+ void ScaleCols_16_C(uint16_t* dst_ptr,
676
+ const uint16_t* src_ptr,
677
+ int dst_width,
678
+ int x,
679
+ int dx) {
680
+ int j;
681
+ for (j = 0; j < dst_width - 1; j += 2) {
682
+ dst_ptr[0] = src_ptr[x >> 16];
683
+ x += dx;
684
+ dst_ptr[1] = src_ptr[x >> 16];
685
+ x += dx;
686
+ dst_ptr += 2;
687
+ }
688
+ if (dst_width & 1) {
689
+ dst_ptr[0] = src_ptr[x >> 16];
690
+ }
691
+ }
692
+
693
+ // Scales a single row of pixels up by 2x using point sampling.
694
+ void ScaleColsUp2_C(uint8_t* dst_ptr,
695
+ const uint8_t* src_ptr,
696
+ int dst_width,
697
+ int x,
698
+ int dx) {
699
+ int j;
700
+ (void)x;
701
+ (void)dx;
702
+ for (j = 0; j < dst_width - 1; j += 2) {
703
+ dst_ptr[1] = dst_ptr[0] = src_ptr[0];
704
+ src_ptr += 1;
705
+ dst_ptr += 2;
706
+ }
707
+ if (dst_width & 1) {
708
+ dst_ptr[0] = src_ptr[0];
709
+ }
710
+ }
711
+
712
+ void ScaleColsUp2_16_C(uint16_t* dst_ptr,
713
+ const uint16_t* src_ptr,
714
+ int dst_width,
715
+ int x,
716
+ int dx) {
717
+ int j;
718
+ (void)x;
719
+ (void)dx;
720
+ for (j = 0; j < dst_width - 1; j += 2) {
721
+ dst_ptr[1] = dst_ptr[0] = src_ptr[0];
722
+ src_ptr += 1;
723
+ dst_ptr += 2;
724
+ }
725
+ if (dst_width & 1) {
726
+ dst_ptr[0] = src_ptr[0];
727
+ }
728
+ }
729
+
730
+ // (1-f)a + fb can be replaced with a + f(b-a)
731
+ #if defined(__arm__) || defined(__aarch64__)
732
+ #define BLENDER(a, b, f) \
733
+ (uint8_t)((int)(a) + ((((int)((f)) * ((int)(b) - (int)(a))) + 0x8000) >> 16))
734
+ #else
735
+ // Intel uses 7 bit math with rounding.
736
+ #define BLENDER(a, b, f) \
737
+ (uint8_t)((int)(a) + (((int)((f) >> 9) * ((int)(b) - (int)(a)) + 0x40) >> 7))
738
+ #endif
739
+
740
+ void ScaleFilterCols_C(uint8_t* dst_ptr,
741
+ const uint8_t* src_ptr,
742
+ int dst_width,
743
+ int x,
744
+ int dx) {
745
+ int j;
746
+ for (j = 0; j < dst_width - 1; j += 2) {
747
+ int xi = x >> 16;
748
+ int a = src_ptr[xi];
749
+ int b = src_ptr[xi + 1];
750
+ dst_ptr[0] = BLENDER(a, b, x & 0xffff);
751
+ x += dx;
752
+ xi = x >> 16;
753
+ a = src_ptr[xi];
754
+ b = src_ptr[xi + 1];
755
+ dst_ptr[1] = BLENDER(a, b, x & 0xffff);
756
+ x += dx;
757
+ dst_ptr += 2;
758
+ }
759
+ if (dst_width & 1) {
760
+ int xi = x >> 16;
761
+ int a = src_ptr[xi];
762
+ int b = src_ptr[xi + 1];
763
+ dst_ptr[0] = BLENDER(a, b, x & 0xffff);
764
+ }
765
+ }
766
+
767
+ void ScaleFilterCols64_C(uint8_t* dst_ptr,
768
+ const uint8_t* src_ptr,
769
+ int dst_width,
770
+ int x32,
771
+ int dx) {
772
+ int64_t x = (int64_t)(x32);
773
+ int j;
774
+ for (j = 0; j < dst_width - 1; j += 2) {
775
+ int64_t xi = x >> 16;
776
+ int a = src_ptr[xi];
777
+ int b = src_ptr[xi + 1];
778
+ dst_ptr[0] = BLENDER(a, b, x & 0xffff);
779
+ x += dx;
780
+ xi = x >> 16;
781
+ a = src_ptr[xi];
782
+ b = src_ptr[xi + 1];
783
+ dst_ptr[1] = BLENDER(a, b, x & 0xffff);
784
+ x += dx;
785
+ dst_ptr += 2;
786
+ }
787
+ if (dst_width & 1) {
788
+ int64_t xi = x >> 16;
789
+ int a = src_ptr[xi];
790
+ int b = src_ptr[xi + 1];
791
+ dst_ptr[0] = BLENDER(a, b, x & 0xffff);
792
+ }
793
+ }
794
+ #undef BLENDER
795
+
796
+ // Same as 8 bit arm blender but return is cast to uint16_t
797
+ #define BLENDER(a, b, f) \
798
+ (uint16_t)( \
799
+ (int)(a) + \
800
+ (int)((((int64_t)((f)) * ((int64_t)(b) - (int)(a))) + 0x8000) >> 16))
801
+
802
+ void ScaleFilterCols_16_C(uint16_t* dst_ptr,
803
+ const uint16_t* src_ptr,
804
+ int dst_width,
805
+ int x,
806
+ int dx) {
807
+ int j;
808
+ for (j = 0; j < dst_width - 1; j += 2) {
809
+ int xi = x >> 16;
810
+ int a = src_ptr[xi];
811
+ int b = src_ptr[xi + 1];
812
+ dst_ptr[0] = BLENDER(a, b, x & 0xffff);
813
+ x += dx;
814
+ xi = x >> 16;
815
+ a = src_ptr[xi];
816
+ b = src_ptr[xi + 1];
817
+ dst_ptr[1] = BLENDER(a, b, x & 0xffff);
818
+ x += dx;
819
+ dst_ptr += 2;
820
+ }
821
+ if (dst_width & 1) {
822
+ int xi = x >> 16;
823
+ int a = src_ptr[xi];
824
+ int b = src_ptr[xi + 1];
825
+ dst_ptr[0] = BLENDER(a, b, x & 0xffff);
826
+ }
827
+ }
828
+
829
+ void ScaleFilterCols64_16_C(uint16_t* dst_ptr,
830
+ const uint16_t* src_ptr,
831
+ int dst_width,
832
+ int x32,
833
+ int dx) {
834
+ int64_t x = (int64_t)(x32);
835
+ int j;
836
+ for (j = 0; j < dst_width - 1; j += 2) {
837
+ int64_t xi = x >> 16;
838
+ int a = src_ptr[xi];
839
+ int b = src_ptr[xi + 1];
840
+ dst_ptr[0] = BLENDER(a, b, x & 0xffff);
841
+ x += dx;
842
+ xi = x >> 16;
843
+ a = src_ptr[xi];
844
+ b = src_ptr[xi + 1];
845
+ dst_ptr[1] = BLENDER(a, b, x & 0xffff);
846
+ x += dx;
847
+ dst_ptr += 2;
848
+ }
849
+ if (dst_width & 1) {
850
+ int64_t xi = x >> 16;
851
+ int a = src_ptr[xi];
852
+ int b = src_ptr[xi + 1];
853
+ dst_ptr[0] = BLENDER(a, b, x & 0xffff);
854
+ }
855
+ }
856
+ #undef BLENDER
857
+
858
+ void ScaleRowDown38_C(const uint8_t* src_ptr,
859
+ ptrdiff_t src_stride,
860
+ uint8_t* dst,
861
+ int dst_width) {
862
+ int x;
863
+ (void)src_stride;
864
+ assert(dst_width % 3 == 0);
865
+ for (x = 0; x < dst_width; x += 3) {
866
+ dst[0] = src_ptr[0];
867
+ dst[1] = src_ptr[3];
868
+ dst[2] = src_ptr[6];
869
+ dst += 3;
870
+ src_ptr += 8;
871
+ }
872
+ }
873
+
874
+ void ScaleRowDown38_16_C(const uint16_t* src_ptr,
875
+ ptrdiff_t src_stride,
876
+ uint16_t* dst,
877
+ int dst_width) {
878
+ int x;
879
+ (void)src_stride;
880
+ assert(dst_width % 3 == 0);
881
+ for (x = 0; x < dst_width; x += 3) {
882
+ dst[0] = src_ptr[0];
883
+ dst[1] = src_ptr[3];
884
+ dst[2] = src_ptr[6];
885
+ dst += 3;
886
+ src_ptr += 8;
887
+ }
888
+ }
889
+
890
+ // 8x3 -> 3x1
891
+ void ScaleRowDown38_3_Box_C(const uint8_t* src_ptr,
892
+ ptrdiff_t src_stride,
893
+ uint8_t* dst_ptr,
894
+ int dst_width) {
895
+ intptr_t stride = src_stride;
896
+ int i;
897
+ assert((dst_width % 3 == 0) && (dst_width > 0));
898
+ for (i = 0; i < dst_width; i += 3) {
899
+ dst_ptr[0] =
900
+ (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[stride + 0] +
901
+ src_ptr[stride + 1] + src_ptr[stride + 2] + src_ptr[stride * 2 + 0] +
902
+ src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2]) *
903
+ (65536 / 9) >>
904
+ 16;
905
+ dst_ptr[1] =
906
+ (src_ptr[3] + src_ptr[4] + src_ptr[5] + src_ptr[stride + 3] +
907
+ src_ptr[stride + 4] + src_ptr[stride + 5] + src_ptr[stride * 2 + 3] +
908
+ src_ptr[stride * 2 + 4] + src_ptr[stride * 2 + 5]) *
909
+ (65536 / 9) >>
910
+ 16;
911
+ dst_ptr[2] =
912
+ (src_ptr[6] + src_ptr[7] + src_ptr[stride + 6] + src_ptr[stride + 7] +
913
+ src_ptr[stride * 2 + 6] + src_ptr[stride * 2 + 7]) *
914
+ (65536 / 6) >>
915
+ 16;
916
+ src_ptr += 8;
917
+ dst_ptr += 3;
918
+ }
919
+ }
920
+
921
+ void ScaleRowDown38_3_Box_16_C(const uint16_t* src_ptr,
922
+ ptrdiff_t src_stride,
923
+ uint16_t* dst_ptr,
924
+ int dst_width) {
925
+ intptr_t stride = src_stride;
926
+ int i;
927
+ assert((dst_width % 3 == 0) && (dst_width > 0));
928
+ for (i = 0; i < dst_width; i += 3) {
929
+ dst_ptr[0] =
930
+ (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[stride + 0] +
931
+ src_ptr[stride + 1] + src_ptr[stride + 2] + src_ptr[stride * 2 + 0] +
932
+ src_ptr[stride * 2 + 1] + src_ptr[stride * 2 + 2]) *
933
+ (65536u / 9u) >>
934
+ 16;
935
+ dst_ptr[1] =
936
+ (src_ptr[3] + src_ptr[4] + src_ptr[5] + src_ptr[stride + 3] +
937
+ src_ptr[stride + 4] + src_ptr[stride + 5] + src_ptr[stride * 2 + 3] +
938
+ src_ptr[stride * 2 + 4] + src_ptr[stride * 2 + 5]) *
939
+ (65536u / 9u) >>
940
+ 16;
941
+ dst_ptr[2] =
942
+ (src_ptr[6] + src_ptr[7] + src_ptr[stride + 6] + src_ptr[stride + 7] +
943
+ src_ptr[stride * 2 + 6] + src_ptr[stride * 2 + 7]) *
944
+ (65536u / 6u) >>
945
+ 16;
946
+ src_ptr += 8;
947
+ dst_ptr += 3;
948
+ }
949
+ }
950
+
951
+ // 8x2 -> 3x1
952
+ void ScaleRowDown38_2_Box_C(const uint8_t* src_ptr,
953
+ ptrdiff_t src_stride,
954
+ uint8_t* dst_ptr,
955
+ int dst_width) {
956
+ intptr_t stride = src_stride;
957
+ int i;
958
+ assert((dst_width % 3 == 0) && (dst_width > 0));
959
+ for (i = 0; i < dst_width; i += 3) {
960
+ dst_ptr[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[stride + 0] +
961
+ src_ptr[stride + 1] + src_ptr[stride + 2]) *
962
+ (65536 / 6) >>
963
+ 16;
964
+ dst_ptr[1] = (src_ptr[3] + src_ptr[4] + src_ptr[5] + src_ptr[stride + 3] +
965
+ src_ptr[stride + 4] + src_ptr[stride + 5]) *
966
+ (65536 / 6) >>
967
+ 16;
968
+ dst_ptr[2] =
969
+ (src_ptr[6] + src_ptr[7] + src_ptr[stride + 6] + src_ptr[stride + 7]) *
970
+ (65536 / 4) >>
971
+ 16;
972
+ src_ptr += 8;
973
+ dst_ptr += 3;
974
+ }
975
+ }
976
+
977
+ void ScaleRowDown38_2_Box_16_C(const uint16_t* src_ptr,
978
+ ptrdiff_t src_stride,
979
+ uint16_t* dst_ptr,
980
+ int dst_width) {
981
+ intptr_t stride = src_stride;
982
+ int i;
983
+ assert((dst_width % 3 == 0) && (dst_width > 0));
984
+ for (i = 0; i < dst_width; i += 3) {
985
+ dst_ptr[0] = (src_ptr[0] + src_ptr[1] + src_ptr[2] + src_ptr[stride + 0] +
986
+ src_ptr[stride + 1] + src_ptr[stride + 2]) *
987
+ (65536u / 6u) >>
988
+ 16;
989
+ dst_ptr[1] = (src_ptr[3] + src_ptr[4] + src_ptr[5] + src_ptr[stride + 3] +
990
+ src_ptr[stride + 4] + src_ptr[stride + 5]) *
991
+ (65536u / 6u) >>
992
+ 16;
993
+ dst_ptr[2] =
994
+ (src_ptr[6] + src_ptr[7] + src_ptr[stride + 6] + src_ptr[stride + 7]) *
995
+ (65536u / 4u) >>
996
+ 16;
997
+ src_ptr += 8;
998
+ dst_ptr += 3;
999
+ }
1000
+ }
1001
+
1002
+ void ScaleAddRow_C(const uint8_t* src_ptr, uint16_t* dst_ptr, int src_width) {
1003
+ int x;
1004
+ assert(src_width > 0);
1005
+ for (x = 0; x < src_width - 1; x += 2) {
1006
+ dst_ptr[0] += src_ptr[0];
1007
+ dst_ptr[1] += src_ptr[1];
1008
+ src_ptr += 2;
1009
+ dst_ptr += 2;
1010
+ }
1011
+ if (src_width & 1) {
1012
+ dst_ptr[0] += src_ptr[0];
1013
+ }
1014
+ }
1015
+
1016
+ void ScaleAddRow_16_C(const uint16_t* src_ptr,
1017
+ uint32_t* dst_ptr,
1018
+ int src_width) {
1019
+ int x;
1020
+ assert(src_width > 0);
1021
+ for (x = 0; x < src_width - 1; x += 2) {
1022
+ dst_ptr[0] += src_ptr[0];
1023
+ dst_ptr[1] += src_ptr[1];
1024
+ src_ptr += 2;
1025
+ dst_ptr += 2;
1026
+ }
1027
+ if (src_width & 1) {
1028
+ dst_ptr[0] += src_ptr[0];
1029
+ }
1030
+ }
1031
+
1032
+ // ARGB scale row functions
1033
+
1034
+ void ScaleARGBRowDown2_C(const uint8_t* src_argb,
1035
+ ptrdiff_t src_stride,
1036
+ uint8_t* dst_argb,
1037
+ int dst_width) {
1038
+ const uint32_t* src = (const uint32_t*)(src_argb);
1039
+ uint32_t* dst = (uint32_t*)(dst_argb);
1040
+ int x;
1041
+ (void)src_stride;
1042
+ for (x = 0; x < dst_width - 1; x += 2) {
1043
+ dst[0] = src[1];
1044
+ dst[1] = src[3];
1045
+ src += 4;
1046
+ dst += 2;
1047
+ }
1048
+ if (dst_width & 1) {
1049
+ dst[0] = src[1];
1050
+ }
1051
+ }
1052
+
1053
+ void ScaleARGBRowDown2Linear_C(const uint8_t* src_argb,
1054
+ ptrdiff_t src_stride,
1055
+ uint8_t* dst_argb,
1056
+ int dst_width) {
1057
+ int x;
1058
+ (void)src_stride;
1059
+ for (x = 0; x < dst_width; ++x) {
1060
+ dst_argb[0] = (src_argb[0] + src_argb[4] + 1) >> 1;
1061
+ dst_argb[1] = (src_argb[1] + src_argb[5] + 1) >> 1;
1062
+ dst_argb[2] = (src_argb[2] + src_argb[6] + 1) >> 1;
1063
+ dst_argb[3] = (src_argb[3] + src_argb[7] + 1) >> 1;
1064
+ src_argb += 8;
1065
+ dst_argb += 4;
1066
+ }
1067
+ }
1068
+
1069
+ void ScaleARGBRowDown2Box_C(const uint8_t* src_argb,
1070
+ ptrdiff_t src_stride,
1071
+ uint8_t* dst_argb,
1072
+ int dst_width) {
1073
+ int x;
1074
+ for (x = 0; x < dst_width; ++x) {
1075
+ dst_argb[0] = (src_argb[0] + src_argb[4] + src_argb[src_stride] +
1076
+ src_argb[src_stride + 4] + 2) >>
1077
+ 2;
1078
+ dst_argb[1] = (src_argb[1] + src_argb[5] + src_argb[src_stride + 1] +
1079
+ src_argb[src_stride + 5] + 2) >>
1080
+ 2;
1081
+ dst_argb[2] = (src_argb[2] + src_argb[6] + src_argb[src_stride + 2] +
1082
+ src_argb[src_stride + 6] + 2) >>
1083
+ 2;
1084
+ dst_argb[3] = (src_argb[3] + src_argb[7] + src_argb[src_stride + 3] +
1085
+ src_argb[src_stride + 7] + 2) >>
1086
+ 2;
1087
+ src_argb += 8;
1088
+ dst_argb += 4;
1089
+ }
1090
+ }
1091
+
1092
+ void ScaleARGBRowDownEven_C(const uint8_t* src_argb,
1093
+ ptrdiff_t src_stride,
1094
+ int src_stepx,
1095
+ uint8_t* dst_argb,
1096
+ int dst_width) {
1097
+ const uint32_t* src = (const uint32_t*)(src_argb);
1098
+ uint32_t* dst = (uint32_t*)(dst_argb);
1099
+ (void)src_stride;
1100
+ int x;
1101
+ for (x = 0; x < dst_width - 1; x += 2) {
1102
+ dst[0] = src[0];
1103
+ dst[1] = src[src_stepx];
1104
+ src += src_stepx * 2;
1105
+ dst += 2;
1106
+ }
1107
+ if (dst_width & 1) {
1108
+ dst[0] = src[0];
1109
+ }
1110
+ }
1111
+
1112
+ void ScaleARGBRowDownEvenBox_C(const uint8_t* src_argb,
1113
+ ptrdiff_t src_stride,
1114
+ int src_stepx,
1115
+ uint8_t* dst_argb,
1116
+ int dst_width) {
1117
+ int x;
1118
+ for (x = 0; x < dst_width; ++x) {
1119
+ dst_argb[0] = (src_argb[0] + src_argb[4] + src_argb[src_stride] +
1120
+ src_argb[src_stride + 4] + 2) >>
1121
+ 2;
1122
+ dst_argb[1] = (src_argb[1] + src_argb[5] + src_argb[src_stride + 1] +
1123
+ src_argb[src_stride + 5] + 2) >>
1124
+ 2;
1125
+ dst_argb[2] = (src_argb[2] + src_argb[6] + src_argb[src_stride + 2] +
1126
+ src_argb[src_stride + 6] + 2) >>
1127
+ 2;
1128
+ dst_argb[3] = (src_argb[3] + src_argb[7] + src_argb[src_stride + 3] +
1129
+ src_argb[src_stride + 7] + 2) >>
1130
+ 2;
1131
+ src_argb += src_stepx * 4;
1132
+ dst_argb += 4;
1133
+ }
1134
+ }
1135
+
1136
+ // Scales a single row of pixels using point sampling.
1137
+ void ScaleARGBCols_C(uint8_t* dst_argb,
1138
+ const uint8_t* src_argb,
1139
+ int dst_width,
1140
+ int x,
1141
+ int dx) {
1142
+ const uint32_t* src = (const uint32_t*)(src_argb);
1143
+ uint32_t* dst = (uint32_t*)(dst_argb);
1144
+ int j;
1145
+ for (j = 0; j < dst_width - 1; j += 2) {
1146
+ dst[0] = src[x >> 16];
1147
+ x += dx;
1148
+ dst[1] = src[x >> 16];
1149
+ x += dx;
1150
+ dst += 2;
1151
+ }
1152
+ if (dst_width & 1) {
1153
+ dst[0] = src[x >> 16];
1154
+ }
1155
+ }
1156
+
1157
+ void ScaleARGBCols64_C(uint8_t* dst_argb,
1158
+ const uint8_t* src_argb,
1159
+ int dst_width,
1160
+ int x32,
1161
+ int dx) {
1162
+ int64_t x = (int64_t)(x32);
1163
+ const uint32_t* src = (const uint32_t*)(src_argb);
1164
+ uint32_t* dst = (uint32_t*)(dst_argb);
1165
+ int j;
1166
+ for (j = 0; j < dst_width - 1; j += 2) {
1167
+ dst[0] = src[x >> 16];
1168
+ x += dx;
1169
+ dst[1] = src[x >> 16];
1170
+ x += dx;
1171
+ dst += 2;
1172
+ }
1173
+ if (dst_width & 1) {
1174
+ dst[0] = src[x >> 16];
1175
+ }
1176
+ }
1177
+
1178
+ // Scales a single row of pixels up by 2x using point sampling.
1179
+ void ScaleARGBColsUp2_C(uint8_t* dst_argb,
1180
+ const uint8_t* src_argb,
1181
+ int dst_width,
1182
+ int x,
1183
+ int dx) {
1184
+ const uint32_t* src = (const uint32_t*)(src_argb);
1185
+ uint32_t* dst = (uint32_t*)(dst_argb);
1186
+ int j;
1187
+ (void)x;
1188
+ (void)dx;
1189
+ for (j = 0; j < dst_width - 1; j += 2) {
1190
+ dst[1] = dst[0] = src[0];
1191
+ src += 1;
1192
+ dst += 2;
1193
+ }
1194
+ if (dst_width & 1) {
1195
+ dst[0] = src[0];
1196
+ }
1197
+ }
1198
+
1199
+ // TODO(fbarchard): Replace 0x7f ^ f with 128-f. bug=607.
1200
+ // Mimics SSSE3 blender
1201
+ #define BLENDER1(a, b, f) ((a) * (0x7f ^ f) + (b)*f) >> 7
1202
+ #define BLENDERC(a, b, f, s) \
1203
+ (uint32_t)(BLENDER1(((a) >> s) & 255, ((b) >> s) & 255, f) << s)
1204
+ #define BLENDER(a, b, f) \
1205
+ BLENDERC(a, b, f, 24) | BLENDERC(a, b, f, 16) | BLENDERC(a, b, f, 8) | \
1206
+ BLENDERC(a, b, f, 0)
1207
+
1208
+ void ScaleARGBFilterCols_C(uint8_t* dst_argb,
1209
+ const uint8_t* src_argb,
1210
+ int dst_width,
1211
+ int x,
1212
+ int dx) {
1213
+ const uint32_t* src = (const uint32_t*)(src_argb);
1214
+ uint32_t* dst = (uint32_t*)(dst_argb);
1215
+ int j;
1216
+ for (j = 0; j < dst_width - 1; j += 2) {
1217
+ int xi = x >> 16;
1218
+ int xf = (x >> 9) & 0x7f;
1219
+ uint32_t a = src[xi];
1220
+ uint32_t b = src[xi + 1];
1221
+ dst[0] = BLENDER(a, b, xf);
1222
+ x += dx;
1223
+ xi = x >> 16;
1224
+ xf = (x >> 9) & 0x7f;
1225
+ a = src[xi];
1226
+ b = src[xi + 1];
1227
+ dst[1] = BLENDER(a, b, xf);
1228
+ x += dx;
1229
+ dst += 2;
1230
+ }
1231
+ if (dst_width & 1) {
1232
+ int xi = x >> 16;
1233
+ int xf = (x >> 9) & 0x7f;
1234
+ uint32_t a = src[xi];
1235
+ uint32_t b = src[xi + 1];
1236
+ dst[0] = BLENDER(a, b, xf);
1237
+ }
1238
+ }
1239
+
1240
+ void ScaleARGBFilterCols64_C(uint8_t* dst_argb,
1241
+ const uint8_t* src_argb,
1242
+ int dst_width,
1243
+ int x32,
1244
+ int dx) {
1245
+ int64_t x = (int64_t)(x32);
1246
+ const uint32_t* src = (const uint32_t*)(src_argb);
1247
+ uint32_t* dst = (uint32_t*)(dst_argb);
1248
+ int j;
1249
+ for (j = 0; j < dst_width - 1; j += 2) {
1250
+ int64_t xi = x >> 16;
1251
+ int xf = (x >> 9) & 0x7f;
1252
+ uint32_t a = src[xi];
1253
+ uint32_t b = src[xi + 1];
1254
+ dst[0] = BLENDER(a, b, xf);
1255
+ x += dx;
1256
+ xi = x >> 16;
1257
+ xf = (x >> 9) & 0x7f;
1258
+ a = src[xi];
1259
+ b = src[xi + 1];
1260
+ dst[1] = BLENDER(a, b, xf);
1261
+ x += dx;
1262
+ dst += 2;
1263
+ }
1264
+ if (dst_width & 1) {
1265
+ int64_t xi = x >> 16;
1266
+ int xf = (x >> 9) & 0x7f;
1267
+ uint32_t a = src[xi];
1268
+ uint32_t b = src[xi + 1];
1269
+ dst[0] = BLENDER(a, b, xf);
1270
+ }
1271
+ }
1272
+ #undef BLENDER1
1273
+ #undef BLENDERC
1274
+ #undef BLENDER
1275
+
1276
+ // UV scale row functions
1277
+ // same as ARGB but 2 channels
1278
+
1279
+ void ScaleUVRowDown2_C(const uint8_t* src_uv,
1280
+ ptrdiff_t src_stride,
1281
+ uint8_t* dst_uv,
1282
+ int dst_width) {
1283
+ int x;
1284
+ (void)src_stride;
1285
+ for (x = 0; x < dst_width; ++x) {
1286
+ dst_uv[0] = src_uv[2]; // Store the 2nd UV
1287
+ dst_uv[1] = src_uv[3];
1288
+ src_uv += 4;
1289
+ dst_uv += 2;
1290
+ }
1291
+ }
1292
+
1293
+ void ScaleUVRowDown2Linear_C(const uint8_t* src_uv,
1294
+ ptrdiff_t src_stride,
1295
+ uint8_t* dst_uv,
1296
+ int dst_width) {
1297
+ int x;
1298
+ (void)src_stride;
1299
+ for (x = 0; x < dst_width; ++x) {
1300
+ dst_uv[0] = (src_uv[0] + src_uv[2] + 1) >> 1;
1301
+ dst_uv[1] = (src_uv[1] + src_uv[3] + 1) >> 1;
1302
+ src_uv += 4;
1303
+ dst_uv += 2;
1304
+ }
1305
+ }
1306
+
1307
+ void ScaleUVRowDown2Box_C(const uint8_t* src_uv,
1308
+ ptrdiff_t src_stride,
1309
+ uint8_t* dst_uv,
1310
+ int dst_width) {
1311
+ int x;
1312
+ for (x = 0; x < dst_width; ++x) {
1313
+ dst_uv[0] = (src_uv[0] + src_uv[2] + src_uv[src_stride] +
1314
+ src_uv[src_stride + 2] + 2) >>
1315
+ 2;
1316
+ dst_uv[1] = (src_uv[1] + src_uv[3] + src_uv[src_stride + 1] +
1317
+ src_uv[src_stride + 3] + 2) >>
1318
+ 2;
1319
+ src_uv += 4;
1320
+ dst_uv += 2;
1321
+ }
1322
+ }
1323
+
1324
+ void ScaleUVRowDownEven_C(const uint8_t* src_uv,
1325
+ ptrdiff_t src_stride,
1326
+ int src_stepx,
1327
+ uint8_t* dst_uv,
1328
+ int dst_width) {
1329
+ const uint16_t* src = (const uint16_t*)(src_uv);
1330
+ uint16_t* dst = (uint16_t*)(dst_uv);
1331
+ (void)src_stride;
1332
+ int x;
1333
+ for (x = 0; x < dst_width - 1; x += 2) {
1334
+ dst[0] = src[0];
1335
+ dst[1] = src[src_stepx];
1336
+ src += src_stepx * 2;
1337
+ dst += 2;
1338
+ }
1339
+ if (dst_width & 1) {
1340
+ dst[0] = src[0];
1341
+ }
1342
+ }
1343
+
1344
+ void ScaleUVRowDownEvenBox_C(const uint8_t* src_uv,
1345
+ ptrdiff_t src_stride,
1346
+ int src_stepx,
1347
+ uint8_t* dst_uv,
1348
+ int dst_width) {
1349
+ int x;
1350
+ for (x = 0; x < dst_width; ++x) {
1351
+ dst_uv[0] = (src_uv[0] + src_uv[2] + src_uv[src_stride] +
1352
+ src_uv[src_stride + 2] + 2) >>
1353
+ 2;
1354
+ dst_uv[1] = (src_uv[1] + src_uv[3] + src_uv[src_stride + 1] +
1355
+ src_uv[src_stride + 3] + 2) >>
1356
+ 2;
1357
+ src_uv += src_stepx * 2;
1358
+ dst_uv += 2;
1359
+ }
1360
+ }
1361
+
1362
+ void ScaleUVRowUp2_Linear_C(const uint8_t* src_ptr,
1363
+ uint8_t* dst_ptr,
1364
+ int dst_width) {
1365
+ int src_width = dst_width >> 1;
1366
+ int x;
1367
+ assert((dst_width % 2 == 0) && (dst_width >= 0));
1368
+ for (x = 0; x < src_width; ++x) {
1369
+ dst_ptr[4 * x + 0] =
1370
+ (src_ptr[2 * x + 0] * 3 + src_ptr[2 * x + 2] * 1 + 2) >> 2;
1371
+ dst_ptr[4 * x + 1] =
1372
+ (src_ptr[2 * x + 1] * 3 + src_ptr[2 * x + 3] * 1 + 2) >> 2;
1373
+ dst_ptr[4 * x + 2] =
1374
+ (src_ptr[2 * x + 0] * 1 + src_ptr[2 * x + 2] * 3 + 2) >> 2;
1375
+ dst_ptr[4 * x + 3] =
1376
+ (src_ptr[2 * x + 1] * 1 + src_ptr[2 * x + 3] * 3 + 2) >> 2;
1377
+ }
1378
+ }
1379
+
1380
+ void ScaleUVRowUp2_Bilinear_C(const uint8_t* src_ptr,
1381
+ ptrdiff_t src_stride,
1382
+ uint8_t* dst_ptr,
1383
+ ptrdiff_t dst_stride,
1384
+ int dst_width) {
1385
+ const uint8_t* s = src_ptr;
1386
+ const uint8_t* t = src_ptr + src_stride;
1387
+ uint8_t* d = dst_ptr;
1388
+ uint8_t* e = dst_ptr + dst_stride;
1389
+ int src_width = dst_width >> 1;
1390
+ int x;
1391
+ assert((dst_width % 2 == 0) && (dst_width >= 0));
1392
+ for (x = 0; x < src_width; ++x) {
1393
+ d[4 * x + 0] = (s[2 * x + 0] * 9 + s[2 * x + 2] * 3 + t[2 * x + 0] * 3 +
1394
+ t[2 * x + 2] * 1 + 8) >>
1395
+ 4;
1396
+ d[4 * x + 1] = (s[2 * x + 1] * 9 + s[2 * x + 3] * 3 + t[2 * x + 1] * 3 +
1397
+ t[2 * x + 3] * 1 + 8) >>
1398
+ 4;
1399
+ d[4 * x + 2] = (s[2 * x + 0] * 3 + s[2 * x + 2] * 9 + t[2 * x + 0] * 1 +
1400
+ t[2 * x + 2] * 3 + 8) >>
1401
+ 4;
1402
+ d[4 * x + 3] = (s[2 * x + 1] * 3 + s[2 * x + 3] * 9 + t[2 * x + 1] * 1 +
1403
+ t[2 * x + 3] * 3 + 8) >>
1404
+ 4;
1405
+ e[4 * x + 0] = (s[2 * x + 0] * 3 + s[2 * x + 2] * 1 + t[2 * x + 0] * 9 +
1406
+ t[2 * x + 2] * 3 + 8) >>
1407
+ 4;
1408
+ e[4 * x + 1] = (s[2 * x + 1] * 3 + s[2 * x + 3] * 1 + t[2 * x + 1] * 9 +
1409
+ t[2 * x + 3] * 3 + 8) >>
1410
+ 4;
1411
+ e[4 * x + 2] = (s[2 * x + 0] * 1 + s[2 * x + 2] * 3 + t[2 * x + 0] * 3 +
1412
+ t[2 * x + 2] * 9 + 8) >>
1413
+ 4;
1414
+ e[4 * x + 3] = (s[2 * x + 1] * 1 + s[2 * x + 3] * 3 + t[2 * x + 1] * 3 +
1415
+ t[2 * x + 3] * 9 + 8) >>
1416
+ 4;
1417
+ }
1418
+ }
1419
+
1420
+ void ScaleUVRowUp2_Linear_16_C(const uint16_t* src_ptr,
1421
+ uint16_t* dst_ptr,
1422
+ int dst_width) {
1423
+ int src_width = dst_width >> 1;
1424
+ int x;
1425
+ assert((dst_width % 2 == 0) && (dst_width >= 0));
1426
+ for (x = 0; x < src_width; ++x) {
1427
+ dst_ptr[4 * x + 0] =
1428
+ (src_ptr[2 * x + 0] * 3 + src_ptr[2 * x + 2] * 1 + 2) >> 2;
1429
+ dst_ptr[4 * x + 1] =
1430
+ (src_ptr[2 * x + 1] * 3 + src_ptr[2 * x + 3] * 1 + 2) >> 2;
1431
+ dst_ptr[4 * x + 2] =
1432
+ (src_ptr[2 * x + 0] * 1 + src_ptr[2 * x + 2] * 3 + 2) >> 2;
1433
+ dst_ptr[4 * x + 3] =
1434
+ (src_ptr[2 * x + 1] * 1 + src_ptr[2 * x + 3] * 3 + 2) >> 2;
1435
+ }
1436
+ }
1437
+
1438
+ void ScaleUVRowUp2_Bilinear_16_C(const uint16_t* src_ptr,
1439
+ ptrdiff_t src_stride,
1440
+ uint16_t* dst_ptr,
1441
+ ptrdiff_t dst_stride,
1442
+ int dst_width) {
1443
+ const uint16_t* s = src_ptr;
1444
+ const uint16_t* t = src_ptr + src_stride;
1445
+ uint16_t* d = dst_ptr;
1446
+ uint16_t* e = dst_ptr + dst_stride;
1447
+ int src_width = dst_width >> 1;
1448
+ int x;
1449
+ assert((dst_width % 2 == 0) && (dst_width >= 0));
1450
+ for (x = 0; x < src_width; ++x) {
1451
+ d[4 * x + 0] = (s[2 * x + 0] * 9 + s[2 * x + 2] * 3 + t[2 * x + 0] * 3 +
1452
+ t[2 * x + 2] * 1 + 8) >>
1453
+ 4;
1454
+ d[4 * x + 1] = (s[2 * x + 1] * 9 + s[2 * x + 3] * 3 + t[2 * x + 1] * 3 +
1455
+ t[2 * x + 3] * 1 + 8) >>
1456
+ 4;
1457
+ d[4 * x + 2] = (s[2 * x + 0] * 3 + s[2 * x + 2] * 9 + t[2 * x + 0] * 1 +
1458
+ t[2 * x + 2] * 3 + 8) >>
1459
+ 4;
1460
+ d[4 * x + 3] = (s[2 * x + 1] * 3 + s[2 * x + 3] * 9 + t[2 * x + 1] * 1 +
1461
+ t[2 * x + 3] * 3 + 8) >>
1462
+ 4;
1463
+ e[4 * x + 0] = (s[2 * x + 0] * 3 + s[2 * x + 2] * 1 + t[2 * x + 0] * 9 +
1464
+ t[2 * x + 2] * 3 + 8) >>
1465
+ 4;
1466
+ e[4 * x + 1] = (s[2 * x + 1] * 3 + s[2 * x + 3] * 1 + t[2 * x + 1] * 9 +
1467
+ t[2 * x + 3] * 3 + 8) >>
1468
+ 4;
1469
+ e[4 * x + 2] = (s[2 * x + 0] * 1 + s[2 * x + 2] * 3 + t[2 * x + 0] * 3 +
1470
+ t[2 * x + 2] * 9 + 8) >>
1471
+ 4;
1472
+ e[4 * x + 3] = (s[2 * x + 1] * 1 + s[2 * x + 3] * 3 + t[2 * x + 1] * 3 +
1473
+ t[2 * x + 3] * 9 + 8) >>
1474
+ 4;
1475
+ }
1476
+ }
1477
+
1478
+ // Scales a single row of pixels using point sampling.
1479
+ void ScaleUVCols_C(uint8_t* dst_uv,
1480
+ const uint8_t* src_uv,
1481
+ int dst_width,
1482
+ int x,
1483
+ int dx) {
1484
+ const uint16_t* src = (const uint16_t*)(src_uv);
1485
+ uint16_t* dst = (uint16_t*)(dst_uv);
1486
+ int j;
1487
+ for (j = 0; j < dst_width - 1; j += 2) {
1488
+ dst[0] = src[x >> 16];
1489
+ x += dx;
1490
+ dst[1] = src[x >> 16];
1491
+ x += dx;
1492
+ dst += 2;
1493
+ }
1494
+ if (dst_width & 1) {
1495
+ dst[0] = src[x >> 16];
1496
+ }
1497
+ }
1498
+
1499
+ void ScaleUVCols64_C(uint8_t* dst_uv,
1500
+ const uint8_t* src_uv,
1501
+ int dst_width,
1502
+ int x32,
1503
+ int dx) {
1504
+ int64_t x = (int64_t)(x32);
1505
+ const uint16_t* src = (const uint16_t*)(src_uv);
1506
+ uint16_t* dst = (uint16_t*)(dst_uv);
1507
+ int j;
1508
+ for (j = 0; j < dst_width - 1; j += 2) {
1509
+ dst[0] = src[x >> 16];
1510
+ x += dx;
1511
+ dst[1] = src[x >> 16];
1512
+ x += dx;
1513
+ dst += 2;
1514
+ }
1515
+ if (dst_width & 1) {
1516
+ dst[0] = src[x >> 16];
1517
+ }
1518
+ }
1519
+
1520
+ // Scales a single row of pixels up by 2x using point sampling.
1521
+ void ScaleUVColsUp2_C(uint8_t* dst_uv,
1522
+ const uint8_t* src_uv,
1523
+ int dst_width,
1524
+ int x,
1525
+ int dx) {
1526
+ const uint16_t* src = (const uint16_t*)(src_uv);
1527
+ uint16_t* dst = (uint16_t*)(dst_uv);
1528
+ int j;
1529
+ (void)x;
1530
+ (void)dx;
1531
+ for (j = 0; j < dst_width - 1; j += 2) {
1532
+ dst[1] = dst[0] = src[0];
1533
+ src += 1;
1534
+ dst += 2;
1535
+ }
1536
+ if (dst_width & 1) {
1537
+ dst[0] = src[0];
1538
+ }
1539
+ }
1540
+
1541
+ // TODO(fbarchard): Replace 0x7f ^ f with 128-f. bug=607.
1542
+ // Mimics SSSE3 blender
1543
+ #define BLENDER1(a, b, f) ((a) * (0x7f ^ f) + (b)*f) >> 7
1544
+ #define BLENDERC(a, b, f, s) \
1545
+ (uint16_t)(BLENDER1(((a) >> s) & 255, ((b) >> s) & 255, f) << s)
1546
+ #define BLENDER(a, b, f) BLENDERC(a, b, f, 8) | BLENDERC(a, b, f, 0)
1547
+
1548
+ void ScaleUVFilterCols_C(uint8_t* dst_uv,
1549
+ const uint8_t* src_uv,
1550
+ int dst_width,
1551
+ int x,
1552
+ int dx) {
1553
+ const uint16_t* src = (const uint16_t*)(src_uv);
1554
+ uint16_t* dst = (uint16_t*)(dst_uv);
1555
+ int j;
1556
+ for (j = 0; j < dst_width - 1; j += 2) {
1557
+ int xi = x >> 16;
1558
+ int xf = (x >> 9) & 0x7f;
1559
+ uint16_t a = src[xi];
1560
+ uint16_t b = src[xi + 1];
1561
+ dst[0] = BLENDER(a, b, xf);
1562
+ x += dx;
1563
+ xi = x >> 16;
1564
+ xf = (x >> 9) & 0x7f;
1565
+ a = src[xi];
1566
+ b = src[xi + 1];
1567
+ dst[1] = BLENDER(a, b, xf);
1568
+ x += dx;
1569
+ dst += 2;
1570
+ }
1571
+ if (dst_width & 1) {
1572
+ int xi = x >> 16;
1573
+ int xf = (x >> 9) & 0x7f;
1574
+ uint16_t a = src[xi];
1575
+ uint16_t b = src[xi + 1];
1576
+ dst[0] = BLENDER(a, b, xf);
1577
+ }
1578
+ }
1579
+
1580
+ void ScaleUVFilterCols64_C(uint8_t* dst_uv,
1581
+ const uint8_t* src_uv,
1582
+ int dst_width,
1583
+ int x32,
1584
+ int dx) {
1585
+ int64_t x = (int64_t)(x32);
1586
+ const uint16_t* src = (const uint16_t*)(src_uv);
1587
+ uint16_t* dst = (uint16_t*)(dst_uv);
1588
+ int j;
1589
+ for (j = 0; j < dst_width - 1; j += 2) {
1590
+ int64_t xi = x >> 16;
1591
+ int xf = (x >> 9) & 0x7f;
1592
+ uint16_t a = src[xi];
1593
+ uint16_t b = src[xi + 1];
1594
+ dst[0] = BLENDER(a, b, xf);
1595
+ x += dx;
1596
+ xi = x >> 16;
1597
+ xf = (x >> 9) & 0x7f;
1598
+ a = src[xi];
1599
+ b = src[xi + 1];
1600
+ dst[1] = BLENDER(a, b, xf);
1601
+ x += dx;
1602
+ dst += 2;
1603
+ }
1604
+ if (dst_width & 1) {
1605
+ int64_t xi = x >> 16;
1606
+ int xf = (x >> 9) & 0x7f;
1607
+ uint16_t a = src[xi];
1608
+ uint16_t b = src[xi + 1];
1609
+ dst[0] = BLENDER(a, b, xf);
1610
+ }
1611
+ }
1612
+ #undef BLENDER1
1613
+ #undef BLENDERC
1614
+ #undef BLENDER
1615
+
1616
+ // Scale plane vertically with bilinear interpolation.
1617
+ void ScalePlaneVertical(int src_height,
1618
+ int dst_width,
1619
+ int dst_height,
1620
+ int src_stride,
1621
+ int dst_stride,
1622
+ const uint8_t* src_argb,
1623
+ uint8_t* dst_argb,
1624
+ int x,
1625
+ int y,
1626
+ int dy,
1627
+ int bpp, // bytes per pixel. 4 for ARGB.
1628
+ enum FilterMode filtering) {
1629
+ // TODO(fbarchard): Allow higher bpp.
1630
+ int dst_width_bytes = dst_width * bpp;
1631
+ void (*InterpolateRow)(uint8_t* dst_argb, const uint8_t* src_argb,
1632
+ ptrdiff_t src_stride, int dst_width,
1633
+ int source_y_fraction) = InterpolateRow_C;
1634
+ const int max_y = (src_height > 1) ? ((src_height - 1) << 16) - 1 : 0;
1635
+ int j;
1636
+ assert(bpp >= 1 && bpp <= 4);
1637
+ assert(src_height != 0);
1638
+ assert(dst_width > 0);
1639
+ assert(dst_height > 0);
1640
+ src_argb += (x >> 16) * bpp;
1641
+ #if defined(HAS_INTERPOLATEROW_SSSE3)
1642
+ if (TestCpuFlag(kCpuHasSSSE3)) {
1643
+ InterpolateRow = InterpolateRow_Any_SSSE3;
1644
+ if (IS_ALIGNED(dst_width_bytes, 16)) {
1645
+ InterpolateRow = InterpolateRow_SSSE3;
1646
+ }
1647
+ }
1648
+ #endif
1649
+ #if defined(HAS_INTERPOLATEROW_AVX2)
1650
+ if (TestCpuFlag(kCpuHasAVX2)) {
1651
+ InterpolateRow = InterpolateRow_Any_AVX2;
1652
+ if (IS_ALIGNED(dst_width_bytes, 32)) {
1653
+ InterpolateRow = InterpolateRow_AVX2;
1654
+ }
1655
+ }
1656
+ #endif
1657
+ #if defined(HAS_INTERPOLATEROW_NEON)
1658
+ if (TestCpuFlag(kCpuHasNEON)) {
1659
+ InterpolateRow = InterpolateRow_Any_NEON;
1660
+ if (IS_ALIGNED(dst_width_bytes, 16)) {
1661
+ InterpolateRow = InterpolateRow_NEON;
1662
+ }
1663
+ }
1664
+ #endif
1665
+ #if defined(HAS_INTERPOLATEROW_SME)
1666
+ if (TestCpuFlag(kCpuHasSME)) {
1667
+ InterpolateRow = InterpolateRow_SME;
1668
+ }
1669
+ #endif
1670
+ #if defined(HAS_INTERPOLATEROW_LSX)
1671
+ if (TestCpuFlag(kCpuHasLSX)) {
1672
+ InterpolateRow = InterpolateRow_Any_LSX;
1673
+ if (IS_ALIGNED(dst_width_bytes, 32)) {
1674
+ InterpolateRow = InterpolateRow_LSX;
1675
+ }
1676
+ }
1677
+ #endif
1678
+ #if defined(HAS_INTERPOLATEROW_RVV)
1679
+ if (TestCpuFlag(kCpuHasRVV)) {
1680
+ InterpolateRow = InterpolateRow_RVV;
1681
+ }
1682
+ #endif
1683
+
1684
+ for (j = 0; j < dst_height; ++j) {
1685
+ int yi;
1686
+ int yf;
1687
+ if (y > max_y) {
1688
+ y = max_y;
1689
+ }
1690
+ yi = y >> 16;
1691
+ yf = filtering ? ((y >> 8) & 255) : 0;
1692
+ InterpolateRow(dst_argb, src_argb + yi * src_stride, src_stride,
1693
+ dst_width_bytes, yf);
1694
+ dst_argb += dst_stride;
1695
+ y += dy;
1696
+ }
1697
+ }
1698
+
1699
+ void ScalePlaneVertical_16(int src_height,
1700
+ int dst_width,
1701
+ int dst_height,
1702
+ int src_stride,
1703
+ int dst_stride,
1704
+ const uint16_t* src_argb,
1705
+ uint16_t* dst_argb,
1706
+ int x,
1707
+ int y,
1708
+ int dy,
1709
+ int wpp, /* words per pixel. normally 1 */
1710
+ enum FilterMode filtering) {
1711
+ // TODO(fbarchard): Allow higher wpp.
1712
+ int dst_width_words = dst_width * wpp;
1713
+ void (*InterpolateRow)(uint16_t* dst_argb, const uint16_t* src_argb,
1714
+ ptrdiff_t src_stride, int dst_width,
1715
+ int source_y_fraction) = InterpolateRow_16_C;
1716
+ const int max_y = (src_height > 1) ? ((src_height - 1) << 16) - 1 : 0;
1717
+ int j;
1718
+ assert(wpp >= 1 && wpp <= 2);
1719
+ assert(src_height != 0);
1720
+ assert(dst_width > 0);
1721
+ assert(dst_height > 0);
1722
+ src_argb += (x >> 16) * wpp;
1723
+ #if defined(HAS_INTERPOLATEROW_16_SSE2)
1724
+ if (TestCpuFlag(kCpuHasSSE2)) {
1725
+ InterpolateRow = InterpolateRow_16_Any_SSE2;
1726
+ if (IS_ALIGNED(dst_width_words, 16)) {
1727
+ InterpolateRow = InterpolateRow_16_SSE2;
1728
+ }
1729
+ }
1730
+ #endif
1731
+ #if defined(HAS_INTERPOLATEROW_16_SSSE3)
1732
+ if (TestCpuFlag(kCpuHasSSSE3)) {
1733
+ InterpolateRow = InterpolateRow_16_Any_SSSE3;
1734
+ if (IS_ALIGNED(dst_width_words, 16)) {
1735
+ InterpolateRow = InterpolateRow_16_SSSE3;
1736
+ }
1737
+ }
1738
+ #endif
1739
+ #if defined(HAS_INTERPOLATEROW_16_AVX2)
1740
+ if (TestCpuFlag(kCpuHasAVX2)) {
1741
+ InterpolateRow = InterpolateRow_16_Any_AVX2;
1742
+ if (IS_ALIGNED(dst_width_words, 32)) {
1743
+ InterpolateRow = InterpolateRow_16_AVX2;
1744
+ }
1745
+ }
1746
+ #endif
1747
+ #if defined(HAS_INTERPOLATEROW_16_NEON)
1748
+ if (TestCpuFlag(kCpuHasNEON)) {
1749
+ InterpolateRow = InterpolateRow_16_Any_NEON;
1750
+ if (IS_ALIGNED(dst_width_words, 8)) {
1751
+ InterpolateRow = InterpolateRow_16_NEON;
1752
+ }
1753
+ }
1754
+ #endif
1755
+ #if defined(HAS_INTERPOLATEROW_16_SME)
1756
+ if (TestCpuFlag(kCpuHasSME)) {
1757
+ InterpolateRow = InterpolateRow_16_SME;
1758
+ }
1759
+ #endif
1760
+ for (j = 0; j < dst_height; ++j) {
1761
+ int yi;
1762
+ int yf;
1763
+ if (y > max_y) {
1764
+ y = max_y;
1765
+ }
1766
+ yi = y >> 16;
1767
+ yf = filtering ? ((y >> 8) & 255) : 0;
1768
+ InterpolateRow(dst_argb, src_argb + yi * src_stride, src_stride,
1769
+ dst_width_words, yf);
1770
+ dst_argb += dst_stride;
1771
+ y += dy;
1772
+ }
1773
+ }
1774
+
1775
+ // Use scale to convert lsb formats to msb, depending how many bits there are:
1776
+ // 32768 = 9 bits
1777
+ // 16384 = 10 bits
1778
+ // 4096 = 12 bits
1779
+ // 256 = 16 bits
1780
+ // TODO(fbarchard): change scale to bits
1781
+ void ScalePlaneVertical_16To8(int src_height,
1782
+ int dst_width,
1783
+ int dst_height,
1784
+ int src_stride,
1785
+ int dst_stride,
1786
+ const uint16_t* src_argb,
1787
+ uint8_t* dst_argb,
1788
+ int x,
1789
+ int y,
1790
+ int dy,
1791
+ int wpp, /* words per pixel. normally 1 */
1792
+ int scale,
1793
+ enum FilterMode filtering) {
1794
+ // TODO(fbarchard): Allow higher wpp.
1795
+ int dst_width_words = dst_width * wpp;
1796
+ // TODO(https://crbug.com/libyuv/931): Add NEON 32 bit and AVX2 versions.
1797
+ void (*InterpolateRow_16To8)(uint8_t* dst_argb, const uint16_t* src_argb,
1798
+ ptrdiff_t src_stride, int scale, int dst_width,
1799
+ int source_y_fraction) = InterpolateRow_16To8_C;
1800
+ const int max_y = (src_height > 1) ? ((src_height - 1) << 16) - 1 : 0;
1801
+ int j;
1802
+ assert(wpp >= 1 && wpp <= 2);
1803
+ assert(src_height != 0);
1804
+ assert(dst_width > 0);
1805
+ assert(dst_height > 0);
1806
+ src_argb += (x >> 16) * wpp;
1807
+
1808
+ #if defined(HAS_INTERPOLATEROW_16TO8_NEON)
1809
+ if (TestCpuFlag(kCpuHasNEON)) {
1810
+ InterpolateRow_16To8 = InterpolateRow_16To8_Any_NEON;
1811
+ if (IS_ALIGNED(dst_width, 8)) {
1812
+ InterpolateRow_16To8 = InterpolateRow_16To8_NEON;
1813
+ }
1814
+ }
1815
+ #endif
1816
+ #if defined(HAS_INTERPOLATEROW_16TO8_SME)
1817
+ if (TestCpuFlag(kCpuHasSME)) {
1818
+ InterpolateRow_16To8 = InterpolateRow_16To8_SME;
1819
+ }
1820
+ #endif
1821
+ #if defined(HAS_INTERPOLATEROW_16TO8_AVX2)
1822
+ if (TestCpuFlag(kCpuHasAVX2)) {
1823
+ InterpolateRow_16To8 = InterpolateRow_16To8_Any_AVX2;
1824
+ if (IS_ALIGNED(dst_width, 32)) {
1825
+ InterpolateRow_16To8 = InterpolateRow_16To8_AVX2;
1826
+ }
1827
+ }
1828
+ #endif
1829
+ for (j = 0; j < dst_height; ++j) {
1830
+ int yi;
1831
+ int yf;
1832
+ if (y > max_y) {
1833
+ y = max_y;
1834
+ }
1835
+ yi = y >> 16;
1836
+ yf = filtering ? ((y >> 8) & 255) : 0;
1837
+ InterpolateRow_16To8(dst_argb, src_argb + yi * src_stride, src_stride,
1838
+ scale, dst_width_words, yf);
1839
+ dst_argb += dst_stride;
1840
+ y += dy;
1841
+ }
1842
+ }
1843
+
1844
+ // Simplify the filtering based on scale factors.
1845
+ enum FilterMode ScaleFilterReduce(int src_width,
1846
+ int src_height,
1847
+ int dst_width,
1848
+ int dst_height,
1849
+ enum FilterMode filtering) {
1850
+ if (src_width < 0) {
1851
+ src_width = -src_width;
1852
+ }
1853
+ if (src_height < 0) {
1854
+ src_height = -src_height;
1855
+ }
1856
+ if (filtering == kFilterBox) {
1857
+ // If scaling either axis to 0.5 or larger, switch from Box to Bilinear.
1858
+ if (dst_width * 2 >= src_width || dst_height * 2 >= src_height) {
1859
+ filtering = kFilterBilinear;
1860
+ }
1861
+ }
1862
+ if (filtering == kFilterBilinear) {
1863
+ if (src_height == 1) {
1864
+ filtering = kFilterLinear;
1865
+ }
1866
+ // TODO(fbarchard): Detect any odd scale factor and reduce to Linear.
1867
+ if (dst_height == src_height || dst_height * 3 == src_height) {
1868
+ filtering = kFilterLinear;
1869
+ }
1870
+ // TODO(fbarchard): Remove 1 pixel wide filter restriction, which is to
1871
+ // avoid reading 2 pixels horizontally that causes memory exception.
1872
+ if (src_width == 1) {
1873
+ filtering = kFilterNone;
1874
+ }
1875
+ }
1876
+ if (filtering == kFilterLinear) {
1877
+ if (src_width == 1) {
1878
+ filtering = kFilterNone;
1879
+ }
1880
+ // TODO(fbarchard): Detect any odd scale factor and reduce to None.
1881
+ if (dst_width == src_width || dst_width * 3 == src_width) {
1882
+ filtering = kFilterNone;
1883
+ }
1884
+ }
1885
+ return filtering;
1886
+ }
1887
+
1888
+ // Divide num by div and return as 16.16 fixed point result.
1889
+ int FixedDiv_C(int num, int div) {
1890
+ return (int)(((int64_t)(num) << 16) / div);
1891
+ }
1892
+
1893
+ // Divide num - 1 by div - 1 and return as 16.16 fixed point result.
1894
+ int FixedDiv1_C(int num, int div) {
1895
+ return (int)((((int64_t)(num) << 16) - 0x00010001) / (div - 1));
1896
+ }
1897
+
1898
+ #define CENTERSTART(dx, s) (dx < 0) ? -((-dx >> 1) + s) : ((dx >> 1) + s)
1899
+
1900
+ // Compute slope values for stepping.
1901
+ void ScaleSlope(int src_width,
1902
+ int src_height,
1903
+ int dst_width,
1904
+ int dst_height,
1905
+ enum FilterMode filtering,
1906
+ int* x,
1907
+ int* y,
1908
+ int* dx,
1909
+ int* dy) {
1910
+ assert(x != NULL);
1911
+ assert(y != NULL);
1912
+ assert(dx != NULL);
1913
+ assert(dy != NULL);
1914
+ assert(src_width != 0);
1915
+ assert(src_height != 0);
1916
+ assert(dst_width > 0);
1917
+ assert(dst_height > 0);
1918
+ // Check for 1 pixel and avoid FixedDiv overflow.
1919
+ if (dst_width == 1 && src_width >= 32768) {
1920
+ dst_width = src_width;
1921
+ }
1922
+ if (dst_height == 1 && src_height >= 32768) {
1923
+ dst_height = src_height;
1924
+ }
1925
+ if (filtering == kFilterBox) {
1926
+ // Scale step for point sampling duplicates all pixels equally.
1927
+ *dx = FixedDiv(Abs(src_width), dst_width);
1928
+ *dy = FixedDiv(src_height, dst_height);
1929
+ *x = 0;
1930
+ *y = 0;
1931
+ } else if (filtering == kFilterBilinear) {
1932
+ // Scale step for bilinear sampling renders last pixel once for upsample.
1933
+ if (dst_width <= Abs(src_width)) {
1934
+ *dx = FixedDiv(Abs(src_width), dst_width);
1935
+ *x = CENTERSTART(*dx, -32768); // Subtract 0.5 (32768) to center filter.
1936
+ } else if (src_width > 1 && dst_width > 1) {
1937
+ *dx = FixedDiv1(Abs(src_width), dst_width);
1938
+ *x = 0;
1939
+ }
1940
+ if (dst_height <= src_height) {
1941
+ *dy = FixedDiv(src_height, dst_height);
1942
+ *y = CENTERSTART(*dy, -32768); // Subtract 0.5 (32768) to center filter.
1943
+ } else if (src_height > 1 && dst_height > 1) {
1944
+ *dy = FixedDiv1(src_height, dst_height);
1945
+ *y = 0;
1946
+ }
1947
+ } else if (filtering == kFilterLinear) {
1948
+ // Scale step for bilinear sampling renders last pixel once for upsample.
1949
+ if (dst_width <= Abs(src_width)) {
1950
+ *dx = FixedDiv(Abs(src_width), dst_width);
1951
+ *x = CENTERSTART(*dx, -32768); // Subtract 0.5 (32768) to center filter.
1952
+ } else if (src_width > 1 && dst_width > 1) {
1953
+ *dx = FixedDiv1(Abs(src_width), dst_width);
1954
+ *x = 0;
1955
+ }
1956
+ *dy = FixedDiv(src_height, dst_height);
1957
+ *y = *dy >> 1;
1958
+ } else {
1959
+ // Scale step for point sampling duplicates all pixels equally.
1960
+ *dx = FixedDiv(Abs(src_width), dst_width);
1961
+ *dy = FixedDiv(src_height, dst_height);
1962
+ *x = CENTERSTART(*dx, 0);
1963
+ *y = CENTERSTART(*dy, 0);
1964
+ }
1965
+ // Negative src_width means horizontally mirror.
1966
+ if (src_width < 0) {
1967
+ *x += (dst_width - 1) * *dx;
1968
+ *dx = -*dx;
1969
+ // src_width = -src_width; // Caller must do this.
1970
+ }
1971
+ }
1972
+ #undef CENTERSTART
1973
+
1974
+ #ifdef __cplusplus
1975
+ } // extern "C"
1976
+ } // namespace libyuv
1977
+ #endif