react-native-vision-camera-spoof-detector 1.1.23 → 1.1.25
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.
- package/android/CMakeLists.txt +12 -0
- package/android/build.gradle +10 -9
- package/android/src/main/cpp/cpp-adapter.cpp +6 -3
- package/ios/HybridSpoofDetectorOutput.swift +112 -72
- package/package.json +1 -1
- package/android/src/main/cpp/CMakeLists.txt +0 -33
- package/android/src/main/cpp/FaceAntiSpoofJSI.cpp +0 -142
- package/android/src/main/cpp/FastYuvJni.cpp +0 -111
- package/android/src/main/cpp/fast_yuv.cpp +0 -342
- package/android/src/main/cpp/fast_yuv.h +0 -23
- package/android/src/main/cpp/libyuv/.clang-format +0 -6
- package/android/src/main/cpp/libyuv/.gn +0 -40
- package/android/src/main/cpp/libyuv/.vpython3 +0 -410
- package/android/src/main/cpp/libyuv/AUTHORS +0 -7
- package/android/src/main/cpp/libyuv/Android.bp +0 -202
- package/android/src/main/cpp/libyuv/Android.mk +0 -106
- package/android/src/main/cpp/libyuv/BUILD.gn +0 -490
- package/android/src/main/cpp/libyuv/CM_linux_packages.cmake +0 -70
- package/android/src/main/cpp/libyuv/CMakeLists.txt +0 -259
- package/android/src/main/cpp/libyuv/DEPS +0 -935
- package/android/src/main/cpp/libyuv/DIR_METADATA +0 -3
- package/android/src/main/cpp/libyuv/LICENSE +0 -29
- package/android/src/main/cpp/libyuv/OWNERS +0 -11
- package/android/src/main/cpp/libyuv/PATENTS +0 -24
- package/android/src/main/cpp/libyuv/PRESUBMIT.py +0 -65
- package/android/src/main/cpp/libyuv/README.chromium +0 -11
- package/android/src/main/cpp/libyuv/README.md +0 -19
- package/android/src/main/cpp/libyuv/build_overrides/build.gni +0 -60
- package/android/src/main/cpp/libyuv/build_overrides/gtest.gni +0 -19
- package/android/src/main/cpp/libyuv/build_overrides/partition_alloc.gni +0 -17
- package/android/src/main/cpp/libyuv/codereview.settings +0 -5
- package/android/src/main/cpp/libyuv/docs/deprecated_builds.md +0 -409
- package/android/src/main/cpp/libyuv/docs/environment_variables.md +0 -64
- package/android/src/main/cpp/libyuv/docs/feature_detection.md +0 -108
- package/android/src/main/cpp/libyuv/docs/filtering.md +0 -196
- package/android/src/main/cpp/libyuv/docs/formats.md +0 -208
- package/android/src/main/cpp/libyuv/docs/getting_started.md +0 -296
- package/android/src/main/cpp/libyuv/docs/rotation.md +0 -107
- package/android/src/main/cpp/libyuv/download_vs_toolchain.py +0 -29
- package/android/src/main/cpp/libyuv/include/libyuv/basic_types.h +0 -68
- package/android/src/main/cpp/libyuv/include/libyuv/compare.h +0 -111
- package/android/src/main/cpp/libyuv/include/libyuv/compare_row.h +0 -112
- package/android/src/main/cpp/libyuv/include/libyuv/convert.h +0 -1117
- package/android/src/main/cpp/libyuv/include/libyuv/convert_argb.h +0 -2335
- package/android/src/main/cpp/libyuv/include/libyuv/convert_from.h +0 -203
- package/android/src/main/cpp/libyuv/include/libyuv/convert_from_argb.h +0 -394
- package/android/src/main/cpp/libyuv/include/libyuv/cpu_id.h +0 -147
- package/android/src/main/cpp/libyuv/include/libyuv/cpu_support.h +0 -99
- package/android/src/main/cpp/libyuv/include/libyuv/loongson_intrinsics.h +0 -1949
- package/android/src/main/cpp/libyuv/include/libyuv/mjpeg_decoder.h +0 -195
- package/android/src/main/cpp/libyuv/include/libyuv/planar_functions.h +0 -1131
- package/android/src/main/cpp/libyuv/include/libyuv/rotate.h +0 -296
- package/android/src/main/cpp/libyuv/include/libyuv/rotate_argb.h +0 -37
- package/android/src/main/cpp/libyuv/include/libyuv/rotate_row.h +0 -265
- package/android/src/main/cpp/libyuv/include/libyuv/row.h +0 -6738
- package/android/src/main/cpp/libyuv/include/libyuv/row_sve.h +0 -2154
- package/android/src/main/cpp/libyuv/include/libyuv/scale.h +0 -336
- package/android/src/main/cpp/libyuv/include/libyuv/scale_argb.h +0 -76
- package/android/src/main/cpp/libyuv/include/libyuv/scale_rgb.h +0 -42
- package/android/src/main/cpp/libyuv/include/libyuv/scale_row.h +0 -1726
- package/android/src/main/cpp/libyuv/include/libyuv/scale_uv.h +0 -51
- package/android/src/main/cpp/libyuv/include/libyuv/version.h +0 -16
- package/android/src/main/cpp/libyuv/include/libyuv/video_common.h +0 -222
- package/android/src/main/cpp/libyuv/include/libyuv.h +0 -33
- package/android/src/main/cpp/libyuv/infra/config/OWNERS +0 -3
- package/android/src/main/cpp/libyuv/infra/config/PRESUBMIT.py +0 -17
- package/android/src/main/cpp/libyuv/infra/config/README.md +0 -2
- package/android/src/main/cpp/libyuv/infra/config/codereview.settings +0 -6
- package/android/src/main/cpp/libyuv/infra/config/commit-queue.cfg +0 -144
- package/android/src/main/cpp/libyuv/infra/config/cr-buildbucket.cfg +0 -1185
- package/android/src/main/cpp/libyuv/infra/config/luci-logdog.cfg +0 -9
- package/android/src/main/cpp/libyuv/infra/config/luci-milo.cfg +0 -246
- package/android/src/main/cpp/libyuv/infra/config/luci-scheduler.cfg +0 -385
- package/android/src/main/cpp/libyuv/infra/config/main.star +0 -402
- package/android/src/main/cpp/libyuv/infra/config/project.cfg +0 -16
- package/android/src/main/cpp/libyuv/infra/config/realms.cfg +0 -111
- package/android/src/main/cpp/libyuv/libyuv.gni +0 -34
- package/android/src/main/cpp/libyuv/libyuv.gyp +0 -149
- package/android/src/main/cpp/libyuv/libyuv.gypi +0 -87
- package/android/src/main/cpp/libyuv/linux.mk +0 -96
- package/android/src/main/cpp/libyuv/public.mk +0 -13
- package/android/src/main/cpp/libyuv/pylintrc +0 -49
- package/android/src/main/cpp/libyuv/riscv_script/prepare_toolchain_qemu.sh +0 -74
- package/android/src/main/cpp/libyuv/riscv_script/riscv-clang.cmake +0 -56
- package/android/src/main/cpp/libyuv/riscv_script/run_qemu.sh +0 -15
- package/android/src/main/cpp/libyuv/source/compare.cc +0 -435
- package/android/src/main/cpp/libyuv/source/compare_common.cc +0 -74
- package/android/src/main/cpp/libyuv/source/compare_gcc.cc +0 -362
- package/android/src/main/cpp/libyuv/source/compare_neon.cc +0 -96
- package/android/src/main/cpp/libyuv/source/compare_neon64.cc +0 -223
- package/android/src/main/cpp/libyuv/source/compare_win.cc +0 -241
- package/android/src/main/cpp/libyuv/source/convert.cc +0 -4746
- package/android/src/main/cpp/libyuv/source/convert_argb.cc +0 -9179
- package/android/src/main/cpp/libyuv/source/convert_from.cc +0 -866
- package/android/src/main/cpp/libyuv/source/convert_from_argb.cc +0 -3671
- package/android/src/main/cpp/libyuv/source/convert_jpeg.cc +0 -602
- package/android/src/main/cpp/libyuv/source/convert_to_argb.cc +0 -391
- package/android/src/main/cpp/libyuv/source/convert_to_i420.cc +0 -288
- package/android/src/main/cpp/libyuv/source/cpu_id.cc +0 -496
- package/android/src/main/cpp/libyuv/source/mjpeg_decoder.cc +0 -580
- package/android/src/main/cpp/libyuv/source/mjpeg_validate.cc +0 -71
- package/android/src/main/cpp/libyuv/source/planar_functions.cc +0 -5663
- package/android/src/main/cpp/libyuv/source/rotate.cc +0 -1241
- package/android/src/main/cpp/libyuv/source/rotate_any.cc +0 -76
- package/android/src/main/cpp/libyuv/source/rotate_argb.cc +0 -259
- package/android/src/main/cpp/libyuv/source/rotate_common.cc +0 -208
- package/android/src/main/cpp/libyuv/source/rotate_gcc.cc +0 -505
- package/android/src/main/cpp/libyuv/source/rotate_lsx.cc +0 -233
- package/android/src/main/cpp/libyuv/source/rotate_neon.cc +0 -219
- package/android/src/main/cpp/libyuv/source/rotate_neon64.cc +0 -273
- package/android/src/main/cpp/libyuv/source/rotate_sme.cc +0 -174
- package/android/src/main/cpp/libyuv/source/rotate_win.cc +0 -253
- package/android/src/main/cpp/libyuv/source/row_any.cc +0 -2519
- package/android/src/main/cpp/libyuv/source/row_common.cc +0 -4461
- package/android/src/main/cpp/libyuv/source/row_gcc.cc +0 -9570
- package/android/src/main/cpp/libyuv/source/row_lasx.cc +0 -2343
- package/android/src/main/cpp/libyuv/source/row_lsx.cc +0 -3030
- package/android/src/main/cpp/libyuv/source/row_neon.cc +0 -4026
- package/android/src/main/cpp/libyuv/source/row_neon64.cc +0 -5617
- package/android/src/main/cpp/libyuv/source/row_rvv.cc +0 -2599
- package/android/src/main/cpp/libyuv/source/row_sme.cc +0 -1183
- package/android/src/main/cpp/libyuv/source/row_sve.cc +0 -1088
- package/android/src/main/cpp/libyuv/source/row_win.cc +0 -6453
- package/android/src/main/cpp/libyuv/source/scale.cc +0 -2710
- package/android/src/main/cpp/libyuv/source/scale_any.cc +0 -991
- package/android/src/main/cpp/libyuv/source/scale_argb.cc +0 -1158
- package/android/src/main/cpp/libyuv/source/scale_common.cc +0 -1977
- package/android/src/main/cpp/libyuv/source/scale_gcc.cc +0 -2947
- package/android/src/main/cpp/libyuv/source/scale_lsx.cc +0 -739
- package/android/src/main/cpp/libyuv/source/scale_neon.cc +0 -1449
- package/android/src/main/cpp/libyuv/source/scale_neon64.cc +0 -1552
- package/android/src/main/cpp/libyuv/source/scale_rgb.cc +0 -82
- package/android/src/main/cpp/libyuv/source/scale_rvv.cc +0 -1971
- package/android/src/main/cpp/libyuv/source/scale_sme.cc +0 -555
- package/android/src/main/cpp/libyuv/source/scale_uv.cc +0 -1159
- package/android/src/main/cpp/libyuv/source/scale_win.cc +0 -1392
- package/android/src/main/cpp/libyuv/source/test.sh +0 -35
- package/android/src/main/cpp/libyuv/source/video_common.cc +0 -62
- package/android/src/main/cpp/libyuv/tools_libyuv/OWNERS +0 -4
- package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/roll_deps.py +0 -931
- package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py +0 -164
- package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS +0 -21
- package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.new +0 -13
- package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old +0 -13
- package/android/src/main/cpp/libyuv/tools_libyuv/get_landmines.py +0 -38
- package/android/src/main/cpp/libyuv/tools_libyuv/msan/OWNERS +0 -3
- package/android/src/main/cpp/libyuv/tools_libyuv/msan/blacklist.txt +0 -9
- package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/OWNERS +0 -3
- package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/blacklist.txt +0 -15
- package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/vptr_blacklist.txt +0 -25
- package/android/src/main/cpp/libyuv/unit_test/basictypes_test.cc +0 -43
- package/android/src/main/cpp/libyuv/unit_test/color_test.cc +0 -848
- package/android/src/main/cpp/libyuv/unit_test/compare_test.cc +0 -739
- package/android/src/main/cpp/libyuv/unit_test/convert_argb_test.cc +0 -2867
- package/android/src/main/cpp/libyuv/unit_test/convert_test.cc +0 -2133
- package/android/src/main/cpp/libyuv/unit_test/cpu_test.cc +0 -427
- package/android/src/main/cpp/libyuv/unit_test/cpu_thread_test.cc +0 -63
- package/android/src/main/cpp/libyuv/unit_test/math_test.cc +0 -160
- package/android/src/main/cpp/libyuv/unit_test/planar_test.cc +0 -4731
- package/android/src/main/cpp/libyuv/unit_test/rotate_argb_test.cc +0 -334
- package/android/src/main/cpp/libyuv/unit_test/rotate_test.cc +0 -962
- package/android/src/main/cpp/libyuv/unit_test/scale_argb_test.cc +0 -590
- package/android/src/main/cpp/libyuv/unit_test/scale_plane_test.cc +0 -465
- package/android/src/main/cpp/libyuv/unit_test/scale_rgb_test.cc +0 -280
- package/android/src/main/cpp/libyuv/unit_test/scale_test.cc +0 -1135
- package/android/src/main/cpp/libyuv/unit_test/scale_uv_test.cc +0 -249
- package/android/src/main/cpp/libyuv/unit_test/testdata/arm_v7.txt +0 -12
- package/android/src/main/cpp/libyuv/unit_test/testdata/mips.txt +0 -7
- package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson2k.txt +0 -5
- package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson3.txt +0 -10
- package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson_mmi.txt +0 -7
- package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64.txt +0 -4
- package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv.txt +0 -4
- package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv_zvfh.txt +0 -4
- package/android/src/main/cpp/libyuv/unit_test/testdata/tegra3.txt +0 -23
- package/android/src/main/cpp/libyuv/unit_test/testdata/test0.jpg +0 -0
- package/android/src/main/cpp/libyuv/unit_test/testdata/test1.jpg +0 -0
- package/android/src/main/cpp/libyuv/unit_test/testdata/test2.jpg +0 -0
- package/android/src/main/cpp/libyuv/unit_test/testdata/test3.jpg +0 -0
- package/android/src/main/cpp/libyuv/unit_test/testdata/test4.jpg +0 -0
- package/android/src/main/cpp/libyuv/unit_test/unit_test.cc +0 -581
- package/android/src/main/cpp/libyuv/unit_test/unit_test.h +0 -232
- package/android/src/main/cpp/libyuv/unit_test/video_common_test.cc +0 -112
- package/android/src/main/cpp/libyuv/util/Makefile +0 -9
- package/android/src/main/cpp/libyuv/util/color.cc +0 -120
- package/android/src/main/cpp/libyuv/util/compare.cc +0 -67
- package/android/src/main/cpp/libyuv/util/cpuid.c +0 -211
- package/android/src/main/cpp/libyuv/util/i444tonv12_eg.cc +0 -28
- package/android/src/main/cpp/libyuv/util/psnr.cc +0 -291
- package/android/src/main/cpp/libyuv/util/psnr.h +0 -47
- package/android/src/main/cpp/libyuv/util/psnr_main.cc +0 -620
- package/android/src/main/cpp/libyuv/util/ssim.cc +0 -364
- package/android/src/main/cpp/libyuv/util/ssim.h +0 -38
- package/android/src/main/cpp/libyuv/util/yuvconstants.c +0 -114
- package/android/src/main/cpp/libyuv/util/yuvconvert.cc +0 -367
- package/android/src/main/cpp/libyuv/winarm.mk +0 -47
- package/android/src/main/java/com/faceantispoof/ByteBufferPool.kt +0 -68
- package/android/src/main/java/com/faceantispoof/FastYuv.kt +0 -51
- package/android/src/main/java/com/faceantispoof/YuvToFloatArrayConverter.kt +0 -584
- package/android/src/main/java/com/faceantispoof/YuvToRgbConverter.kt +0 -73
package/android/CMakeLists.txt
CHANGED
|
@@ -18,6 +18,9 @@ include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/VisionCameraSpoofDetec
|
|
|
18
18
|
|
|
19
19
|
find_library(LOG_LIB log)
|
|
20
20
|
find_package(react-native-vision-camera REQUIRED)
|
|
21
|
+
find_package(ReactAndroid REQUIRED)
|
|
22
|
+
find_package(fbjni REQUIRED)
|
|
23
|
+
find_package(react-native-nitro-modules REQUIRED)
|
|
21
24
|
|
|
22
25
|
target_link_options(${PACKAGE_NAME} PRIVATE "-Wl,-z,max-page-size=16384")
|
|
23
26
|
|
|
@@ -25,5 +28,14 @@ target_link_libraries(
|
|
|
25
28
|
${PACKAGE_NAME}
|
|
26
29
|
${LOG_LIB}
|
|
27
30
|
android
|
|
31
|
+
fbjni::fbjni
|
|
32
|
+
ReactAndroid::jsi
|
|
33
|
+
react-native-nitro-modules::NitroModules
|
|
28
34
|
react-native-vision-camera::VisionCamera
|
|
29
35
|
)
|
|
36
|
+
|
|
37
|
+
if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
38
|
+
target_link_libraries(${PACKAGE_NAME} ReactAndroid::reactnative)
|
|
39
|
+
else()
|
|
40
|
+
target_link_libraries(${PACKAGE_NAME} ReactAndroid::react_nativemodule_core)
|
|
41
|
+
endif()
|
package/android/build.gradle
CHANGED
|
@@ -38,15 +38,6 @@ android {
|
|
|
38
38
|
|
|
39
39
|
buildConfigField "String", "MODEL_FILE", "\"FaceAntiSpoofing.tflite\""
|
|
40
40
|
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
41
|
-
|
|
42
|
-
// Needed for JSI / C++ build
|
|
43
|
-
externalNativeBuild {
|
|
44
|
-
cmake {
|
|
45
|
-
cppFlags "-frtti -fexceptions -Wall -Wextra -fstack-protector-all"
|
|
46
|
-
arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
|
|
47
|
-
abiFilters (*reactNativeArchitectures())
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
41
|
}
|
|
51
42
|
|
|
52
43
|
buildTypes {
|
|
@@ -98,6 +89,16 @@ android {
|
|
|
98
89
|
}
|
|
99
90
|
}
|
|
100
91
|
|
|
92
|
+
defaultConfig {
|
|
93
|
+
externalNativeBuild {
|
|
94
|
+
cmake {
|
|
95
|
+
cppFlags "-frtti -fexceptions -Wall -Wextra -fstack-protector-all"
|
|
96
|
+
arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
|
|
97
|
+
abiFilters(*reactNativeArchitectures())
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
101
102
|
externalNativeBuild {
|
|
102
103
|
cmake {
|
|
103
104
|
path "CMakeLists.txt"
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
#include "VisionCameraSpoofDetectorOnLoad.hpp"
|
|
2
|
-
#include <fbjni/fbjni.h>
|
|
3
1
|
#include <jni.h>
|
|
2
|
+
#include <fbjni/fbjni.h>
|
|
3
|
+
|
|
4
|
+
#include "VisionCameraSpoofDetectorOnLoad.hpp"
|
|
4
5
|
|
|
6
|
+
extern "C" {
|
|
5
7
|
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
6
8
|
return facebook::jni::initialize(vm, []() {
|
|
7
9
|
margelo::nitro::camera::spoofdetector::registerAllNatives();
|
|
8
10
|
});
|
|
9
|
-
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import AVFoundation
|
|
2
|
-
import CoreImage
|
|
3
2
|
import Foundation
|
|
4
3
|
import NitroModules
|
|
5
4
|
import VisionCamera
|
|
@@ -8,11 +7,12 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
8
7
|
private let queue = DispatchQueue(label: "com.faceantispoof.output", qos: .userInitiated)
|
|
9
8
|
private let options: SpoofDetectorOutputOptions
|
|
10
9
|
private let delegate: SpoofDetectorDelegate
|
|
11
|
-
private let ciContext = CIContext(options: nil)
|
|
12
10
|
private let stateLock = NSLock()
|
|
13
11
|
private let targetSize = 256
|
|
14
12
|
private var isBusy = false
|
|
15
13
|
private var isDisposed = false
|
|
14
|
+
private var frameCounter = 0
|
|
15
|
+
private var lastFrameBrightness: Float = 0
|
|
16
16
|
|
|
17
17
|
let output = AVCaptureVideoDataOutput()
|
|
18
18
|
let requiresAudioInput = false
|
|
@@ -27,7 +27,10 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
var targetResolution: ResolutionRule {
|
|
30
|
-
|
|
30
|
+
let resolution = options.targetResolution.map {
|
|
31
|
+
margelo.nitro.camera.Size(width: $0.width, height: $0.height)
|
|
32
|
+
} ?? margelo.nitro.camera.Size(width: 720.0, height: 1280.0)
|
|
33
|
+
return .closestTo(resolution)
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
init(options: SpoofDetectorOutputOptions) {
|
|
@@ -35,6 +38,9 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
35
38
|
self.delegate = SpoofDetectorDelegate()
|
|
36
39
|
super.init()
|
|
37
40
|
|
|
41
|
+
output.videoSettings = [
|
|
42
|
+
kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA,
|
|
43
|
+
]
|
|
38
44
|
delegate.onSampleBuffer = { [weak self] sampleBuffer in
|
|
39
45
|
self?.process(sampleBuffer)
|
|
40
46
|
}
|
|
@@ -63,7 +69,7 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
63
69
|
isBusy = true
|
|
64
70
|
stateLock.unlock()
|
|
65
71
|
|
|
66
|
-
guard let
|
|
72
|
+
guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
|
|
67
73
|
stateLock.lock()
|
|
68
74
|
isBusy = false
|
|
69
75
|
stateLock.unlock()
|
|
@@ -71,69 +77,115 @@ final class HybridSpoofDetectorOutput: HybridCameraOutputSpec, NativeCameraOutpu
|
|
|
71
77
|
return
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
self.isBusy = false
|
|
79
|
-
self.stateLock.unlock()
|
|
80
|
-
}
|
|
80
|
+
CVPixelBufferLockBaseAddress(pixelBuffer, .readOnly)
|
|
81
|
+
defer {
|
|
82
|
+
CVPixelBufferUnlockBaseAddress(pixelBuffer, .readOnly)
|
|
83
|
+
}
|
|
81
84
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
neuralNetworkScore: result.neuralNetworkScore,
|
|
89
|
-
laplacianScore: result.laplacianScore,
|
|
90
|
-
combinedScore: result.combinedScore,
|
|
91
|
-
confidence: result.confidence
|
|
92
|
-
)
|
|
93
|
-
)
|
|
94
|
-
} catch {
|
|
95
|
-
self.options.onError?(error)
|
|
96
|
-
}
|
|
85
|
+
guard shouldProcessFrame(pixelBuffer),
|
|
86
|
+
let input = makeRGBInput(from: pixelBuffer) else {
|
|
87
|
+
stateLock.lock()
|
|
88
|
+
isBusy = false
|
|
89
|
+
stateLock.unlock()
|
|
90
|
+
return
|
|
97
91
|
}
|
|
98
|
-
}
|
|
99
92
|
|
|
100
|
-
|
|
101
|
-
|
|
93
|
+
defer {
|
|
94
|
+
stateLock.lock()
|
|
95
|
+
isBusy = false
|
|
96
|
+
stateLock.unlock()
|
|
97
|
+
}
|
|
102
98
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
do {
|
|
100
|
+
let result = try FaceAntiSpoofManager.process(input: input)
|
|
101
|
+
options.onResult(
|
|
102
|
+
AntiSpoofingResult(
|
|
103
|
+
isLive: result.isLive,
|
|
104
|
+
label: result.isLive ? "Live Face" : "Spoof Face",
|
|
105
|
+
neuralNetworkScore: result.neuralNetworkScore,
|
|
106
|
+
laplacianScore: result.laplacianScore,
|
|
107
|
+
combinedScore: result.combinedScore,
|
|
108
|
+
confidence: result.confidence
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
} catch {
|
|
112
|
+
options.onError?(error)
|
|
107
113
|
}
|
|
114
|
+
}
|
|
108
115
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
let
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
116
|
+
private func shouldProcessFrame(_ pixelBuffer: CVPixelBuffer) -> Bool {
|
|
117
|
+
frameCounter += 1
|
|
118
|
+
guard frameCounter % 3 == 0 else { return false }
|
|
119
|
+
|
|
120
|
+
let width = CVPixelBufferGetWidth(pixelBuffer)
|
|
121
|
+
let height = CVPixelBufferGetHeight(pixelBuffer)
|
|
122
|
+
let bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer)
|
|
123
|
+
guard let baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer) else { return false }
|
|
124
|
+
let bytes = baseAddress.assumingMemoryBound(to: UInt8.self)
|
|
125
|
+
let sampleStep = max(1, min(width, height) / 32)
|
|
126
|
+
var brightnessSum: Float = 0
|
|
127
|
+
var brightnessSquaredSum: Float = 0
|
|
128
|
+
var sampleCount: Float = 0
|
|
129
|
+
|
|
130
|
+
for y in stride(from: 0, to: height, by: sampleStep) {
|
|
131
|
+
for x in stride(from: 0, to: width, by: sampleStep) {
|
|
132
|
+
let offset = y * bytesPerRow + x * 4
|
|
133
|
+
let blue = Float(bytes[offset])
|
|
134
|
+
let green = Float(bytes[offset + 1])
|
|
135
|
+
let red = Float(bytes[offset + 2])
|
|
136
|
+
let luma = 0.299 * red + 0.587 * green + 0.114 * blue
|
|
137
|
+
brightnessSum += luma
|
|
138
|
+
brightnessSquaredSum += luma * luma
|
|
139
|
+
sampleCount += 1
|
|
140
|
+
}
|
|
127
141
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
142
|
+
|
|
143
|
+
guard sampleCount > 0 else { return false }
|
|
144
|
+
let average = brightnessSum / sampleCount
|
|
145
|
+
let variance = (brightnessSquaredSum / sampleCount) - (average * average)
|
|
146
|
+
let brightnessDelta = abs(average - lastFrameBrightness)
|
|
147
|
+
let isFirstSample = lastFrameBrightness == 0
|
|
148
|
+
lastFrameBrightness = average
|
|
149
|
+
|
|
150
|
+
return average >= 24 && average <= 220 && variance >= 1500 &&
|
|
151
|
+
(isFirstSample || brightnessDelta >= 8)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private func makeRGBInput(from pixelBuffer: CVPixelBuffer) -> [Float]? {
|
|
155
|
+
guard CVPixelBufferGetPixelFormatType(pixelBuffer) == kCVPixelFormatType_32BGRA,
|
|
156
|
+
let baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer) else { return nil }
|
|
157
|
+
|
|
158
|
+
let sourceWidth = CVPixelBufferGetWidth(pixelBuffer)
|
|
159
|
+
let sourceHeight = CVPixelBufferGetHeight(pixelBuffer)
|
|
160
|
+
let bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer)
|
|
161
|
+
let bytes = baseAddress.assumingMemoryBound(to: UInt8.self)
|
|
162
|
+
var result = [Float](repeating: 0, count: targetSize * targetSize * 3)
|
|
163
|
+
let isQuarterTurn = outputOrientation == .right || outputOrientation == .left
|
|
164
|
+
let orientedWidth = isQuarterTurn ? sourceHeight : sourceWidth
|
|
165
|
+
let orientedHeight = isQuarterTurn ? sourceWidth : sourceHeight
|
|
166
|
+
|
|
167
|
+
for targetY in 0..<targetSize {
|
|
168
|
+
let orientedY = min(orientedHeight - 1, targetY * orientedHeight / targetSize)
|
|
169
|
+
for targetX in 0..<targetSize {
|
|
170
|
+
let orientedX = min(orientedWidth - 1, targetX * orientedWidth / targetSize)
|
|
171
|
+
let sourcePoint: (x: Int, y: Int)
|
|
172
|
+
switch outputOrientation {
|
|
173
|
+
case .right:
|
|
174
|
+
sourcePoint = (orientedY, sourceHeight - 1 - orientedX)
|
|
175
|
+
case .down:
|
|
176
|
+
sourcePoint = (sourceWidth - 1 - orientedX, sourceHeight - 1 - orientedY)
|
|
177
|
+
case .left:
|
|
178
|
+
sourcePoint = (sourceWidth - 1 - orientedY, orientedX)
|
|
179
|
+
default:
|
|
180
|
+
sourcePoint = (orientedX, orientedY)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
let source = sourcePoint.y * bytesPerRow + sourcePoint.x * 4
|
|
184
|
+
let destination = (targetY * targetSize + targetX) * 3
|
|
185
|
+
result[destination] = Float(bytes[source + 2]) / 255
|
|
186
|
+
result[destination + 1] = Float(bytes[source + 1]) / 255
|
|
187
|
+
result[destination + 2] = Float(bytes[source]) / 255
|
|
188
|
+
}
|
|
137
189
|
}
|
|
138
190
|
return result
|
|
139
191
|
}
|
|
@@ -150,15 +202,3 @@ private final class SpoofDetectorDelegate: NSObject, AVCaptureVideoDataOutputSam
|
|
|
150
202
|
onSampleBuffer?(sampleBuffer)
|
|
151
203
|
}
|
|
152
204
|
}
|
|
153
|
-
|
|
154
|
-
private extension CameraOrientation {
|
|
155
|
-
var exifOrientation: Int32 {
|
|
156
|
-
switch self {
|
|
157
|
-
case .up: return 1
|
|
158
|
-
case .right: return 6
|
|
159
|
-
case .down: return 3
|
|
160
|
-
case .left: return 8
|
|
161
|
-
@unknown default: return 1
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-vision-camera-spoof-detector",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.25",
|
|
4
4
|
"description": "High-performance face anti-spoofing and liveness detection module for React Native Vision Camera. Uses TensorFlow Lite with GPU acceleration and optimized YUV processing.",
|
|
5
5
|
"homepage": "https://github.com/dpraful/react-native-vision-camera-spoof-detector",
|
|
6
6
|
"repository": {
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
cmake_minimum_required(VERSION 3.18)
|
|
2
|
-
project(VisionCameraSpoofDetector)
|
|
3
|
-
|
|
4
|
-
set(CMAKE_CXX_STANDARD 17)
|
|
5
|
-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
6
|
-
set(CMAKE_SUPPRESS_REGENERATION ON)
|
|
7
|
-
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
8
|
-
set(CMAKE_ANDROID_STL_TYPE c++_shared)
|
|
9
|
-
|
|
10
|
-
set(PACKAGE_NAME VisionCameraSpoofDetector)
|
|
11
|
-
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
12
|
-
|
|
13
|
-
add_library(${PACKAGE_NAME} SHARED
|
|
14
|
-
cpp-adapter.cpp
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
# Nitrogen-generated hybrid bindings
|
|
18
|
-
include(${CMAKE_SOURCE_DIR}/../../../../nitrogen/generated/android/VisionCameraSpoofDetector+autolinking.cmake)
|
|
19
|
-
|
|
20
|
-
find_library(LOG_LIB log)
|
|
21
|
-
find_package(react-native-vision-camera REQUIRED)
|
|
22
|
-
|
|
23
|
-
# Android 15+ 16KB page support
|
|
24
|
-
target_link_options(${PACKAGE_NAME} PRIVATE "-Wl,-z,max-page-size=16384")
|
|
25
|
-
|
|
26
|
-
target_link_libraries(
|
|
27
|
-
${PACKAGE_NAME}
|
|
28
|
-
${LOG_LIB}
|
|
29
|
-
android
|
|
30
|
-
react-native-vision-camera::VisionCamera
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
#include <jni.h>
|
|
2
|
-
#include <jsi/jsi.h>
|
|
3
|
-
#include <string>
|
|
4
|
-
#include <vector>
|
|
5
|
-
#include <algorithm>
|
|
6
|
-
#include <android/log.h>
|
|
7
|
-
|
|
8
|
-
using namespace facebook;
|
|
9
|
-
|
|
10
|
-
// Logging macro
|
|
11
|
-
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "FaceAntiSpoofJSI", __VA_ARGS__))
|
|
12
|
-
|
|
13
|
-
static JavaVM *javaVm = nullptr;
|
|
14
|
-
|
|
15
|
-
jsi::Value faceAntiSpoof(jsi::Runtime &runtime, const jsi::Value &frame) {
|
|
16
|
-
if (!frame.isObject()) {
|
|
17
|
-
throw jsi::JSError(runtime, "FaceAntiSpoof expected a Frame object");
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
auto frameObject = frame.asObject(runtime);
|
|
21
|
-
auto planesValue = frameObject.getProperty(runtime, "getPlanes").asObject(runtime)
|
|
22
|
-
.asFunction(runtime).call(runtime, frameObject);
|
|
23
|
-
auto planes = planesValue.asObject(runtime);
|
|
24
|
-
auto length = static_cast<size_t>(planes.getProperty(runtime, "length").asNumber());
|
|
25
|
-
if (length < 3) {
|
|
26
|
-
throw jsi::JSError(runtime, "FaceAntiSpoof expected Y, U and V planes");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
std::vector<std::vector<uint8_t>> planeData(3);
|
|
30
|
-
jint rowStrides[3] = {};
|
|
31
|
-
jint pixelStrides[3] = {};
|
|
32
|
-
for (size_t index = 0; index < 3; index++) {
|
|
33
|
-
auto plane = planes.getProperty(runtime, jsi::Value(static_cast<double>(index))).asObject(runtime);
|
|
34
|
-
auto buffer = plane.getProperty(runtime, "getPixelBuffer").asObject(runtime)
|
|
35
|
-
.asFunction(runtime).call(runtime, plane).asObject(runtime);
|
|
36
|
-
auto arrayBuffer = std::move(buffer).getArrayBuffer(runtime);
|
|
37
|
-
auto *data = static_cast<const uint8_t *>(arrayBuffer.data(runtime));
|
|
38
|
-
planeData[index].assign(data, data + arrayBuffer.size(runtime));
|
|
39
|
-
rowStrides[index] = static_cast<jint>(plane.getProperty(runtime, "bytesPerRow").asNumber());
|
|
40
|
-
auto planeWidth = plane.getProperty(runtime, "width").asNumber();
|
|
41
|
-
pixelStrides[index] = std::max(1, static_cast<jint>(rowStrides[index] / planeWidth));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
JNIEnv *env = nullptr;
|
|
45
|
-
bool attached = false;
|
|
46
|
-
if (javaVm == nullptr) {
|
|
47
|
-
throw jsi::JSError(runtime, "FaceAntiSpoof Android runtime is unavailable");
|
|
48
|
-
}
|
|
49
|
-
if (javaVm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) == JNI_EDETACHED) {
|
|
50
|
-
if (javaVm->AttachCurrentThread(&env, nullptr) != JNI_OK) {
|
|
51
|
-
throw jsi::JSError(runtime, "FaceAntiSpoof could not attach to Android runtime");
|
|
52
|
-
}
|
|
53
|
-
attached = true;
|
|
54
|
-
}
|
|
55
|
-
auto moduleClass = env->FindClass("com/faceantispoof/FaceAntiSpoofModule");
|
|
56
|
-
auto process = env->GetStaticMethodID(moduleClass, "processFrameFromJSI", "([[BII[I[I)[D");
|
|
57
|
-
auto javaPlanes = env->NewObjectArray(3, env->FindClass("[B"), nullptr);
|
|
58
|
-
auto javaRowStrides = env->NewIntArray(3);
|
|
59
|
-
auto javaPixelStrides = env->NewIntArray(3);
|
|
60
|
-
env->SetIntArrayRegion(javaRowStrides, 0, 3, rowStrides);
|
|
61
|
-
env->SetIntArrayRegion(javaPixelStrides, 0, 3, pixelStrides);
|
|
62
|
-
for (int index = 0; index < 3; index++) {
|
|
63
|
-
auto bytes = env->NewByteArray(static_cast<jsize>(planeData[index].size()));
|
|
64
|
-
env->SetByteArrayRegion(bytes, 0, static_cast<jsize>(planeData[index].size()),
|
|
65
|
-
reinterpret_cast<const jbyte *>(planeData[index].data()));
|
|
66
|
-
env->SetObjectArrayElement(javaPlanes, index, bytes);
|
|
67
|
-
env->DeleteLocalRef(bytes);
|
|
68
|
-
}
|
|
69
|
-
auto values = static_cast<jdoubleArray>(env->CallStaticObjectMethod(
|
|
70
|
-
moduleClass, process, javaPlanes, static_cast<jint>(frameObject.getProperty(runtime, "width").asNumber()),
|
|
71
|
-
static_cast<jint>(frameObject.getProperty(runtime, "height").asNumber()),
|
|
72
|
-
javaRowStrides, javaPixelStrides));
|
|
73
|
-
jdouble output[5] = {};
|
|
74
|
-
if (values != nullptr) env->GetDoubleArrayRegion(values, 0, 5, output);
|
|
75
|
-
env->DeleteLocalRef(values);
|
|
76
|
-
env->DeleteLocalRef(javaPixelStrides);
|
|
77
|
-
env->DeleteLocalRef(javaRowStrides);
|
|
78
|
-
env->DeleteLocalRef(javaPlanes);
|
|
79
|
-
env->DeleteLocalRef(moduleClass);
|
|
80
|
-
if (attached) javaVm->DetachCurrentThread();
|
|
81
|
-
|
|
82
|
-
jsi::Object result(runtime);
|
|
83
|
-
result.setProperty(runtime, "isLive", output[0] != 0.0);
|
|
84
|
-
result.setProperty(runtime, "label", output[0] != 0.0 ? "Live Face" : "Spoof Face");
|
|
85
|
-
result.setProperty(runtime, "neuralNetworkScore", output[1]);
|
|
86
|
-
result.setProperty(runtime, "laplacianScore", output[2]);
|
|
87
|
-
result.setProperty(runtime, "combinedScore", output[3]);
|
|
88
|
-
result.setProperty(runtime, "confidence", output[4]);
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *) {
|
|
93
|
-
javaVm = vm;
|
|
94
|
-
return JNI_VERSION_1_6;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// JSI registration function
|
|
98
|
-
extern "C"
|
|
99
|
-
JNIEXPORT void JNICALL
|
|
100
|
-
Java_com_faceantispoof_FaceAntiSpoofModule_registerJSIFunction(JNIEnv *env, jobject thiz, jlong jsContextPtr) {
|
|
101
|
-
LOGI("registerJSIFunction called with jsContextPtr = %ld", (long)jsContextPtr);
|
|
102
|
-
|
|
103
|
-
if (jsContextPtr == 0) {
|
|
104
|
-
LOGI("FaceAntiSpoofJSI: JS runtime pointer is 0 (null)!");
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
auto *runtime = reinterpret_cast<jsi::Runtime *>(jsContextPtr);
|
|
109
|
-
if (!runtime) {
|
|
110
|
-
LOGI("FaceAntiSpoofJSI: Runtime reinterpret_cast resulted in null pointer!");
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
try {
|
|
115
|
-
LOGI("FaceAntiSpoofJSI: Creating JSI function...");
|
|
116
|
-
|
|
117
|
-
jsi::Function func = jsi::Function::createFromHostFunction(
|
|
118
|
-
*runtime,
|
|
119
|
-
jsi::PropNameID::forAscii(*runtime, "__faceAntiSpoof"),
|
|
120
|
-
1,
|
|
121
|
-
[](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
122
|
-
LOGI("FaceAntiSpoofJSI: __faceAntiSpoof function called");
|
|
123
|
-
if (count < 1) {
|
|
124
|
-
jsi::Object error(rt);
|
|
125
|
-
error.setProperty(rt, "isLive", false);
|
|
126
|
-
error.setProperty(rt, "label", "No frame provided");
|
|
127
|
-
error.setProperty(rt, "confidence", 0.0);
|
|
128
|
-
return error;
|
|
129
|
-
}
|
|
130
|
-
return faceAntiSpoof(rt, args[0]);
|
|
131
|
-
}
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
LOGI("FaceAntiSpoofJSI: Setting __faceAntiSpoof on global object...");
|
|
135
|
-
runtime->global().setProperty(*runtime, "__faceAntiSpoof", std::move(func));
|
|
136
|
-
LOGI("FaceAntiSpoofJSI: __faceAntiSpoof registered successfully!");
|
|
137
|
-
} catch (const std::exception &e) {
|
|
138
|
-
LOGI("FaceAntiSpoofJSI: Exception during JSI registration: %s", e.what());
|
|
139
|
-
} catch (...) {
|
|
140
|
-
LOGI("FaceAntiSpoofJSI: Unknown exception during JSI registration!");
|
|
141
|
-
}
|
|
142
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
#include <jni.h>
|
|
2
|
-
#include <android/log.h>
|
|
3
|
-
#include <string.h>
|
|
4
|
-
#include "fast_yuv.h"
|
|
5
|
-
|
|
6
|
-
#define LOG_TAG "FastYuvJNI"
|
|
7
|
-
#define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)
|
|
8
|
-
|
|
9
|
-
extern "C" {
|
|
10
|
-
|
|
11
|
-
JNIEXPORT jboolean JNICALL Java_com_visioncamera_fastyuv_FastYuv_nativeNV21ToARGB(JNIEnv* env, jclass clazz,
|
|
12
|
-
jbyteArray nv21Array,
|
|
13
|
-
jint width, jint height,
|
|
14
|
-
jbyteArray outArgbArray) {
|
|
15
|
-
if (!nv21Array || !outArgbArray) return JNI_FALSE;
|
|
16
|
-
jsize in_len = env->GetArrayLength(nv21Array);
|
|
17
|
-
jsize out_len = env->GetArrayLength(outArgbArray);
|
|
18
|
-
int expected_in = width * height + (width * height) / 2;
|
|
19
|
-
int expected_out = width * height * 4;
|
|
20
|
-
if (in_len < expected_in || out_len < expected_out) return JNI_FALSE;
|
|
21
|
-
|
|
22
|
-
jbyte* in_bytes = env->GetByteArrayElements(nv21Array, nullptr);
|
|
23
|
-
jbyte* out_bytes = env->GetByteArrayElements(outArgbArray, nullptr);
|
|
24
|
-
bool ok = fastyuv::NV21ToARGB((const uint8_t*)in_bytes, width, height, (uint8_t*)out_bytes);
|
|
25
|
-
env->ReleaseByteArrayElements(nv21Array, in_bytes, JNI_ABORT);
|
|
26
|
-
env->ReleaseByteArrayElements(outArgbArray, out_bytes, 0);
|
|
27
|
-
return ok ? JNI_TRUE : JNI_FALSE;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
JNIEXPORT jboolean JNICALL Java_com_visioncamera_fastyuv_FastYuv_nativeNV21ToRGB(JNIEnv* env, jclass clazz,
|
|
31
|
-
jbyteArray nv21Array,
|
|
32
|
-
jint width, jint height,
|
|
33
|
-
jbyteArray outRgbArray) {
|
|
34
|
-
if (!nv21Array || !outRgbArray) return JNI_FALSE;
|
|
35
|
-
jsize in_len = env->GetArrayLength(nv21Array);
|
|
36
|
-
jsize out_len = env->GetArrayLength(outRgbArray);
|
|
37
|
-
int expected_in = width * height + (width * height) / 2;
|
|
38
|
-
int expected_out = width * height * 3;
|
|
39
|
-
if (in_len < expected_in || out_len < expected_out) return JNI_FALSE;
|
|
40
|
-
|
|
41
|
-
jbyte* in_bytes = env->GetByteArrayElements(nv21Array, nullptr);
|
|
42
|
-
jbyte* out_bytes = env->GetByteArrayElements(outRgbArray, nullptr);
|
|
43
|
-
bool ok = fastyuv::NV21ToRGB24((const uint8_t*)in_bytes, width, height, (uint8_t*)out_bytes);
|
|
44
|
-
env->ReleaseByteArrayElements(nv21Array, in_bytes, JNI_ABORT);
|
|
45
|
-
env->ReleaseByteArrayElements(outRgbArray, out_bytes, 0);
|
|
46
|
-
return ok ? JNI_TRUE : JNI_FALSE;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
JNIEXPORT jboolean JNICALL Java_com_visioncamera_fastyuv_FastYuv_nativeNV21ToBGR(JNIEnv* env, jclass clazz,
|
|
50
|
-
jbyteArray nv21Array,
|
|
51
|
-
jint width, jint height,
|
|
52
|
-
jbyteArray outBgrArray) {
|
|
53
|
-
if (!nv21Array || !outBgrArray) return JNI_FALSE;
|
|
54
|
-
jsize in_len = env->GetArrayLength(nv21Array);
|
|
55
|
-
jsize out_len = env->GetArrayLength(outBgrArray);
|
|
56
|
-
int expected_in = width * height + (width * height) / 2;
|
|
57
|
-
int expected_out = width * height * 3;
|
|
58
|
-
if (in_len < expected_in || out_len < expected_out) return JNI_FALSE;
|
|
59
|
-
|
|
60
|
-
jbyte* in_bytes = env->GetByteArrayElements(nv21Array, nullptr);
|
|
61
|
-
jbyte* out_bytes = env->GetByteArrayElements(outBgrArray, nullptr);
|
|
62
|
-
bool ok = fastyuv::NV21ToBGR24((const uint8_t*)in_bytes, width, height, (uint8_t*)out_bytes);
|
|
63
|
-
env->ReleaseByteArrayElements(nv21Array, in_bytes, JNI_ABORT);
|
|
64
|
-
env->ReleaseByteArrayElements(outBgrArray, out_bytes, 0);
|
|
65
|
-
return ok ? JNI_TRUE : JNI_FALSE;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
JNIEXPORT jboolean JNICALL Java_com_visioncamera_fastyuv_FastYuv_nativeNV21ToARGBResize(JNIEnv* env, jclass clazz,
|
|
69
|
-
jbyteArray nv21Array,
|
|
70
|
-
jint src_w, jint src_h,
|
|
71
|
-
jbyteArray outArgbArray,
|
|
72
|
-
jint dst_w, jint dst_h) {
|
|
73
|
-
if (!nv21Array || !outArgbArray) return JNI_FALSE;
|
|
74
|
-
jsize in_len = env->GetArrayLength(nv21Array);
|
|
75
|
-
jsize out_len = env->GetArrayLength(outArgbArray);
|
|
76
|
-
int expected_in = src_w * src_h + (src_w * src_h) / 2;
|
|
77
|
-
int expected_out = dst_w * dst_h * 4;
|
|
78
|
-
if (in_len < expected_in || out_len < expected_out) return JNI_FALSE;
|
|
79
|
-
|
|
80
|
-
jbyte* in_bytes = env->GetByteArrayElements(nv21Array, nullptr);
|
|
81
|
-
jbyte* out_bytes = env->GetByteArrayElements(outArgbArray, nullptr);
|
|
82
|
-
bool ok = fastyuv::NV21ToARGBResize((const uint8_t*)in_bytes, src_w, src_h, (uint8_t*)out_bytes, dst_w, dst_h);
|
|
83
|
-
env->ReleaseByteArrayElements(nv21Array, in_bytes, JNI_ABORT);
|
|
84
|
-
env->ReleaseByteArrayElements(outArgbArray, out_bytes, 0);
|
|
85
|
-
return ok ? JNI_TRUE : JNI_FALSE;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
JNIEXPORT jboolean JNICALL Java_com_visioncamera_fastyuv_FastYuv_nativeNV21ToARGBRotate(JNIEnv* env, jclass clazz,
|
|
89
|
-
jbyteArray nv21Array,
|
|
90
|
-
jint src_w, jint src_h,
|
|
91
|
-
jbyteArray outArgbArray,
|
|
92
|
-
jint rotation) {
|
|
93
|
-
if (!nv21Array || !outArgbArray) return JNI_FALSE;
|
|
94
|
-
jsize in_len = env->GetArrayLength(nv21Array);
|
|
95
|
-
jsize out_len = env->GetArrayLength(outArgbArray);
|
|
96
|
-
int expected_in = src_w * src_h + (src_w * src_h) / 2;
|
|
97
|
-
// rotation may swap dims; allocate expected_out conservatively using max dims
|
|
98
|
-
int dst_w = (rotation % 180 == 0) ? src_w : src_h;
|
|
99
|
-
int dst_h = (rotation % 180 == 0) ? src_h : src_w;
|
|
100
|
-
int expected_out = dst_w * dst_h * 4;
|
|
101
|
-
if (in_len < expected_in || out_len < expected_out) return JNI_FALSE;
|
|
102
|
-
|
|
103
|
-
jbyte* in_bytes = env->GetByteArrayElements(nv21Array, nullptr);
|
|
104
|
-
jbyte* out_bytes = env->GetByteArrayElements(outArgbArray, nullptr);
|
|
105
|
-
bool ok = fastyuv::NV21ToARGBRotate((const uint8_t*)in_bytes, src_w, src_h, (uint8_t*)out_bytes, rotation);
|
|
106
|
-
env->ReleaseByteArrayElements(nv21Array, in_bytes, JNI_ABORT);
|
|
107
|
-
env->ReleaseByteArrayElements(outArgbArray, out_bytes, 0);
|
|
108
|
-
return ok ? JNI_TRUE : JNI_FALSE;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
} // extern "C"
|