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.
Files changed (133) hide show
  1. package/android/.cxx/Debug/2a1it684/arm64-v8a/.cmake/api/v1/reply/{codemodel-v2-6af431df2d09cde56941.json → codemodel-v2-390962e2784a6a84fa3e.json} +2 -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
  3. package/android/.cxx/Debug/2a1it684/arm64-v8a/.cmake/api/v1/reply/{target-yuv-Debug-d9c8b9c64fd8df9f1bcd.json → target-yuv-Debug-1e27b8a2bdcddd47b87d.json} +3 -3
  4. 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
  5. package/android/.cxx/Debug/2a1it684/arm64-v8a/.ninja_deps +0 -0
  6. package/android/.cxx/Debug/2a1it684/arm64-v8a/.ninja_log +99 -99
  7. package/android/.cxx/Debug/2a1it684/arm64-v8a/configure_fingerprint.bin +14 -14
  8. package/android/.cxx/Debug/2a1it684/armeabi-v7a/.ninja_deps +0 -0
  9. package/android/.cxx/Debug/2a1it684/armeabi-v7a/.ninja_log +92 -149
  10. package/android/.cxx/Debug/2a1it684/armeabi-v7a/configure_fingerprint.bin +14 -14
  11. package/android/.cxx/Debug/2a1it684/x86/.ninja_deps +0 -0
  12. package/android/.cxx/Debug/2a1it684/x86/.ninja_log +90 -143
  13. package/android/.cxx/Debug/2a1it684/x86/configure_fingerprint.bin +14 -14
  14. package/android/.cxx/Debug/2a1it684/x86_64/.ninja_deps +0 -0
  15. package/android/.cxx/Debug/2a1it684/x86_64/.ninja_log +88 -88
  16. package/android/.cxx/Debug/2a1it684/x86_64/configure_fingerprint.bin +14 -14
  17. package/android/build/.transforms/4ebf3dd0dca4f83fe1776360e21ded81/transformed/classes/classes_dex/classes.dex +0 -0
  18. package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/AntiSpoofingResult.dex +0 -0
  19. package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/FaceAntiSpoofFrameProcessor.dex +0 -0
  20. package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/FaceAntiSpoofingAdvanced$Companion.dex +0 -0
  21. package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/FaceAntiSpoofingAdvanced$EnvironmentAssessment.dex +0 -0
  22. package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/FaceAntiSpoofingAdvanced$SpoofDetectionResult.dex +0 -0
  23. package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/FaceAntiSpoofingAdvanced.dex +0 -0
  24. package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/ImageFormatEncoder$ImageFormat.dex +0 -0
  25. package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/ImageFormatEncoder$WhenMappings.dex +0 -0
  26. package/android/build/.transforms/c0a07cd9442d741ad3cef3760159211f/transformed/bundleLibRuntimeToDirDebug/bundleLibRuntimeToDirDebug_dex/com/faceantispoof/ImageFormatEncoder.dex +0 -0
  27. package/android/build/intermediates/compile_library_classes_jar/debug/bundleLibCompileToJarDebug/classes.jar +0 -0
  28. package/android/build/intermediates/cxx/Debug/2a1it684/logs/arm64-v8a/build_stdout_targets.txt +51 -51
  29. package/android/build/intermediates/cxx/Debug/2a1it684/logs/arm64-v8a/generate_cxx_metadata_2655_timing.txt +9 -0
  30. package/android/build/intermediates/cxx/Debug/2a1it684/logs/armeabi-v7a/build_stdout_targets.txt +43 -43
  31. package/android/build/intermediates/cxx/Debug/2a1it684/logs/x86/build_stdout_targets.txt +47 -47
  32. package/android/build/intermediates/cxx/Debug/2a1it684/logs/x86_64/build_stdout_targets.txt +39 -39
  33. package/android/build/intermediates/cxx/Debug/2a1it684/logs/x86_64/generate_cxx_metadata_2653_timing.txt +9 -0
  34. package/android/build/intermediates/incremental/debug/packageDebugResources/compile-file-map.properties +1 -1
  35. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/AntiSpoofingResult.class +0 -0
  36. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/FaceAntiSpoofFrameProcessor.class +0 -0
  37. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/FaceAntiSpoofingAdvanced$Companion.class +0 -0
  38. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/FaceAntiSpoofingAdvanced$EnvironmentAssessment.class +0 -0
  39. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/FaceAntiSpoofingAdvanced$SpoofDetectionResult.class +0 -0
  40. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/FaceAntiSpoofingAdvanced.class +0 -0
  41. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/ImageFormatEncoder$ImageFormat.class +0 -0
  42. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/ImageFormatEncoder$WhenMappings.class +0 -0
  43. package/android/build/intermediates/runtime_library_classes_dir/debug/bundleLibRuntimeToDirDebug/com/faceantispoof/ImageFormatEncoder.class +0 -0
  44. package/android/build/intermediates/runtime_library_classes_jar/debug/bundleLibRuntimeToJarDebug/classes.jar +0 -0
  45. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab +0 -0
  46. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream +0 -0
  47. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.keystream.len +0 -0
  48. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.len +0 -0
  49. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab.values.at +0 -0
  50. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/inputs/source-to-output.tab_i +0 -0
  51. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab +0 -0
  52. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream +0 -0
  53. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.keystream.len +0 -0
  54. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.len +0 -0
  55. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab.values.at +0 -0
  56. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-attributes.tab_i +0 -0
  57. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab +0 -0
  58. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream +0 -0
  59. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.keystream.len +0 -0
  60. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.len +0 -0
  61. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab.values.at +0 -0
  62. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/class-fq-name-to-source.tab_i +0 -0
  63. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/constants.tab.values.at +0 -0
  64. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab +0 -0
  65. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream +0 -0
  66. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.keystream.len +0 -0
  67. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.len +0 -0
  68. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab.values.at +0 -0
  69. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/internal-name-to-source.tab_i +0 -0
  70. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab +0 -0
  71. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream +0 -0
  72. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.keystream.len +0 -0
  73. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.len +0 -0
  74. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab.values.at +0 -0
  75. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/proto.tab_i +0 -0
  76. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab +0 -0
  77. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream +0 -0
  78. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.keystream.len +0 -0
  79. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.len +0 -0
  80. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab.values.at +0 -0
  81. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/source-to-classes.tab_i +0 -0
  82. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab +0 -0
  83. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream +0 -0
  84. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.keystream.len +0 -0
  85. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.len +0 -0
  86. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab.values.at +0 -0
  87. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/subtypes.tab_i +0 -0
  88. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab +0 -0
  89. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream +0 -0
  90. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.keystream.len +0 -0
  91. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.len +0 -0
  92. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab.values.at +0 -0
  93. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/jvm/kotlin/supertypes.tab_i +0 -0
  94. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/counters.tab +1 -1
  95. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab +0 -0
  96. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream +0 -0
  97. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.keystream.len +0 -0
  98. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.len +0 -0
  99. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab.values.at +0 -0
  100. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/file-to-id.tab_i +0 -0
  101. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab +0 -0
  102. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream +0 -0
  103. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.keystream.len +0 -0
  104. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.len +0 -0
  105. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab.values.at +0 -0
  106. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/id-to-file.tab_i +0 -0
  107. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab +0 -0
  108. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream +0 -0
  109. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.keystream.len +0 -0
  110. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.len +0 -0
  111. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab.values.at +0 -0
  112. package/android/build/kotlin/compileDebugKotlin/cacheable/caches-jvm/lookups/lookups.tab_i +0 -0
  113. package/android/build/kotlin/compileDebugKotlin/cacheable/last-build.bin +0 -0
  114. package/android/build/kotlin/compileDebugKotlin/classpath-snapshot/shrunk-classpath-snapshot.bin +0 -0
  115. package/android/build/kotlin/compileDebugKotlin/local-state/build-history.bin +0 -0
  116. package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/AntiSpoofingResult.class +0 -0
  117. package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/FaceAntiSpoofFrameProcessor.class +0 -0
  118. package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/FaceAntiSpoofingAdvanced$Companion.class +0 -0
  119. package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/FaceAntiSpoofingAdvanced$EnvironmentAssessment.class +0 -0
  120. package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/FaceAntiSpoofingAdvanced$SpoofDetectionResult.class +0 -0
  121. package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/FaceAntiSpoofingAdvanced.class +0 -0
  122. package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/ImageFormatEncoder$ImageFormat.class +0 -0
  123. package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/ImageFormatEncoder$WhenMappings.class +0 -0
  124. package/android/build/tmp/kotlin-classes/debug/com/faceantispoof/ImageFormatEncoder.class +0 -0
  125. package/android/src/main/java/com/faceantispoof/FaceAntiSpoofFrameProcessor.kt +5 -1
  126. package/android/src/main/java/com/faceantispoof/FaceAntiSpoofingAdvanced.kt +141 -26
  127. package/android/src/main/java/com/faceantispoof/ImageFormatEncoder.kt +247 -0
  128. package/package.json +1 -1
  129. package/android/build/intermediates/cxx/Debug/2a1it684/logs/arm64-v8a/generate_cxx_metadata_715_timing.txt +0 -9
  130. package/android/build/intermediates/cxx/Debug/2a1it684/logs/x86_64/generate_cxx_metadata_714_timing.txt +0 -9
  131. /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
  132. /package/android/build/intermediates/cxx/Debug/2a1it684/logs/armeabi-v7a/{generate_cxx_metadata_716_timing.txt → generate_cxx_metadata_2653_timing.txt} +0 -0
  133. /package/android/build/intermediates/cxx/Debug/2a1it684/logs/x86/{generate_cxx_metadata_716_timing.txt → generate_cxx_metadata_2653_timing.txt} +0 -0
@@ -132,7 +132,11 @@ class FaceAntiSpoofFrameProcessor : FrameProcessorPlugin() {
132
132
  "neuralNetworkScore" to result.neuralNetworkScore.toDouble(),
133
133
  "laplacianScore" to result.laplacianScore,
134
134
  "combinedScore" to result.combinedScore.toDouble(),
135
- "recognitionImageBase64" to result.recognitionImageBase64
135
+ "recognitionImageBase64" to result.recognitionImageBase64,
136
+ // Image format metadata
137
+ "imageFormat" to result.imageFormat,
138
+ "imageResolution" to result.imageResolution,
139
+ "imageQuality" to result.imageQuality
136
140
  )
137
141
 
138
142
  // Update the latest result for the next callback
@@ -15,6 +15,8 @@ import java.util.*
15
15
  import android.util.Log
16
16
  import kotlin.collections.ArrayList
17
17
  import android.util.Base64
18
+ import com.faceantispoof.ImageFormatEncoder
19
+ import com.faceantispoof.ImageFormatEncoder.ImageFormat
18
20
 
19
21
  class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
20
22
 
@@ -32,6 +34,12 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
32
34
  const val ACCELERATOR_GPU = "GPU"
33
35
  const val ACCELERATOR_NNAPI = "NNAPI"
34
36
 
37
+ // Image format configuration for face recognition systems
38
+ // Supported: JPEG (compressed), PNG (lossless), BMP (uncompressed)
39
+ const val DEFAULT_IMAGE_FORMAT = "JPEG" // Options: "JPEG", "PNG", "BMP"
40
+ const val DEFAULT_JPEG_QUALITY = 85 // 0-100, higher = better quality but larger
41
+ const val DEFAULT_OUTPUT_RESOLUTION = 640 // 640×640 for face recognition
42
+
35
43
  // Advanced spoof detection constants
36
44
  private const val HISTORY_SIZE = 10
37
45
  private const val TEMPORAL_CONSISTENCY_THRESHOLD = 0.08f
@@ -48,6 +56,11 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
48
56
  private var gpuDelegate: GpuDelegate? = null
49
57
  private var currentAccelerator: String = ACCELERATOR_CPU
50
58
 
59
+ // Image format configuration for face recognition
60
+ private var outputImageFormat: String = DEFAULT_IMAGE_FORMAT
61
+ private var outputImageQuality: Int = DEFAULT_JPEG_QUALITY
62
+ private var outputImageResolution: Int = DEFAULT_OUTPUT_RESOLUTION
63
+
51
64
  // Reusable buffers to avoid per-frame allocations
52
65
  private val inputImageSize = INPUT_IMAGE_SIZE
53
66
  private val inputBuffer: ByteBuffer = ByteBuffer.allocateDirect(4 * inputImageSize * inputImageSize * 3).order(ByteOrder.nativeOrder())
@@ -142,6 +155,57 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
142
155
 
143
156
  fun getAccelerator(): String = currentAccelerator
144
157
 
158
+ /**
159
+ * Configure output image format for face recognition system.
160
+ * Supports JPEG (compressed), PNG (lossless), or BMP (uncompressed).
161
+ *
162
+ * @param format Image format: "JPEG" (default), "PNG", or "BMP"
163
+ * @param quality JPEG quality 0-100 (only applies to JPEG, ignored for PNG/BMP)
164
+ * @param resolution Output resolution in pixels (640 for 640×640, etc.)
165
+ */
166
+ fun setImageFormatConfig(
167
+ format: String = "JPEG",
168
+ quality: Int = 85,
169
+ resolution: Int = 640
170
+ ) {
171
+ val uppercaseFormat = format.uppercase()
172
+ outputImageFormat = if (uppercaseFormat in listOf("JPEG", "PNG", "BMP")) {
173
+ uppercaseFormat
174
+ } else {
175
+ "JPEG"
176
+ }
177
+ outputImageQuality = quality.coerceIn(1, 100)
178
+ outputImageResolution = resolution.coerceIn(64, 2048)
179
+ Log.d(TAG, "Image format config: $outputImageFormat quality=$outputImageQuality resolution=${outputImageResolution}×${outputImageResolution}")
180
+ }
181
+
182
+ /**
183
+ * Get current image format configuration.
184
+ * @return Map containing format, quality, and resolution
185
+ */
186
+ fun getImageFormatConfig(): Map<String, Any> {
187
+ return mapOf(
188
+ "format" to outputImageFormat,
189
+ "quality" to outputImageQuality,
190
+ "resolution" to outputImageResolution,
191
+ "estimatedSize" to estimateImageSize()
192
+ )
193
+ }
194
+
195
+ /**
196
+ * Estimate output image size for current format configuration.
197
+ * Useful for memory and network planning.
198
+ */
199
+ private fun estimateImageSize(): Long {
200
+ val pixelCount = outputImageResolution.toLong() * outputImageResolution
201
+ return when (outputImageFormat) {
202
+ "JPEG" -> (pixelCount * (100 - outputImageQuality) * 0.0012).toLong() // Quality-based estimation
203
+ "PNG" -> (pixelCount * 0.5).toLong() // PNG typically 2-4x larger than JPEG
204
+ "BMP" -> pixelCount * 3 // Uncompressed RGB
205
+ else -> (pixelCount * 0.12).toLong()
206
+ }
207
+ }
208
+
145
209
  fun advancedAntiSpoofing(nv21: ByteArray, width: Int, height: Int): AntiSpoofingResult {
146
210
  if (!isInitialized) {
147
211
  return AntiSpoofingResult(
@@ -154,18 +218,23 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
154
218
  isLive = false,
155
219
  confidence = 0f,
156
220
  label = "Not Initialized",
157
- spoofType = "UNKNOWN"
221
+ spoofType = "UNKNOWN",
222
+ imageFormat = outputImageFormat,
223
+ imageResolution = outputImageResolution,
224
+ imageQuality = outputImageQuality
158
225
  )
159
226
  }
160
227
 
161
228
  // Enhanced input validation
162
229
  if (nv21.isEmpty()) {
163
- return AntiSpoofingResult(0f, 0, 0, 0f, 0f, 0f, false, 0f, "Error: Invalid NV21 buffer", "INVALID_INPUT")
230
+ return AntiSpoofingResult(0f, 0, 0, 0f, 0f, 0f, false, 0f, "Error: Invalid NV21 buffer", "INVALID_INPUT",
231
+ imageFormat = outputImageFormat, imageResolution = outputImageResolution, imageQuality = outputImageQuality)
164
232
  }
165
233
 
166
234
  val expectedSize = width * height + (width * height) / 2
167
235
  if (nv21.size < expectedSize) {
168
- return AntiSpoofingResult(0f, 0, 0, 0f, 0f, 0f, false, 0f, "Error: Buffer size mismatch", "INVALID_INPUT")
236
+ return AntiSpoofingResult(0f, 0, 0, 0f, 0f, 0f, false, 0f, "Error: Buffer size mismatch", "INVALID_INPUT",
237
+ imageFormat = outputImageFormat, imageResolution = outputImageResolution, imageQuality = outputImageQuality)
169
238
  }
170
239
 
171
240
  return try {
@@ -201,14 +270,14 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
201
270
  spoofDetection
202
271
  )
203
272
 
204
- // Generate 640×640 JPEG Base64 for Recognition API when face is live
273
+ // Generate recognition image (JPEG/PNG/BMP) Base64 when face is live
205
274
  var recognitionImageBase64: String? = null
206
275
  val DEBUG_FORCE_BASE64 = false // Set to true to force Base64 generation for testing
207
276
 
208
277
  if (isLive || DEBUG_FORCE_BASE64) {
209
- Log.d(TAG, "🔍 isLive=$isLive (DEBUG_FORCE_BASE64=$DEBUG_FORCE_BASE64) - generating 640x640 JPEG Base64...")
278
+ Log.d(TAG, "🔍 isLive=$isLive (DEBUG_FORCE_BASE64=$DEBUG_FORCE_BASE64) - generating ${outputImageResolution}×${outputImageResolution} $outputImageFormat Base64...")
210
279
  try {
211
- recognitionImageBase64 = generate640x640JpegBase64(nv21, width, height)
280
+ recognitionImageBase64 = generateRecognitionImageBase64(nv21, width, height)
212
281
  if (recognitionImageBase64 != null) {
213
282
  Log.d(TAG, " Generated 640x640 JPEG Base64 for recognition API (size: ${recognitionImageBase64.length} bytes)")
214
283
  } else {
@@ -233,11 +302,15 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
233
302
  confidence = confidence,
234
303
  label = if (isLive) "Live Face" else "Spoof Face: ${spoofDetection.type}",
235
304
  spoofType = spoofDetection.type,
236
- recognitionImageBase64 = recognitionImageBase64
305
+ recognitionImageBase64 = recognitionImageBase64,
306
+ imageFormat = outputImageFormat,
307
+ imageResolution = outputImageResolution,
308
+ imageQuality = outputImageQuality
237
309
  )
238
310
  } catch (e: Exception) {
239
311
  Log.e(TAG, "Error in advancedAntiSpoofing", e)
240
- AntiSpoofingResult(0f, 0, 0, 0f, 0f, 0f, false, 0f, "Error: ${e.message}", "PROCESSING_ERROR")
312
+ AntiSpoofingResult(0f, 0, 0, 0f, 0f, 0f, false, 0f, "Error: ${e.message}", "PROCESSING_ERROR",
313
+ imageFormat = outputImageFormat, imageResolution = outputImageResolution, imageQuality = outputImageQuality)
241
314
  }
242
315
  }
243
316
 
@@ -296,52 +369,90 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
296
369
  }
297
370
 
298
371
  /**
299
- * Generate 640×640 JPEG image as Base64 string for Recognition API.
300
- * Optimized for high-speed encoding without intermediate allocations.
372
+ * Generate image as Base64 string for face recognition API.
373
+ * Supports JPEG, PNG, and BMP formats with configurable resolution.
374
+ * Compatible with OpenCV cv2.imdecode() for face recognition systems.
301
375
  *
302
376
  * @param nv21 NV21 encoded YUV frame
303
377
  * @param width Original frame width
304
378
  * @param height Original frame height
305
- * @return Base64 encoded JPEG string (640×640), or null if generation fails
379
+ * @return Base64 encoded image string, or null if generation fails
306
380
  */
307
- private fun generate640x640JpegBase64(nv21: ByteArray, width: Int, height: Int): String? {
381
+ private fun generateRecognitionImageBase64(nv21: ByteArray, width: Int, height: Int): String? {
308
382
  return try {
309
- val TARGET_SIZE = 640
310
- Log.d(TAG, "Starting 640x640 JPEG generation. Input: ${width}x${height}, NV21 size: ${nv21.size}")
383
+ Log.d(TAG, "Starting ${outputImageResolution}×${outputImageResolution} $outputImageFormat generation. Input: ${width}x${height}, NV21 size: ${nv21.size}")
311
384
 
312
- // Convert NV21 to RGB byte array directly (640×640)
313
- val rgbBytes = ByteArray(TARGET_SIZE * TARGET_SIZE * 3)
385
+ // Convert NV21 to RGB byte array directly (configurable resolution)
386
+ val rgbBytes = ByteArray(outputImageResolution * outputImageResolution * 3)
314
387
  Log.d(TAG, "Allocated RGB buffer: ${rgbBytes.size} bytes")
315
388
 
316
389
  val startConvert = System.currentTimeMillis()
317
390
  val convertedRgb = yuvConverter.nv21ToRgbByteArray(
318
391
  nv21, width, height,
319
- TARGET_SIZE, TARGET_SIZE,
392
+ outputImageResolution, outputImageResolution,
320
393
  rgbBytes
321
394
  )
322
395
  val convertTime = System.currentTimeMillis() - startConvert
323
396
  Log.d(TAG, "YUV to RGB conversion completed in ${convertTime}ms. RGB data: ${convertedRgb.size} bytes")
324
397
 
325
- // Encode RGB to JPEG Base64 with quality 85
326
- val startJpeg = System.currentTimeMillis()
327
- val base64Result = JpegEncoder.rgbToJpegBase64(convertedRgb, TARGET_SIZE, TARGET_SIZE, quality = 85)
328
- val jpegTime = System.currentTimeMillis() - startJpeg
398
+ // Encode RGB to target format (JPEG, PNG, or BMP) and Base64
399
+ val startEncode = System.currentTimeMillis()
400
+ val format = when (outputImageFormat) {
401
+ "PNG" -> ImageFormatEncoder.ImageFormat.PNG
402
+ "BMP" -> ImageFormatEncoder.ImageFormat.BMP
403
+ else -> ImageFormatEncoder.ImageFormat.JPEG
404
+ }
405
+
406
+ val base64Result = ImageFormatEncoder.rgbToBase64(
407
+ convertedRgb,
408
+ outputImageResolution,
409
+ outputImageResolution,
410
+ format,
411
+ outputImageQuality
412
+ )
413
+ val encodeTime = System.currentTimeMillis() - startEncode
329
414
 
330
415
  if (base64Result != null) {
331
- Log.d(TAG, "JPEG encoding completed in ${jpegTime}ms. Base64 size: ${base64Result.length} bytes")
332
- Log.d(TAG, " Generated 640x640 JPEG Base64 for recognition API (total: ${convertTime + jpegTime}ms)")
416
+ Log.d(TAG, "$outputImageFormat encoding completed in ${encodeTime}ms. Base64 size: ${base64Result.length} bytes")
417
+ Log.d(TAG, " Generated ${outputImageResolution}×${outputImageResolution} $outputImageFormat Base64 for recognition API (total: ${convertTime + encodeTime}ms)")
418
+ val estSize = estimateImageSize()
419
+ Log.d(TAG, "Format: $outputImageFormat, Quality: $outputImageQuality, Estimated: ${estSize / 1024}KB")
333
420
  } else {
334
- Log.w(TAG, " JpegEncoder returned null")
421
+ Log.w(TAG, "⚠️ ImageFormatEncoder returned null")
335
422
  }
336
423
 
337
424
  base64Result
338
425
  } catch (e: Exception) {
339
- Log.e(TAG, " Error generating 640x640 JPEG Base64: ${e.message}", e)
426
+ Log.e(TAG, " Error generating ${outputImageResolution}×${outputImageResolution} $outputImageFormat Base64: ${e.message}", e)
340
427
  e.printStackTrace()
341
428
  null
342
429
  }
343
430
  }
344
431
 
432
+ /**
433
+ * Legacy method: Generate 640×640 JPEG image as Base64 string.
434
+ * Kept for backward compatibility. Use generateRecognitionImageBase64() for new code.
435
+ */
436
+ @Deprecated("Use generateRecognitionImageBase64() instead", ReplaceWith("generateRecognitionImageBase64(nv21, width, height)"))
437
+ private fun generate640x640JpegBase64(nv21: ByteArray, width: Int, height: Int): String? {
438
+ // Temporarily set format to JPEG for backward compatibility
439
+ val savedFormat = outputImageFormat
440
+ outputImageFormat = "JPEG"
441
+ val savedQuality = outputImageQuality
442
+ outputImageQuality = 85
443
+ val savedResolution = outputImageResolution
444
+ outputImageResolution = 640
445
+
446
+ val result = generateRecognitionImageBase64(nv21, width, height)
447
+
448
+ // Restore original config
449
+ outputImageFormat = savedFormat
450
+ outputImageQuality = savedQuality
451
+ outputImageResolution = savedResolution
452
+
453
+ return result
454
+ }
455
+
345
456
  private fun leafScore1(clssPred: Array<FloatArray>, leafNodeMask: Array<FloatArray>): Float {
346
457
  var score = 0f
347
458
  for (i in 0 until 8) {
@@ -643,5 +754,9 @@ data class AntiSpoofingResult(
643
754
  val confidence: Float,
644
755
  val label: String,
645
756
  val spoofType: String,
646
- val recognitionImageBase64: String? = null
757
+ val recognitionImageBase64: String? = null,
758
+ // Image format metadata
759
+ val imageFormat: String = "JPEG", // Format: JPEG, PNG, BMP
760
+ val imageResolution: Int = 640, // 640×640, 1280×720, etc.
761
+ val imageQuality: Int = 85 // Quality for JPEG (0-100)
647
762
  )