react-native-rectangle-doc-scanner 7.27.0 → 7.29.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,8 +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
|
-
//
|
|
250
|
-
val
|
|
249
|
+
// Prefer 4:3 to match iOS FOV on phones; use view aspect on tablets to reduce crop.
|
|
250
|
+
val isTablet = context.resources.configuration.smallestScreenWidthDp >= 600
|
|
251
|
+
val targetPreviewAspect = if (isTablet) viewAspect else 4.0 / 3.0
|
|
251
252
|
previewSize = chooseBestSize(previewSizes, targetPreviewAspect, null, preferClosestAspect = true)
|
|
252
253
|
?: chooseBestSize(previewSizes, viewAspect, null, preferClosestAspect = true)
|
|
253
254
|
?: previewSizes?.maxByOrNull { it.width * it.height }
|
|
@@ -564,25 +565,27 @@ class CameraController(
|
|
|
564
565
|
)
|
|
565
566
|
|
|
566
567
|
val matrix = Matrix()
|
|
568
|
+
val isSwapped = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270
|
|
569
|
+
val bufferWidth = if (isSwapped) preview.height.toFloat() else preview.width.toFloat()
|
|
570
|
+
val bufferHeight = if (isSwapped) preview.width.toFloat() else preview.height.toFloat()
|
|
567
571
|
val viewRect = RectF(0f, 0f, viewWidth, viewHeight)
|
|
568
|
-
val bufferRect = RectF(0f, 0f,
|
|
572
|
+
val bufferRect = RectF(0f, 0f, bufferWidth, bufferHeight)
|
|
569
573
|
val centerX = viewRect.centerX()
|
|
570
574
|
val centerY = viewRect.centerY()
|
|
571
575
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
matrix.
|
|
585
|
-
matrix.postTranslate((viewWidth - scaledWidth) / 2f, (viewHeight - scaledHeight) / 2f)
|
|
576
|
+
// Uniform scale to avoid stretching; then center-crop to fill the view.
|
|
577
|
+
matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.CENTER)
|
|
578
|
+
val scale = max(viewWidth / bufferWidth, viewHeight / bufferHeight)
|
|
579
|
+
matrix.postScale(scale, scale, centerX, centerY)
|
|
580
|
+
|
|
581
|
+
if (rotation != Surface.ROTATION_0) {
|
|
582
|
+
val rotateDegrees = when (rotation) {
|
|
583
|
+
Surface.ROTATION_90 -> -90f
|
|
584
|
+
Surface.ROTATION_180 -> 180f
|
|
585
|
+
Surface.ROTATION_270 -> 90f
|
|
586
|
+
else -> 0f
|
|
587
|
+
}
|
|
588
|
+
matrix.postRotate(rotateDegrees, centerX, centerY)
|
|
586
589
|
}
|
|
587
590
|
|
|
588
591
|
previewView.setTransform(matrix)
|