react-native-rectangle-doc-scanner 7.31.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.
|
@@ -565,29 +565,25 @@ class CameraController(
|
|
|
565
565
|
)
|
|
566
566
|
|
|
567
567
|
val matrix = Matrix()
|
|
568
|
-
val
|
|
569
|
-
val
|
|
570
|
-
val
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
if (rotation
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
else -> 0f
|
|
588
|
-
}
|
|
589
|
-
matrix.postRotate(rotateDegrees, centerX, centerY)
|
|
590
|
-
}
|
|
568
|
+
val bufferWidth = preview.width.toFloat()
|
|
569
|
+
val bufferHeight = preview.height.toFloat()
|
|
570
|
+
val rotateDegrees = when (rotation) {
|
|
571
|
+
Surface.ROTATION_90 -> -90f
|
|
572
|
+
Surface.ROTATION_180 -> 180f
|
|
573
|
+
Surface.ROTATION_270 -> 90f
|
|
574
|
+
else -> 0f
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// Move buffer center to origin, rotate, scale uniformly to fill view, then move to view center.
|
|
578
|
+
matrix.postTranslate(-bufferWidth / 2f, -bufferHeight / 2f)
|
|
579
|
+
if (rotateDegrees != 0f) {
|
|
580
|
+
matrix.postRotate(rotateDegrees)
|
|
581
|
+
}
|
|
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
|
|
584
|
+
val scale = max(viewWidth / rotatedWidth, viewHeight / rotatedHeight)
|
|
585
|
+
matrix.postScale(scale, scale)
|
|
586
|
+
matrix.postTranslate(viewWidth / 2f, viewHeight / 2f)
|
|
591
587
|
|
|
592
588
|
previewView.setTransform(matrix)
|
|
593
589
|
Log.d(TAG, "[TRANSFORM] Matrix applied successfully")
|
|
@@ -621,22 +617,18 @@ class CameraController(
|
|
|
621
617
|
}
|
|
622
618
|
|
|
623
619
|
if (preferClosestAspect) {
|
|
624
|
-
//
|
|
625
|
-
val minAcceptableArea =
|
|
626
|
-
val
|
|
627
|
-
val pool = if (highResSizes.isNotEmpty()) highResSizes else capped
|
|
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 }
|
|
628
623
|
|
|
629
|
-
//
|
|
624
|
+
// Prefer aspect ratio match first, then pick the highest resolution among matches.
|
|
630
625
|
pool.forEach { size ->
|
|
631
626
|
val diff = aspectDiff(size)
|
|
632
627
|
Log.d(TAG, "[SIZE_SELECTION] ${size.width}x${size.height} aspect=${size.width.toDouble()/size.height} diff=$diff")
|
|
633
628
|
}
|
|
634
629
|
|
|
635
630
|
val bestDiff = pool.minOf { aspectDiff(it) }
|
|
636
|
-
// Use very tight tolerance (0.001) to get only the best aspect ratio matches
|
|
637
631
|
val close = pool.filter { aspectDiff(it) <= bestDiff + 0.001 }
|
|
638
|
-
|
|
639
|
-
// Among best aspect ratio matches, prefer higher resolution
|
|
640
632
|
val selected = close.maxByOrNull { it.width * it.height } ?: pool.maxByOrNull { it.width * it.height }
|
|
641
633
|
Log.d(TAG, "[SIZE_SELECTION] Best aspect diff: $bestDiff, candidates: ${close.size}, selected: ${selected?.width}x${selected?.height}")
|
|
642
634
|
return selected
|