react-native-rectangle-doc-scanner 7.53.0 → 7.54.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.
@@ -330,6 +330,13 @@ class CameraController(
330
330
  captureSize = chooseBestSize(captureSizes, previewAspect, null, preferClosestAspect = true)
331
331
  ?: captureSizes?.maxByOrNull { it.width * it.height }
332
332
 
333
+ val previewDiff = previewSize?.let { abs(it.width.toDouble() / it.height.toDouble() - targetPreviewAspect) }
334
+ Log.d(
335
+ TAG,
336
+ "[SIZE_SELECTION] targetAspect=$targetPreviewAspect viewAspect=$viewAspect " +
337
+ "previewAspect=$previewAspect diff=$previewDiff selected=${previewSize?.width}x${previewSize?.height}"
338
+ )
339
+
333
340
  setupImageReaders()
334
341
  Log.d(
335
342
  TAG,
@@ -429,6 +436,7 @@ class CameraController(
429
436
  val preview = previewSize ?: return
430
437
 
431
438
  surfaceTexture.setDefaultBufferSize(preview.width, preview.height)
439
+ Log.d(TAG, "[CAMERA2] SurfaceTexture defaultBufferSize=${preview.width}x${preview.height}")
432
440
  val previewSurface = Surface(surfaceTexture)
433
441
 
434
442
  val targets = mutableListOf(previewSurface)
@@ -638,29 +646,36 @@ class CameraController(
638
646
  val centerX = viewRect.centerX()
639
647
  val centerY = viewRect.centerY()
640
648
 
641
- val bufferWidth = preview.width.toFloat()
642
- val bufferHeight = preview.height.toFloat()
649
+ val isSwapped = rotationDegrees == 90 || rotationDegrees == 270
650
+ val bufferWidth = if (isSwapped) preview.height.toFloat() else preview.width.toFloat()
651
+ val bufferHeight = if (isSwapped) preview.width.toFloat() else preview.height.toFloat()
643
652
  val bufferRect = RectF(0f, 0f, bufferWidth, bufferHeight)
644
- val rotatedRect = RectF(bufferRect)
653
+ bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
645
654
 
655
+ matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
656
+ val scale = max(viewWidth / bufferWidth, viewHeight / bufferHeight)
657
+ matrix.postScale(scale, scale, centerX, centerY)
646
658
  if (rotationDegrees != 0) {
647
- matrix.postRotate(rotationDegrees.toFloat(), bufferRect.centerX(), bufferRect.centerY())
648
- matrix.mapRect(rotatedRect, bufferRect)
659
+ matrix.postRotate(rotationDegrees.toFloat(), centerX, centerY)
649
660
  }
650
661
 
651
- val scale = max(viewWidth / rotatedRect.width(), viewHeight / rotatedRect.height())
652
- matrix.postScale(scale, scale, rotatedRect.centerX(), rotatedRect.centerY())
653
- matrix.postTranslate(centerX - rotatedRect.centerX(), centerY - rotatedRect.centerY())
654
-
655
662
  previewView.setTransform(matrix)
656
663
  latestTransform = Matrix(matrix)
657
664
  latestBufferWidth = preview.width
658
665
  latestBufferHeight = preview.height
666
+
667
+ val pts = floatArrayOf(
668
+ 0f, 0f,
669
+ bufferWidth, 0f,
670
+ 0f, bufferHeight,
671
+ bufferWidth, bufferHeight
672
+ )
673
+ matrix.mapPoints(pts)
659
674
  Log.d(
660
675
  TAG,
661
676
  "[TRANSFORM] viewClass=${previewView.javaClass.name} isTextureView=${previewView is TextureView} " +
662
- "buffer=${preview.width}x${preview.height} rotated=${rotatedRect.width()}x${rotatedRect.height()} " +
663
- "scale=$scale center=${centerX}x${centerY} matrix=$matrix"
677
+ "buffer=${bufferWidth}x${bufferHeight} scale=$scale center=${centerX}x${centerY} matrix=$matrix " +
678
+ "pts=[${pts[0]},${pts[1]} ${pts[2]},${pts[3]} ${pts[4]},${pts[5]} ${pts[6]},${pts[7]}]"
664
679
  )
665
680
  Log.d(TAG, "[TRANSFORM] Matrix applied successfully")
666
681
  }
@@ -696,9 +711,7 @@ class CameraController(
696
711
  fun aspectDiff(size: Size): Double {
697
712
  val w = size.width.toDouble()
698
713
  val h = size.height.toDouble()
699
- val direct = abs(w / h - targetAspect)
700
- val inverted = abs(h / w - targetAspect)
701
- return min(direct, inverted)
714
+ return abs(w / h - targetAspect)
702
715
  }
703
716
 
704
717
  if (preferClosestAspect) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.53.0",
3
+ "version": "7.54.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",