react-native-rectangle-doc-scanner 7.11.0 → 7.13.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
|
|
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
|
-
(
|
|
527
|
+
(sensorOrientation + displayRotation) % 360
|
|
529
528
|
} else {
|
|
530
|
-
|
|
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
|
|
@@ -554,23 +553,28 @@ class CameraController(
|
|
|
554
553
|
Log.d(TAG, "[TRANSFORM] rotation=$rotationDegrees view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}")
|
|
555
554
|
|
|
556
555
|
val matrix = Matrix()
|
|
557
|
-
val
|
|
558
|
-
val
|
|
559
|
-
val
|
|
560
|
-
val
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
556
|
+
val centerX = viewWidth / 2f
|
|
557
|
+
val centerY = viewHeight / 2f
|
|
558
|
+
val isSwapped = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270
|
|
559
|
+
val bufferWidth = if (isSwapped) preview.height.toFloat() else preview.width.toFloat()
|
|
560
|
+
val bufferHeight = if (isSwapped) preview.width.toFloat() else preview.height.toFloat()
|
|
561
|
+
val scale = maxOf(viewWidth / bufferWidth, viewHeight / bufferHeight)
|
|
562
|
+
val scaledWidth = bufferWidth * scale
|
|
563
|
+
val scaledHeight = bufferHeight * scale
|
|
564
|
+
val dx = (viewWidth - scaledWidth) / 2f
|
|
565
|
+
val dy = (viewHeight - scaledHeight) / 2f
|
|
566
|
+
|
|
567
|
+
matrix.setScale(scale, scale)
|
|
568
|
+
matrix.postTranslate(dx, dy)
|
|
569
|
+
|
|
570
|
+
if (rotation != Surface.ROTATION_0) {
|
|
571
|
+
val rotateDegrees = when (rotation) {
|
|
572
|
+
Surface.ROTATION_90 -> -90f
|
|
573
|
+
Surface.ROTATION_180 -> 180f
|
|
574
|
+
Surface.ROTATION_270 -> 90f
|
|
575
|
+
else -> 0f
|
|
576
|
+
}
|
|
571
577
|
matrix.postRotate(rotateDegrees, centerX, centerY)
|
|
572
|
-
} else if (rotation == Surface.ROTATION_180) {
|
|
573
|
-
matrix.postRotate(180f, centerX, centerY)
|
|
574
578
|
}
|
|
575
579
|
|
|
576
580
|
previewView.setTransform(matrix)
|