react-native-rectangle-doc-scanner 4.4.0 → 4.6.0
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.
|
@@ -227,6 +227,13 @@ class CameraController(
|
|
|
227
227
|
?: captureSizes?.maxByOrNull { it.width * it.height }
|
|
228
228
|
|
|
229
229
|
setupImageReaders()
|
|
230
|
+
Log.d(
|
|
231
|
+
TAG,
|
|
232
|
+
"[CAMERA2] view=${previewView.width}x${previewView.height} " +
|
|
233
|
+
"preview=${previewSize?.width}x${previewSize?.height} " +
|
|
234
|
+
"analysis=${analysisSize?.width}x${analysisSize?.height} " +
|
|
235
|
+
"capture=${captureSize?.width}x${captureSize?.height}"
|
|
236
|
+
)
|
|
230
237
|
|
|
231
238
|
if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
|
|
232
239
|
Log.e(TAG, "[CAMERA2] Camera permission not granted")
|
|
@@ -552,10 +559,13 @@ class CameraController(
|
|
|
552
559
|
}
|
|
553
560
|
|
|
554
561
|
if (preferClosestAspect) {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
)
|
|
562
|
+
val maxAreaOverall = capped.maxOf { it.width * it.height }
|
|
563
|
+
val minAcceptableArea = max(640 * 480, (maxAreaOverall * 0.1).toInt())
|
|
564
|
+
val sized = capped.filter { it.width * it.height >= minAcceptableArea }
|
|
565
|
+
val pool = if (sized.isNotEmpty()) sized else capped
|
|
566
|
+
val bestDiff = pool.minOf { aspectDiff(it) }
|
|
567
|
+
val close = pool.filter { aspectDiff(it) <= bestDiff + 0.05 }
|
|
568
|
+
return close.maxByOrNull { it.width * it.height } ?: pool.maxByOrNull { it.width * it.height }
|
|
559
569
|
}
|
|
560
570
|
|
|
561
571
|
val matching = capped.filter { aspectDiff(it) <= ANALYSIS_ASPECT_TOLERANCE }
|
|
@@ -130,6 +130,13 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
|
|
|
130
130
|
initializeCameraWhenReady()
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
|
|
134
|
+
super.onLayout(changed, left, top, right, bottom)
|
|
135
|
+
if (changed) {
|
|
136
|
+
Log.d(TAG, "[LAYOUT] View size: ${right - left}x${bottom - top}, PreviewView: ${previewView.width}x${previewView.height}")
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
133
140
|
private fun initializeCameraWhenReady() {
|
|
134
141
|
// If view is already laid out, start camera immediately
|
|
135
142
|
if (width > 0 && height > 0) {
|
|
@@ -384,13 +391,23 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
|
|
|
384
391
|
shouldCrop = shouldCrop
|
|
385
392
|
)
|
|
386
393
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
394
|
+
fun buildResult(
|
|
395
|
+
croppedPath: String,
|
|
396
|
+
initialPath: String,
|
|
397
|
+
rectangle: Rectangle?
|
|
398
|
+
): WritableMap {
|
|
399
|
+
return Arguments.createMap().apply {
|
|
400
|
+
putString("croppedImage", croppedPath)
|
|
401
|
+
putString("initialImage", initialPath)
|
|
402
|
+
putMap("rectangleCoordinates", rectangle?.toMap()?.toWritableMap())
|
|
393
403
|
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
val (resultForPromise, resultForEvent) = if (useBase64) {
|
|
407
|
+
val croppedBase64 = ImageProcessor.bitmapToBase64(processed.croppedImage, quality)
|
|
408
|
+
val initialBase64 = ImageProcessor.bitmapToBase64(processed.initialImage, quality)
|
|
409
|
+
buildResult(croppedBase64, initialBase64, detectedRectangle) to
|
|
410
|
+
buildResult(croppedBase64, initialBase64, detectedRectangle)
|
|
394
411
|
} else {
|
|
395
412
|
val timestamp = System.currentTimeMillis()
|
|
396
413
|
val croppedPath = ImageProcessor.saveBitmapToFile(
|
|
@@ -405,22 +422,18 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
|
|
|
405
422
|
"initial_img_$timestamp.jpeg",
|
|
406
423
|
quality
|
|
407
424
|
)
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
putString("croppedImage", croppedPath)
|
|
411
|
-
putString("initialImage", initialPath)
|
|
412
|
-
putMap("rectangleCoordinates", detectedRectangle?.toMap()?.toWritableMap())
|
|
413
|
-
}
|
|
425
|
+
buildResult(croppedPath, initialPath, detectedRectangle) to
|
|
426
|
+
buildResult(croppedPath, initialPath, detectedRectangle)
|
|
414
427
|
}
|
|
415
428
|
|
|
416
429
|
withContext(Dispatchers.Main) {
|
|
417
430
|
Log.d(TAG, "Processing completed, resolving promise: ${promise != null}")
|
|
418
431
|
|
|
419
432
|
// Resolve promise first (if provided) - matches iOS behavior
|
|
420
|
-
promise?.resolve(
|
|
433
|
+
promise?.resolve(resultForPromise)
|
|
421
434
|
|
|
422
435
|
// Then send event for backwards compatibility
|
|
423
|
-
sendPictureTakenEvent(
|
|
436
|
+
sendPictureTakenEvent(resultForEvent)
|
|
424
437
|
|
|
425
438
|
isCapturing = false
|
|
426
439
|
|
|
@@ -442,9 +455,8 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
|
|
|
442
455
|
}
|
|
443
456
|
|
|
444
457
|
private fun sendPictureTakenEvent(data: WritableMap) {
|
|
445
|
-
val event = data.toHashMap().toWritableMap()
|
|
446
458
|
themedContext.getJSModule(RCTEventEmitter::class.java)
|
|
447
|
-
.receiveEvent(id, "onPictureTaken",
|
|
459
|
+
.receiveEvent(id, "onPictureTaken", data)
|
|
448
460
|
}
|
|
449
461
|
|
|
450
462
|
private fun sendRectangleDetectEvent(
|