react-native-rectangle-doc-scanner 7.32.0 → 7.33.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.
|
@@ -558,7 +558,7 @@ class CameraController(
|
|
|
558
558
|
val viewHeight = previewView.height.toFloat()
|
|
559
559
|
val preview = previewSize ?: return
|
|
560
560
|
if (viewWidth == 0f || viewHeight == 0f) return
|
|
561
|
-
val
|
|
561
|
+
val rotation = previewView.display?.rotation ?: Surface.ROTATION_0
|
|
562
562
|
Log.d(
|
|
563
563
|
TAG,
|
|
564
564
|
"[TRANSFORM] rotation=${displayRotationDegrees()} view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}"
|
|
@@ -567,15 +567,20 @@ class CameraController(
|
|
|
567
567
|
val matrix = Matrix()
|
|
568
568
|
val bufferWidth = preview.width.toFloat()
|
|
569
569
|
val bufferHeight = preview.height.toFloat()
|
|
570
|
-
val rotateDegrees =
|
|
570
|
+
val rotateDegrees = when (rotation) {
|
|
571
|
+
Surface.ROTATION_90 -> -90f
|
|
572
|
+
Surface.ROTATION_180 -> 180f
|
|
573
|
+
Surface.ROTATION_270 -> 90f
|
|
574
|
+
else -> 0f
|
|
575
|
+
}
|
|
571
576
|
|
|
572
577
|
// Move buffer center to origin, rotate, scale uniformly to fill view, then move to view center.
|
|
573
578
|
matrix.postTranslate(-bufferWidth / 2f, -bufferHeight / 2f)
|
|
574
579
|
if (rotateDegrees != 0f) {
|
|
575
580
|
matrix.postRotate(rotateDegrees)
|
|
576
581
|
}
|
|
577
|
-
val rotatedWidth = if (
|
|
578
|
-
val rotatedHeight = if (
|
|
582
|
+
val rotatedWidth = if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) bufferHeight else bufferWidth
|
|
583
|
+
val rotatedHeight = if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) bufferWidth else bufferHeight
|
|
579
584
|
val scale = max(viewWidth / rotatedWidth, viewHeight / rotatedHeight)
|
|
580
585
|
matrix.postScale(scale, scale)
|
|
581
586
|
matrix.postTranslate(viewWidth / 2f, viewHeight / 2f)
|
|
@@ -612,15 +617,19 @@ class CameraController(
|
|
|
612
617
|
}
|
|
613
618
|
|
|
614
619
|
if (preferClosestAspect) {
|
|
620
|
+
// Avoid tiny preview sizes even if aspect matches; prefer reasonable resolution.
|
|
621
|
+
val minAcceptableArea = 640 * 480
|
|
622
|
+
val pool = capped.filter { it.width * it.height >= minAcceptableArea }.ifEmpty { capped }
|
|
623
|
+
|
|
615
624
|
// Prefer aspect ratio match first, then pick the highest resolution among matches.
|
|
616
|
-
|
|
625
|
+
pool.forEach { size ->
|
|
617
626
|
val diff = aspectDiff(size)
|
|
618
627
|
Log.d(TAG, "[SIZE_SELECTION] ${size.width}x${size.height} aspect=${size.width.toDouble()/size.height} diff=$diff")
|
|
619
628
|
}
|
|
620
629
|
|
|
621
|
-
val bestDiff =
|
|
622
|
-
val close =
|
|
623
|
-
val selected = close.maxByOrNull { it.width * it.height } ?:
|
|
630
|
+
val bestDiff = pool.minOf { aspectDiff(it) }
|
|
631
|
+
val close = pool.filter { aspectDiff(it) <= bestDiff + 0.001 }
|
|
632
|
+
val selected = close.maxByOrNull { it.width * it.height } ?: pool.maxByOrNull { it.width * it.height }
|
|
624
633
|
Log.d(TAG, "[SIZE_SELECTION] Best aspect diff: $bestDiff, candidates: ${close.size}, selected: ${selected?.width}x${selected?.height}")
|
|
625
634
|
return selected
|
|
626
635
|
}
|