react-native-rectangle-doc-scanner 7.11.0 → 7.12.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.
@@ -35,7 +35,6 @@ import java.io.ByteArrayInputStream
35
35
  import java.util.concurrent.atomic.AtomicReference
36
36
  import java.util.concurrent.atomic.AtomicBoolean
37
37
  import kotlin.math.abs
38
- import kotlin.math.max
39
38
  import kotlin.math.min
40
39
 
41
40
  class CameraController(
@@ -485,7 +484,8 @@ class CameraController(
485
484
  val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
486
485
  ?: throw IllegalStateException("Failed to decode JPEG")
487
486
 
488
- val rotated = rotateAndMirror(bitmap, exifRotation, useFrontCamera)
487
+ val rotation = if (exifRotation != 0) exifRotation else computeRotationDegrees()
488
+ val rotated = rotateAndMirror(bitmap, rotation, useFrontCamera)
489
489
  val photoFile = File(pending.outputDirectory, "doc_scan_${System.currentTimeMillis()}.jpg")
490
490
  FileOutputStream(photoFile).use { out ->
491
491
  rotated.compress(Bitmap.CompressFormat.JPEG, 95, out)
@@ -523,11 +523,10 @@ class CameraController(
523
523
 
524
524
  private fun computeRotationDegrees(): Int {
525
525
  val displayRotation = displayRotationDegrees()
526
- val baseRotation = (sensorOrientation + displayRotation) % 360
527
526
  val rotation = if (useFrontCamera) {
528
- (360 - baseRotation) % 360
527
+ (sensorOrientation + displayRotation) % 360
529
528
  } else {
530
- baseRotation
529
+ (sensorOrientation - displayRotation + 360) % 360
531
530
  }
532
531
  Log.d(TAG, "[ROTATION] sensor=$sensorOrientation display=$displayRotation front=$useFrontCamera -> rotation=$rotation")
533
532
  return rotation
@@ -561,16 +560,14 @@ class CameraController(
561
560
 
562
561
  if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
563
562
  bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
564
- matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
565
- val scale = max(
566
- viewHeight / preview.height.toFloat(),
567
- viewWidth / preview.width.toFloat()
568
- )
569
- matrix.postScale(scale, scale, centerX, centerY)
563
+ matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.CENTER)
570
564
  val rotateDegrees = if (rotation == Surface.ROTATION_90) -90f else 90f
571
565
  matrix.postRotate(rotateDegrees, centerX, centerY)
572
- } else if (rotation == Surface.ROTATION_180) {
573
- matrix.postRotate(180f, centerX, centerY)
566
+ } else {
567
+ matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.CENTER)
568
+ if (rotation == Surface.ROTATION_180) {
569
+ matrix.postRotate(180f, centerX, centerY)
570
+ }
574
571
  }
575
572
 
576
573
  previewView.setTransform(matrix)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.11.0",
3
+ "version": "7.12.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",