react-native-rectangle-doc-scanner 4.9.0 → 4.11.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.
|
@@ -209,14 +209,35 @@ class CameraController(
|
|
|
209
209
|
?: return
|
|
210
210
|
sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION) ?: 0
|
|
211
211
|
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
// Calculate view aspect ratio considering sensor orientation
|
|
213
|
+
// For portrait mode with 90/270 degree sensor, we need to swap width/height
|
|
214
|
+
val displayRotation = displayRotationDegrees()
|
|
215
|
+
val totalRotation = if (useFrontCamera) {
|
|
216
|
+
(sensorOrientation + displayRotation) % 360
|
|
214
217
|
} else {
|
|
215
|
-
|
|
218
|
+
(sensorOrientation - displayRotation + 360) % 360
|
|
216
219
|
}
|
|
217
220
|
|
|
221
|
+
val viewWidth = previewView.width.takeIf { it > 0 } ?: 1200
|
|
222
|
+
val viewHeight = previewView.height.takeIf { it > 0 } ?: 1928
|
|
223
|
+
|
|
224
|
+
// If total rotation is 90 or 270, the sensor output is rotated, so we need to match against swapped aspect
|
|
225
|
+
val viewAspect = if (totalRotation == 90 || totalRotation == 270) {
|
|
226
|
+
// Sensor outputs landscape (e.g., 1920x1080), but we display portrait
|
|
227
|
+
// So we want to find sensor size with aspect ~= viewHeight/viewWidth
|
|
228
|
+
viewHeight.toDouble() / viewWidth.toDouble()
|
|
229
|
+
} else {
|
|
230
|
+
viewWidth.toDouble() / viewHeight.toDouble()
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
Log.d(TAG, "[CAMERA2] sensorOrientation=$sensorOrientation displayRotation=$displayRotation totalRotation=$totalRotation")
|
|
234
|
+
Log.d(TAG, "[CAMERA2] viewAspect=$viewAspect (view: ${viewWidth}x${viewHeight})")
|
|
235
|
+
|
|
218
236
|
val previewSizes = streamConfigMap.getOutputSizes(SurfaceTexture::class.java)
|
|
237
|
+
Log.d(TAG, "[CAMERA2] Available preview sizes: ${previewSizes?.take(10)?.joinToString { "${it.width}x${it.height}" }}")
|
|
238
|
+
|
|
219
239
|
previewSize = chooseBestSize(previewSizes, viewAspect, null, preferClosestAspect = true)
|
|
240
|
+
Log.d(TAG, "[CAMERA2] Selected preview size: ${previewSize?.width}x${previewSize?.height}")
|
|
220
241
|
|
|
221
242
|
val previewAspect = previewSize?.let { it.width.toDouble() / it.height.toDouble() } ?: viewAspect
|
|
222
243
|
val analysisSizes = streamConfigMap.getOutputSizes(ImageFormat.YUV_420_888)
|
|
@@ -569,12 +590,16 @@ class CameraController(
|
|
|
569
590
|
}
|
|
570
591
|
|
|
571
592
|
if (preferClosestAspect) {
|
|
572
|
-
|
|
573
|
-
val minAcceptableArea =
|
|
574
|
-
val
|
|
575
|
-
val pool = if (
|
|
593
|
+
// Prefer high-resolution sizes: minimum 1080p (1920x1080 or 1080x1920)
|
|
594
|
+
val minAcceptableArea = 1920 * 1080
|
|
595
|
+
val highResSizes = capped.filter { it.width * it.height >= minAcceptableArea }
|
|
596
|
+
val pool = if (highResSizes.isNotEmpty()) highResSizes else capped
|
|
597
|
+
|
|
576
598
|
val bestDiff = pool.minOf { aspectDiff(it) }
|
|
577
|
-
|
|
599
|
+
// Allow slightly more tolerance for aspect ratio (0.15 instead of 0.05) to find better matches
|
|
600
|
+
val close = pool.filter { aspectDiff(it) <= bestDiff + 0.15 }
|
|
601
|
+
|
|
602
|
+
// Return the highest resolution among good aspect ratio matches
|
|
578
603
|
return close.maxByOrNull { it.width * it.height } ?: pool.maxByOrNull { it.width * it.height }
|
|
579
604
|
}
|
|
580
605
|
|