react-native-rectangle-doc-scanner 7.32.0 → 7.34.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.
@@ -249,7 +249,8 @@ class CameraController(
249
249
  // Prefer 4:3 to match iOS FOV on phones; use view aspect on tablets to reduce crop.
250
250
  val isTablet = context.resources.configuration.smallestScreenWidthDp >= 600
251
251
  val targetPreviewAspect = if (isTablet) viewAspect else 4.0 / 3.0
252
- previewSize = chooseBestSize(previewSizes, targetPreviewAspect, null, preferClosestAspect = true)
252
+ val minPreviewArea = if (isTablet) 1280 * 720 else 960 * 720
253
+ previewSize = chooseBestSize(previewSizes, targetPreviewAspect, null, minPreviewArea, preferClosestAspect = true)
253
254
  ?: chooseBestSize(previewSizes, viewAspect, null, preferClosestAspect = true)
254
255
  ?: previewSizes?.maxByOrNull { it.width * it.height }
255
256
  Log.d(TAG, "[CAMERA2] Selected preview size: ${previewSize?.width}x${previewSize?.height}")
@@ -558,7 +559,7 @@ class CameraController(
558
559
  val viewHeight = previewView.height.toFloat()
559
560
  val preview = previewSize ?: return
560
561
  if (viewWidth == 0f || viewHeight == 0f) return
561
- val rotationDegrees = computeRotationDegrees()
562
+ val rotation = previewView.display?.rotation ?: Surface.ROTATION_0
562
563
  Log.d(
563
564
  TAG,
564
565
  "[TRANSFORM] rotation=${displayRotationDegrees()} view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}"
@@ -567,15 +568,20 @@ class CameraController(
567
568
  val matrix = Matrix()
568
569
  val bufferWidth = preview.width.toFloat()
569
570
  val bufferHeight = preview.height.toFloat()
570
- val rotateDegrees = rotationDegrees.toFloat()
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
 
572
578
  // Move buffer center to origin, rotate, scale uniformly to fill view, then move to view center.
573
579
  matrix.postTranslate(-bufferWidth / 2f, -bufferHeight / 2f)
574
580
  if (rotateDegrees != 0f) {
575
581
  matrix.postRotate(rotateDegrees)
576
582
  }
577
- val rotatedWidth = if (rotationDegrees == 90 || rotationDegrees == 270) bufferHeight else bufferWidth
578
- val rotatedHeight = if (rotationDegrees == 90 || rotationDegrees == 270) bufferWidth else bufferHeight
583
+ val rotatedWidth = if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) bufferHeight else bufferWidth
584
+ val rotatedHeight = if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) bufferWidth else bufferHeight
579
585
  val scale = max(viewWidth / rotatedWidth, viewHeight / rotatedHeight)
580
586
  matrix.postScale(scale, scale)
581
587
  matrix.postTranslate(viewWidth / 2f, viewHeight / 2f)
@@ -588,6 +594,7 @@ class CameraController(
588
594
  sizes: Array<Size>?,
589
595
  targetAspect: Double,
590
596
  maxArea: Int?,
597
+ minArea: Int? = null,
591
598
  preferClosestAspect: Boolean = false
592
599
  ): Size? {
593
600
  if (sizes == null || sizes.isEmpty()) return null
@@ -603,6 +610,14 @@ class CameraController(
603
610
  return sorted.first()
604
611
  }
605
612
 
613
+ val minCapped = if (minArea != null) {
614
+ capped.filter { it.width * it.height >= minArea }
615
+ } else {
616
+ capped
617
+ }
618
+
619
+ val poolForSelection = if (minCapped.isNotEmpty()) minCapped else capped
620
+
606
621
  fun aspectDiff(size: Size): Double {
607
622
  val w = size.width.toDouble()
608
623
  val h = size.height.toDouble()
@@ -613,21 +628,21 @@ class CameraController(
613
628
 
614
629
  if (preferClosestAspect) {
615
630
  // Prefer aspect ratio match first, then pick the highest resolution among matches.
616
- capped.forEach { size ->
631
+ poolForSelection.forEach { size ->
617
632
  val diff = aspectDiff(size)
618
633
  Log.d(TAG, "[SIZE_SELECTION] ${size.width}x${size.height} aspect=${size.width.toDouble()/size.height} diff=$diff")
619
634
  }
620
635
 
621
- val bestDiff = capped.minOf { aspectDiff(it) }
622
- val close = capped.filter { aspectDiff(it) <= bestDiff + 0.001 }
623
- val selected = close.maxByOrNull { it.width * it.height } ?: capped.maxByOrNull { it.width * it.height }
636
+ val bestDiff = poolForSelection.minOf { aspectDiff(it) }
637
+ val close = poolForSelection.filter { aspectDiff(it) <= bestDiff + 0.001 }
638
+ val selected = close.maxByOrNull { it.width * it.height } ?: poolForSelection.maxByOrNull { it.width * it.height }
624
639
  Log.d(TAG, "[SIZE_SELECTION] Best aspect diff: $bestDiff, candidates: ${close.size}, selected: ${selected?.width}x${selected?.height}")
625
640
  return selected
626
641
  }
627
642
 
628
- val matching = capped.filter { aspectDiff(it) <= ANALYSIS_ASPECT_TOLERANCE }
643
+ val matching = poolForSelection.filter { aspectDiff(it) <= ANALYSIS_ASPECT_TOLERANCE }
629
644
 
630
- return matching.firstOrNull() ?: capped.first()
645
+ return matching.firstOrNull() ?: poolForSelection.first()
631
646
  }
632
647
 
633
648
  private fun rotateAndMirror(bitmap: Bitmap, rotationDegrees: Int, mirror: Boolean): Bitmap {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "7.32.0",
3
+ "version": "7.34.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",