react-native-rectangle-doc-scanner 10.38.0 → 10.40.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.
|
@@ -118,11 +118,11 @@ class CameraController(
|
|
|
118
118
|
Log.d(TAG, "[CAMERAX] TextureView visibility: ${textureView.visibility}")
|
|
119
119
|
Log.d(TAG, "[CAMERAX] TextureView isAvailable: ${textureView.isAvailable}")
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
Log.d(TAG, "[CAMERAX] Setting target rotation to ROTATION_0 (portrait-only app)")
|
|
121
|
+
val targetRotation = textureView.display?.rotation ?: android.view.Surface.ROTATION_0
|
|
122
|
+
Log.d(TAG, "[CAMERAX] Setting target rotation to $targetRotation")
|
|
124
123
|
|
|
125
124
|
preview = Preview.Builder()
|
|
125
|
+
.setTargetAspectRatio(AspectRatio.RATIO_4_3)
|
|
126
126
|
.setTargetRotation(targetRotation) // Force portrait
|
|
127
127
|
.build()
|
|
128
128
|
.also { previewUseCase ->
|
|
@@ -185,7 +185,7 @@ class CameraController(
|
|
|
185
185
|
// ImageAnalysis UseCase for document detection
|
|
186
186
|
imageAnalyzer = ImageAnalysis.Builder()
|
|
187
187
|
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
|
|
188
|
-
.
|
|
188
|
+
.setTargetAspectRatio(AspectRatio.RATIO_4_3)
|
|
189
189
|
.setTargetRotation(targetRotation) // Match preview rotation
|
|
190
190
|
.build()
|
|
191
191
|
.also {
|
|
@@ -201,6 +201,7 @@ class CameraController(
|
|
|
201
201
|
// ImageCapture UseCase
|
|
202
202
|
imageCapture = ImageCapture.Builder()
|
|
203
203
|
.setCaptureMode(ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY)
|
|
204
|
+
.setTargetAspectRatio(AspectRatio.RATIO_4_3)
|
|
204
205
|
.setTargetRotation(targetRotation) // Match preview rotation
|
|
205
206
|
.build()
|
|
206
207
|
|
|
@@ -494,8 +495,6 @@ class CameraController(
|
|
|
494
495
|
return
|
|
495
496
|
}
|
|
496
497
|
|
|
497
|
-
// Get sensor orientation to determine correct rotation
|
|
498
|
-
val sensorOrientation = getCameraSensorOrientation()
|
|
499
498
|
val displayRotationDegrees = when (textureView.display?.rotation ?: Surface.ROTATION_0) {
|
|
500
499
|
Surface.ROTATION_0 -> 0
|
|
501
500
|
Surface.ROTATION_90 -> 90
|
|
@@ -507,36 +506,16 @@ class CameraController(
|
|
|
507
506
|
Log.d(
|
|
508
507
|
TAG,
|
|
509
508
|
"[TRANSFORM] View: ${viewWidth}x${viewHeight}, Buffer: ${bufferWidth}x${bufferHeight}, " +
|
|
510
|
-
"
|
|
509
|
+
"Display: ${displayRotationDegrees}°"
|
|
511
510
|
)
|
|
512
511
|
|
|
513
512
|
val matrix = android.graphics.Matrix()
|
|
514
513
|
val centerX = viewWidth / 2f
|
|
515
514
|
val centerY = viewHeight / 2f
|
|
516
515
|
|
|
517
|
-
//
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
val tabletUpsideDownFix = if (sensorOrientation == 0 && displayRotationDegrees == 90) 180 else 0
|
|
521
|
-
val rotationDegrees = ((displayRotationDegrees + tabletUpsideDownFix) % 360).toFloat()
|
|
522
|
-
|
|
523
|
-
Log.d(TAG, "[TRANSFORM] Applying rotation: ${rotationDegrees}°")
|
|
524
|
-
|
|
525
|
-
if (rotationDegrees != 0f) {
|
|
526
|
-
matrix.postRotate(rotationDegrees, centerX, centerY)
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
// After rotation, determine effective buffer size
|
|
530
|
-
val rotatedBufferWidth = if (rotationDegrees == 90f || rotationDegrees == 270f) {
|
|
531
|
-
bufferHeight
|
|
532
|
-
} else {
|
|
533
|
-
bufferWidth
|
|
534
|
-
}
|
|
535
|
-
val rotatedBufferHeight = if (rotationDegrees == 90f || rotationDegrees == 270f) {
|
|
536
|
-
bufferWidth
|
|
537
|
-
} else {
|
|
538
|
-
bufferHeight
|
|
539
|
-
}
|
|
516
|
+
// Preview buffers are already rotated to match targetRotation.
|
|
517
|
+
val rotatedBufferWidth = bufferWidth
|
|
518
|
+
val rotatedBufferHeight = bufferHeight
|
|
540
519
|
|
|
541
520
|
// Scale to fill the view while maintaining aspect ratio (center-crop).
|
|
542
521
|
val scaleX = viewWidth.toFloat() / rotatedBufferWidth.toFloat()
|
package/dist/DocScanner.js
CHANGED
|
@@ -121,24 +121,14 @@ const mirrorRectangleHorizontally = (rectangle, imageWidth) => ({
|
|
|
121
121
|
const mapRectangleToView = (rectangle, imageWidth, imageHeight, viewWidth, viewHeight, density) => {
|
|
122
122
|
const viewWidthPx = viewWidth * density;
|
|
123
123
|
const viewHeightPx = viewHeight * density;
|
|
124
|
-
const scale =
|
|
125
|
-
? Math.max(viewWidthPx / imageWidth, viewHeightPx / imageHeight)
|
|
126
|
-
: Math.min(viewWidthPx / imageWidth, viewHeightPx / imageHeight);
|
|
124
|
+
const scale = Math.max(viewWidthPx / imageWidth, viewHeightPx / imageHeight);
|
|
127
125
|
const scaledImageWidth = imageWidth * scale;
|
|
128
126
|
const scaledImageHeight = imageHeight * scale;
|
|
129
|
-
const offsetX =
|
|
130
|
-
|
|
131
|
-
: (viewWidthPx - scaledImageWidth) / 2;
|
|
132
|
-
const offsetY = react_native_1.Platform.OS === 'ios'
|
|
133
|
-
? (scaledImageHeight - viewHeightPx) / 2
|
|
134
|
-
: (viewHeightPx - scaledImageHeight) / 2;
|
|
127
|
+
const offsetX = (scaledImageWidth - viewWidthPx) / 2;
|
|
128
|
+
const offsetY = (scaledImageHeight - viewHeightPx) / 2;
|
|
135
129
|
const mapPoint = (point) => ({
|
|
136
|
-
x:
|
|
137
|
-
|
|
138
|
-
: (point.x * scale + offsetX) / density,
|
|
139
|
-
y: react_native_1.Platform.OS === 'ios'
|
|
140
|
-
? (point.y * scale - offsetY) / density
|
|
141
|
-
: (point.y * scale + offsetY) / density,
|
|
130
|
+
x: (point.x * scale - offsetX) / density,
|
|
131
|
+
y: (point.y * scale - offsetY) / density,
|
|
142
132
|
});
|
|
143
133
|
return {
|
|
144
134
|
topLeft: mapPoint(rectangle.topLeft),
|
package/package.json
CHANGED
package/src/DocScanner.tsx
CHANGED
|
@@ -188,30 +188,15 @@ const mapRectangleToView = (
|
|
|
188
188
|
): Rectangle => {
|
|
189
189
|
const viewWidthPx = viewWidth * density;
|
|
190
190
|
const viewHeightPx = viewHeight * density;
|
|
191
|
-
const scale =
|
|
192
|
-
Platform.OS === 'ios'
|
|
193
|
-
? Math.max(viewWidthPx / imageWidth, viewHeightPx / imageHeight)
|
|
194
|
-
: Math.min(viewWidthPx / imageWidth, viewHeightPx / imageHeight);
|
|
191
|
+
const scale = Math.max(viewWidthPx / imageWidth, viewHeightPx / imageHeight);
|
|
195
192
|
const scaledImageWidth = imageWidth * scale;
|
|
196
193
|
const scaledImageHeight = imageHeight * scale;
|
|
197
|
-
const offsetX =
|
|
198
|
-
|
|
199
|
-
? (scaledImageWidth - viewWidthPx) / 2
|
|
200
|
-
: (viewWidthPx - scaledImageWidth) / 2;
|
|
201
|
-
const offsetY =
|
|
202
|
-
Platform.OS === 'ios'
|
|
203
|
-
? (scaledImageHeight - viewHeightPx) / 2
|
|
204
|
-
: (viewHeightPx - scaledImageHeight) / 2;
|
|
194
|
+
const offsetX = (scaledImageWidth - viewWidthPx) / 2;
|
|
195
|
+
const offsetY = (scaledImageHeight - viewHeightPx) / 2;
|
|
205
196
|
|
|
206
197
|
const mapPoint = (point: Point): Point => ({
|
|
207
|
-
x:
|
|
208
|
-
|
|
209
|
-
? (point.x * scale - offsetX) / density
|
|
210
|
-
: (point.x * scale + offsetX) / density,
|
|
211
|
-
y:
|
|
212
|
-
Platform.OS === 'ios'
|
|
213
|
-
? (point.y * scale - offsetY) / density
|
|
214
|
-
: (point.y * scale + offsetY) / density,
|
|
198
|
+
x: (point.x * scale - offsetX) / density,
|
|
199
|
+
y: (point.y * scale - offsetY) / density,
|
|
215
200
|
});
|
|
216
201
|
|
|
217
202
|
return {
|