react-native-rectangle-doc-scanner 7.7.0 → 7.9.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.
|
@@ -118,10 +118,10 @@ class CameraController(
|
|
|
118
118
|
return
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
// Always set the listener so we get size-change callbacks for transform updates.
|
|
122
|
+
previewView.surfaceTextureListener = textureListener
|
|
121
123
|
if (previewView.isAvailable) {
|
|
122
124
|
openCamera()
|
|
123
|
-
} else {
|
|
124
|
-
previewView.surfaceTextureListener = textureListener
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
@@ -150,8 +150,8 @@ class CameraController(
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
try {
|
|
153
|
-
//
|
|
154
|
-
val jpegOrientation =
|
|
153
|
+
// Match JPEG orientation to current device rotation and sensor orientation.
|
|
154
|
+
val jpegOrientation = computeRotationDegrees()
|
|
155
155
|
Log.d(TAG, "[CAPTURE] Setting JPEG_ORIENTATION to $jpegOrientation")
|
|
156
156
|
|
|
157
157
|
val requestBuilder = device.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE).apply {
|
|
@@ -240,7 +240,9 @@ class CameraController(
|
|
|
240
240
|
val previewSizes = streamConfigMap.getOutputSizes(SurfaceTexture::class.java)
|
|
241
241
|
Log.d(TAG, "[CAMERA2] Available preview sizes: ${previewSizes?.take(10)?.joinToString { "${it.width}x${it.height}" }}")
|
|
242
242
|
|
|
243
|
+
// Prefer a preview size that matches the view aspect to avoid letterboxing.
|
|
243
244
|
previewSize = chooseBestSize(previewSizes, viewAspect, null, preferClosestAspect = true)
|
|
245
|
+
?: previewSizes?.maxByOrNull { it.width * it.height }
|
|
244
246
|
Log.d(TAG, "[CAMERA2] Selected preview size: ${previewSize?.width}x${previewSize?.height}")
|
|
245
247
|
|
|
246
248
|
val previewAspect = previewSize?.let { it.width.toDouble() / it.height.toDouble() } ?: viewAspect
|
|
@@ -551,28 +553,26 @@ class CameraController(
|
|
|
551
553
|
val centerX = viewWidth / 2f
|
|
552
554
|
val centerY = viewHeight / 2f
|
|
553
555
|
|
|
554
|
-
//
|
|
555
|
-
// - The camera sensor output is landscape (1920x1088)
|
|
556
|
-
// - We need to rotate 270 degrees to display it in portrait
|
|
557
|
-
// - Then scale to fill the entire view
|
|
556
|
+
// Match iOS behavior: use the full preview extent and scale to fill
|
|
558
557
|
if (rotation == 270 || rotation == 90) {
|
|
559
|
-
//
|
|
560
|
-
matrix.postRotate(rotation.toFloat(), centerX, centerY)
|
|
561
|
-
|
|
562
|
-
// After rotation, the dimensions are swapped
|
|
558
|
+
// After rotation, dimensions are swapped
|
|
563
559
|
val rotatedWidth = preview.height.toFloat()
|
|
564
560
|
val rotatedHeight = preview.width.toFloat()
|
|
565
561
|
|
|
566
562
|
Log.d(TAG, "[TRANSFORM] After rotation: ${rotatedWidth}x${rotatedHeight}")
|
|
567
563
|
|
|
568
|
-
// Calculate scale to fill the view
|
|
564
|
+
// Calculate scale to completely fill the view (aspect fill - crop mode like iOS)
|
|
565
|
+
// This will crop the image but fill the entire screen
|
|
569
566
|
val scaleX = viewWidth / rotatedWidth
|
|
570
567
|
val scaleY = viewHeight / rotatedHeight
|
|
571
568
|
val scale = maxOf(scaleX, scaleY)
|
|
572
569
|
|
|
573
570
|
Log.d(TAG, "[TRANSFORM] scaleX=$scaleX scaleY=$scaleY finalScale=$scale")
|
|
574
571
|
|
|
575
|
-
// Apply
|
|
572
|
+
// Apply rotation around center first
|
|
573
|
+
matrix.postRotate(rotation.toFloat(), centerX, centerY)
|
|
574
|
+
|
|
575
|
+
// Then scale to fill (will crop excess)
|
|
576
576
|
matrix.postScale(scale, scale, centerX, centerY)
|
|
577
577
|
} else {
|
|
578
578
|
// For 0 or 180 degree rotation
|
|
@@ -649,11 +649,11 @@ class CameraController(
|
|
|
649
649
|
private fun rotateAndMirror(bitmap: Bitmap, rotationDegrees: Int, mirror: Boolean): Bitmap {
|
|
650
650
|
Log.d(TAG, "[ROTATE_MIRROR] rotationDegrees=$rotationDegrees mirror=$mirror bitmap=${bitmap.width}x${bitmap.height}")
|
|
651
651
|
|
|
652
|
-
// JPEG_ORIENTATION is already set
|
|
653
|
-
// We only need to apply mirror for front camera
|
|
652
|
+
// JPEG_ORIENTATION is already set, so the image should already be rotated correctly.
|
|
653
|
+
// We only need to apply mirror for front camera.
|
|
654
654
|
if (!mirror) {
|
|
655
|
-
// Back camera: no additional processing needed since JPEG_ORIENTATION handles rotation
|
|
656
|
-
Log.d(TAG, "[ROTATE_MIRROR] Back camera: returning bitmap as-is (JPEG_ORIENTATION
|
|
655
|
+
// Back camera: no additional processing needed since JPEG_ORIENTATION handles rotation.
|
|
656
|
+
Log.d(TAG, "[ROTATE_MIRROR] Back camera: returning bitmap as-is (JPEG_ORIENTATION already applied)")
|
|
657
657
|
return bitmap
|
|
658
658
|
}
|
|
659
659
|
|