react-native-rectangle-doc-scanner 3.204.0 → 3.205.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.
@@ -65,8 +65,8 @@ class CameraController(
65
65
 
66
66
  companion object {
67
67
  private const val TAG = "CameraController"
68
- private const val MAX_PREVIEW_WIDTH = 2560
69
- private const val MAX_PREVIEW_HEIGHT = 1440
68
+ private const val MAX_ANALYSIS_WIDTH = 1280
69
+ private const val MAX_ANALYSIS_HEIGHT = 720
70
70
  }
71
71
 
72
72
  private data class LastFrame(
@@ -267,8 +267,8 @@ class CameraController(
267
267
  null
268
268
  }
269
269
 
270
- previewSize = chooseSize(previewChoices, MAX_PREVIEW_WIDTH, MAX_PREVIEW_HEIGHT, targetRatio)
271
- analysisSize = chooseSize(analysisChoices, MAX_PREVIEW_WIDTH, MAX_PREVIEW_HEIGHT, targetRatio)
270
+ previewSize = choosePreviewSize(previewChoices, targetRatio)
271
+ analysisSize = chooseAnalysisSize(analysisChoices, targetRatio)
272
272
  Log.d(TAG, "[CAMERA2] Selected sizes - preview: $previewSize, analysis: $analysisSize")
273
273
  }
274
274
 
@@ -386,8 +386,8 @@ class CameraController(
386
386
  null
387
387
  }
388
388
 
389
- val newPreview = chooseSize(previewChoices, MAX_PREVIEW_WIDTH, MAX_PREVIEW_HEIGHT, targetRatio)
390
- val newAnalysis = chooseSize(analysisChoices, MAX_PREVIEW_WIDTH, MAX_PREVIEW_HEIGHT, targetRatio)
389
+ val newPreview = choosePreviewSize(previewChoices, targetRatio)
390
+ val newAnalysis = chooseAnalysisSize(analysisChoices, targetRatio)
391
391
 
392
392
  if (newPreview != null && newPreview != previewSize) {
393
393
  previewSize = newPreview
@@ -578,20 +578,48 @@ class CameraController(
578
578
  }
579
579
  }
580
580
 
581
- private fun chooseSize(
581
+ private fun choosePreviewSize(
582
582
  choices: Array<Size>,
583
- maxWidth: Int,
584
- maxHeight: Int,
585
583
  targetRatio: Float?
586
584
  ): Size? {
587
585
  if (choices.isEmpty()) {
588
586
  return null
589
587
  }
590
- val maxCandidates = choices.filter { it.width <= maxWidth && it.height <= maxHeight }
591
- val candidates = if (maxCandidates.isNotEmpty()) maxCandidates else choices.toList()
588
+ val candidates = choices.toList()
592
589
 
593
590
  if (targetRatio == null) {
594
- return candidates.sortedBy { it.width * it.height }.last()
591
+ return candidates.maxByOrNull { it.width * it.height }
592
+ }
593
+
594
+ val normalizedTarget = targetRatio
595
+ val sorted = candidates.sortedWith(
596
+ compareBy<Size> { size ->
597
+ val ratio = if (normalizedTarget < 1f) {
598
+ size.height.toFloat() / size.width.toFloat()
599
+ } else {
600
+ size.width.toFloat() / size.height.toFloat()
601
+ }
602
+ kotlin.math.abs(ratio - normalizedTarget)
603
+ }.thenByDescending { size ->
604
+ size.width * size.height
605
+ }
606
+ )
607
+ return sorted.first()
608
+ }
609
+
610
+ private fun chooseAnalysisSize(
611
+ choices: Array<Size>,
612
+ targetRatio: Float?
613
+ ): Size? {
614
+ if (choices.isEmpty()) {
615
+ return null
616
+ }
617
+
618
+ val capped = choices.filter { it.width <= MAX_ANALYSIS_WIDTH && it.height <= MAX_ANALYSIS_HEIGHT }
619
+ val candidates = if (capped.isNotEmpty()) capped else choices.toList()
620
+
621
+ if (targetRatio == null) {
622
+ return candidates.maxByOrNull { it.width * it.height }
595
623
  }
596
624
 
597
625
  val normalizedTarget = targetRatio
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "3.204.0",
3
+ "version": "3.205.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",