react-native-rectangle-doc-scanner 7.47.0 → 7.49.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.
|
@@ -246,10 +246,9 @@ class CameraController(
|
|
|
246
246
|
val previewSizes = streamConfigMap.getOutputSizes(SurfaceTexture::class.java)
|
|
247
247
|
Log.d(TAG, "[CAMERA2] Available preview sizes: ${previewSizes?.take(10)?.joinToString { "${it.width}x${it.height}" }}")
|
|
248
248
|
|
|
249
|
-
// Prefer 4:3
|
|
250
|
-
val
|
|
251
|
-
val
|
|
252
|
-
val minPreviewArea = if (isTablet) 1280 * 720 else 960 * 720
|
|
249
|
+
// Prefer 4:3 so height-based scaling fills the screen without stretching.
|
|
250
|
+
val targetPreviewAspect = 4.0 / 3.0
|
|
251
|
+
val minPreviewArea = 960 * 720
|
|
253
252
|
previewSize = chooseBestSize(previewSizes, targetPreviewAspect, null, minPreviewArea, preferClosestAspect = true)
|
|
254
253
|
?: chooseBestSize(previewSizes, viewAspect, null, preferClosestAspect = true)
|
|
255
254
|
?: previewSizes?.maxByOrNull { it.width * it.height }
|
|
@@ -575,50 +574,31 @@ class CameraController(
|
|
|
575
574
|
|
|
576
575
|
val matrix = Matrix()
|
|
577
576
|
val viewRect = RectF(0f, 0f, viewWidth, viewHeight)
|
|
578
|
-
val bufferRect = RectF(0f, 0f, preview.width.toFloat(), preview.height.toFloat())
|
|
579
577
|
val centerX = viewRect.centerX()
|
|
580
578
|
val centerY = viewRect.centerY()
|
|
581
579
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
val targetCenterX = viewWidth / 2f
|
|
597
|
-
val targetCenterY = viewHeight / 2f
|
|
598
|
-
|
|
599
|
-
// Step 1: Map buffer rect to view target rect with CENTER mode (maintains aspect ratio)
|
|
600
|
-
matrix.setRectToRect(bufferRect, viewTargetRect, Matrix.ScaleToFit.CENTER)
|
|
601
|
-
|
|
602
|
-
// Step 2: Translate to center of actual view
|
|
603
|
-
val scaledBufferWidth = bufferWidth * (effectiveHeight / bufferHeight)
|
|
604
|
-
val scaledBufferHeight = effectiveHeight
|
|
605
|
-
matrix.postTranslate(
|
|
606
|
-
targetCenterX - scaledBufferWidth / 2f,
|
|
607
|
-
targetCenterY - scaledBufferHeight / 2f
|
|
608
|
-
)
|
|
580
|
+
val isSwapped = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270
|
|
581
|
+
val bufferWidth = if (isSwapped) preview.height.toFloat() else preview.width.toFloat()
|
|
582
|
+
val bufferHeight = if (isSwapped) preview.width.toFloat() else preview.height.toFloat()
|
|
583
|
+
var scale = if (isSwapped) {
|
|
584
|
+
// Scale by height to preserve aspect, then ensure width fills the view.
|
|
585
|
+
viewHeight / bufferHeight
|
|
586
|
+
} else {
|
|
587
|
+
viewHeight / bufferHeight
|
|
588
|
+
}
|
|
589
|
+
if (bufferWidth * scale < viewWidth) {
|
|
590
|
+
scale = viewWidth / bufferWidth
|
|
591
|
+
}
|
|
592
|
+
val scaledWidth = bufferWidth * scale
|
|
593
|
+
val scaledHeight = bufferHeight * scale
|
|
609
594
|
|
|
610
|
-
|
|
611
|
-
|
|
595
|
+
matrix.setScale(scale, scale)
|
|
596
|
+
matrix.postTranslate((viewWidth - scaledWidth) / 2f, (viewHeight - scaledHeight) / 2f)
|
|
612
597
|
|
|
613
|
-
|
|
598
|
+
if (isSwapped) {
|
|
599
|
+
matrix.postRotate(90f * (rotation - 2), centerX, centerY)
|
|
614
600
|
} else if (rotation == Surface.ROTATION_180) {
|
|
615
601
|
matrix.postRotate(180f, centerX, centerY)
|
|
616
|
-
} else {
|
|
617
|
-
val scale = max(viewWidth / preview.width.toFloat(), viewHeight / preview.height.toFloat())
|
|
618
|
-
val scaledWidth = preview.width.toFloat() * scale
|
|
619
|
-
val scaledHeight = preview.height.toFloat() * scale
|
|
620
|
-
matrix.setScale(scale, scale)
|
|
621
|
-
matrix.postTranslate((viewWidth - scaledWidth) / 2f, (viewHeight - scaledHeight) / 2f)
|
|
622
602
|
}
|
|
623
603
|
|
|
624
604
|
previewView.setTransform(matrix)
|