react-native-rectangle-doc-scanner 3.197.0 → 3.199.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.
|
@@ -244,8 +244,16 @@ class CameraController(
|
|
|
244
244
|
val previewChoices = streamConfig?.getOutputSizes(SurfaceTexture::class.java) ?: emptyArray()
|
|
245
245
|
val analysisChoices = streamConfig?.getOutputSizes(ImageFormat.YUV_420_888) ?: emptyArray()
|
|
246
246
|
|
|
247
|
-
|
|
248
|
-
|
|
247
|
+
val viewWidth = if (previewView.width > 0) previewView.width else context.resources.displayMetrics.widthPixels
|
|
248
|
+
val viewHeight = if (previewView.height > 0) previewView.height else context.resources.displayMetrics.heightPixels
|
|
249
|
+
val targetRatio = if (viewWidth > 0 && viewHeight > 0) {
|
|
250
|
+
viewWidth.toFloat() / viewHeight.toFloat()
|
|
251
|
+
} else {
|
|
252
|
+
null
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
previewSize = chooseSize(previewChoices, MAX_PREVIEW_WIDTH, MAX_PREVIEW_HEIGHT, targetRatio)
|
|
256
|
+
analysisSize = chooseSize(analysisChoices, MAX_PREVIEW_WIDTH, MAX_PREVIEW_HEIGHT, targetRatio)
|
|
249
257
|
Log.d(TAG, "[CAMERA2] Selected sizes - preview: $previewSize, analysis: $analysisSize")
|
|
250
258
|
}
|
|
251
259
|
|
|
@@ -369,14 +377,8 @@ class CameraController(
|
|
|
369
377
|
val centerY = viewRect.centerY()
|
|
370
378
|
|
|
371
379
|
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
val scale = if (rotationDegrees == 90 || rotationDegrees == 270) {
|
|
375
|
-
maxOf(viewHeight.toFloat() / previewSize.height, viewWidth.toFloat() / previewSize.width)
|
|
376
|
-
} else {
|
|
377
|
-
maxOf(viewWidth.toFloat() / previewSize.width, viewHeight.toFloat() / previewSize.height)
|
|
378
|
-
}
|
|
379
|
-
matrix.postScale(scale, scale, centerX, centerY)
|
|
380
|
+
// Fit entire buffer into view (no crop).
|
|
381
|
+
matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.CENTER)
|
|
380
382
|
|
|
381
383
|
when (rotationDegrees) {
|
|
382
384
|
90 -> matrix.postRotate(90f, centerX, centerY)
|
|
@@ -501,13 +503,29 @@ class CameraController(
|
|
|
501
503
|
}
|
|
502
504
|
}
|
|
503
505
|
|
|
504
|
-
private fun chooseSize(
|
|
506
|
+
private fun chooseSize(
|
|
507
|
+
choices: Array<Size>,
|
|
508
|
+
maxWidth: Int,
|
|
509
|
+
maxHeight: Int,
|
|
510
|
+
targetRatio: Float?
|
|
511
|
+
): Size? {
|
|
505
512
|
if (choices.isEmpty()) {
|
|
506
513
|
return null
|
|
507
514
|
}
|
|
508
|
-
val
|
|
509
|
-
val candidates = if (
|
|
510
|
-
|
|
515
|
+
val maxCandidates = choices.filter { it.width <= maxWidth && it.height <= maxHeight }
|
|
516
|
+
val candidates = if (maxCandidates.isNotEmpty()) maxCandidates else choices.toList()
|
|
517
|
+
|
|
518
|
+
val ratioFiltered = if (targetRatio != null) {
|
|
519
|
+
candidates.filter { size ->
|
|
520
|
+
val ratio = size.width.toFloat() / size.height.toFloat()
|
|
521
|
+
kotlin.math.abs(ratio - targetRatio) <= 0.05f
|
|
522
|
+
}
|
|
523
|
+
} else {
|
|
524
|
+
emptyList()
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
val pickFrom = if (ratioFiltered.isNotEmpty()) ratioFiltered else candidates
|
|
528
|
+
return pickFrom.sortedBy { it.width * it.height }.last()
|
|
511
529
|
}
|
|
512
530
|
|
|
513
531
|
private fun startBackgroundThread() {
|
package/package.json
CHANGED