react-native-rectangle-doc-scanner 3.204.0 → 3.206.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.
|
@@ -65,8 +65,8 @@ class CameraController(
|
|
|
65
65
|
|
|
66
66
|
companion object {
|
|
67
67
|
private const val TAG = "CameraController"
|
|
68
|
-
private const val
|
|
69
|
-
private const val
|
|
68
|
+
private const val MAX_ANALYSIS_WIDTH = 1280
|
|
69
|
+
private const val MAX_ANALYSIS_HEIGHT = 720
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
private data class LastFrame(
|
|
@@ -267,9 +267,13 @@ class CameraController(
|
|
|
267
267
|
null
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
previewSize =
|
|
271
|
-
analysisSize =
|
|
272
|
-
Log.d(
|
|
270
|
+
previewSize = choosePreviewSize(previewChoices, targetRatio)
|
|
271
|
+
analysisSize = chooseAnalysisSize(analysisChoices, targetRatio)
|
|
272
|
+
Log.d(
|
|
273
|
+
TAG,
|
|
274
|
+
"[CAMERA2] chooseCamera view=${viewWidth}x${viewHeight} ratio=$targetRatio " +
|
|
275
|
+
"sensorOrientation=$sensorOrientation preview=$previewSize analysis=$analysisSize"
|
|
276
|
+
)
|
|
273
277
|
}
|
|
274
278
|
|
|
275
279
|
private fun openCamera() {
|
|
@@ -320,6 +324,12 @@ class CameraController(
|
|
|
320
324
|
val previewSize = sizes.first ?: return
|
|
321
325
|
val analysisSize = sizes.second ?: previewSize
|
|
322
326
|
|
|
327
|
+
Log.d(
|
|
328
|
+
TAG,
|
|
329
|
+
"[CAMERA2] createPreviewSession view=${previewView.width}x${previewView.height} " +
|
|
330
|
+
"preview=${previewSize.width}x${previewSize.height} analysis=${analysisSize.width}x${analysisSize.height}"
|
|
331
|
+
)
|
|
332
|
+
|
|
323
333
|
texture.setDefaultBufferSize(previewSize.width, previewSize.height)
|
|
324
334
|
val previewSurface = Surface(texture)
|
|
325
335
|
|
|
@@ -386,8 +396,8 @@ class CameraController(
|
|
|
386
396
|
null
|
|
387
397
|
}
|
|
388
398
|
|
|
389
|
-
val newPreview =
|
|
390
|
-
val newAnalysis =
|
|
399
|
+
val newPreview = choosePreviewSize(previewChoices, targetRatio)
|
|
400
|
+
val newAnalysis = chooseAnalysisSize(analysisChoices, targetRatio)
|
|
391
401
|
|
|
392
402
|
if (newPreview != null && newPreview != previewSize) {
|
|
393
403
|
previewSize = newPreview
|
|
@@ -396,6 +406,11 @@ class CameraController(
|
|
|
396
406
|
analysisSize = newAnalysis
|
|
397
407
|
}
|
|
398
408
|
|
|
409
|
+
Log.d(
|
|
410
|
+
TAG,
|
|
411
|
+
"[CAMERA2] ensurePreviewSizes view=${viewWidth}x${viewHeight} ratio=$targetRatio " +
|
|
412
|
+
"preview=${previewSize?.width}x${previewSize?.height} analysis=${analysisSize?.width}x${analysisSize?.height}"
|
|
413
|
+
)
|
|
399
414
|
return Pair(previewSize, analysisSize)
|
|
400
415
|
}
|
|
401
416
|
|
|
@@ -439,6 +454,11 @@ class CameraController(
|
|
|
439
454
|
matrix.postTranslate(viewWidth / 2f, viewHeight / 2f)
|
|
440
455
|
|
|
441
456
|
previewView.setTransform(matrix)
|
|
457
|
+
Log.d(
|
|
458
|
+
TAG,
|
|
459
|
+
"[CAMERA2] transform view=${viewWidth}x${viewHeight} buffer=${bufferWidth}x${bufferHeight} " +
|
|
460
|
+
"rotated=${rotatedBufferWidth}x${rotatedBufferHeight} rotation=$rotationDegrees scale=$scale"
|
|
461
|
+
)
|
|
442
462
|
}
|
|
443
463
|
|
|
444
464
|
private fun ensureMatchParent() {
|
|
@@ -462,6 +482,7 @@ class CameraController(
|
|
|
462
482
|
layoutParams.gravity = Gravity.CENTER
|
|
463
483
|
previewView.layoutParams = layoutParams
|
|
464
484
|
}
|
|
485
|
+
Log.d(TAG, "[CAMERA2] parent=${parentWidth}x${parentHeight} previewView=${previewView.width}x${previewView.height}")
|
|
465
486
|
}
|
|
466
487
|
|
|
467
488
|
private fun handleImage(image: Image) {
|
|
@@ -578,20 +599,48 @@ class CameraController(
|
|
|
578
599
|
}
|
|
579
600
|
}
|
|
580
601
|
|
|
581
|
-
private fun
|
|
602
|
+
private fun choosePreviewSize(
|
|
603
|
+
choices: Array<Size>,
|
|
604
|
+
targetRatio: Float?
|
|
605
|
+
): Size? {
|
|
606
|
+
if (choices.isEmpty()) {
|
|
607
|
+
return null
|
|
608
|
+
}
|
|
609
|
+
val candidates = choices.toList()
|
|
610
|
+
|
|
611
|
+
if (targetRatio == null) {
|
|
612
|
+
return candidates.maxByOrNull { it.width * it.height }
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
val normalizedTarget = targetRatio
|
|
616
|
+
val sorted = candidates.sortedWith(
|
|
617
|
+
compareBy<Size> { size ->
|
|
618
|
+
val ratio = if (normalizedTarget < 1f) {
|
|
619
|
+
size.height.toFloat() / size.width.toFloat()
|
|
620
|
+
} else {
|
|
621
|
+
size.width.toFloat() / size.height.toFloat()
|
|
622
|
+
}
|
|
623
|
+
kotlin.math.abs(ratio - normalizedTarget)
|
|
624
|
+
}.thenByDescending { size ->
|
|
625
|
+
size.width * size.height
|
|
626
|
+
}
|
|
627
|
+
)
|
|
628
|
+
return sorted.first()
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
private fun chooseAnalysisSize(
|
|
582
632
|
choices: Array<Size>,
|
|
583
|
-
maxWidth: Int,
|
|
584
|
-
maxHeight: Int,
|
|
585
633
|
targetRatio: Float?
|
|
586
634
|
): Size? {
|
|
587
635
|
if (choices.isEmpty()) {
|
|
588
636
|
return null
|
|
589
637
|
}
|
|
590
|
-
|
|
591
|
-
val
|
|
638
|
+
|
|
639
|
+
val capped = choices.filter { it.width <= MAX_ANALYSIS_WIDTH && it.height <= MAX_ANALYSIS_HEIGHT }
|
|
640
|
+
val candidates = if (capped.isNotEmpty()) capped else choices.toList()
|
|
592
641
|
|
|
593
642
|
if (targetRatio == null) {
|
|
594
|
-
return candidates.
|
|
643
|
+
return candidates.maxByOrNull { it.width * it.height }
|
|
595
644
|
}
|
|
596
645
|
|
|
597
646
|
val normalizedTarget = targetRatio
|
package/package.json
CHANGED