react-native-rectangle-doc-scanner 7.19.0 → 7.21.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.
@@ -8,6 +8,7 @@ import android.graphics.BitmapFactory
8
8
  import android.graphics.Matrix
9
9
  import android.graphics.SurfaceTexture
10
10
  import android.graphics.Rect
11
+ import android.graphics.RectF
11
12
  import android.graphics.ImageFormat
12
13
  import android.hardware.camera2.CameraCaptureSession
13
14
  import android.hardware.camera2.CameraCharacteristics
@@ -555,31 +556,34 @@ class CameraController(
555
556
  val preview = previewSize ?: return
556
557
  if (viewWidth == 0f || viewHeight == 0f) return
557
558
  val rotation = previewView.display?.rotation ?: Surface.ROTATION_0
558
- val rotationDegrees = displayRotationDegrees()
559
- Log.d(TAG, "[TRANSFORM] rotation=$rotationDegrees view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}")
559
+ Log.d(
560
+ TAG,
561
+ "[TRANSFORM] rotation=${displayRotationDegrees()} view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}"
562
+ )
560
563
 
561
564
  val matrix = Matrix()
562
- val centerX = viewWidth / 2f
563
- val centerY = viewHeight / 2f
564
- val isSwapped = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270
565
- val bufferWidth = if (isSwapped) preview.height.toFloat() else preview.width.toFloat()
566
- val bufferHeight = if (isSwapped) preview.width.toFloat() else preview.height.toFloat()
567
- val scale = max(viewWidth / bufferWidth, viewHeight / bufferHeight)
568
- val scaledWidth = bufferWidth * scale
569
- val scaledHeight = bufferHeight * scale
570
- val dx = (viewWidth - scaledWidth) / 2f
571
- val dy = (viewHeight - scaledHeight) / 2f
572
- matrix.setScale(scale, scale)
573
- matrix.postTranslate(dx, dy)
574
-
575
- if (rotation != Surface.ROTATION_0) {
576
- val rotateDegrees = when (rotation) {
577
- Surface.ROTATION_90 -> -90f
578
- Surface.ROTATION_180 -> 180f
579
- Surface.ROTATION_270 -> 90f
580
- else -> 0f
581
- }
582
- matrix.postRotate(rotateDegrees, centerX, centerY)
565
+ val viewRect = RectF(0f, 0f, viewWidth, viewHeight)
566
+ val bufferRect = RectF(0f, 0f, preview.width.toFloat(), preview.height.toFloat())
567
+ val centerX = viewRect.centerX()
568
+ val centerY = viewRect.centerY()
569
+
570
+ if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
571
+ bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
572
+ matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
573
+ val scale = max(
574
+ viewHeight / preview.height.toFloat(),
575
+ viewWidth / preview.width.toFloat()
576
+ )
577
+ matrix.postScale(scale, scale, centerX, centerY)
578
+ matrix.postRotate(90f * (rotation - 2), centerX, centerY)
579
+ } else if (rotation == Surface.ROTATION_180) {
580
+ matrix.postRotate(180f, centerX, centerY)
581
+ } else {
582
+ val scale = max(viewWidth / preview.width.toFloat(), viewHeight / preview.height.toFloat())
583
+ val scaledWidth = preview.width.toFloat() * scale
584
+ val scaledHeight = preview.height.toFloat() * scale
585
+ matrix.setScale(scale, scale)
586
+ matrix.postTranslate((viewWidth - scaledWidth) / 2f, (viewHeight - scaledHeight) / 2f)
583
587
  }
584
588
 
585
589
  previewView.setTransform(matrix)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.19.0",
3
+ "version": "7.21.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",