react-native-rectangle-doc-scanner 7.14.0 → 7.15.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.
@@ -20,6 +20,7 @@ import android.media.ImageReader
20
20
  import android.os.Handler
21
21
  import android.os.HandlerThread
22
22
  import android.util.Log
23
+ import android.util.SparseIntArray
23
24
  import android.util.Size
24
25
  import android.view.Surface
25
26
  import android.view.TextureView
@@ -35,6 +36,7 @@ import java.io.ByteArrayInputStream
35
36
  import java.util.concurrent.atomic.AtomicReference
36
37
  import java.util.concurrent.atomic.AtomicBoolean
37
38
  import kotlin.math.abs
39
+ import kotlin.math.max
38
40
  import kotlin.math.min
39
41
 
40
42
  class CameraController(
@@ -80,6 +82,12 @@ class CameraController(
80
82
  companion object {
81
83
  private const val TAG = "CameraController"
82
84
  private const val ANALYSIS_ASPECT_TOLERANCE = 0.15
85
+ private val ORIENTATIONS = SparseIntArray().apply {
86
+ append(Surface.ROTATION_0, 90)
87
+ append(Surface.ROTATION_90, 0)
88
+ append(Surface.ROTATION_180, 270)
89
+ append(Surface.ROTATION_270, 180)
90
+ }
83
91
  }
84
92
 
85
93
  private data class PendingCapture(
@@ -527,13 +535,13 @@ class CameraController(
527
535
  }
528
536
 
529
537
  private fun computeRotationDegrees(): Int {
530
- val displayRotation = displayRotationDegrees()
531
- val rotation = if (useFrontCamera) {
532
- (sensorOrientation + displayRotation) % 360
533
- } else {
534
- (sensorOrientation - displayRotation + 360) % 360
538
+ val displayRotation = previewView.display?.rotation ?: Surface.ROTATION_0
539
+ val deviceRotation = ORIENTATIONS.get(displayRotation, 0)
540
+ var rotation = (sensorOrientation + deviceRotation + 360) % 360
541
+ if (useFrontCamera) {
542
+ rotation = (360 - rotation) % 360
535
543
  }
536
- Log.d(TAG, "[ROTATION] sensor=$sensorOrientation display=$displayRotation front=$useFrontCamera -> rotation=$rotation")
544
+ Log.d(TAG, "[ROTATION] sensor=$sensorOrientation display=${displayRotationDegrees()} front=$useFrontCamera -> rotation=$rotation")
537
545
  return rotation
538
546
  }
539
547
 
@@ -559,24 +567,22 @@ class CameraController(
559
567
 
560
568
  val matrix = Matrix()
561
569
  val viewRect = RectF(0f, 0f, viewWidth, viewHeight)
562
- val bufferRect = if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
563
- RectF(0f, 0f, preview.height.toFloat(), preview.width.toFloat())
564
- } else {
565
- RectF(0f, 0f, preview.width.toFloat(), preview.height.toFloat())
566
- }
570
+ val bufferRect = RectF(0f, 0f, preview.height.toFloat(), preview.width.toFloat())
567
571
  val centerX = viewRect.centerX()
568
572
  val centerY = viewRect.centerY()
569
573
 
570
- bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
571
- matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.FILL)
572
- if (rotation != Surface.ROTATION_0) {
573
- val rotateDegrees = when (rotation) {
574
- Surface.ROTATION_90 -> -90f
575
- Surface.ROTATION_180 -> 180f
576
- Surface.ROTATION_270 -> 90f
577
- else -> 0f
578
- }
574
+ if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
575
+ bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
576
+ matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
577
+ val scale = max(
578
+ viewHeight / preview.height.toFloat(),
579
+ viewWidth / preview.width.toFloat()
580
+ )
581
+ matrix.postScale(scale, scale, centerX, centerY)
582
+ val rotateDegrees = 90f * (rotation - 2)
579
583
  matrix.postRotate(rotateDegrees, centerX, centerY)
584
+ } else if (rotation == Surface.ROTATION_180) {
585
+ matrix.postRotate(180f, centerX, centerY)
580
586
  }
581
587
 
582
588
  previewView.setTransform(matrix)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.14.0",
3
+ "version": "7.15.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",