react-native-rectangle-doc-scanner 7.14.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.
|
@@ -35,6 +35,7 @@ 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
|
|
38
39
|
import kotlin.math.min
|
|
39
40
|
|
|
40
41
|
class CameraController(
|
|
@@ -484,12 +485,7 @@ class CameraController(
|
|
|
484
485
|
val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
|
|
485
486
|
?: throw IllegalStateException("Failed to decode JPEG")
|
|
486
487
|
|
|
487
|
-
val
|
|
488
|
-
val rotation = if (exifRotation == 0 || exifRotation != computedRotation) {
|
|
489
|
-
computedRotation
|
|
490
|
-
} else {
|
|
491
|
-
exifRotation
|
|
492
|
-
}
|
|
488
|
+
val rotation = if (exifRotation != 0) exifRotation else computeRotationDegrees()
|
|
493
489
|
val rotated = rotateAndMirror(bitmap, rotation, useFrontCamera)
|
|
494
490
|
val photoFile = File(pending.outputDirectory, "doc_scan_${System.currentTimeMillis()}.jpg")
|
|
495
491
|
FileOutputStream(photoFile).use { out ->
|
|
@@ -558,17 +554,20 @@ class CameraController(
|
|
|
558
554
|
Log.d(TAG, "[TRANSFORM] rotation=$rotationDegrees view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}")
|
|
559
555
|
|
|
560
556
|
val matrix = Matrix()
|
|
561
|
-
val
|
|
562
|
-
val
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
val
|
|
568
|
-
val
|
|
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)
|
|
569
570
|
|
|
570
|
-
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
|
|
571
|
-
matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.FILL)
|
|
572
571
|
if (rotation != Surface.ROTATION_0) {
|
|
573
572
|
val rotateDegrees = when (rotation) {
|
|
574
573
|
Surface.ROTATION_90 -> -90f
|