react-native-rectangle-doc-scanner 7.5.0 → 7.6.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.
|
@@ -543,34 +543,48 @@ class CameraController(
|
|
|
543
543
|
val rotation = computeRotationDegrees()
|
|
544
544
|
Log.d(TAG, "[TRANSFORM] rotation=$rotation view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}")
|
|
545
545
|
|
|
546
|
-
|
|
547
|
-
val bufferWidth = if (rotation == 90 || rotation == 270) preview.height.toFloat() else preview.width.toFloat()
|
|
548
|
-
val bufferHeight = if (rotation == 90 || rotation == 270) preview.width.toFloat() else preview.height.toFloat()
|
|
549
|
-
|
|
550
|
-
Log.d(TAG, "[TRANSFORM] buffer after rotation: ${bufferWidth}x${bufferHeight}")
|
|
551
|
-
|
|
546
|
+
val matrix = Matrix()
|
|
552
547
|
val centerX = viewWidth / 2f
|
|
553
548
|
val centerY = viewHeight / 2f
|
|
554
549
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
//
|
|
558
|
-
|
|
550
|
+
// For 270 degree rotation (portrait mode with back camera):
|
|
551
|
+
// - The camera sensor output is landscape (1920x1088)
|
|
552
|
+
// - We need to rotate 270 degrees to display it in portrait
|
|
553
|
+
// - Then scale to fill the entire view
|
|
554
|
+
if (rotation == 270 || rotation == 90) {
|
|
555
|
+
// Rotate first
|
|
559
556
|
matrix.postRotate(rotation.toFloat(), centerX, centerY)
|
|
560
|
-
}
|
|
561
557
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
val scale = maxOf(scaleX, scaleY)
|
|
558
|
+
// After rotation, the dimensions are swapped
|
|
559
|
+
val rotatedWidth = preview.height.toFloat()
|
|
560
|
+
val rotatedHeight = preview.width.toFloat()
|
|
566
561
|
|
|
567
|
-
|
|
562
|
+
Log.d(TAG, "[TRANSFORM] After rotation: ${rotatedWidth}x${rotatedHeight}")
|
|
568
563
|
|
|
569
|
-
|
|
570
|
-
|
|
564
|
+
// Calculate scale to fill the view completely (aspect fill/crop mode)
|
|
565
|
+
val scaleX = viewWidth / rotatedWidth
|
|
566
|
+
val scaleY = viewHeight / rotatedHeight
|
|
567
|
+
val scale = maxOf(scaleX, scaleY)
|
|
571
568
|
|
|
572
|
-
|
|
569
|
+
Log.d(TAG, "[TRANSFORM] scaleX=$scaleX scaleY=$scaleY finalScale=$scale")
|
|
570
|
+
|
|
571
|
+
// Apply scale at center
|
|
572
|
+
matrix.postScale(scale, scale, centerX, centerY)
|
|
573
|
+
} else {
|
|
574
|
+
// For 0 or 180 degree rotation
|
|
575
|
+
val scaleX = viewWidth / preview.width.toFloat()
|
|
576
|
+
val scaleY = viewHeight / preview.height.toFloat()
|
|
577
|
+
val scale = maxOf(scaleX, scaleY)
|
|
573
578
|
|
|
579
|
+
Log.d(TAG, "[TRANSFORM] scaleX=$scaleX scaleY=$scaleY finalScale=$scale")
|
|
580
|
+
|
|
581
|
+
if (rotation != 0) {
|
|
582
|
+
matrix.postRotate(rotation.toFloat(), centerX, centerY)
|
|
583
|
+
}
|
|
584
|
+
matrix.postScale(scale, scale, centerX, centerY)
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
previewView.setTransform(matrix)
|
|
574
588
|
Log.d(TAG, "[TRANSFORM] Matrix applied successfully")
|
|
575
589
|
}
|
|
576
590
|
|
|
@@ -630,27 +644,35 @@ class CameraController(
|
|
|
630
644
|
|
|
631
645
|
private fun rotateAndMirror(bitmap: Bitmap, rotationDegrees: Int, mirror: Boolean): Bitmap {
|
|
632
646
|
Log.d(TAG, "[ROTATE_MIRROR] rotationDegrees=$rotationDegrees mirror=$mirror bitmap=${bitmap.width}x${bitmap.height}")
|
|
633
|
-
|
|
634
|
-
return bitmap
|
|
635
|
-
}
|
|
647
|
+
|
|
636
648
|
val matrix = Matrix()
|
|
637
649
|
|
|
638
|
-
// For
|
|
639
|
-
//
|
|
640
|
-
if
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
matrix.postScale(-1f, 1f, bitmap.width / 2f, bitmap.height / 2f)
|
|
647
|
-
Log.d(TAG, "[ROTATE_MIRROR] Applied horizontal flip for front camera")
|
|
650
|
+
// For 270 degree rotation (back camera in portrait mode):
|
|
651
|
+
// 1. First rotate 90 degrees (not 270)
|
|
652
|
+
// 2. Then flip horizontally if needed
|
|
653
|
+
// This is because the sensor orientation is 0, but we're holding the phone at 90 degrees
|
|
654
|
+
val actualRotation = when (rotationDegrees) {
|
|
655
|
+
270 -> 90 // Convert 270 to 90 for correct orientation
|
|
656
|
+
90 -> 270 // Convert 90 to 270 for front camera
|
|
657
|
+
else -> rotationDegrees
|
|
648
658
|
}
|
|
649
659
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
660
|
+
Log.d(TAG, "[ROTATE_MIRROR] Adjusted rotation: $rotationDegrees -> $actualRotation")
|
|
661
|
+
|
|
662
|
+
// Apply rotation first
|
|
663
|
+
if (actualRotation != 0) {
|
|
664
|
+
matrix.postRotate(actualRotation.toFloat())
|
|
665
|
+
Log.d(TAG, "[ROTATE_MIRROR] Applied rotation: $actualRotation degrees")
|
|
653
666
|
}
|
|
667
|
+
|
|
668
|
+
// Apply mirror for front camera only
|
|
669
|
+
if (mirror) {
|
|
670
|
+
// Front camera needs horizontal flip after rotation
|
|
671
|
+
val rotatedWidth = if (actualRotation == 90 || actualRotation == 270) bitmap.height else bitmap.width
|
|
672
|
+
matrix.postScale(-1f, 1f, rotatedWidth / 2f, 0f)
|
|
673
|
+
Log.d(TAG, "[ROTATE_MIRROR] Applied horizontal flip for front camera")
|
|
674
|
+
}
|
|
675
|
+
|
|
654
676
|
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
|
|
655
677
|
}
|
|
656
678
|
|