react-native-vision-camera-spoof-detector 1.0.3 → 1.0.4
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/.cxx/Debug/2a1it684/arm64-v8a/.cmake/api/v1/reply/{codemodel-v2-6af431df2d09cde56941.json → codemodel-v2-390962e2784a6a84fa3e.json} +2 -2
- package/android/.cxx/Debug/2a1it684/arm64-v8a/.cmake/api/v1/reply/{index-2025-11-24T09-46-02-0941.json → index-2025-11-24T13-21-59-0659.json} +2 -2
- package/android/.cxx/Debug/2a1it684/arm64-v8a/.cmake/api/v1/reply/{target-yuv-Debug-d9c8b9c64fd8df9f1bcd.json → target-yuv-Debug-1e27b8a2bdcddd47b87d.json} +3 -3
- package/android/.cxx/Debug/2a1it684/arm64-v8a/.cmake/api/v1/reply/{target-yuv_shared-Debug-ffb5efa9f8837691d492.json → target-yuv_shared-Debug-ac9194487d1fc1268a87.json} +3 -3
- package/android/.cxx/Debug/2a1it684/arm64-v8a/.ninja_deps +0 -0
- package/android/.cxx/Debug/2a1it684/arm64-v8a/.ninja_log +99 -99
- package/android/.cxx/Debug/2a1it684/arm64-v8a/configure_fingerprint.bin +14 -14
- package/android/.cxx/Debug/2a1it684/armeabi-v7a/.ninja_deps +0 -0
- package/android/.cxx/Debug/2a1it684/armeabi-v7a/.ninja_log +92 -149
- package/android/.cxx/Debug/2a1it684/armeabi-v7a/configure_fingerprint.bin +14 -14
- package/android/.cxx/Debug/2a1it684/x86/.ninja_deps +0 -0
- package/android/.cxx/Debug/2a1it684/x86/.ninja_log +90 -143
- package/android/.cxx/Debug/2a1it684/x86/configure_fingerprint.bin +14 -14
- package/android/.cxx/Debug/2a1it684/x86_64/.ninja_deps +0 -0
- package/android/.cxx/Debug/2a1it684/x86_64/.ninja_log +88 -88
- package/android/.cxx/Debug/2a1it684/x86_64/configure_fingerprint.bin +14 -14
- package/android/build/.transforms/4ebf3dd0dca4f83fe1776360e21ded81/transformed/classes/classes_dex/classes.dex +0 -0
- package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/AntiSpoofingResult.dex +0 -0
- package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/FaceAntiSpoofFrameProcessor.dex +0 -0
- package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/FaceAntiSpoofingAdvanced$Companion.dex +0 -0
- package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/FaceAntiSpoofingAdvanced$EnvironmentAssessment.dex +0 -0
- package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/FaceAntiSpoofingAdvanced$SpoofDetectionResult.dex +0 -0
- package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/FaceAntiSpoofingAdvanced.dex +0 -0
- package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/ImageFormatEncoder$ImageFormat.dex +0 -0
- package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/ImageFormatEncoder$WhenMappings.dex +0 -0
- package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/ImageFormatEncoder.dex +0 -0
- package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
- package/android/build/intermediates/cxx/Debug/2a1it684/logs/arm64-v8a/build_stdout_targets.txt +51 -51
- package/android/build/intermediates/cxx/Debug/2a1it684/logs/arm64-v8a/generate_cxx_metadata_2655_timing.txt +9 -0
- package/android/build/intermediates/cxx/Debug/2a1it684/logs/armeabi-v7a/build_stdout_targets.txt +43 -43
- package/android/build/intermediates/cxx/Debug/2a1it684/logs/x86/build_stdout_targets.txt +47 -47
- package/android/build/intermediates/cxx/Debug/2a1it684/logs/x86_64/build_stdout_targets.txt +39 -39
- package/android/build/intermediates/cxx/Debug/2a1it684/logs/x86_64/generate_cxx_metadata_2653_timing.txt +9 -0
- package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +1 -1
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/AntiSpoofingResult.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/FaceAntiSpoofFrameProcessor.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/FaceAntiSpoofingAdvanced$Companion.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/FaceAntiSpoofingAdvanced$EnvironmentAssessment.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/FaceAntiSpoofingAdvanced$SpoofDetectionResult.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/FaceAntiSpoofingAdvanced.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/ImageFormatEncoder$ImageFormat.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/ImageFormatEncoder$WhenMappings.class +0 -0
- package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/ImageFormatEncoder.class +0 -0
- package/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab +1 -1
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.len +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.values.at +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i +0 -0
- package/android/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
- package/android/build/kotlin/compileDebugKotlin/classpath-snapshot/shrunk-classpath-snapshot.bin +0 -0
- package/android/build/kotlin/compileDebugKotlin/local-state/build-history.bin +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/AntiSpoofingResult.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/FaceAntiSpoofFrameProcessor.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/FaceAntiSpoofingAdvanced$Companion.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/FaceAntiSpoofingAdvanced$EnvironmentAssessment.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/FaceAntiSpoofingAdvanced$SpoofDetectionResult.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/FaceAntiSpoofingAdvanced.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/ImageFormatEncoder$ImageFormat.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/ImageFormatEncoder$WhenMappings.class +0 -0
- package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/ImageFormatEncoder.class +0 -0
- package/android/src/main/java/com/faceantispoof/FaceAntiSpoofFrameProcessor.kt +5 -1
- package/android/src/main/java/com/faceantispoof/FaceAntiSpoofingAdvanced.kt +141 -26
- package/android/src/main/java/com/faceantispoof/ImageFormatEncoder.kt +247 -0
- package/package.json +1 -1
- package/android/build/intermediates/cxx/Debug/2a1it684/logs/arm64-v8a/generate_cxx_metadata_715_timing.txt +0 -9
- package/android/build/intermediates/cxx/Debug/2a1it684/logs/x86_64/generate_cxx_metadata_714_timing.txt +0 -9
- /package/android/.cxx/Debug/2a1it684/x86_64/.cmake/api/v1/reply/{index-2025-11-24T09-46-22-0202.json → index-2025-11-24T13-22-20-0304.json} +0 -0
- /package/android/build/intermediates/cxx/Debug/2a1it684/logs/armeabi-v7a/{generate_cxx_metadata_716_timing.txt → generate_cxx_metadata_2653_timing.txt} +0 -0
- /package/android/build/intermediates/cxx/Debug/2a1it684/logs/x86/{generate_cxx_metadata_716_timing.txt → generate_cxx_metadata_2653_timing.txt} +0 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
package com.faceantispoof
|
|
2
|
+
|
|
3
|
+
import android.graphics.Bitmap
|
|
4
|
+
import android.graphics.Bitmap.CompressFormat
|
|
5
|
+
import android.util.Base64
|
|
6
|
+
import android.util.Log
|
|
7
|
+
import java.io.ByteArrayOutputStream
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Multi-format image encoder supporting JPEG, PNG, and BMP.
|
|
11
|
+
* Handles RGB data conversion to various image formats for compatibility
|
|
12
|
+
* with face recognition systems (OpenCV cv2.imdecode compatible).
|
|
13
|
+
*
|
|
14
|
+
* Supported formats:
|
|
15
|
+
* - JPEG: Compressed, good for network transmission (~80-100 KB at quality 85)
|
|
16
|
+
* - PNG: Lossless, larger file size (~200-300 KB)
|
|
17
|
+
* - BMP: Raw uncompressed, largest size (~2-3 MB for 640×640)
|
|
18
|
+
*
|
|
19
|
+
* Optimized for common resolutions:
|
|
20
|
+
* - 640×480 (VGA)
|
|
21
|
+
* - 1280×720 (HD)
|
|
22
|
+
* - 1920×1080 (Full HD)
|
|
23
|
+
* - 640×640 (Custom square format for face recognition)
|
|
24
|
+
*/
|
|
25
|
+
object ImageFormatEncoder {
|
|
26
|
+
|
|
27
|
+
private const val TAG = "ImageFormatEncoder"
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Supported image formats for face recognition system
|
|
31
|
+
*/
|
|
32
|
+
enum class ImageFormat(val compressFormat: CompressFormat, val mimeType: String) {
|
|
33
|
+
JPEG(CompressFormat.JPEG, "image/jpeg"),
|
|
34
|
+
PNG(CompressFormat.PNG, "image/png"),
|
|
35
|
+
BMP(CompressFormat.WEBP, "image/bmp") // Android uses WebP as fallback for BMP
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Convert RGB data to specified image format and return as Base64 string.
|
|
40
|
+
* Compatible with OpenCV cv2.imdecode() for face recognition systems.
|
|
41
|
+
*
|
|
42
|
+
* @param rgbData RGB data as byte array (format: RGBRGBRGB..., 3 channels)
|
|
43
|
+
* @param width Image width (pixels)
|
|
44
|
+
* @param height Image height (pixels)
|
|
45
|
+
* @param format Target image format (JPEG, PNG, BMP)
|
|
46
|
+
* @param quality Compression quality for JPEG (0-100), ignored for PNG/BMP
|
|
47
|
+
* @return Base64 encoded image string, or null if encoding fails
|
|
48
|
+
*/
|
|
49
|
+
fun rgbToBase64(
|
|
50
|
+
rgbData: ByteArray,
|
|
51
|
+
width: Int,
|
|
52
|
+
height: Int,
|
|
53
|
+
format: ImageFormat = ImageFormat.JPEG,
|
|
54
|
+
quality: Int = 85
|
|
55
|
+
): String? {
|
|
56
|
+
return try {
|
|
57
|
+
validateImageDimensions(width, height)
|
|
58
|
+
validateRgbData(rgbData, width, height)
|
|
59
|
+
|
|
60
|
+
val imageBytes = rgbToImageBytes(rgbData, width, height, format, quality)
|
|
61
|
+
?: return null
|
|
62
|
+
|
|
63
|
+
Base64.encodeToString(imageBytes, Base64.NO_WRAP)
|
|
64
|
+
} catch (e: Exception) {
|
|
65
|
+
Log.e(TAG, "Failed to convert RGB to ${format.name} Base64: ${e.message}", e)
|
|
66
|
+
null
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Convert RGB float array (normalized 0-1) to image format and return as Base64.
|
|
72
|
+
* Each pixel is stored as 3 floats (R, G, B).
|
|
73
|
+
*
|
|
74
|
+
* @param rgbFloats RGB data as float array (normalized to 0-1)
|
|
75
|
+
* @param width Image width
|
|
76
|
+
* @param height Image height
|
|
77
|
+
* @param format Target image format
|
|
78
|
+
* @param quality Compression quality for JPEG
|
|
79
|
+
* @return Base64 encoded image string
|
|
80
|
+
*/
|
|
81
|
+
fun rgbFloatToBase64(
|
|
82
|
+
rgbFloats: FloatArray,
|
|
83
|
+
width: Int,
|
|
84
|
+
height: Int,
|
|
85
|
+
format: ImageFormat = ImageFormat.JPEG,
|
|
86
|
+
quality: Int = 85
|
|
87
|
+
): String? {
|
|
88
|
+
return try {
|
|
89
|
+
validateImageDimensions(width, height)
|
|
90
|
+
|
|
91
|
+
// Convert float array (normalized 0-1) to byte array (0-255)
|
|
92
|
+
val rgbBytes = ByteArray(width * height * 3)
|
|
93
|
+
var idx = 0
|
|
94
|
+
for (i in rgbFloats.indices) {
|
|
95
|
+
rgbBytes[idx++] = (rgbFloats[i] * 255f).toInt().coerceIn(0, 255).toByte()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
rgbToBase64(rgbBytes, width, height, format, quality)
|
|
99
|
+
} catch (e: Exception) {
|
|
100
|
+
Log.e(TAG, "Failed to convert RGB float to ${format.name} Base64: ${e.message}", e)
|
|
101
|
+
null
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Convert RGB data to raw image bytes (not Base64).
|
|
107
|
+
*
|
|
108
|
+
* @param rgbData RGB data as byte array
|
|
109
|
+
* @param width Image width
|
|
110
|
+
* @param height Image height
|
|
111
|
+
* @param format Target image format
|
|
112
|
+
* @param quality Compression quality for JPEG
|
|
113
|
+
* @return Raw image bytes, or null if encoding fails
|
|
114
|
+
*/
|
|
115
|
+
fun rgbToImageBytes(
|
|
116
|
+
rgbData: ByteArray,
|
|
117
|
+
width: Int,
|
|
118
|
+
height: Int,
|
|
119
|
+
format: ImageFormat = ImageFormat.JPEG,
|
|
120
|
+
quality: Int = 85
|
|
121
|
+
): ByteArray? {
|
|
122
|
+
return try {
|
|
123
|
+
validateImageDimensions(width, height)
|
|
124
|
+
validateRgbData(rgbData, width, height)
|
|
125
|
+
|
|
126
|
+
val bitmap = createBitmapFromRgb(rgbData, width, height)
|
|
127
|
+
val imageBytes = when (format) {
|
|
128
|
+
ImageFormat.JPEG -> compressBitmapToBytes(bitmap, format, quality)
|
|
129
|
+
ImageFormat.PNG -> compressBitmapToBytes(bitmap, format, 100)
|
|
130
|
+
ImageFormat.BMP -> compressBitmapToBytes(bitmap, format, 100)
|
|
131
|
+
}
|
|
132
|
+
bitmap.recycle()
|
|
133
|
+
imageBytes
|
|
134
|
+
} catch (e: Exception) {
|
|
135
|
+
Log.e(TAG, "Failed to convert RGB to ${format.name} bytes: ${e.message}", e)
|
|
136
|
+
null
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Get optimal image format based on use case.
|
|
142
|
+
* Returns format recommendation for face recognition systems.
|
|
143
|
+
*
|
|
144
|
+
* @param useCase One of: "network" (JPEG), "storage" (PNG), "opencv" (JPEG)
|
|
145
|
+
* @return Recommended ImageFormat
|
|
146
|
+
*/
|
|
147
|
+
fun getOptimalFormat(useCase: String = "network"): ImageFormat {
|
|
148
|
+
return when (useCase.lowercase()) {
|
|
149
|
+
"network" -> ImageFormat.JPEG // Smaller size for transmission
|
|
150
|
+
"storage" -> ImageFormat.PNG // Lossless for long-term storage
|
|
151
|
+
"opencv" -> ImageFormat.JPEG // OpenCV optimized
|
|
152
|
+
else -> ImageFormat.JPEG
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Get estimated output size for given resolution and format.
|
|
158
|
+
* Helps with memory allocation and network planning.
|
|
159
|
+
*
|
|
160
|
+
* @param width Image width
|
|
161
|
+
* @param height Image height
|
|
162
|
+
* @param format Image format
|
|
163
|
+
* @param quality JPEG quality if applicable
|
|
164
|
+
* @return Estimated size in bytes
|
|
165
|
+
*/
|
|
166
|
+
fun estimateOutputSize(
|
|
167
|
+
width: Int,
|
|
168
|
+
height: Int,
|
|
169
|
+
format: ImageFormat = ImageFormat.JPEG,
|
|
170
|
+
quality: Int = 85
|
|
171
|
+
): Long {
|
|
172
|
+
val pixelCount = width.toLong() * height
|
|
173
|
+
return when (format) {
|
|
174
|
+
ImageFormat.JPEG -> {
|
|
175
|
+
// Estimated: 0.1 - 0.15 bytes per pixel at quality 85
|
|
176
|
+
(pixelCount * 0.12).toLong()
|
|
177
|
+
}
|
|
178
|
+
ImageFormat.PNG -> {
|
|
179
|
+
// PNG typically 2-4x larger than JPEG
|
|
180
|
+
(pixelCount * 0.5).toLong()
|
|
181
|
+
}
|
|
182
|
+
ImageFormat.BMP -> {
|
|
183
|
+
// BMP uncompressed: 3 bytes per pixel
|
|
184
|
+
pixelCount * 3
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Get format information string for logging.
|
|
191
|
+
*/
|
|
192
|
+
fun getFormatInfo(format: ImageFormat, width: Int, height: Int, quality: Int = 85): String {
|
|
193
|
+
val estimatedSize = estimateOutputSize(width, height, format, quality)
|
|
194
|
+
return "${format.name} (${width}×${height}) est. ${estimatedSize / 1024}KB"
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// ============ Private Helper Methods ============
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Create Bitmap from RGB byte array.
|
|
201
|
+
* RGB format: RGBRGBRGB... (3 bytes per pixel, no alpha)
|
|
202
|
+
*/
|
|
203
|
+
private fun createBitmapFromRgb(rgbData: ByteArray, width: Int, height: Int): Bitmap {
|
|
204
|
+
// Convert RGB to ARGB for Bitmap (Android uses ARGB_8888)
|
|
205
|
+
val pixels = IntArray(width * height)
|
|
206
|
+
var rgbIdx = 0
|
|
207
|
+
for (i in pixels.indices) {
|
|
208
|
+
val r = rgbData[rgbIdx++].toInt() and 0xFF
|
|
209
|
+
val g = rgbData[rgbIdx++].toInt() and 0xFF
|
|
210
|
+
val b = rgbData[rgbIdx++].toInt() and 0xFF
|
|
211
|
+
pixels[i] = 0xFF000000.toInt() or (r shl 16) or (g shl 8) or b // ARGB
|
|
212
|
+
}
|
|
213
|
+
return Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Compress Bitmap to specified format bytes.
|
|
218
|
+
*/
|
|
219
|
+
private fun compressBitmapToBytes(
|
|
220
|
+
bitmap: Bitmap,
|
|
221
|
+
format: ImageFormat,
|
|
222
|
+
quality: Int
|
|
223
|
+
): ByteArray {
|
|
224
|
+
val outputStream = ByteArrayOutputStream()
|
|
225
|
+
bitmap.compress(format.compressFormat, quality, outputStream)
|
|
226
|
+
return outputStream.toByteArray()
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Validate image dimensions are within reasonable bounds.
|
|
231
|
+
*/
|
|
232
|
+
private fun validateImageDimensions(width: Int, height: Int) {
|
|
233
|
+
require(width > 0 && width <= 4096) { "Image width must be 1-4096 pixels, got $width" }
|
|
234
|
+
require(height > 0 && height <= 4096) { "Image height must be 1-4096 pixels, got $height" }
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Validate RGB data buffer is correct size.
|
|
239
|
+
* RGB format requires exactly width * height * 3 bytes
|
|
240
|
+
*/
|
|
241
|
+
private fun validateRgbData(rgbData: ByteArray, width: Int, height: Int) {
|
|
242
|
+
val expectedSize = width * height * 3
|
|
243
|
+
require(rgbData.size >= expectedSize) {
|
|
244
|
+
"RGB data size mismatch: expected $expectedSize bytes for ${width}×${height}, got ${rgbData.size}"
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-vision-camera-spoof-detector",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
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/jescon-tech/react-native-vision-camera-spoof-detector",
|
|
6
6
|
"repository": {
|
|
File without changes
|
|
File without changes
|