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,47 +1,47 @@
1
- # This is a generic makefile for libyuv for Windows Arm.
2
- # call "c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_arm\vcvarsx86_arm.bat"
3
- # nmake /f winarm.mk
4
- # make -f winarm.mk
5
- # nmake /f winarm.mk clean
6
- # consider /arch:ARMv7VE
7
- CC=cl
8
- CCFLAGS=/Ox /nologo /Iinclude /DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP
9
- AR=lib
10
- ARFLAGS=/MACHINE:ARM /NOLOGO /SUBSYSTEM:NATIVE
11
- RM=cmd /c del
12
-
13
- LOCAL_OBJ_FILES = \
14
- source/compare.o\
15
- source/compare_common.o\
16
- source/convert.o\
17
- source/convert_argb.o\
18
- source/convert_from.o\
19
- source/convert_from_argb.o\
20
- source/convert_to_argb.o\
21
- source/convert_to_i420.o\
22
- source/cpu_id.o\
23
- source/planar_functions.o\
24
- source/rotate.o\
25
- source/rotate_any.o\
26
- source/rotate_argb.o\
27
- source/rotate_common.o\
28
- source/row_any.o\
29
- source/row_common.o\
30
- source/scale.o\
31
- source/scale_any.o\
32
- source/scale_argb.o\
33
- source/scale_common.o\
34
- source/scale_uv.o\
35
- source/video_common.o
36
-
37
- .cc.o:
38
- $(CC) /c $(CCFLAGS) $*.cc /Fo$@
39
-
40
- all: libyuv_arm.lib winarm.mk
41
-
42
- libyuv_arm.lib: $(LOCAL_OBJ_FILES) winarm.mk
43
- $(AR) $(ARFLAGS) /OUT:$@ $(LOCAL_OBJ_FILES)
44
-
45
- clean:
46
- $(RM) "source\*.o" libyuv_arm.lib
47
-
1
+ # This is a generic makefile for libyuv for Windows Arm.
2
+ # call "c:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_arm\vcvarsx86_arm.bat"
3
+ # nmake /f winarm.mk
4
+ # make -f winarm.mk
5
+ # nmake /f winarm.mk clean
6
+ # consider /arch:ARMv7VE
7
+ CC=cl
8
+ CCFLAGS=/Ox /nologo /Iinclude /DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP
9
+ AR=lib
10
+ ARFLAGS=/MACHINE:ARM /NOLOGO /SUBSYSTEM:NATIVE
11
+ RM=cmd /c del
12
+
13
+ LOCAL_OBJ_FILES = \
14
+ source/compare.o\
15
+ source/compare_common.o\
16
+ source/convert.o\
17
+ source/convert_argb.o\
18
+ source/convert_from.o\
19
+ source/convert_from_argb.o\
20
+ source/convert_to_argb.o\
21
+ source/convert_to_i420.o\
22
+ source/cpu_id.o\
23
+ source/planar_functions.o\
24
+ source/rotate.o\
25
+ source/rotate_any.o\
26
+ source/rotate_argb.o\
27
+ source/rotate_common.o\
28
+ source/row_any.o\
29
+ source/row_common.o\
30
+ source/scale.o\
31
+ source/scale_any.o\
32
+ source/scale_argb.o\
33
+ source/scale_common.o\
34
+ source/scale_uv.o\
35
+ source/video_common.o
36
+
37
+ .cc.o:
38
+ $(CC) /c $(CCFLAGS) $*.cc /Fo$@
39
+
40
+ all: libyuv_arm.lib winarm.mk
41
+
42
+ libyuv_arm.lib: $(LOCAL_OBJ_FILES) winarm.mk
43
+ $(AR) $(ARFLAGS) /OUT:$@ $(LOCAL_OBJ_FILES)
44
+
45
+ clean:
46
+ $(RM) "source\*.o" libyuv_arm.lib
47
+
package/index.js CHANGED
@@ -3,7 +3,19 @@ import { VisionCameraProxy } from 'react-native-vision-camera';
3
3
 
4
4
  const { FaceAntiSpoof } = NativeModules;
5
5
 
6
- const _faceAntiSpoofPlugin = VisionCameraProxy.initFrameProcessorPlugin('faceAntiSpoof', {});
6
+ // Lazily initialize the frame processor plugin after native initialize() succeeds.
7
+ let _faceAntiSpoofPlugin = null;
8
+
9
+ function ensurePluginInitialized() {
10
+ if (!_faceAntiSpoofPlugin) {
11
+ try {
12
+ _faceAntiSpoofPlugin = VisionCameraProxy.initFrameProcessorPlugin('faceAntiSpoof', {});
13
+ } catch (e) {
14
+ console.warn('[FaceAntiSpoof] Failed to init frame processor plugin:', e);
15
+ _faceAntiSpoofPlugin = null;
16
+ }
17
+ }
18
+ }
7
19
 
8
20
  // Worklet called by VisionCamera
9
21
  export const faceAntiSpoofFrameProcessor = function (frame) {
@@ -67,6 +79,10 @@ export const initializeFaceAntiSpoof = async () => {
67
79
  }
68
80
 
69
81
  const isSuccess = result && status.pluginAvailable;
82
+ // If native initialization succeeded, register the frame processor plugin for worklets
83
+ if (isSuccess) {
84
+ ensurePluginInitialized();
85
+ }
70
86
  console.log('[FaceAntiSpoof] Initialization result:', isSuccess);
71
87
  return isSuccess;
72
88
  } catch (error) {
@@ -0,0 +1,283 @@
1
+ import Foundation
2
+
3
+ #if canImport(VisionCamera)
4
+ import VisionCamera
5
+ import AVFoundation
6
+ import CoreImage
7
+ import UIKit
8
+ import Accelerate
9
+
10
+ #if canImport(TensorFlowLite)
11
+ import TensorFlowLite
12
+ #endif
13
+
14
+ typealias FaceAntiSpoofFrameType = Frame
15
+ typealias FaceAntiSpoofProxyType = VisionCameraProxyHolder
16
+ typealias FaceAntiSpoofPluginBase = FrameProcessorPlugin
17
+
18
+ @objc(FaceAntiSpoofFrameProcessor)
19
+ class FaceAntiSpoofFrameProcessor: FaceAntiSpoofPluginBase {
20
+ private weak var proxyHolder: FaceAntiSpoofProxyType?
21
+
22
+ // Processing state
23
+ private let processingQueue = DispatchQueue(label: "com.faceantispoof.processing", qos: .userInitiated)
24
+ private var isProcessing: Bool = false
25
+ private var latestResult: [String: Any] = ["error": "Not initialized", "isLive": false, "label": "Not Initialized"]
26
+ private static let INPUT_IMAGE_SIZE: Int = 256
27
+
28
+ #if canImport(TensorFlowLite)
29
+ // Interpreter is provided by FaceAntiSpoofManager.sharedInterpreter
30
+ #endif
31
+
32
+ override init(
33
+ proxy: FaceAntiSpoofProxyType,
34
+ options: [AnyHashable : Any]! = [:]
35
+ ) {
36
+ #if canImport(VisionCamera)
37
+ super.init(proxy: proxy, options: options)
38
+ #else
39
+ super.init(proxy: proxy, options: options as NSDictionary?)
40
+ #endif
41
+ self.proxyHolder = proxy
42
+
43
+ #if canImport(TensorFlowLite)
44
+ let managerInited = FaceAntiSpoofManager.initializeModel()
45
+ if managerInited {
46
+ NSLog("[FaceAntiSpoof] Manager initialized model")
47
+ } else {
48
+ NSLog("[FaceAntiSpoof] Manager failed to initialize model; running stub")
49
+ }
50
+ #else
51
+ NSLog("[FaceAntiSpoof] TensorFlowLite not available; running stub")
52
+ #endif
53
+ }
54
+
55
+ deinit {
56
+ NSLog("[FaceAntiSpoof] deinit - releasing resources")
57
+ self.proxyHolder = nil
58
+ }
59
+
60
+ override func callback(
61
+ _ frame: FaceAntiSpoofFrameType,
62
+ withArguments arguments: [AnyHashable : Any]?
63
+ ) -> Any {
64
+ #if canImport(TensorFlowLite)
65
+ guard FaceAntiSpoofManager.isModelLoaded() else {
66
+ return ["error": "Model not loaded", "isLive": false, "label": "stub"]
67
+ }
68
+
69
+ let sampleBuffer = frame.buffer
70
+ guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
71
+ return ["error": "No pixel buffer", "isLive": false, "label": "stub"]
72
+ }
73
+
74
+ let width = CVPixelBufferGetWidth(pixelBuffer)
75
+ let height = CVPixelBufferGetHeight(pixelBuffer)
76
+
77
+ // If processing already in flight, return latest cached result immediately
78
+ var shouldReturnLatest = false
79
+ objc_sync_enter(self)
80
+ if isProcessing {
81
+ shouldReturnLatest = true
82
+ } else {
83
+ isProcessing = true
84
+ }
85
+ objc_sync_exit(self)
86
+
87
+ if shouldReturnLatest {
88
+ return latestResult
89
+ }
90
+
91
+ // Capture a small, resized RGB float snapshot synchronously while the pixel buffer is valid
92
+ let targetSize = CGSize(width: Self.INPUT_IMAGE_SIZE, height: Self.INPUT_IMAGE_SIZE)
93
+ guard let rgbInput = Self.rgbFloatData(from: pixelBuffer, size: targetSize) else {
94
+ objc_sync_enter(self)
95
+ isProcessing = false
96
+ objc_sync_exit(self)
97
+ latestResult = ["error": "Failed to create RGB snapshot", "isLive": false, "label": "error"]
98
+ return latestResult
99
+ }
100
+
101
+ // Offload heavy model work to a background queue
102
+ processingQueue.async { [weak self] in
103
+ guard let self = self else { return }
104
+ defer {
105
+ objc_sync_enter(self)
106
+ self.isProcessing = false
107
+ objc_sync_exit(self)
108
+ }
109
+
110
+ guard let interpreter = FaceAntiSpoofManager.sharedInterpreter else {
111
+ self.latestResult = ["error": "Interpreter not available", "isLive": false, "label": "error"]
112
+ return
113
+ }
114
+
115
+ do {
116
+ // Prepare input Data (Float32 little-endian)
117
+ var inputFloats = rgbInput
118
+ let inputData = Data(bytes: &inputFloats, count: inputFloats.count * MemoryLayout<Float>.size)
119
+
120
+ try interpreter.copy(inputData, toInputAt: 0)
121
+ try interpreter.invoke()
122
+
123
+ // Read outputs (assume indices 0 and 1 correspond to clssPred and leafNodeMask)
124
+ let out0 = try interpreter.output(at: 0)
125
+ let out1 = try interpreter.output(at: 1)
126
+
127
+ let clssPred: [Float] = out0.data.withUnsafeBytes { ptr in
128
+ let floatPtr = ptr.bindMemory(to: Float.self)
129
+ return Array(floatPtr)
130
+ }
131
+ let leafMask: [Float] = out1.data.withUnsafeBytes { ptr in
132
+ let floatPtr = ptr.bindMemory(to: Float.self)
133
+ return Array(floatPtr)
134
+ }
135
+
136
+ // Compute neural network score similar to Android leafScore1
137
+ let count = min(clssPred.count, leafMask.count)
138
+ var nnScore: Float = 0.0
139
+ for i in 0..<count {
140
+ nnScore += abs(clssPred[i]) * leafMask[i]
141
+ }
142
+
143
+ // Laplacian score computed from the RGB snapshot (resized)
144
+ let lapScore = Self.calculateLaplacianScore(from: rgbInput, width: Self.INPUT_IMAGE_SIZE, height: Self.INPUT_IMAGE_SIZE)
145
+
146
+ let combined = Self.calculateCombinedScore(neuralScore: nnScore, laplacianScore: lapScore)
147
+ let confidence = Self.calculateConfidence(neuralScore: nnScore, laplacianScore: lapScore)
148
+
149
+ self.latestResult = [
150
+ "neuralNetworkScore": Double(nnScore),
151
+ "laplacianScore": lapScore,
152
+ "combinedScore": Double(combined),
153
+ "confidence": Double(confidence),
154
+ "isLive": combined > 0.5,
155
+ "label": combined > 0.5 ? "live" : "spoof",
156
+ "width": width,
157
+ "height": height
158
+ ]
159
+ } catch {
160
+ self.latestResult = ["error": "Processing error: \(error)", "isLive": false, "label": "error"]
161
+ }
162
+ }
163
+
164
+ // Return latest result immediately (may be previous or initial)
165
+ return latestResult
166
+ #else
167
+ return ["error": "TensorFlowLite not available", "isLive": false, "label": "stub"]
168
+ #endif
169
+ }
170
+
171
+ // MARK: - Helpers
172
+ #if canImport(TensorFlowLite)
173
+ private static func floatArray(from data: Data) -> [Float] {
174
+ let count = data.count / MemoryLayout<Float>.size
175
+ return data.withUnsafeBytes { buffer -> [Float] in
176
+ let ptr = buffer.bindMemory(to: Float.self)
177
+ return Array(UnsafeBufferPointer(start: ptr.baseAddress, count: count))
178
+ }
179
+ }
180
+
181
+ private static let sharedCIContext: CIContext = CIContext(options: nil)
182
+
183
+ private static func rgbFloatData(from pixelBuffer: CVPixelBuffer, size: CGSize) -> [Float]? {
184
+ CVPixelBufferLockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.readOnly)
185
+ defer { CVPixelBufferUnlockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.readOnly) }
186
+
187
+ let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
188
+ let context = Self.sharedCIContext
189
+ guard let cgImage = context.createCGImage(ciImage, from: ciImage.extent) else { return nil }
190
+
191
+ let width = Int(size.width)
192
+ let height = Int(size.height)
193
+ let colorSpace = CGColorSpaceCreateDeviceRGB()
194
+ var rawData = [UInt8](repeating: 0, count: width * height * 4)
195
+ rawData.withUnsafeMutableBytes { ptr in
196
+ if let base = ptr.baseAddress {
197
+ let bytesPerRow = width * 4
198
+ if let ctx = CGContext(data: base,
199
+ width: width,
200
+ height: height,
201
+ bitsPerComponent: 8,
202
+ bytesPerRow: bytesPerRow,
203
+ space: colorSpace,
204
+ bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) {
205
+ ctx.interpolationQuality = .high
206
+ ctx.draw(cgImage, in: CGRect(x: 0, y: 0, width: width, height: height))
207
+ }
208
+ }
209
+ }
210
+
211
+ var floatData = [Float](repeating: 0, count: width * height * 3)
212
+ var idx = 0
213
+ for y in 0..<height {
214
+ for x in 0..<width {
215
+ let pixelIndex = (y * width + x) * 4
216
+ let r = Float(rawData[pixelIndex]) / 255.0
217
+ let g = Float(rawData[pixelIndex + 1]) / 255.0
218
+ let b = Float(rawData[pixelIndex + 2]) / 255.0
219
+ floatData[idx] = r
220
+ floatData[idx + 1] = g
221
+ floatData[idx + 2] = b
222
+ idx += 3
223
+ }
224
+ }
225
+ return floatData
226
+ }
227
+
228
+ private static func calculateLaplacianScore(from rgbData: [Float], width: Int, height: Int) -> Int {
229
+ var grey = [Int](repeating: 0, count: width * height)
230
+ var i = 0
231
+ for y in 0..<height {
232
+ for x in 0..<width {
233
+ let base = (y * width + x) * 3
234
+ let r = Int((rgbData[base] * 255).rounded())
235
+ let g = Int((rgbData[base + 1] * 255).rounded())
236
+ let b = Int((rgbData[base + 2] * 255).rounded())
237
+ let value = Int(0.299 * Float(r) + 0.587 * Float(g) + 0.114 * Float(b))
238
+ grey[i] = value
239
+ i += 1
240
+ }
241
+ }
242
+
243
+ let laplace = [[0,1,0],[1,-4,1],[0,1,0]]
244
+ let size = 3
245
+ var score = 0
246
+ let threshold = 50
247
+ for y in 0..<(height - size + 1) {
248
+ for x in 0..<(width - size + 1) {
249
+ var result = 0
250
+ for ky in 0..<size {
251
+ for kx in 0..<size {
252
+ result += grey[(y + ky) * width + (x + kx)] * laplace[ky][kx]
253
+ }
254
+ }
255
+ if result > threshold {
256
+ score += 1
257
+ }
258
+ }
259
+ }
260
+ return score
261
+ }
262
+
263
+ private static func calculateCombinedScore(neuralScore: Float, laplacianScore: Int) -> Float {
264
+ let normalizedNeural = min(max(neuralScore, 0), 1)
265
+ let normalizedLaplacian = min(max(Float(laplacianScore) / 4000.0, 0), 1)
266
+ let neuralWeight: Float = 0.6
267
+ let laplacianWeight: Float = 0.4
268
+ let invertedNeural = 1.0 - normalizedNeural
269
+ return (invertedNeural * neuralWeight) + (normalizedLaplacian * laplacianWeight)
270
+ }
271
+
272
+ private static func calculateConfidence(neuralScore: Float, laplacianScore: Int) -> Float {
273
+ let neuralConfidence = min(max(neuralScore, 0), 1)
274
+ let laplacianConfidence = min(max(Float(laplacianScore) / 4000.0, 0), 1)
275
+ let invertedNeural = 1.0 - neuralConfidence
276
+ return (invertedNeural * 0.6 + laplacianConfidence * 0.4)
277
+ }
278
+ #endif
279
+ }
280
+
281
+ #endif
282
+
283
+
@@ -0,0 +1,12 @@
1
+ // Simple header for JSI install stub
2
+ #import <Foundation/Foundation.h>
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ void FaceAntiSpoofJSI_install(void *runtimePtr);
9
+
10
+ #ifdef __cplusplus
11
+ }
12
+ #endif
@@ -0,0 +1,92 @@
1
+ // Objective-C++ JSI registration for FaceAntiSpoof
2
+ #import "FaceAntiSpoofJSI.h"
3
+ #import <Foundation/Foundation.h>
4
+ #import <objc/runtime.h>
5
+ #import <objc/message.h>
6
+
7
+ #ifdef __cplusplus
8
+ #include <jsi/jsi.h>
9
+ using namespace facebook;
10
+ #endif
11
+
12
+ // Helper to call +[FaceAntiSpoofManager isModelLoaded]
13
+ static bool FaceAntiSpoofManager_isModelLoaded() {
14
+ Class managerClass = objc_getClass("FaceAntiSpoofManager");
15
+ if (!managerClass) return false;
16
+ SEL sel = sel_getUid("isModelLoaded");
17
+ if (!sel) return false;
18
+ BOOL (*msgSendBool)(id, SEL) = (BOOL (*)(id, SEL))objc_msgSend;
19
+ return msgSendBool((id)managerClass, sel);
20
+ }
21
+
22
+ // Helper to call +[FaceAntiSpoofManager initializeModel]
23
+ static bool FaceAntiSpoofManager_initialize() {
24
+ Class managerClass = objc_getClass("FaceAntiSpoofManager");
25
+ if (!managerClass) return false;
26
+ SEL sel = sel_getUid("initializeModel");
27
+ if (!sel) return false;
28
+ BOOL (*msgSendBool)(id, SEL) = (BOOL (*)(id, SEL))objc_msgSend;
29
+ return msgSendBool((id)managerClass, sel);
30
+ }
31
+
32
+ extern "C" void FaceAntiSpoofJSI_install(void *runtimePtr) {
33
+ #ifdef __cplusplus
34
+ if (!runtimePtr) {
35
+ NSLog(@"[FaceAntiSpoof] JSI install called with NULL runtime pointer");
36
+ return;
37
+ }
38
+
39
+ jsi::Runtime *rt = reinterpret_cast<jsi::Runtime*>(runtimePtr);
40
+ if (!rt) {
41
+ NSLog(@"[FaceAntiSpoof] JSI install: invalid runtime pointer");
42
+ return;
43
+ }
44
+
45
+ try {
46
+ // Register faceAntiSpoof_isModelLoaded()
47
+ auto isLoadedFunc = jsi::Function::createFromHostFunction(*rt,
48
+ jsi::PropNameID::forAscii(*rt, "faceAntiSpoof_isModelLoaded"), 0,
49
+ [](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
50
+ bool loaded = FaceAntiSpoofManager_isModelLoaded();
51
+ return jsi::Value(loaded);
52
+ }
53
+ );
54
+ rt->global().setProperty(*rt, "faceAntiSpoof_isModelLoaded", isLoadedFunc);
55
+
56
+ // Register faceAntiSpoof_initialize()
57
+ auto initFunc = jsi::Function::createFromHostFunction(*rt,
58
+ jsi::PropNameID::forAscii(*rt, "faceAntiSpoof_initialize"), 0,
59
+ [](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
60
+ bool ok = FaceAntiSpoofManager_initialize();
61
+ return jsi::Value(ok);
62
+ }
63
+ );
64
+ rt->global().setProperty(*rt, "faceAntiSpoof_initialize", initFunc);
65
+
66
+ // Register faceAntiSpoof_getModuleInfo()
67
+ auto infoFunc = jsi::Function::createFromHostFunction(*rt,
68
+ jsi::PropNameID::forAscii(*rt, "faceAntiSpoof_getModuleInfo"), 0,
69
+ [](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
70
+ jsi::Object obj(rt);
71
+ obj.setProperty(rt, "name", jsi::String::createFromUtf8(rt, "FaceAntiSpoof"));
72
+ jsi::Array methods(rt, 4);
73
+ methods.setValueAtIndex(rt, 0, jsi::String::createFromUtf8(rt, "initialize"));
74
+ methods.setValueAtIndex(rt, 1, jsi::String::createFromUtf8(rt, "checkModelStatus"));
75
+ methods.setValueAtIndex(rt, 2, jsi::String::createFromUtf8(rt, "isAvailable"));
76
+ methods.setValueAtIndex(rt, 3, jsi::String::createFromUtf8(rt, "cleanup"));
77
+ obj.setProperty(rt, "methods", methods);
78
+ return obj;
79
+ }
80
+ );
81
+ rt->global().setProperty(*rt, "faceAntiSpoof_getModuleInfo", infoFunc);
82
+
83
+ NSLog(@"[FaceAntiSpoof] JSI functions registered");
84
+ } catch (const std::exception &ex) {
85
+ NSLog(@"[FaceAntiSpoof] JSI registration exception: %s", ex.what());
86
+ } catch (...) {
87
+ NSLog(@"[FaceAntiSpoof] JSI registration unknown exception");
88
+ }
89
+ #else
90
+ NSLog(@"[FaceAntiSpoof] JSI install compiled without C++ support");
91
+ #endif
92
+ }
@@ -0,0 +1,63 @@
1
+ import Foundation
2
+
3
+ #if canImport(TensorFlowLite)
4
+ import TensorFlowLite
5
+ #endif
6
+
7
+ @objcMembers
8
+ public class FaceAntiSpoofManager: NSObject {
9
+ #if canImport(TensorFlowLite)
10
+ public static var sharedInterpreter: Interpreter?
11
+ #endif
12
+
13
+ @objc public class func initializeModel() -> Bool {
14
+ #if canImport(TensorFlowLite)
15
+ if sharedInterpreter != nil { return true }
16
+
17
+ // Look in main bundle then plugin bundle
18
+ var modelPath = Bundle.main.path(forResource: "FaceAntiSpoofing", ofType: "tflite")
19
+ if modelPath == nil {
20
+ if let fpsClass = NSClassFromString("FaceAntiSpoofFrameProcessor") as? AnyClass {
21
+ let podBundle = Bundle(for: fpsClass)
22
+ modelPath = podBundle.path(forResource: "FaceAntiSpoofing", ofType: "tflite")
23
+ }
24
+ }
25
+
26
+ guard let path = modelPath else {
27
+ NSLog("[FaceAntiSpoof] Manager: model not found")
28
+ return false
29
+ }
30
+
31
+ do {
32
+ var options = Interpreter.Options()
33
+ options.threadCount = 2
34
+ sharedInterpreter = try Interpreter(modelPath: path, options: options)
35
+ try sharedInterpreter?.allocateTensors()
36
+ NSLog("[FaceAntiSpoof] Manager: Loaded model at \(path)")
37
+ return true
38
+ } catch {
39
+ NSLog("[FaceAntiSpoof] Manager: Failed to create interpreter: \(error)")
40
+ sharedInterpreter = nil
41
+ return false
42
+ }
43
+ #else
44
+ NSLog("[FaceAntiSpoof] Manager: TensorFlowLite not available")
45
+ return false
46
+ #endif
47
+ }
48
+
49
+ @objc public class func isModelLoaded() -> Bool {
50
+ #if canImport(TensorFlowLite)
51
+ return sharedInterpreter != nil
52
+ #else
53
+ return false
54
+ #endif
55
+ }
56
+
57
+ @objc public class func cleanupModel() {
58
+ #if canImport(TensorFlowLite)
59
+ sharedInterpreter = nil
60
+ #endif
61
+ NSLog("[FaceAntiSpoof] Manager: cleaned up model")
62
+ }
63
+ }