react-native-vision-camera-spoof-detector 1.1.0 → 1.1.7

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.

Potentially problematic release.


This version of react-native-vision-camera-spoof-detector might be problematic. Click here for more details.

Files changed (43) hide show
  1. package/.npmignore +16 -0
  2. package/android/CMakeLists.txt +29 -0
  3. package/android/build.gradle +26 -10
  4. package/android/fix-prefab.gradle +4 -0
  5. package/android/src/main/AndroidManifest.xml +1 -1
  6. package/android/src/main/cpp/CMakeLists.txt +18 -86
  7. package/android/src/main/cpp/FaceAntiSpoofJSI.cpp +80 -6
  8. package/android/src/main/cpp/cpp-adapter.cpp +9 -0
  9. package/android/src/main/java/com/faceantispoof/FaceAntiSpoofModule.kt +53 -103
  10. package/android/src/main/java/com/faceantispoof/FaceAntiSpoofPackage.kt +15 -8
  11. package/android/src/main/java/com/margelo/nitro/camera/spoofdetector/HybridSpoofDetectorFactory.kt +15 -0
  12. package/android/src/main/java/com/margelo/nitro/camera/spoofdetector/HybridSpoofDetectorOutput.kt +107 -0
  13. package/index.js +23 -42
  14. package/nitro.json +20 -0
  15. package/nitrogen/generated/.gitattributes +1 -0
  16. package/nitrogen/generated/android/VisionCameraSpoofDetector+autolinking.cmake +81 -0
  17. package/nitrogen/generated/android/VisionCameraSpoofDetector+autolinking.gradle +27 -0
  18. package/nitrogen/generated/android/VisionCameraSpoofDetectorOnLoad.cpp +58 -0
  19. package/nitrogen/generated/android/VisionCameraSpoofDetectorOnLoad.hpp +34 -0
  20. package/nitrogen/generated/android/c++/JAntiSpoofingResult.hpp +77 -0
  21. package/nitrogen/generated/android/c++/JFunc_void_AntiSpoofingResult.hpp +78 -0
  22. package/nitrogen/generated/android/c++/JFunc_void_std__exception_ptr.hpp +76 -0
  23. package/nitrogen/generated/android/c++/JHybridSpoofDetectorFactorySpec.cpp +75 -0
  24. package/nitrogen/generated/android/c++/JHybridSpoofDetectorFactorySpec.hpp +63 -0
  25. package/nitrogen/generated/android/c++/JSize.hpp +61 -0
  26. package/nitrogen/generated/android/c++/JSpoofDetectorOutputOptions.hpp +91 -0
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/AntiSpoofingResult.kt +76 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/Func_void_AntiSpoofingResult.kt +78 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/Func_void_std__exception_ptr.kt +78 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/HybridSpoofDetectorFactorySpec.kt +57 -0
  31. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/Size.kt +56 -0
  32. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/SpoofDetectorOutputOptions.kt +65 -0
  33. package/nitrogen/generated/android/kotlin/com/margelo/nitro/camera/spoofdetector/VisionCameraSpoofDetectorOnLoad.kt +35 -0
  34. package/nitrogen/generated/shared/c++/AntiSpoofingResult.hpp +103 -0
  35. package/nitrogen/generated/shared/c++/HybridSpoofDetectorFactorySpec.cpp +21 -0
  36. package/nitrogen/generated/shared/c++/HybridSpoofDetectorFactorySpec.hpp +67 -0
  37. package/nitrogen/generated/shared/c++/Size.hpp +87 -0
  38. package/nitrogen/generated/shared/c++/SpoofDetectorOutputOptions.hpp +98 -0
  39. package/package.json +10 -8
  40. package/src/specs/SpoofDetectorFactory.nitro.ts +23 -0
  41. package/android/src/main/assets/spoof_model_scale_2_7.tflite +0 -0
  42. package/android/src/main/assets/spoof_model_scale_4_0.tflite +0 -0
  43. /package/{android/src/main → lib}/assets/FaceAntiSpoofing.tflite +0 -0
@@ -0,0 +1,107 @@
1
+ package com.margelo.nitro.camera.spoofdetector
2
+
3
+ import androidx.camera.core.ImageAnalysis
4
+ import androidx.camera.core.ImageProxy
5
+ import androidx.camera.core.resolutionselector.ResolutionSelector
6
+ import androidx.camera.core.resolutionselector.ResolutionStrategy
7
+ import com.margelo.nitro.NitroModules
8
+ import com.margelo.nitro.camera.CameraOrientation
9
+ import com.margelo.nitro.camera.HybridCameraOutputSpec
10
+ import com.margelo.nitro.camera.MediaType
11
+ import com.margelo.nitro.camera.MirrorMode
12
+ import com.margelo.nitro.camera.extensions.setAllowDroppingLateFrames
13
+ import com.margelo.nitro.camera.extensions.surfaceRotation
14
+ import com.margelo.nitro.camera.public.NativeCameraOutput
15
+ import com.faceantispoof.FaceAntiSpoofingAdvanced
16
+ import java.util.concurrent.Executors
17
+ import java.util.concurrent.atomic.AtomicBoolean
18
+
19
+ class HybridSpoofDetectorOutput(
20
+ private val options: SpoofDetectorOutputOptions,
21
+ ) : HybridCameraOutputSpec(), ImageAnalysis.Analyzer, NativeCameraOutput {
22
+ override val mediaType: MediaType = MediaType.VIDEO
23
+ override val mirrorMode: MirrorMode = MirrorMode.AUTO
24
+ override var outputOrientation: CameraOrientation = CameraOrientation.UP
25
+ set(value) {
26
+ field = value
27
+ imageAnalysis?.targetRotation = value.surfaceRotation
28
+ }
29
+ override val currentResolution: com.margelo.nitro.camera.Size?
30
+ get() = null
31
+
32
+ private val executor = Executors.newSingleThreadExecutor()
33
+ private val busy = AtomicBoolean(false)
34
+ private val detector = FaceAntiSpoofingAdvanced(
35
+ NitroModules.applicationContext?.assets ?: error("FaceAntiSpoof: no application context")
36
+ )
37
+ private var imageAnalysis: ImageAnalysis? = null
38
+
39
+ override fun createUseCase(
40
+ mirrorMode: MirrorMode,
41
+ config: NativeCameraOutput.Config,
42
+ ): NativeCameraOutput.PreparedUseCase {
43
+ val target = options.targetResolution
44
+ val selector = target?.let {
45
+ ResolutionSelector.Builder()
46
+ .setResolutionStrategy(
47
+ ResolutionStrategy(
48
+ android.util.Size(it.width.toInt(), it.height.toInt()),
49
+ ResolutionStrategy.FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER,
50
+ )
51
+ )
52
+ .build()
53
+ }
54
+ val analysis = ImageAnalysis.Builder()
55
+ .setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_YUV_420_888)
56
+ .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
57
+ .setAllowDroppingLateFrames(true)
58
+ .apply { if (selector != null) setResolutionSelector(selector) }
59
+ .build()
60
+ return NativeCameraOutput.PreparedUseCase(analysis) {
61
+ imageAnalysis = analysis
62
+ analysis.setAnalyzer(executor, this)
63
+ }
64
+ }
65
+
66
+ override fun analyze(image: ImageProxy) {
67
+ if (!busy.compareAndSet(false, true)) {
68
+ image.close()
69
+ return
70
+ }
71
+ try {
72
+ val planes = image.planes.take(3).map { plane ->
73
+ val buffer = plane.buffer.duplicate()
74
+ ByteArray(buffer.remaining()).also(buffer::get)
75
+ }.toTypedArray()
76
+ val rowStrides = image.planes.take(3).map { it.rowStride }.toIntArray()
77
+ val pixelStrides = image.planes.take(3).map { it.pixelStride.coerceAtLeast(1) }.toIntArray()
78
+ val result = detector.advancedAntiSpoofing(
79
+ planes, image.width, image.height, rowStrides, pixelStrides
80
+ )
81
+ val isLive = result.neuralNetworkScore < FaceAntiSpoofingAdvanced.BASE_THRESHOLD &&
82
+ result.laplacianScore > FaceAntiSpoofingAdvanced.LAPLACIAN_THRESHOLD
83
+ options.onResult.invoke(
84
+ AntiSpoofingResult(
85
+ isLive,
86
+ if (isLive) "Live Face" else "Spoof Face",
87
+ result.neuralNetworkScore.toDouble(),
88
+ result.laplacianScore.toDouble(),
89
+ result.combinedScore.toDouble(),
90
+ result.confidence.toDouble(),
91
+ )
92
+ )
93
+ } catch (error: Throwable) {
94
+ options.onError?.invoke(error)
95
+ } finally {
96
+ image.close()
97
+ busy.set(false)
98
+ }
99
+ }
100
+
101
+ override fun dispose() {
102
+ imageAnalysis?.clearAnalyzer()
103
+ detector.close()
104
+ executor.shutdown()
105
+ super.dispose()
106
+ }
107
+ }
package/index.js CHANGED
@@ -1,50 +1,31 @@
1
- import { NativeModules } from 'react-native';
2
- import { useFrameOutput } from 'react-native-vision-camera';
1
+ import { useMemo, useRef } from 'react';
2
+ import { NativeModules } from 'react-native';
3
+ import { NitroModules } from 'react-native-nitro-modules';
3
4
  import { scheduleOnRN } from 'react-native-worklets';
4
5
 
5
6
  const { FaceAntiSpoof } = NativeModules;
6
7
 
7
- const processFrameOnRN = (frameData, width, height, onResult) => {
8
- FaceAntiSpoof.processFrame(frameData.planes, width, height, frameData.rowStrides, frameData.pixelStrides)
9
- .then(onResult)
10
- .catch((error) => console.error('[FaceAntiSpoof] Frame processing failed:', error));
11
- };
12
-
13
8
  export const useFaceAntiSpoofFrameOutput = ({ onResult, ...options } = {}) => {
14
- const onFrame = (frame) => {
15
- 'worklet';
16
- try {
17
- const planes = frame.getPlanes();
18
- if (planes.length < 3) return;
19
-
20
- const planeData = planes.map((plane) => Array.from(new Uint8Array(plane.getPixelBuffer())));
21
- const rowStrides = planes.map((plane) => plane.bytesPerRow);
22
- const pixelStrides = planes.map((plane) => plane.bytesPerRow / plane.width);
23
- scheduleOnRN(
24
- processFrameOnRN,
25
- { planes: planeData, rowStrides, pixelStrides },
26
- frame.width,
27
- frame.height,
28
- onResult,
29
- );
30
- } finally {
31
- frame.dispose();
32
- }
33
- };
34
-
35
- return useFrameOutput({
36
- ...options,
37
- pixelFormat: 'yuv',
38
- targetResolution: { width: 256, height: 256 },
39
- onFrame,
40
- });
41
- };
42
-
43
- // Kept as a named export for source compatibility. VisionCamera 5 applications
44
- // must use useFaceAntiSpoofFrameOutput because the old plugin API was removed.
45
- export const faceAntiSpoofFrameProcessor = function () {
46
- 'worklet';
47
- return null;
9
+ const resultRef = useRef(onResult);
10
+ resultRef.current = onResult;
11
+ const errorRef = useRef(options.onError);
12
+ errorRef.current = options.onError;
13
+ const factory = useMemo(
14
+ () => NitroModules.createHybridObject('SpoofDetectorFactory'),
15
+ [],
16
+ );
17
+ return useMemo(
18
+ () => factory.createSpoofDetectorOutput({
19
+ targetResolution: options.targetResolution ?? { width: 256, height: 256 },
20
+ onResult(result) {
21
+ resultRef.current?.(result);
22
+ },
23
+ onError(error) {
24
+ errorRef.current?.(error);
25
+ },
26
+ }),
27
+ [factory, options.targetResolution],
28
+ );
48
29
  };
49
30
 
50
31
  export default FaceAntiSpoof;
package/nitro.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://nitro.margelo.com/nitro.schema.json",
3
+ "cxxNamespace": ["camera", "spoofdetector"],
4
+ "ios": {
5
+ "iosModuleName": "VisionCameraSpoofDetector"
6
+ },
7
+ "android": {
8
+ "androidNamespace": ["camera", "spoofdetector"],
9
+ "androidCxxLibName": "VisionCameraSpoofDetector"
10
+ },
11
+ "autolinking": {
12
+ "SpoofDetectorFactory": {
13
+ "android": {
14
+ "language": "kotlin",
15
+ "implementationClassName": "HybridSpoofDetectorFactory"
16
+ }
17
+ }
18
+ },
19
+ "ignorePaths": ["**/node_modules"]
20
+ }
@@ -0,0 +1 @@
1
+ ** linguist-generated=true
@@ -0,0 +1,81 @@
1
+ #
2
+ # VisionCameraSpoofDetector+autolinking.cmake
3
+ # This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ # https://github.com/mrousavy/nitro
5
+ # Copyright © Marc Rousavy @ Margelo
6
+ #
7
+
8
+ # This is a CMake file that adds all files generated by Nitrogen
9
+ # to the current CMake project.
10
+ #
11
+ # To use it, add this to your CMakeLists.txt:
12
+ # ```cmake
13
+ # include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/VisionCameraSpoofDetector+autolinking.cmake)
14
+ # ```
15
+
16
+ # Define a flag to check if we are building properly
17
+ add_definitions(-DBUILDING_VISIONCAMERASPOOFDETECTOR_WITH_GENERATED_CMAKE_PROJECT)
18
+
19
+ # Enable Raw Props parsing in react-native (for Nitro Views)
20
+ add_definitions(-DRN_SERIALIZABLE_STATE)
21
+
22
+ # Add all headers that were generated by Nitrogen
23
+ include_directories(
24
+ "../nitrogen/generated/shared/c++"
25
+ "../nitrogen/generated/android/c++"
26
+ "../nitrogen/generated/android/"
27
+ )
28
+
29
+ # Add all .cpp sources that were generated by Nitrogen
30
+ target_sources(
31
+ # CMake project name (Android C++ library name)
32
+ VisionCameraSpoofDetector PRIVATE
33
+ # Autolinking Setup
34
+ ../nitrogen/generated/android/VisionCameraSpoofDetectorOnLoad.cpp
35
+ # Shared Nitrogen C++ sources
36
+ ../nitrogen/generated/shared/c++/HybridSpoofDetectorFactorySpec.cpp
37
+ # Android-specific Nitrogen C++ sources
38
+ ../nitrogen/generated/android/c++/JHybridSpoofDetectorFactorySpec.cpp
39
+ )
40
+
41
+ # From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
42
+ # Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
43
+ target_compile_definitions(
44
+ VisionCameraSpoofDetector PRIVATE
45
+ -DFOLLY_NO_CONFIG=1
46
+ -DFOLLY_HAVE_CLOCK_GETTIME=1
47
+ -DFOLLY_USE_LIBCPP=1
48
+ -DFOLLY_CFG_NO_COROUTINES=1
49
+ -DFOLLY_MOBILE=1
50
+ -DFOLLY_HAVE_RECVMMSG=1
51
+ -DFOLLY_HAVE_PTHREAD=1
52
+ # Once we target android-23 above, we can comment
53
+ # the following line. NDK uses GNU style stderror_r() after API 23.
54
+ -DFOLLY_HAVE_XSI_STRERROR_R=1
55
+ )
56
+
57
+ # Add all libraries required by the generated specs
58
+ find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
59
+ find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
60
+ find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library
61
+
62
+ # Link all libraries together
63
+ target_link_libraries(
64
+ VisionCameraSpoofDetector
65
+ fbjni::fbjni # <-- Facebook C++ JNI helpers
66
+ ReactAndroid::jsi # <-- RN: JSI
67
+ react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
68
+ )
69
+
70
+ # Link react-native (different prefab between RN 0.75 and RN 0.76)
71
+ if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
72
+ target_link_libraries(
73
+ VisionCameraSpoofDetector
74
+ ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
75
+ )
76
+ else()
77
+ target_link_libraries(
78
+ VisionCameraSpoofDetector
79
+ ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
80
+ )
81
+ endif()
@@ -0,0 +1,27 @@
1
+ ///
2
+ /// VisionCameraSpoofDetector+autolinking.gradle
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ /// This is a Gradle file that adds all files generated by Nitrogen
9
+ /// to the current Gradle project.
10
+ ///
11
+ /// To use it, add this to your build.gradle:
12
+ /// ```gradle
13
+ /// apply from: '../nitrogen/generated/android/VisionCameraSpoofDetector+autolinking.gradle'
14
+ /// ```
15
+
16
+ logger.warn("[NitroModules] 🔥 VisionCameraSpoofDetector is boosted by nitro!")
17
+
18
+ android {
19
+ sourceSets {
20
+ main {
21
+ java.srcDirs += [
22
+ // Nitrogen files
23
+ "${project.projectDir}/../nitrogen/generated/android/kotlin"
24
+ ]
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,58 @@
1
+ ///
2
+ /// VisionCameraSpoofDetectorOnLoad.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #ifndef BUILDING_VISIONCAMERASPOOFDETECTOR_WITH_GENERATED_CMAKE_PROJECT
9
+ #error VisionCameraSpoofDetectorOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
10
+ #endif
11
+
12
+ #include "VisionCameraSpoofDetectorOnLoad.hpp"
13
+
14
+ #include <jni.h>
15
+ #include <fbjni/fbjni.h>
16
+ #include <NitroModules/HybridObjectRegistry.hpp>
17
+
18
+ #include "JHybridSpoofDetectorFactorySpec.hpp"
19
+ #include "JFunc_void_AntiSpoofingResult.hpp"
20
+ #include "JFunc_void_std__exception_ptr.hpp"
21
+ #include <NitroModules/DefaultConstructableObject.hpp>
22
+
23
+ namespace margelo::nitro::camera::spoofdetector {
24
+
25
+ int initialize(JavaVM* vm) {
26
+ return facebook::jni::initialize(vm, []() {
27
+ ::margelo::nitro::camera::spoofdetector::registerAllNatives();
28
+ });
29
+ }
30
+
31
+ struct JHybridSpoofDetectorFactorySpecImpl: public jni::JavaClass<JHybridSpoofDetectorFactorySpecImpl, JHybridSpoofDetectorFactorySpec::JavaPart> {
32
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/camera/spoofdetector/HybridSpoofDetectorFactory;";
33
+ static std::shared_ptr<JHybridSpoofDetectorFactorySpec> create() {
34
+ static const auto constructorFn = javaClassStatic()->getConstructor<JHybridSpoofDetectorFactorySpecImpl::javaobject()>();
35
+ jni::local_ref<JHybridSpoofDetectorFactorySpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
36
+ return javaPart->getJHybridSpoofDetectorFactorySpec();
37
+ }
38
+ };
39
+
40
+ void registerAllNatives() {
41
+ using namespace margelo::nitro;
42
+ using namespace margelo::nitro::camera::spoofdetector;
43
+
44
+ // Register native JNI methods
45
+ margelo::nitro::camera::spoofdetector::JHybridSpoofDetectorFactorySpec::CxxPart::registerNatives();
46
+ margelo::nitro::camera::spoofdetector::JFunc_void_AntiSpoofingResult_cxx::registerNatives();
47
+ margelo::nitro::camera::spoofdetector::JFunc_void_std__exception_ptr_cxx::registerNatives();
48
+
49
+ // Register Nitro Hybrid Objects
50
+ HybridObjectRegistry::registerHybridObjectConstructor(
51
+ "SpoofDetectorFactory",
52
+ []() -> std::shared_ptr<HybridObject> {
53
+ return JHybridSpoofDetectorFactorySpecImpl::create();
54
+ }
55
+ );
56
+ }
57
+
58
+ } // namespace margelo::nitro::camera::spoofdetector
@@ -0,0 +1,34 @@
1
+ ///
2
+ /// VisionCameraSpoofDetectorOnLoad.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include <jni.h>
9
+ #include <functional>
10
+ #include <NitroModules/NitroDefines.hpp>
11
+
12
+ namespace margelo::nitro::camera::spoofdetector {
13
+
14
+ [[deprecated("Use registerNatives() instead.")]]
15
+ int initialize(JavaVM* vm);
16
+
17
+ /**
18
+ * Register the native (C++) part of VisionCameraSpoofDetector, and autolinks all Hybrid Objects.
19
+ * Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
20
+ * inside a `facebook::jni::initialize(vm, ...)` call.
21
+ * Example:
22
+ * ```cpp (cpp-adapter.cpp)
23
+ * JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
24
+ * return facebook::jni::initialize(vm, []() {
25
+ * // register all VisionCameraSpoofDetector HybridObjects
26
+ * margelo::nitro::camera::spoofdetector::registerNatives();
27
+ * // any other custom registrations go here.
28
+ * });
29
+ * }
30
+ * ```
31
+ */
32
+ void registerAllNatives();
33
+
34
+ } // namespace margelo::nitro::camera::spoofdetector
@@ -0,0 +1,77 @@
1
+ ///
2
+ /// JAntiSpoofingResult.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "AntiSpoofingResult.hpp"
12
+
13
+ #include <string>
14
+
15
+ namespace margelo::nitro::camera::spoofdetector {
16
+
17
+ using namespace facebook;
18
+
19
+ /**
20
+ * The C++ JNI bridge between the C++ struct "AntiSpoofingResult" and the Kotlin data class "AntiSpoofingResult".
21
+ */
22
+ struct JAntiSpoofingResult final: public jni::JavaClass<JAntiSpoofingResult> {
23
+ public:
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/camera/spoofdetector/AntiSpoofingResult;";
25
+
26
+ public:
27
+ /**
28
+ * Convert this Java/Kotlin-based struct to the C++ struct AntiSpoofingResult by copying all values to C++.
29
+ */
30
+ [[maybe_unused]]
31
+ [[nodiscard]]
32
+ AntiSpoofingResult toCpp() const {
33
+ static const auto clazz = javaClassStatic();
34
+ static const auto fieldIsLive = clazz->getField<jboolean>("isLive");
35
+ jboolean isLive = this->getFieldValue(fieldIsLive);
36
+ static const auto fieldLabel = clazz->getField<jni::JString>("label");
37
+ jni::local_ref<jni::JString> label = this->getFieldValue(fieldLabel);
38
+ static const auto fieldNeuralNetworkScore = clazz->getField<double>("neuralNetworkScore");
39
+ double neuralNetworkScore = this->getFieldValue(fieldNeuralNetworkScore);
40
+ static const auto fieldLaplacianScore = clazz->getField<double>("laplacianScore");
41
+ double laplacianScore = this->getFieldValue(fieldLaplacianScore);
42
+ static const auto fieldCombinedScore = clazz->getField<double>("combinedScore");
43
+ double combinedScore = this->getFieldValue(fieldCombinedScore);
44
+ static const auto fieldConfidence = clazz->getField<double>("confidence");
45
+ double confidence = this->getFieldValue(fieldConfidence);
46
+ return AntiSpoofingResult(
47
+ static_cast<bool>(isLive),
48
+ label->toStdString(),
49
+ neuralNetworkScore,
50
+ laplacianScore,
51
+ combinedScore,
52
+ confidence
53
+ );
54
+ }
55
+
56
+ public:
57
+ /**
58
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
59
+ */
60
+ [[maybe_unused]]
61
+ static jni::local_ref<JAntiSpoofingResult::javaobject> fromCpp(const AntiSpoofingResult& value) {
62
+ using JSignature = JAntiSpoofingResult(jboolean, jni::alias_ref<jni::JString>, double, double, double, double);
63
+ static const auto clazz = javaClassStatic();
64
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
65
+ return create(
66
+ clazz,
67
+ value.isLive,
68
+ jni::make_jstring(value.label),
69
+ value.neuralNetworkScore,
70
+ value.laplacianScore,
71
+ value.combinedScore,
72
+ value.confidence
73
+ );
74
+ }
75
+ };
76
+
77
+ } // namespace margelo::nitro::camera::spoofdetector
@@ -0,0 +1,78 @@
1
+ ///
2
+ /// JFunc_void_AntiSpoofingResult.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include <functional>
12
+
13
+ #include "AntiSpoofingResult.hpp"
14
+ #include <functional>
15
+ #include <NitroModules/JNICallable.hpp>
16
+ #include "JAntiSpoofingResult.hpp"
17
+ #include <string>
18
+
19
+ namespace margelo::nitro::camera::spoofdetector {
20
+
21
+ using namespace facebook;
22
+
23
+ /**
24
+ * Represents the Java/Kotlin callback `(result: AntiSpoofingResult) -> Unit`.
25
+ * This can be passed around between C++ and Java/Kotlin.
26
+ */
27
+ struct JFunc_void_AntiSpoofingResult: public jni::JavaClass<JFunc_void_AntiSpoofingResult> {
28
+ public:
29
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/camera/spoofdetector/Func_void_AntiSpoofingResult;";
30
+
31
+ public:
32
+ /**
33
+ * Invokes the function this `JFunc_void_AntiSpoofingResult` instance holds through JNI.
34
+ */
35
+ void invoke(const AntiSpoofingResult& result) const {
36
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JAntiSpoofingResult> /* result */)>("invoke");
37
+ method(self(), JAntiSpoofingResult::fromCpp(result));
38
+ }
39
+ };
40
+
41
+ /**
42
+ * An implementation of Func_void_AntiSpoofingResult that is backed by a C++ implementation (using `std::function<...>`)
43
+ */
44
+ class JFunc_void_AntiSpoofingResult_cxx final: public jni::HybridClass<JFunc_void_AntiSpoofingResult_cxx, JFunc_void_AntiSpoofingResult> {
45
+ public:
46
+ static jni::local_ref<JFunc_void_AntiSpoofingResult::javaobject> fromCpp(const std::function<void(const AntiSpoofingResult& /* result */)>& func) {
47
+ return JFunc_void_AntiSpoofingResult_cxx::newObjectCxxArgs(func);
48
+ }
49
+
50
+ public:
51
+ /**
52
+ * Invokes the C++ `std::function<...>` this `JFunc_void_AntiSpoofingResult_cxx` instance holds.
53
+ */
54
+ void invoke_cxx(jni::alias_ref<JAntiSpoofingResult> result) {
55
+ _func(result->toCpp());
56
+ }
57
+
58
+ public:
59
+ [[nodiscard]]
60
+ inline const std::function<void(const AntiSpoofingResult& /* result */)>& getFunction() const {
61
+ return _func;
62
+ }
63
+
64
+ public:
65
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/camera/spoofdetector/Func_void_AntiSpoofingResult_cxx;";
66
+ static void registerNatives() {
67
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_AntiSpoofingResult_cxx::invoke_cxx)});
68
+ }
69
+
70
+ private:
71
+ explicit JFunc_void_AntiSpoofingResult_cxx(const std::function<void(const AntiSpoofingResult& /* result */)>& func): _func(func) { }
72
+
73
+ private:
74
+ friend HybridBase;
75
+ std::function<void(const AntiSpoofingResult& /* result */)> _func;
76
+ };
77
+
78
+ } // namespace margelo::nitro::camera::spoofdetector
@@ -0,0 +1,76 @@
1
+ ///
2
+ /// JFunc_void_std__exception_ptr.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include <functional>
12
+
13
+ #include <exception>
14
+ #include <functional>
15
+ #include <NitroModules/JNICallable.hpp>
16
+
17
+ namespace margelo::nitro::camera::spoofdetector {
18
+
19
+ using namespace facebook;
20
+
21
+ /**
22
+ * Represents the Java/Kotlin callback `(error: Throwable) -> Unit`.
23
+ * This can be passed around between C++ and Java/Kotlin.
24
+ */
25
+ struct JFunc_void_std__exception_ptr: public jni::JavaClass<JFunc_void_std__exception_ptr> {
26
+ public:
27
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/camera/spoofdetector/Func_void_std__exception_ptr;";
28
+
29
+ public:
30
+ /**
31
+ * Invokes the function this `JFunc_void_std__exception_ptr` instance holds through JNI.
32
+ */
33
+ void invoke(const std::exception_ptr& error) const {
34
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JThrowable> /* error */)>("invoke");
35
+ method(self(), jni::getJavaExceptionForCppException(error));
36
+ }
37
+ };
38
+
39
+ /**
40
+ * An implementation of Func_void_std__exception_ptr that is backed by a C++ implementation (using `std::function<...>`)
41
+ */
42
+ class JFunc_void_std__exception_ptr_cxx final: public jni::HybridClass<JFunc_void_std__exception_ptr_cxx, JFunc_void_std__exception_ptr> {
43
+ public:
44
+ static jni::local_ref<JFunc_void_std__exception_ptr::javaobject> fromCpp(const std::function<void(const std::exception_ptr& /* error */)>& func) {
45
+ return JFunc_void_std__exception_ptr_cxx::newObjectCxxArgs(func);
46
+ }
47
+
48
+ public:
49
+ /**
50
+ * Invokes the C++ `std::function<...>` this `JFunc_void_std__exception_ptr_cxx` instance holds.
51
+ */
52
+ void invoke_cxx(jni::alias_ref<jni::JThrowable> error) {
53
+ _func(std::make_exception_ptr(jni::JniException(error)));
54
+ }
55
+
56
+ public:
57
+ [[nodiscard]]
58
+ inline const std::function<void(const std::exception_ptr& /* error */)>& getFunction() const {
59
+ return _func;
60
+ }
61
+
62
+ public:
63
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/camera/spoofdetector/Func_void_std__exception_ptr_cxx;";
64
+ static void registerNatives() {
65
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__exception_ptr_cxx::invoke_cxx)});
66
+ }
67
+
68
+ private:
69
+ explicit JFunc_void_std__exception_ptr_cxx(const std::function<void(const std::exception_ptr& /* error */)>& func): _func(func) { }
70
+
71
+ private:
72
+ friend HybridBase;
73
+ std::function<void(const std::exception_ptr& /* error */)> _func;
74
+ };
75
+
76
+ } // namespace margelo::nitro::camera::spoofdetector