react-native-rectangle-doc-scanner 3.198.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,8 +377,8 @@ class CameraController(
|
|
|
369
377
|
val centerY = viewRect.centerY()
|
|
370
378
|
|
|
371
379
|
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
|
|
372
|
-
//
|
|
373
|
-
matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.
|
|
380
|
+
// Fit entire buffer into view (no crop).
|
|
381
|
+
matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.CENTER)
|
|
374
382
|
|
|
375
383
|
when (rotationDegrees) {
|
|
376
384
|
90 -> matrix.postRotate(90f, centerX, centerY)
|
|
@@ -495,13 +503,29 @@ class CameraController(
|
|
|
495
503
|
}
|
|
496
504
|
}
|
|
497
505
|
|
|
498
|
-
private fun chooseSize(
|
|
506
|
+
private fun chooseSize(
|
|
507
|
+
choices: Array<Size>,
|
|
508
|
+
maxWidth: Int,
|
|
509
|
+
maxHeight: Int,
|
|
510
|
+
targetRatio: Float?
|
|
511
|
+
): Size? {
|
|
499
512
|
if (choices.isEmpty()) {
|
|
500
513
|
return null
|
|
501
514
|
}
|
|
502
|
-
val
|
|
503
|
-
val candidates = if (
|
|
504
|
-
|
|
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()
|
|
505
529
|
}
|
|
506
530
|
|
|
507
531
|
private fun startBackgroundThread() {
|
package/package.json
CHANGED