react-native-rectangle-doc-scanner 7.15.0 → 7.16.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,7 +20,6 @@ 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
|
|
24
23
|
import android.util.Size
|
|
25
24
|
import android.view.Surface
|
|
26
25
|
import android.view.TextureView
|
|
@@ -82,12 +81,6 @@ class CameraController(
|
|
|
82
81
|
companion object {
|
|
83
82
|
private const val TAG = "CameraController"
|
|
84
83
|
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
|
-
}
|
|
91
84
|
}
|
|
92
85
|
|
|
93
86
|
private data class PendingCapture(
|
|
@@ -492,12 +485,7 @@ class CameraController(
|
|
|
492
485
|
val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
|
|
493
486
|
?: throw IllegalStateException("Failed to decode JPEG")
|
|
494
487
|
|
|
495
|
-
val
|
|
496
|
-
val rotation = if (exifRotation == 0 || exifRotation != computedRotation) {
|
|
497
|
-
computedRotation
|
|
498
|
-
} else {
|
|
499
|
-
exifRotation
|
|
500
|
-
}
|
|
488
|
+
val rotation = if (exifRotation != 0) exifRotation else computeRotationDegrees()
|
|
501
489
|
val rotated = rotateAndMirror(bitmap, rotation, useFrontCamera)
|
|
502
490
|
val photoFile = File(pending.outputDirectory, "doc_scan_${System.currentTimeMillis()}.jpg")
|
|
503
491
|
FileOutputStream(photoFile).use { out ->
|
|
@@ -535,13 +523,13 @@ class CameraController(
|
|
|
535
523
|
}
|
|
536
524
|
|
|
537
525
|
private fun computeRotationDegrees(): Int {
|
|
538
|
-
val displayRotation =
|
|
539
|
-
val
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
526
|
+
val displayRotation = displayRotationDegrees()
|
|
527
|
+
val rotation = if (useFrontCamera) {
|
|
528
|
+
(sensorOrientation + displayRotation) % 360
|
|
529
|
+
} else {
|
|
530
|
+
(sensorOrientation - displayRotation + 360) % 360
|
|
543
531
|
}
|
|
544
|
-
Log.d(TAG, "[ROTATION] sensor=$sensorOrientation display=$
|
|
532
|
+
Log.d(TAG, "[ROTATION] sensor=$sensorOrientation display=$displayRotation front=$useFrontCamera -> rotation=$rotation")
|
|
545
533
|
return rotation
|
|
546
534
|
}
|
|
547
535
|
|
|
@@ -566,23 +554,28 @@ class CameraController(
|
|
|
566
554
|
Log.d(TAG, "[TRANSFORM] rotation=$rotationDegrees view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}")
|
|
567
555
|
|
|
568
556
|
val matrix = Matrix()
|
|
569
|
-
val
|
|
570
|
-
val
|
|
571
|
-
val
|
|
572
|
-
val
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
557
|
+
val centerX = viewWidth / 2f
|
|
558
|
+
val centerY = viewHeight / 2f
|
|
559
|
+
val isSwapped = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270
|
|
560
|
+
val bufferWidth = if (isSwapped) preview.height.toFloat() else preview.width.toFloat()
|
|
561
|
+
val bufferHeight = if (isSwapped) preview.width.toFloat() else preview.height.toFloat()
|
|
562
|
+
val scale = max(viewWidth / bufferWidth, viewHeight / bufferHeight)
|
|
563
|
+
val scaledWidth = bufferWidth * scale
|
|
564
|
+
val scaledHeight = bufferHeight * scale
|
|
565
|
+
val dx = (viewWidth - scaledWidth) / 2f
|
|
566
|
+
val dy = (viewHeight - scaledHeight) / 2f
|
|
567
|
+
|
|
568
|
+
matrix.setScale(scale, scale)
|
|
569
|
+
matrix.postTranslate(dx, dy)
|
|
570
|
+
|
|
571
|
+
if (rotation != Surface.ROTATION_0) {
|
|
572
|
+
val rotateDegrees = when (rotation) {
|
|
573
|
+
Surface.ROTATION_90 -> -90f
|
|
574
|
+
Surface.ROTATION_180 -> 180f
|
|
575
|
+
Surface.ROTATION_270 -> 90f
|
|
576
|
+
else -> 0f
|
|
577
|
+
}
|
|
583
578
|
matrix.postRotate(rotateDegrees, centerX, centerY)
|
|
584
|
-
} else if (rotation == Surface.ROTATION_180) {
|
|
585
|
-
matrix.postRotate(180f, centerX, centerY)
|
|
586
579
|
}
|
|
587
580
|
|
|
588
581
|
previewView.setTransform(matrix)
|