react-native-vision-camera-spoof-detector 1.1.22 → 1.1.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 (201) hide show
  1. package/android/CMakeLists.txt +12 -0
  2. package/android/build.gradle +10 -9
  3. package/android/src/main/cpp/cpp-adapter.cpp +6 -3
  4. package/android/src/main/java/com/faceantispoof/FaceAntiSpoofingAdvanced.kt +83 -0
  5. package/android/src/main/java/com/margelo/nitro/camera/spoofdetector/HybridSpoofDetectorOutput.kt +26 -11
  6. package/package.json +1 -1
  7. package/android/src/main/cpp/CMakeLists.txt +0 -33
  8. package/android/src/main/cpp/FaceAntiSpoofJSI.cpp +0 -142
  9. package/android/src/main/cpp/FastYuvJni.cpp +0 -111
  10. package/android/src/main/cpp/fast_yuv.cpp +0 -342
  11. package/android/src/main/cpp/fast_yuv.h +0 -23
  12. package/android/src/main/cpp/libyuv/.clang-format +0 -6
  13. package/android/src/main/cpp/libyuv/.gn +0 -40
  14. package/android/src/main/cpp/libyuv/.vpython3 +0 -410
  15. package/android/src/main/cpp/libyuv/AUTHORS +0 -7
  16. package/android/src/main/cpp/libyuv/Android.bp +0 -202
  17. package/android/src/main/cpp/libyuv/Android.mk +0 -106
  18. package/android/src/main/cpp/libyuv/BUILD.gn +0 -490
  19. package/android/src/main/cpp/libyuv/CM_linux_packages.cmake +0 -70
  20. package/android/src/main/cpp/libyuv/CMakeLists.txt +0 -259
  21. package/android/src/main/cpp/libyuv/DEPS +0 -935
  22. package/android/src/main/cpp/libyuv/DIR_METADATA +0 -3
  23. package/android/src/main/cpp/libyuv/LICENSE +0 -29
  24. package/android/src/main/cpp/libyuv/OWNERS +0 -11
  25. package/android/src/main/cpp/libyuv/PATENTS +0 -24
  26. package/android/src/main/cpp/libyuv/PRESUBMIT.py +0 -65
  27. package/android/src/main/cpp/libyuv/README.chromium +0 -11
  28. package/android/src/main/cpp/libyuv/README.md +0 -19
  29. package/android/src/main/cpp/libyuv/build_overrides/build.gni +0 -60
  30. package/android/src/main/cpp/libyuv/build_overrides/gtest.gni +0 -19
  31. package/android/src/main/cpp/libyuv/build_overrides/partition_alloc.gni +0 -17
  32. package/android/src/main/cpp/libyuv/codereview.settings +0 -5
  33. package/android/src/main/cpp/libyuv/docs/deprecated_builds.md +0 -409
  34. package/android/src/main/cpp/libyuv/docs/environment_variables.md +0 -64
  35. package/android/src/main/cpp/libyuv/docs/feature_detection.md +0 -108
  36. package/android/src/main/cpp/libyuv/docs/filtering.md +0 -196
  37. package/android/src/main/cpp/libyuv/docs/formats.md +0 -208
  38. package/android/src/main/cpp/libyuv/docs/getting_started.md +0 -296
  39. package/android/src/main/cpp/libyuv/docs/rotation.md +0 -107
  40. package/android/src/main/cpp/libyuv/download_vs_toolchain.py +0 -29
  41. package/android/src/main/cpp/libyuv/include/libyuv/basic_types.h +0 -68
  42. package/android/src/main/cpp/libyuv/include/libyuv/compare.h +0 -111
  43. package/android/src/main/cpp/libyuv/include/libyuv/compare_row.h +0 -112
  44. package/android/src/main/cpp/libyuv/include/libyuv/convert.h +0 -1117
  45. package/android/src/main/cpp/libyuv/include/libyuv/convert_argb.h +0 -2335
  46. package/android/src/main/cpp/libyuv/include/libyuv/convert_from.h +0 -203
  47. package/android/src/main/cpp/libyuv/include/libyuv/convert_from_argb.h +0 -394
  48. package/android/src/main/cpp/libyuv/include/libyuv/cpu_id.h +0 -147
  49. package/android/src/main/cpp/libyuv/include/libyuv/cpu_support.h +0 -99
  50. package/android/src/main/cpp/libyuv/include/libyuv/loongson_intrinsics.h +0 -1949
  51. package/android/src/main/cpp/libyuv/include/libyuv/mjpeg_decoder.h +0 -195
  52. package/android/src/main/cpp/libyuv/include/libyuv/planar_functions.h +0 -1131
  53. package/android/src/main/cpp/libyuv/include/libyuv/rotate.h +0 -296
  54. package/android/src/main/cpp/libyuv/include/libyuv/rotate_argb.h +0 -37
  55. package/android/src/main/cpp/libyuv/include/libyuv/rotate_row.h +0 -265
  56. package/android/src/main/cpp/libyuv/include/libyuv/row.h +0 -6738
  57. package/android/src/main/cpp/libyuv/include/libyuv/row_sve.h +0 -2154
  58. package/android/src/main/cpp/libyuv/include/libyuv/scale.h +0 -336
  59. package/android/src/main/cpp/libyuv/include/libyuv/scale_argb.h +0 -76
  60. package/android/src/main/cpp/libyuv/include/libyuv/scale_rgb.h +0 -42
  61. package/android/src/main/cpp/libyuv/include/libyuv/scale_row.h +0 -1726
  62. package/android/src/main/cpp/libyuv/include/libyuv/scale_uv.h +0 -51
  63. package/android/src/main/cpp/libyuv/include/libyuv/version.h +0 -16
  64. package/android/src/main/cpp/libyuv/include/libyuv/video_common.h +0 -222
  65. package/android/src/main/cpp/libyuv/include/libyuv.h +0 -33
  66. package/android/src/main/cpp/libyuv/infra/config/OWNERS +0 -3
  67. package/android/src/main/cpp/libyuv/infra/config/PRESUBMIT.py +0 -17
  68. package/android/src/main/cpp/libyuv/infra/config/README.md +0 -2
  69. package/android/src/main/cpp/libyuv/infra/config/codereview.settings +0 -6
  70. package/android/src/main/cpp/libyuv/infra/config/commit-queue.cfg +0 -144
  71. package/android/src/main/cpp/libyuv/infra/config/cr-buildbucket.cfg +0 -1185
  72. package/android/src/main/cpp/libyuv/infra/config/luci-logdog.cfg +0 -9
  73. package/android/src/main/cpp/libyuv/infra/config/luci-milo.cfg +0 -246
  74. package/android/src/main/cpp/libyuv/infra/config/luci-scheduler.cfg +0 -385
  75. package/android/src/main/cpp/libyuv/infra/config/main.star +0 -402
  76. package/android/src/main/cpp/libyuv/infra/config/project.cfg +0 -16
  77. package/android/src/main/cpp/libyuv/infra/config/realms.cfg +0 -111
  78. package/android/src/main/cpp/libyuv/libyuv.gni +0 -34
  79. package/android/src/main/cpp/libyuv/libyuv.gyp +0 -149
  80. package/android/src/main/cpp/libyuv/libyuv.gypi +0 -87
  81. package/android/src/main/cpp/libyuv/linux.mk +0 -96
  82. package/android/src/main/cpp/libyuv/public.mk +0 -13
  83. package/android/src/main/cpp/libyuv/pylintrc +0 -49
  84. package/android/src/main/cpp/libyuv/riscv_script/prepare_toolchain_qemu.sh +0 -74
  85. package/android/src/main/cpp/libyuv/riscv_script/riscv-clang.cmake +0 -56
  86. package/android/src/main/cpp/libyuv/riscv_script/run_qemu.sh +0 -15
  87. package/android/src/main/cpp/libyuv/source/compare.cc +0 -435
  88. package/android/src/main/cpp/libyuv/source/compare_common.cc +0 -74
  89. package/android/src/main/cpp/libyuv/source/compare_gcc.cc +0 -362
  90. package/android/src/main/cpp/libyuv/source/compare_neon.cc +0 -96
  91. package/android/src/main/cpp/libyuv/source/compare_neon64.cc +0 -223
  92. package/android/src/main/cpp/libyuv/source/compare_win.cc +0 -241
  93. package/android/src/main/cpp/libyuv/source/convert.cc +0 -4746
  94. package/android/src/main/cpp/libyuv/source/convert_argb.cc +0 -9179
  95. package/android/src/main/cpp/libyuv/source/convert_from.cc +0 -866
  96. package/android/src/main/cpp/libyuv/source/convert_from_argb.cc +0 -3671
  97. package/android/src/main/cpp/libyuv/source/convert_jpeg.cc +0 -602
  98. package/android/src/main/cpp/libyuv/source/convert_to_argb.cc +0 -391
  99. package/android/src/main/cpp/libyuv/source/convert_to_i420.cc +0 -288
  100. package/android/src/main/cpp/libyuv/source/cpu_id.cc +0 -496
  101. package/android/src/main/cpp/libyuv/source/mjpeg_decoder.cc +0 -580
  102. package/android/src/main/cpp/libyuv/source/mjpeg_validate.cc +0 -71
  103. package/android/src/main/cpp/libyuv/source/planar_functions.cc +0 -5663
  104. package/android/src/main/cpp/libyuv/source/rotate.cc +0 -1241
  105. package/android/src/main/cpp/libyuv/source/rotate_any.cc +0 -76
  106. package/android/src/main/cpp/libyuv/source/rotate_argb.cc +0 -259
  107. package/android/src/main/cpp/libyuv/source/rotate_common.cc +0 -208
  108. package/android/src/main/cpp/libyuv/source/rotate_gcc.cc +0 -505
  109. package/android/src/main/cpp/libyuv/source/rotate_lsx.cc +0 -233
  110. package/android/src/main/cpp/libyuv/source/rotate_neon.cc +0 -219
  111. package/android/src/main/cpp/libyuv/source/rotate_neon64.cc +0 -273
  112. package/android/src/main/cpp/libyuv/source/rotate_sme.cc +0 -174
  113. package/android/src/main/cpp/libyuv/source/rotate_win.cc +0 -253
  114. package/android/src/main/cpp/libyuv/source/row_any.cc +0 -2519
  115. package/android/src/main/cpp/libyuv/source/row_common.cc +0 -4461
  116. package/android/src/main/cpp/libyuv/source/row_gcc.cc +0 -9570
  117. package/android/src/main/cpp/libyuv/source/row_lasx.cc +0 -2343
  118. package/android/src/main/cpp/libyuv/source/row_lsx.cc +0 -3030
  119. package/android/src/main/cpp/libyuv/source/row_neon.cc +0 -4026
  120. package/android/src/main/cpp/libyuv/source/row_neon64.cc +0 -5617
  121. package/android/src/main/cpp/libyuv/source/row_rvv.cc +0 -2599
  122. package/android/src/main/cpp/libyuv/source/row_sme.cc +0 -1183
  123. package/android/src/main/cpp/libyuv/source/row_sve.cc +0 -1088
  124. package/android/src/main/cpp/libyuv/source/row_win.cc +0 -6453
  125. package/android/src/main/cpp/libyuv/source/scale.cc +0 -2710
  126. package/android/src/main/cpp/libyuv/source/scale_any.cc +0 -991
  127. package/android/src/main/cpp/libyuv/source/scale_argb.cc +0 -1158
  128. package/android/src/main/cpp/libyuv/source/scale_common.cc +0 -1977
  129. package/android/src/main/cpp/libyuv/source/scale_gcc.cc +0 -2947
  130. package/android/src/main/cpp/libyuv/source/scale_lsx.cc +0 -739
  131. package/android/src/main/cpp/libyuv/source/scale_neon.cc +0 -1449
  132. package/android/src/main/cpp/libyuv/source/scale_neon64.cc +0 -1552
  133. package/android/src/main/cpp/libyuv/source/scale_rgb.cc +0 -82
  134. package/android/src/main/cpp/libyuv/source/scale_rvv.cc +0 -1971
  135. package/android/src/main/cpp/libyuv/source/scale_sme.cc +0 -555
  136. package/android/src/main/cpp/libyuv/source/scale_uv.cc +0 -1159
  137. package/android/src/main/cpp/libyuv/source/scale_win.cc +0 -1392
  138. package/android/src/main/cpp/libyuv/source/test.sh +0 -35
  139. package/android/src/main/cpp/libyuv/source/video_common.cc +0 -62
  140. package/android/src/main/cpp/libyuv/tools_libyuv/OWNERS +0 -4
  141. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/roll_deps.py +0 -931
  142. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py +0 -164
  143. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS +0 -21
  144. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.new +0 -13
  145. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old +0 -13
  146. package/android/src/main/cpp/libyuv/tools_libyuv/get_landmines.py +0 -38
  147. package/android/src/main/cpp/libyuv/tools_libyuv/msan/OWNERS +0 -3
  148. package/android/src/main/cpp/libyuv/tools_libyuv/msan/blacklist.txt +0 -9
  149. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/OWNERS +0 -3
  150. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/blacklist.txt +0 -15
  151. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/vptr_blacklist.txt +0 -25
  152. package/android/src/main/cpp/libyuv/unit_test/basictypes_test.cc +0 -43
  153. package/android/src/main/cpp/libyuv/unit_test/color_test.cc +0 -848
  154. package/android/src/main/cpp/libyuv/unit_test/compare_test.cc +0 -739
  155. package/android/src/main/cpp/libyuv/unit_test/convert_argb_test.cc +0 -2867
  156. package/android/src/main/cpp/libyuv/unit_test/convert_test.cc +0 -2133
  157. package/android/src/main/cpp/libyuv/unit_test/cpu_test.cc +0 -427
  158. package/android/src/main/cpp/libyuv/unit_test/cpu_thread_test.cc +0 -63
  159. package/android/src/main/cpp/libyuv/unit_test/math_test.cc +0 -160
  160. package/android/src/main/cpp/libyuv/unit_test/planar_test.cc +0 -4731
  161. package/android/src/main/cpp/libyuv/unit_test/rotate_argb_test.cc +0 -334
  162. package/android/src/main/cpp/libyuv/unit_test/rotate_test.cc +0 -962
  163. package/android/src/main/cpp/libyuv/unit_test/scale_argb_test.cc +0 -590
  164. package/android/src/main/cpp/libyuv/unit_test/scale_plane_test.cc +0 -465
  165. package/android/src/main/cpp/libyuv/unit_test/scale_rgb_test.cc +0 -280
  166. package/android/src/main/cpp/libyuv/unit_test/scale_test.cc +0 -1135
  167. package/android/src/main/cpp/libyuv/unit_test/scale_uv_test.cc +0 -249
  168. package/android/src/main/cpp/libyuv/unit_test/testdata/arm_v7.txt +0 -12
  169. package/android/src/main/cpp/libyuv/unit_test/testdata/mips.txt +0 -7
  170. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson2k.txt +0 -5
  171. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson3.txt +0 -10
  172. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson_mmi.txt +0 -7
  173. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64.txt +0 -4
  174. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv.txt +0 -4
  175. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv_zvfh.txt +0 -4
  176. package/android/src/main/cpp/libyuv/unit_test/testdata/tegra3.txt +0 -23
  177. package/android/src/main/cpp/libyuv/unit_test/testdata/test0.jpg +0 -0
  178. package/android/src/main/cpp/libyuv/unit_test/testdata/test1.jpg +0 -0
  179. package/android/src/main/cpp/libyuv/unit_test/testdata/test2.jpg +0 -0
  180. package/android/src/main/cpp/libyuv/unit_test/testdata/test3.jpg +0 -0
  181. package/android/src/main/cpp/libyuv/unit_test/testdata/test4.jpg +0 -0
  182. package/android/src/main/cpp/libyuv/unit_test/unit_test.cc +0 -581
  183. package/android/src/main/cpp/libyuv/unit_test/unit_test.h +0 -232
  184. package/android/src/main/cpp/libyuv/unit_test/video_common_test.cc +0 -112
  185. package/android/src/main/cpp/libyuv/util/Makefile +0 -9
  186. package/android/src/main/cpp/libyuv/util/color.cc +0 -120
  187. package/android/src/main/cpp/libyuv/util/compare.cc +0 -67
  188. package/android/src/main/cpp/libyuv/util/cpuid.c +0 -211
  189. package/android/src/main/cpp/libyuv/util/i444tonv12_eg.cc +0 -28
  190. package/android/src/main/cpp/libyuv/util/psnr.cc +0 -291
  191. package/android/src/main/cpp/libyuv/util/psnr.h +0 -47
  192. package/android/src/main/cpp/libyuv/util/psnr_main.cc +0 -620
  193. package/android/src/main/cpp/libyuv/util/ssim.cc +0 -364
  194. package/android/src/main/cpp/libyuv/util/ssim.h +0 -38
  195. package/android/src/main/cpp/libyuv/util/yuvconstants.c +0 -114
  196. package/android/src/main/cpp/libyuv/util/yuvconvert.cc +0 -367
  197. package/android/src/main/cpp/libyuv/winarm.mk +0 -47
  198. package/android/src/main/java/com/faceantispoof/ByteBufferPool.kt +0 -68
  199. package/android/src/main/java/com/faceantispoof/FastYuv.kt +0 -51
  200. package/android/src/main/java/com/faceantispoof/YuvToFloatArrayConverter.kt +0 -584
  201. package/android/src/main/java/com/faceantispoof/YuvToRgbConverter.kt +0 -73
@@ -1,580 +0,0 @@
1
- /*
2
- * Copyright 2012 The LibYuv Project Authors. All rights reserved.
3
- *
4
- * Use of this source code is governed by a BSD-style license
5
- * that can be found in the LICENSE file in the root of the source
6
- * tree. An additional intellectual property rights grant can be found
7
- * in the file PATENTS. All contributing project authors may
8
- * be found in the AUTHORS file in the root of the source tree.
9
- */
10
-
11
- #include "libyuv/mjpeg_decoder.h"
12
-
13
- #ifdef HAVE_JPEG
14
- #include <assert.h>
15
-
16
- #if !defined(__pnacl__) && !defined(__CLR_VER) && !defined(COVERAGE_ENABLED)
17
- // Must be included before jpeglib.
18
- #include <setjmp.h>
19
- #define HAVE_SETJMP
20
-
21
- #if defined(_MSC_VER)
22
- // disable warning 4324: structure was padded due to __declspec(align())
23
- #pragma warning(disable : 4324)
24
- #endif
25
-
26
- #endif
27
-
28
- #include <stdio.h> // For jpeglib.h.
29
-
30
- // C++ build requires extern C for jpeg internals.
31
- #ifdef __cplusplus
32
- extern "C" {
33
- #endif
34
-
35
- #include <jpeglib.h>
36
-
37
- #ifdef __cplusplus
38
- } // extern "C"
39
- #endif
40
-
41
- #include "libyuv/planar_functions.h" // For CopyPlane().
42
-
43
- namespace libyuv {
44
-
45
- #ifdef HAVE_SETJMP
46
- struct SetJmpErrorMgr {
47
- jpeg_error_mgr base; // Must be at the top
48
- jmp_buf setjmp_buffer;
49
- };
50
- #endif
51
-
52
- const int MJpegDecoder::kColorSpaceUnknown = JCS_UNKNOWN;
53
- const int MJpegDecoder::kColorSpaceGrayscale = JCS_GRAYSCALE;
54
- const int MJpegDecoder::kColorSpaceRgb = JCS_RGB;
55
- const int MJpegDecoder::kColorSpaceYCbCr = JCS_YCbCr;
56
- const int MJpegDecoder::kColorSpaceCMYK = JCS_CMYK;
57
- const int MJpegDecoder::kColorSpaceYCCK = JCS_YCCK;
58
-
59
- // Methods that are passed to jpeglib.
60
- boolean fill_input_buffer(jpeg_decompress_struct* cinfo);
61
- void init_source(jpeg_decompress_struct* cinfo);
62
- void skip_input_data(jpeg_decompress_struct* cinfo, long num_bytes); // NOLINT
63
- void term_source(jpeg_decompress_struct* cinfo);
64
- void ErrorHandler(jpeg_common_struct* cinfo);
65
- void OutputHandler(jpeg_common_struct* cinfo);
66
-
67
- MJpegDecoder::MJpegDecoder()
68
- : has_scanline_padding_(LIBYUV_FALSE),
69
- num_outbufs_(0),
70
- scanlines_(NULL),
71
- scanlines_sizes_(NULL),
72
- databuf_(NULL),
73
- databuf_strides_(NULL) {
74
- decompress_struct_ = new jpeg_decompress_struct;
75
- source_mgr_ = new jpeg_source_mgr;
76
- #ifdef HAVE_SETJMP
77
- error_mgr_ = new SetJmpErrorMgr;
78
- decompress_struct_->err = jpeg_std_error(&error_mgr_->base);
79
- // Override standard exit()-based error handler.
80
- error_mgr_->base.error_exit = &ErrorHandler;
81
- error_mgr_->base.output_message = &OutputHandler;
82
- #endif
83
- decompress_struct_->client_data = NULL;
84
- source_mgr_->init_source = &init_source;
85
- source_mgr_->fill_input_buffer = &fill_input_buffer;
86
- source_mgr_->skip_input_data = &skip_input_data;
87
- source_mgr_->resync_to_restart = &jpeg_resync_to_restart;
88
- source_mgr_->term_source = &term_source;
89
- jpeg_create_decompress(decompress_struct_);
90
- decompress_struct_->src = source_mgr_;
91
- buf_vec_.buffers = &buf_;
92
- buf_vec_.len = 1;
93
- }
94
-
95
- MJpegDecoder::~MJpegDecoder() {
96
- jpeg_destroy_decompress(decompress_struct_);
97
- delete decompress_struct_;
98
- delete source_mgr_;
99
- #ifdef HAVE_SETJMP
100
- delete error_mgr_;
101
- #endif
102
- DestroyOutputBuffers();
103
- }
104
-
105
- LIBYUV_BOOL MJpegDecoder::LoadFrame(const uint8_t* src, size_t src_len) {
106
- if (!ValidateJpeg(src, src_len)) {
107
- return LIBYUV_FALSE;
108
- }
109
-
110
- buf_.data = src;
111
- buf_.len = (int)src_len;
112
- buf_vec_.pos = 0;
113
- decompress_struct_->client_data = &buf_vec_;
114
- #ifdef HAVE_SETJMP
115
- if (setjmp(error_mgr_->setjmp_buffer)) {
116
- // We called jpeg_read_header, it experienced an error, and we called
117
- // longjmp() and rewound the stack to here. Return error.
118
- return LIBYUV_FALSE;
119
- }
120
- #endif
121
- if (jpeg_read_header(decompress_struct_, TRUE) != JPEG_HEADER_OK) {
122
- // ERROR: Bad MJPEG header
123
- return LIBYUV_FALSE;
124
- }
125
- AllocOutputBuffers(GetNumComponents());
126
- for (int i = 0; i < num_outbufs_; ++i) {
127
- int scanlines_size = GetComponentScanlinesPerImcuRow(i);
128
- if (scanlines_sizes_[i] != scanlines_size) {
129
- if (scanlines_[i]) {
130
- delete scanlines_[i];
131
- }
132
- scanlines_[i] = new uint8_t*[scanlines_size];
133
- scanlines_sizes_[i] = scanlines_size;
134
- }
135
-
136
- // We allocate padding for the final scanline to pad it up to DCTSIZE bytes
137
- // to avoid memory errors, since jpeglib only reads full MCUs blocks. For
138
- // the preceding scanlines, the padding is not needed/wanted because the
139
- // following addresses will already be valid (they are the initial bytes of
140
- // the next scanline) and will be overwritten when jpeglib writes out that
141
- // next scanline.
142
- int databuf_stride = GetComponentStride(i);
143
- int databuf_size = scanlines_size * databuf_stride;
144
- if (databuf_strides_[i] != databuf_stride) {
145
- if (databuf_[i]) {
146
- delete databuf_[i];
147
- }
148
- databuf_[i] = new uint8_t[databuf_size];
149
- databuf_strides_[i] = databuf_stride;
150
- }
151
-
152
- if (GetComponentStride(i) != GetComponentWidth(i)) {
153
- has_scanline_padding_ = LIBYUV_TRUE;
154
- }
155
- }
156
- return LIBYUV_TRUE;
157
- }
158
-
159
- static int DivideAndRoundUp(int numerator, int denominator) {
160
- return (numerator + denominator - 1) / denominator;
161
- }
162
-
163
- static int DivideAndRoundDown(int numerator, int denominator) {
164
- return numerator / denominator;
165
- }
166
-
167
- // Returns width of the last loaded frame.
168
- int MJpegDecoder::GetWidth() {
169
- return decompress_struct_->image_width;
170
- }
171
-
172
- // Returns height of the last loaded frame.
173
- int MJpegDecoder::GetHeight() {
174
- return decompress_struct_->image_height;
175
- }
176
-
177
- // Returns format of the last loaded frame. The return value is one of the
178
- // kColorSpace* constants.
179
- int MJpegDecoder::GetColorSpace() {
180
- return decompress_struct_->jpeg_color_space;
181
- }
182
-
183
- // Number of color components in the color space.
184
- int MJpegDecoder::GetNumComponents() {
185
- return decompress_struct_->num_components;
186
- }
187
-
188
- // Sample factors of the n-th component.
189
- int MJpegDecoder::GetHorizSampFactor(int component) {
190
- return decompress_struct_->comp_info[component].h_samp_factor;
191
- }
192
-
193
- int MJpegDecoder::GetVertSampFactor(int component) {
194
- return decompress_struct_->comp_info[component].v_samp_factor;
195
- }
196
-
197
- int MJpegDecoder::GetHorizSubSampFactor(int component) {
198
- return decompress_struct_->max_h_samp_factor / GetHorizSampFactor(component);
199
- }
200
-
201
- int MJpegDecoder::GetVertSubSampFactor(int component) {
202
- return decompress_struct_->max_v_samp_factor / GetVertSampFactor(component);
203
- }
204
-
205
- int MJpegDecoder::GetImageScanlinesPerImcuRow() {
206
- return decompress_struct_->max_v_samp_factor * DCTSIZE;
207
- }
208
-
209
- int MJpegDecoder::GetComponentScanlinesPerImcuRow(int component) {
210
- int vs = GetVertSubSampFactor(component);
211
- return DivideAndRoundUp(GetImageScanlinesPerImcuRow(), vs);
212
- }
213
-
214
- int MJpegDecoder::GetComponentWidth(int component) {
215
- int hs = GetHorizSubSampFactor(component);
216
- return DivideAndRoundUp(GetWidth(), hs);
217
- }
218
-
219
- int MJpegDecoder::GetComponentHeight(int component) {
220
- int vs = GetVertSubSampFactor(component);
221
- return DivideAndRoundUp(GetHeight(), vs);
222
- }
223
-
224
- // Get width in bytes padded out to a multiple of DCTSIZE
225
- int MJpegDecoder::GetComponentStride(int component) {
226
- return (GetComponentWidth(component) + DCTSIZE - 1) & ~(DCTSIZE - 1);
227
- }
228
-
229
- int MJpegDecoder::GetComponentSize(int component) {
230
- return GetComponentWidth(component) * GetComponentHeight(component);
231
- }
232
-
233
- LIBYUV_BOOL MJpegDecoder::UnloadFrame() {
234
- #ifdef HAVE_SETJMP
235
- if (setjmp(error_mgr_->setjmp_buffer)) {
236
- // We called jpeg_abort_decompress, it experienced an error, and we called
237
- // longjmp() and rewound the stack to here. Return error.
238
- return LIBYUV_FALSE;
239
- }
240
- #endif
241
- jpeg_abort_decompress(decompress_struct_);
242
- return LIBYUV_TRUE;
243
- }
244
-
245
- // TODO(fbarchard): Allow rectangle to be specified: x, y, width, height.
246
- LIBYUV_BOOL MJpegDecoder::DecodeToBuffers(uint8_t** planes,
247
- int dst_width,
248
- int dst_height) {
249
- if (dst_width != GetWidth() || dst_height > GetHeight()) {
250
- // ERROR: Bad dimensions
251
- return LIBYUV_FALSE;
252
- }
253
- #ifdef HAVE_SETJMP
254
- if (setjmp(error_mgr_->setjmp_buffer)) {
255
- // We called into jpeglib, it experienced an error sometime during this
256
- // function call, and we called longjmp() and rewound the stack to here.
257
- // Return error.
258
- return LIBYUV_FALSE;
259
- }
260
- #endif
261
- if (!StartDecode()) {
262
- return LIBYUV_FALSE;
263
- }
264
- SetScanlinePointers(databuf_);
265
- int lines_left = dst_height;
266
- // Compute amount of lines to skip to implement vertical crop.
267
- // TODO(fbarchard): Ensure skip is a multiple of maximum component
268
- // subsample. ie 2
269
- int skip = (GetHeight() - dst_height) / 2;
270
- if (skip > 0) {
271
- // There is no API to skip lines in the output data, so we read them
272
- // into the temp buffer.
273
- while (skip >= GetImageScanlinesPerImcuRow()) {
274
- if (!DecodeImcuRow()) {
275
- FinishDecode();
276
- return LIBYUV_FALSE;
277
- }
278
- skip -= GetImageScanlinesPerImcuRow();
279
- }
280
- if (skip > 0) {
281
- // Have a partial iMCU row left over to skip. Must read it and then
282
- // copy the parts we want into the destination.
283
- if (!DecodeImcuRow()) {
284
- FinishDecode();
285
- return LIBYUV_FALSE;
286
- }
287
- for (int i = 0; i < num_outbufs_; ++i) {
288
- // TODO(fbarchard): Compute skip to avoid this
289
- assert(skip % GetVertSubSampFactor(i) == 0);
290
- int rows_to_skip = DivideAndRoundDown(skip, GetVertSubSampFactor(i));
291
- int scanlines_to_copy =
292
- GetComponentScanlinesPerImcuRow(i) - rows_to_skip;
293
- int data_to_skip = rows_to_skip * GetComponentStride(i);
294
- CopyPlane(databuf_[i] + data_to_skip, GetComponentStride(i), planes[i],
295
- GetComponentWidth(i), GetComponentWidth(i),
296
- scanlines_to_copy);
297
- planes[i] += scanlines_to_copy * GetComponentWidth(i);
298
- }
299
- lines_left -= (GetImageScanlinesPerImcuRow() - skip);
300
- }
301
- }
302
-
303
- // Read full MCUs but cropped horizontally
304
- for (; lines_left > GetImageScanlinesPerImcuRow();
305
- lines_left -= GetImageScanlinesPerImcuRow()) {
306
- if (!DecodeImcuRow()) {
307
- FinishDecode();
308
- return LIBYUV_FALSE;
309
- }
310
- for (int i = 0; i < num_outbufs_; ++i) {
311
- int scanlines_to_copy = GetComponentScanlinesPerImcuRow(i);
312
- CopyPlane(databuf_[i], GetComponentStride(i), planes[i],
313
- GetComponentWidth(i), GetComponentWidth(i), scanlines_to_copy);
314
- planes[i] += scanlines_to_copy * GetComponentWidth(i);
315
- }
316
- }
317
-
318
- if (lines_left > 0) {
319
- // Have a partial iMCU row left over to decode.
320
- if (!DecodeImcuRow()) {
321
- FinishDecode();
322
- return LIBYUV_FALSE;
323
- }
324
- for (int i = 0; i < num_outbufs_; ++i) {
325
- int scanlines_to_copy =
326
- DivideAndRoundUp(lines_left, GetVertSubSampFactor(i));
327
- CopyPlane(databuf_[i], GetComponentStride(i), planes[i],
328
- GetComponentWidth(i), GetComponentWidth(i), scanlines_to_copy);
329
- planes[i] += scanlines_to_copy * GetComponentWidth(i);
330
- }
331
- }
332
- return FinishDecode();
333
- }
334
-
335
- LIBYUV_BOOL MJpegDecoder::DecodeToCallback(CallbackFunction fn,
336
- void* opaque,
337
- int dst_width,
338
- int dst_height) {
339
- if (dst_width != GetWidth() || dst_height > GetHeight()) {
340
- // ERROR: Bad dimensions
341
- return LIBYUV_FALSE;
342
- }
343
- #ifdef HAVE_SETJMP
344
- if (setjmp(error_mgr_->setjmp_buffer)) {
345
- // We called into jpeglib, it experienced an error sometime during this
346
- // function call, and we called longjmp() and rewound the stack to here.
347
- // Return error.
348
- return LIBYUV_FALSE;
349
- }
350
- #endif
351
- if (!StartDecode()) {
352
- return LIBYUV_FALSE;
353
- }
354
- SetScanlinePointers(databuf_);
355
- int lines_left = dst_height;
356
- // TODO(fbarchard): Compute amount of lines to skip to implement vertical crop
357
- int skip = (GetHeight() - dst_height) / 2;
358
- if (skip > 0) {
359
- while (skip >= GetImageScanlinesPerImcuRow()) {
360
- if (!DecodeImcuRow()) {
361
- FinishDecode();
362
- return LIBYUV_FALSE;
363
- }
364
- skip -= GetImageScanlinesPerImcuRow();
365
- }
366
- if (skip > 0) {
367
- // Have a partial iMCU row left over to skip.
368
- if (!DecodeImcuRow()) {
369
- FinishDecode();
370
- return LIBYUV_FALSE;
371
- }
372
- for (int i = 0; i < num_outbufs_; ++i) {
373
- // TODO(fbarchard): Compute skip to avoid this
374
- assert(skip % GetVertSubSampFactor(i) == 0);
375
- int rows_to_skip = DivideAndRoundDown(skip, GetVertSubSampFactor(i));
376
- int data_to_skip = rows_to_skip * GetComponentStride(i);
377
- // Change our own data buffer pointers so we can pass them to the
378
- // callback.
379
- databuf_[i] += data_to_skip;
380
- }
381
- int scanlines_to_copy = GetImageScanlinesPerImcuRow() - skip;
382
- (*fn)(opaque, databuf_, databuf_strides_, scanlines_to_copy);
383
- // Now change them back.
384
- for (int i = 0; i < num_outbufs_; ++i) {
385
- int rows_to_skip = DivideAndRoundDown(skip, GetVertSubSampFactor(i));
386
- int data_to_skip = rows_to_skip * GetComponentStride(i);
387
- databuf_[i] -= data_to_skip;
388
- }
389
- lines_left -= scanlines_to_copy;
390
- }
391
- }
392
- // Read full MCUs until we get to the crop point.
393
- for (; lines_left >= GetImageScanlinesPerImcuRow();
394
- lines_left -= GetImageScanlinesPerImcuRow()) {
395
- if (!DecodeImcuRow()) {
396
- FinishDecode();
397
- return LIBYUV_FALSE;
398
- }
399
- (*fn)(opaque, databuf_, databuf_strides_, GetImageScanlinesPerImcuRow());
400
- }
401
- if (lines_left > 0) {
402
- // Have a partial iMCU row left over to decode.
403
- if (!DecodeImcuRow()) {
404
- FinishDecode();
405
- return LIBYUV_FALSE;
406
- }
407
- (*fn)(opaque, databuf_, databuf_strides_, lines_left);
408
- }
409
- return FinishDecode();
410
- }
411
-
412
- void init_source(j_decompress_ptr cinfo) {
413
- fill_input_buffer(cinfo);
414
- }
415
-
416
- boolean fill_input_buffer(j_decompress_ptr cinfo) {
417
- BufferVector* buf_vec = reinterpret_cast<BufferVector*>(cinfo->client_data);
418
- if (buf_vec->pos >= buf_vec->len) {
419
- // ERROR: No more data
420
- return FALSE;
421
- }
422
- cinfo->src->next_input_byte = buf_vec->buffers[buf_vec->pos].data;
423
- cinfo->src->bytes_in_buffer = buf_vec->buffers[buf_vec->pos].len;
424
- ++buf_vec->pos;
425
- return TRUE;
426
- }
427
-
428
- void skip_input_data(j_decompress_ptr cinfo, long num_bytes) { // NOLINT
429
- jpeg_source_mgr* src = cinfo->src;
430
- size_t bytes = (size_t)num_bytes;
431
- if (bytes > src->bytes_in_buffer) {
432
- src->next_input_byte = nullptr;
433
- src->bytes_in_buffer = 0;
434
- } else {
435
- src->next_input_byte += bytes;
436
- src->bytes_in_buffer -= bytes;
437
- }
438
- }
439
-
440
- void term_source(j_decompress_ptr cinfo) {
441
- (void)cinfo; // Nothing to do.
442
- }
443
-
444
- #ifdef HAVE_SETJMP
445
- void ErrorHandler(j_common_ptr cinfo) {
446
- // This is called when a jpeglib command experiences an error. Unfortunately
447
- // jpeglib's error handling model is not very flexible, because it expects the
448
- // error handler to not return--i.e., it wants the program to terminate. To
449
- // recover from errors we use setjmp() as shown in their example. setjmp() is
450
- // C's implementation for the "call with current continuation" functionality
451
- // seen in some functional programming languages.
452
- // A formatted message can be output, but is unsafe for release.
453
- #ifdef DEBUG
454
- char buf[JMSG_LENGTH_MAX];
455
- (*cinfo->err->format_message)(cinfo, buf);
456
- // ERROR: Error in jpeglib: buf
457
- #endif
458
-
459
- SetJmpErrorMgr* mgr = reinterpret_cast<SetJmpErrorMgr*>(cinfo->err);
460
- // This rewinds the call stack to the point of the corresponding setjmp()
461
- // and causes it to return (for a second time) with value 1.
462
- longjmp(mgr->setjmp_buffer, 1);
463
- }
464
-
465
- // Suppress fprintf warnings.
466
- void OutputHandler(j_common_ptr cinfo) {
467
- (void)cinfo;
468
- }
469
-
470
- #endif // HAVE_SETJMP
471
-
472
- void MJpegDecoder::AllocOutputBuffers(int num_outbufs) {
473
- if (num_outbufs != num_outbufs_) {
474
- // We could perhaps optimize this case to resize the output buffers without
475
- // necessarily having to delete and recreate each one, but it's not worth
476
- // it.
477
- DestroyOutputBuffers();
478
-
479
- scanlines_ = new uint8_t**[num_outbufs];
480
- scanlines_sizes_ = new int[num_outbufs];
481
- databuf_ = new uint8_t*[num_outbufs];
482
- databuf_strides_ = new int[num_outbufs];
483
-
484
- for (int i = 0; i < num_outbufs; ++i) {
485
- scanlines_[i] = NULL;
486
- scanlines_sizes_[i] = 0;
487
- databuf_[i] = NULL;
488
- databuf_strides_[i] = 0;
489
- }
490
-
491
- num_outbufs_ = num_outbufs;
492
- }
493
- }
494
-
495
- void MJpegDecoder::DestroyOutputBuffers() {
496
- for (int i = 0; i < num_outbufs_; ++i) {
497
- delete[] scanlines_[i];
498
- delete[] databuf_[i];
499
- }
500
- delete[] scanlines_;
501
- delete[] databuf_;
502
- delete[] scanlines_sizes_;
503
- delete[] databuf_strides_;
504
- scanlines_ = NULL;
505
- databuf_ = NULL;
506
- scanlines_sizes_ = NULL;
507
- databuf_strides_ = NULL;
508
- num_outbufs_ = 0;
509
- }
510
-
511
- // JDCT_IFAST and do_block_smoothing improve performance substantially.
512
- LIBYUV_BOOL MJpegDecoder::StartDecode() {
513
- decompress_struct_->raw_data_out = TRUE;
514
- decompress_struct_->dct_method = JDCT_IFAST; // JDCT_ISLOW is default
515
- decompress_struct_->dither_mode = JDITHER_NONE;
516
- // Not applicable to 'raw':
517
- decompress_struct_->do_fancy_upsampling = (boolean)(LIBYUV_FALSE);
518
- // Only for buffered mode:
519
- decompress_struct_->enable_2pass_quant = (boolean)(LIBYUV_FALSE);
520
- // Blocky but fast:
521
- decompress_struct_->do_block_smoothing = (boolean)(LIBYUV_FALSE);
522
-
523
- if (!jpeg_start_decompress(decompress_struct_)) {
524
- // ERROR: Couldn't start JPEG decompressor";
525
- return LIBYUV_FALSE;
526
- }
527
- return LIBYUV_TRUE;
528
- }
529
-
530
- LIBYUV_BOOL MJpegDecoder::FinishDecode() {
531
- // jpeglib considers it an error if we finish without decoding the whole
532
- // image, so we call "abort" rather than "finish".
533
- jpeg_abort_decompress(decompress_struct_);
534
- return LIBYUV_TRUE;
535
- }
536
-
537
- void MJpegDecoder::SetScanlinePointers(uint8_t** data) {
538
- for (int i = 0; i < num_outbufs_; ++i) {
539
- uint8_t* data_i = data[i];
540
- for (int j = 0; j < scanlines_sizes_[i]; ++j) {
541
- scanlines_[i][j] = data_i;
542
- data_i += GetComponentStride(i);
543
- }
544
- }
545
- }
546
-
547
- inline LIBYUV_BOOL MJpegDecoder::DecodeImcuRow() {
548
- return (unsigned int)(GetImageScanlinesPerImcuRow()) ==
549
- jpeg_read_raw_data(decompress_struct_, scanlines_,
550
- GetImageScanlinesPerImcuRow());
551
- }
552
-
553
- // The helper function which recognizes the jpeg sub-sampling type.
554
- JpegSubsamplingType MJpegDecoder::JpegSubsamplingTypeHelper(
555
- int* subsample_x,
556
- int* subsample_y,
557
- int number_of_components) {
558
- if (number_of_components == 3) { // Color images.
559
- if (subsample_x[0] == 1 && subsample_y[0] == 1 && subsample_x[1] == 2 &&
560
- subsample_y[1] == 2 && subsample_x[2] == 2 && subsample_y[2] == 2) {
561
- return kJpegYuv420;
562
- }
563
- if (subsample_x[0] == 1 && subsample_y[0] == 1 && subsample_x[1] == 2 &&
564
- subsample_y[1] == 1 && subsample_x[2] == 2 && subsample_y[2] == 1) {
565
- return kJpegYuv422;
566
- }
567
- if (subsample_x[0] == 1 && subsample_y[0] == 1 && subsample_x[1] == 1 &&
568
- subsample_y[1] == 1 && subsample_x[2] == 1 && subsample_y[2] == 1) {
569
- return kJpegYuv444;
570
- }
571
- } else if (number_of_components == 1) { // Grey-scale images.
572
- if (subsample_x[0] == 1 && subsample_y[0] == 1) {
573
- return kJpegYuv400;
574
- }
575
- }
576
- return kJpegUnknown;
577
- }
578
-
579
- } // namespace libyuv
580
- #endif // HAVE_JPEG
@@ -1,71 +0,0 @@
1
- /*
2
- * Copyright 2012 The LibYuv Project Authors. All rights reserved.
3
- *
4
- * Use of this source code is governed by a BSD-style license
5
- * that can be found in the LICENSE file in the root of the source
6
- * tree. An additional intellectual property rights grant can be found
7
- * in the file PATENTS. All contributing project authors may
8
- * be found in the AUTHORS file in the root of the source tree.
9
- */
10
-
11
- #include "libyuv/mjpeg_decoder.h"
12
-
13
- #include <string.h> // For memchr.
14
-
15
- #ifdef __cplusplus
16
- namespace libyuv {
17
- extern "C" {
18
- #endif
19
-
20
- // Helper function to scan for EOI marker (0xff 0xd9).
21
- static LIBYUV_BOOL ScanEOI(const uint8_t* src_mjpg, size_t src_size_mjpg) {
22
- if (src_size_mjpg >= 2) {
23
- const uint8_t* end = src_mjpg + src_size_mjpg - 1;
24
- const uint8_t* it = src_mjpg;
25
- while (it < end) {
26
- // TODO(fbarchard): scan for 0xd9 instead.
27
- it = (const uint8_t*)(memchr(it, 0xff, end - it));
28
- if (it == NULL) {
29
- break;
30
- }
31
- if (it[1] == 0xd9) {
32
- return LIBYUV_TRUE; // Success: Valid jpeg.
33
- }
34
- ++it; // Skip over current 0xff.
35
- }
36
- }
37
- // ERROR: Invalid jpeg end code not found. Size src_size_mjpg
38
- return LIBYUV_FALSE;
39
- }
40
-
41
- // Helper function to validate the jpeg appears intact.
42
- LIBYUV_BOOL ValidateJpeg(const uint8_t* src_mjpg, size_t src_size_mjpg) {
43
- // Maximum size that ValidateJpeg will consider valid.
44
- const size_t kMaxJpegSize = 0x7fffffffull;
45
- const size_t kBackSearchSize = 1024;
46
- if (src_size_mjpg < 64 || src_size_mjpg > kMaxJpegSize || !src_mjpg) {
47
- // ERROR: Invalid jpeg size: src_size_mjpg
48
- return LIBYUV_FALSE;
49
- }
50
- // SOI marker
51
- if (src_mjpg[0] != 0xff || src_mjpg[1] != 0xd8 || src_mjpg[2] != 0xff) {
52
- // ERROR: Invalid jpeg initial start code
53
- return LIBYUV_FALSE;
54
- }
55
-
56
- // Look for the End Of Image (EOI) marker near the end of the buffer.
57
- if (src_size_mjpg > kBackSearchSize) {
58
- if (ScanEOI(src_mjpg + src_size_mjpg - kBackSearchSize, kBackSearchSize)) {
59
- return LIBYUV_TRUE; // Success: Valid jpeg.
60
- }
61
- // Reduce search size for forward search.
62
- src_size_mjpg = src_size_mjpg - kBackSearchSize + 1;
63
- }
64
- // Step over SOI marker and scan for EOI.
65
- return ScanEOI(src_mjpg + 2, src_size_mjpg - 2);
66
- }
67
-
68
- #ifdef __cplusplus
69
- } // extern "C"
70
- } // namespace libyuv
71
- #endif