react-native-rectangle-doc-scanner 7.63.0 → 7.65.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.
|
@@ -669,79 +669,44 @@ class CameraController(
|
|
|
669
669
|
val centerX = viewRect.centerX()
|
|
670
670
|
val centerY = viewRect.centerY()
|
|
671
671
|
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
candidate.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
|
|
681
|
-
val scale = max(viewWidth / bufferRect.width(), viewHeight / bufferRect.height())
|
|
682
|
-
candidate.postScale(scale, scale, centerX, centerY)
|
|
683
|
-
if (appliedRotation != 0) {
|
|
684
|
-
candidate.postRotate(appliedRotation.toFloat(), centerX, centerY)
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
val pts = floatArrayOf(
|
|
688
|
-
0f, 0f,
|
|
689
|
-
bufferWidth, 0f,
|
|
690
|
-
0f, bufferHeight,
|
|
691
|
-
bufferWidth, bufferHeight
|
|
692
|
-
)
|
|
693
|
-
candidate.mapPoints(pts)
|
|
694
|
-
return Pair(candidate, pts)
|
|
695
|
-
}
|
|
672
|
+
// Portrait-only mode: swap buffer dimensions based on sensor orientation
|
|
673
|
+
// sensorOrientation=90 means camera is rotated 90° from device natural orientation
|
|
674
|
+
val swap = sensorOrientation == 90 || sensorOrientation == 270
|
|
675
|
+
val bufferWidth = if (swap) preview.height.toFloat() else preview.width.toFloat()
|
|
676
|
+
val bufferHeight = if (swap) preview.width.toFloat() else preview.height.toFloat()
|
|
677
|
+
val bufferRect = RectF(0f, 0f, bufferWidth, bufferHeight)
|
|
678
|
+
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
|
|
696
679
|
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
val left = max(viewRect.left, minX)
|
|
704
|
-
val top = max(viewRect.top, minY)
|
|
705
|
-
val right = min(viewRect.right, maxX)
|
|
706
|
-
val bottom = min(viewRect.bottom, maxY)
|
|
707
|
-
val intersection = if (right > left && bottom > top) (right - left) * (bottom - top) else 0f
|
|
708
|
-
val viewArea = viewRect.width() * viewRect.height()
|
|
709
|
-
return if (viewArea > 0f) intersection / viewArea else 0f
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
val positive = rotationDegrees
|
|
713
|
-
val negative = if (rotationDegrees == 0) 0 else (360 - rotationDegrees) % 360
|
|
714
|
-
val (matrixPos, ptsPos) = buildTransform(positive)
|
|
715
|
-
val (matrixNeg, ptsNeg) = buildTransform(negative)
|
|
716
|
-
val scorePos = scoreCoverage(ptsPos)
|
|
717
|
-
val scoreNeg = scoreCoverage(ptsNeg)
|
|
680
|
+
val matrix = Matrix()
|
|
681
|
+
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
|
|
682
|
+
val scale = max(viewWidth / bufferRect.width(), viewHeight / bufferRect.height())
|
|
683
|
+
matrix.postScale(scale, scale, centerX, centerY)
|
|
684
|
+
// Portrait-only: no additional rotation needed, sensor orientation is already handled by buffer swap
|
|
718
685
|
|
|
719
|
-
val
|
|
720
|
-
|
|
721
|
-
|
|
686
|
+
val pts = floatArrayOf(
|
|
687
|
+
0f, 0f,
|
|
688
|
+
bufferWidth, 0f,
|
|
689
|
+
0f, bufferHeight,
|
|
690
|
+
bufferWidth, bufferHeight
|
|
691
|
+
)
|
|
692
|
+
matrix.mapPoints(pts)
|
|
722
693
|
|
|
723
694
|
Log.d(
|
|
724
695
|
TAG,
|
|
725
|
-
"[TRANSFORM]
|
|
726
|
-
"view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}"
|
|
696
|
+
"[TRANSFORM] sensor=$sensorOrientation display=$displayRotation swap=$swap " +
|
|
697
|
+
"view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height} buffer=${bufferWidth}x${bufferHeight}"
|
|
727
698
|
)
|
|
728
699
|
|
|
729
|
-
previewView.setTransform(
|
|
730
|
-
latestTransform = Matrix(
|
|
700
|
+
previewView.setTransform(matrix)
|
|
701
|
+
latestTransform = Matrix(matrix)
|
|
731
702
|
latestBufferWidth = preview.width
|
|
732
703
|
latestBufferHeight = preview.height
|
|
733
|
-
latestTransformRotation =
|
|
704
|
+
latestTransformRotation = 0 // Portrait-only mode, no rotation applied
|
|
734
705
|
|
|
735
706
|
Log.d(
|
|
736
707
|
TAG,
|
|
737
|
-
"[TRANSFORM]
|
|
738
|
-
"isTextureView=${previewView is TextureView} matrix=$appliedMatrix " +
|
|
739
|
-
"pts=[${appliedPts[0]},${appliedPts[1]} ${appliedPts[2]},${appliedPts[3]} ${appliedPts[4]},${appliedPts[5]} ${appliedPts[6]},${appliedPts[7]}]"
|
|
708
|
+
"[TRANSFORM] scale=$scale matrix=$matrix"
|
|
740
709
|
)
|
|
741
|
-
val recomputed = computeRotationDegrees()
|
|
742
|
-
if (rotationDegrees != recomputed) {
|
|
743
|
-
Log.e(TAG, "[TRANSFORM] rotation mismatch computed=$rotationDegrees recomputed=$recomputed")
|
|
744
|
-
}
|
|
745
710
|
Log.d(TAG, "[TRANSFORM] Matrix applied successfully")
|
|
746
711
|
}
|
|
747
712
|
|