react-native-rectangle-doc-scanner 7.5.0 → 7.7.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.
@@ -150,6 +150,10 @@ class CameraController(
150
150
  }
151
151
 
152
152
  try {
153
+ // Use 90 degrees for back camera in portrait mode
154
+ val jpegOrientation = 90
155
+ Log.d(TAG, "[CAPTURE] Setting JPEG_ORIENTATION to $jpegOrientation")
156
+
153
157
  val requestBuilder = device.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE).apply {
154
158
  addTarget(reader.surface)
155
159
  set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE)
@@ -157,7 +161,7 @@ class CameraController(
157
161
  if (torchEnabled) {
158
162
  set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_TORCH)
159
163
  }
160
- set(CaptureRequest.JPEG_ORIENTATION, 0)
164
+ set(CaptureRequest.JPEG_ORIENTATION, jpegOrientation)
161
165
  }
162
166
 
163
167
  session.capture(requestBuilder.build(), object : CameraCaptureSession.CaptureCallback() {}, cameraHandler)
@@ -543,34 +547,48 @@ class CameraController(
543
547
  val rotation = computeRotationDegrees()
544
548
  Log.d(TAG, "[TRANSFORM] rotation=$rotation view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}")
545
549
 
546
- // Calculate buffer dimensions after rotation
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
-
550
+ val matrix = Matrix()
552
551
  val centerX = viewWidth / 2f
553
552
  val centerY = viewHeight / 2f
554
553
 
555
- val matrix = Matrix()
556
-
557
- // Apply rotation
558
- if (rotation != 0) {
554
+ // For 270 degree rotation (portrait mode with back camera):
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
558
+ if (rotation == 270 || rotation == 90) {
559
+ // Rotate first
559
560
  matrix.postRotate(rotation.toFloat(), centerX, centerY)
560
- }
561
561
 
562
- // Calculate scale to fill the view (crop mode)
563
- val scaleX = viewWidth / bufferWidth
564
- val scaleY = viewHeight / bufferHeight
565
- val scale = maxOf(scaleX, scaleY)
562
+ // After rotation, the dimensions are swapped
563
+ val rotatedWidth = preview.height.toFloat()
564
+ val rotatedHeight = preview.width.toFloat()
566
565
 
567
- Log.d(TAG, "[TRANSFORM] scaleX=$scaleX scaleY=$scaleY finalScale=$scale")
566
+ Log.d(TAG, "[TRANSFORM] After rotation: ${rotatedWidth}x${rotatedHeight}")
568
567
 
569
- // Apply scale
570
- matrix.postScale(scale, scale, centerX, centerY)
568
+ // Calculate scale to fill the view completely (aspect fill/crop mode)
569
+ val scaleX = viewWidth / rotatedWidth
570
+ val scaleY = viewHeight / rotatedHeight
571
+ val scale = maxOf(scaleX, scaleY)
571
572
 
572
- previewView.setTransform(matrix)
573
+ Log.d(TAG, "[TRANSFORM] scaleX=$scaleX scaleY=$scaleY finalScale=$scale")
574
+
575
+ // Apply scale at center
576
+ matrix.postScale(scale, scale, centerX, centerY)
577
+ } else {
578
+ // For 0 or 180 degree rotation
579
+ val scaleX = viewWidth / preview.width.toFloat()
580
+ val scaleY = viewHeight / preview.height.toFloat()
581
+ val scale = maxOf(scaleX, scaleY)
582
+
583
+ Log.d(TAG, "[TRANSFORM] scaleX=$scaleX scaleY=$scaleY finalScale=$scale")
573
584
 
585
+ if (rotation != 0) {
586
+ matrix.postRotate(rotation.toFloat(), centerX, centerY)
587
+ }
588
+ matrix.postScale(scale, scale, centerX, centerY)
589
+ }
590
+
591
+ previewView.setTransform(matrix)
574
592
  Log.d(TAG, "[TRANSFORM] Matrix applied successfully")
575
593
  }
576
594
 
@@ -630,27 +648,20 @@ class CameraController(
630
648
 
631
649
  private fun rotateAndMirror(bitmap: Bitmap, rotationDegrees: Int, mirror: Boolean): Bitmap {
632
650
  Log.d(TAG, "[ROTATE_MIRROR] rotationDegrees=$rotationDegrees mirror=$mirror bitmap=${bitmap.width}x${bitmap.height}")
633
- if (rotationDegrees == 0 && !mirror) {
634
- return bitmap
635
- }
636
- val matrix = Matrix()
637
651
 
638
- // For back camera, we need to mirror horizontally to fix the flip issue
639
- // The camera sensor output is already mirrored, so we need to flip it back
652
+ // JPEG_ORIENTATION is already set to 90, so the image should already be rotated correctly
653
+ // We only need to apply mirror for front camera
640
654
  if (!mirror) {
641
- // Back camera: flip horizontally
642
- matrix.postScale(-1f, 1f, bitmap.width / 2f, bitmap.height / 2f)
643
- Log.d(TAG, "[ROTATE_MIRROR] Applied horizontal flip for back camera")
644
- } else {
645
- // Front camera: keep mirror
646
- matrix.postScale(-1f, 1f, bitmap.width / 2f, bitmap.height / 2f)
647
- Log.d(TAG, "[ROTATE_MIRROR] Applied horizontal flip for front camera")
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=90 already applied)")
657
+ return bitmap
648
658
  }
649
659
 
650
- if (rotationDegrees != 0) {
651
- matrix.postRotate(rotationDegrees.toFloat(), bitmap.width / 2f, bitmap.height / 2f)
652
- Log.d(TAG, "[ROTATE_MIRROR] Applied rotation: $rotationDegrees degrees")
653
- }
660
+ // Front camera: apply horizontal mirror
661
+ val matrix = Matrix()
662
+ matrix.postScale(-1f, 1f, bitmap.width / 2f, bitmap.height / 2f)
663
+ Log.d(TAG, "[ROTATE_MIRROR] Front camera: applied horizontal mirror")
664
+
654
665
  return Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
655
666
  }
656
667
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.5.0",
3
+ "version": "7.7.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",