react-native-rectangle-doc-scanner 7.30.0 → 7.32.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,33 +558,27 @@ 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 rotationDegrees = computeRotationDegrees()
|
|
562
562
|
Log.d(
|
|
563
563
|
TAG,
|
|
564
564
|
"[TRANSFORM] rotation=${displayRotationDegrees()} view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}"
|
|
565
565
|
)
|
|
566
566
|
|
|
567
567
|
val matrix = Matrix()
|
|
568
|
-
val
|
|
569
|
-
val
|
|
570
|
-
val
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
matrix.
|
|
576
|
-
val scale = max(viewHeight / preview.height.toFloat(), viewWidth / preview.width.toFloat())
|
|
577
|
-
matrix.postScale(scale, scale, centerX, centerY)
|
|
578
|
-
matrix.postRotate(90f * (rotation - 2), centerX, centerY)
|
|
579
|
-
} else if (rotation == Surface.ROTATION_180) {
|
|
580
|
-
matrix.postRotate(180f, centerX, centerY)
|
|
581
|
-
} else {
|
|
582
|
-
val bufferRect = RectF(0f, 0f, preview.width.toFloat(), preview.height.toFloat())
|
|
583
|
-
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
|
|
584
|
-
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
|
|
585
|
-
val scale = max(viewWidth / preview.width.toFloat(), viewHeight / preview.height.toFloat())
|
|
586
|
-
matrix.postScale(scale, scale, centerX, centerY)
|
|
568
|
+
val bufferWidth = preview.width.toFloat()
|
|
569
|
+
val bufferHeight = preview.height.toFloat()
|
|
570
|
+
val rotateDegrees = rotationDegrees.toFloat()
|
|
571
|
+
|
|
572
|
+
// Move buffer center to origin, rotate, scale uniformly to fill view, then move to view center.
|
|
573
|
+
matrix.postTranslate(-bufferWidth / 2f, -bufferHeight / 2f)
|
|
574
|
+
if (rotateDegrees != 0f) {
|
|
575
|
+
matrix.postRotate(rotateDegrees)
|
|
587
576
|
}
|
|
577
|
+
val rotatedWidth = if (rotationDegrees == 90 || rotationDegrees == 270) bufferHeight else bufferWidth
|
|
578
|
+
val rotatedHeight = if (rotationDegrees == 90 || rotationDegrees == 270) bufferWidth else bufferHeight
|
|
579
|
+
val scale = max(viewWidth / rotatedWidth, viewHeight / rotatedHeight)
|
|
580
|
+
matrix.postScale(scale, scale)
|
|
581
|
+
matrix.postTranslate(viewWidth / 2f, viewHeight / 2f)
|
|
588
582
|
|
|
589
583
|
previewView.setTransform(matrix)
|
|
590
584
|
Log.d(TAG, "[TRANSFORM] Matrix applied successfully")
|
|
@@ -618,23 +612,15 @@ class CameraController(
|
|
|
618
612
|
}
|
|
619
613
|
|
|
620
614
|
if (preferClosestAspect) {
|
|
621
|
-
// Prefer
|
|
622
|
-
|
|
623
|
-
val highResSizes = capped.filter { it.width * it.height >= minAcceptableArea }
|
|
624
|
-
val pool = if (highResSizes.isNotEmpty()) highResSizes else capped
|
|
625
|
-
|
|
626
|
-
// Debug: log aspect ratio diff for each size
|
|
627
|
-
pool.forEach { size ->
|
|
615
|
+
// Prefer aspect ratio match first, then pick the highest resolution among matches.
|
|
616
|
+
capped.forEach { size ->
|
|
628
617
|
val diff = aspectDiff(size)
|
|
629
618
|
Log.d(TAG, "[SIZE_SELECTION] ${size.width}x${size.height} aspect=${size.width.toDouble()/size.height} diff=$diff")
|
|
630
619
|
}
|
|
631
620
|
|
|
632
|
-
val bestDiff =
|
|
633
|
-
|
|
634
|
-
val
|
|
635
|
-
|
|
636
|
-
// Among best aspect ratio matches, prefer higher resolution
|
|
637
|
-
val selected = close.maxByOrNull { it.width * it.height } ?: pool.maxByOrNull { it.width * it.height }
|
|
621
|
+
val bestDiff = capped.minOf { aspectDiff(it) }
|
|
622
|
+
val close = capped.filter { aspectDiff(it) <= bestDiff + 0.001 }
|
|
623
|
+
val selected = close.maxByOrNull { it.width * it.height } ?: capped.maxByOrNull { it.width * it.height }
|
|
638
624
|
Log.d(TAG, "[SIZE_SELECTION] Best aspect diff: $bestDiff, candidates: ${close.size}, selected: ${selected?.width}x${selected?.height}")
|
|
639
625
|
return selected
|
|
640
626
|
}
|