react-native-rectangle-doc-scanner 10.35.0 → 10.37.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.
@@ -457,69 +457,36 @@ class CameraController(
457
457
  else -> 0
458
458
  }
459
459
 
460
- // The coordinates coming from ImageAnalysis are in sensor's native orientation.
461
- // For a 90° sensor (phones in portrait), the camera buffer is landscape but coordinates
462
- // are in sensor space. We need to rotate coordinates to match the display orientation.
460
+ // For sensor 90° (phones): coordinates are in sensor space, need 90° rotation
461
+ // For sensor 0° (tablets): coordinates are already correct orientation
463
462
 
464
- // The TextureView rotation for display
465
- val tabletUpsideDownFix = if (sensorOrientation == 0 && displayRotationDegrees == 90) 180 else 0
466
- val textureViewRotation = ((displayRotationDegrees + tabletUpsideDownFix) % 360).toFloat()
467
-
468
- // For coordinate mapping: we need to account for BOTH sensor orientation AND display rotation
469
- // - Sensor 90° + Display 0°: Coordinates are in landscape sensor space, need 90° rotation to portrait
470
- // - Sensor 0° + Display 90°: Coordinates are in portrait, need 270° rotation (display + fix)
471
- val rotationDegrees = if (sensorOrientation == 90 && displayRotationDegrees == 0) {
472
- 90f // Rotate coordinates 90° to match portrait display
473
- } else {
474
- textureViewRotation // Use TextureView rotation
475
- }
476
-
477
- Log.d(TAG, "[MAPPING] Image: ${imageWidth}x${imageHeight}, Sensor: ${sensorOrientation}°, " +
478
- "Display: ${displayRotationDegrees}°, TextureView rotation: ${textureViewRotation}°, " +
479
- "Coordinate rotation: ${rotationDegrees}°")
480
-
481
- // Apply rotation to coordinates to match display orientation
463
+ // First rotate coordinates if needed (sensor 90° means image is rotated 90° CW in sensor space)
482
464
  fun rotatePoint(point: org.opencv.core.Point): org.opencv.core.Point {
483
- return when (rotationDegrees.toInt()) {
484
- 90 -> org.opencv.core.Point(
485
- imageHeight - point.y,
486
- point.x
487
- )
488
- 180 -> org.opencv.core.Point(
489
- imageWidth - point.x,
490
- imageHeight - point.y
491
- )
492
- 270 -> org.opencv.core.Point(
465
+ return if (sensorOrientation == 90) {
466
+ // Rotate 90° CCW to convert from sensor space to display space
467
+ org.opencv.core.Point(
493
468
  point.y,
494
469
  imageWidth - point.x
495
470
  )
496
- else -> point // 0 degrees, no rotation
471
+ } else {
472
+ point
497
473
  }
498
474
  }
499
475
 
500
- // Determine dimensions after rotation
501
- val rotatedImageWidth = if (rotationDegrees == 90f || rotationDegrees == 270f) {
502
- imageHeight
503
- } else {
504
- imageWidth
505
- }
506
- val rotatedImageHeight = if (rotationDegrees == 90f || rotationDegrees == 270f) {
507
- imageWidth
508
- } else {
509
- imageHeight
510
- }
476
+ // After rotation, determine final dimensions
477
+ val finalWidth = if (sensorOrientation == 90) imageHeight else imageWidth
478
+ val finalHeight = if (sensorOrientation == 90) imageWidth else imageHeight
511
479
 
512
- // Calculate scaling to fit the rotated image into the view (matching transform)
513
- val scaleX = viewWidth / rotatedImageWidth.toFloat()
514
- val scaleY = viewHeight / rotatedImageHeight.toFloat()
515
- val scale = scaleX.coerceAtMost(scaleY) // Fit (preserve aspect ratio)
480
+ // Then apply fit-center scaling
481
+ val scaleX = viewWidth / finalWidth.toFloat()
482
+ val scaleY = viewHeight / finalHeight.toFloat()
483
+ val scale = scaleX.coerceAtMost(scaleY)
516
484
 
517
- val scaledWidth = rotatedImageWidth * scale
518
- val scaledHeight = rotatedImageHeight * scale
485
+ val scaledWidth = finalWidth * scale
486
+ val scaledHeight = finalHeight * scale
519
487
  val offsetX = (viewWidth - scaledWidth) / 2f
520
488
  val offsetY = (viewHeight - scaledHeight) / 2f
521
489
 
522
- // Transform coordinates: rotate first, then scale and center
523
490
  fun transformPoint(point: org.opencv.core.Point): org.opencv.core.Point {
524
491
  val rotated = rotatePoint(point)
525
492
  return org.opencv.core.Point(
@@ -535,8 +502,11 @@ class CameraController(
535
502
  transformPoint(rectangle.bottomRight)
536
503
  )
537
504
 
538
- Log.d(TAG, "[MAPPING] Original TL: (${rectangle.topLeft.x}, ${rectangle.topLeft.y}) → " +
539
- "Transformed: (${result.topLeft.x}, ${result.topLeft.y})")
505
+ Log.d(TAG, "[MAPPING] Sensor: ${sensorOrientation}°, Image: ${imageWidth}x${imageHeight}Final: ${finalWidth}x${finalHeight}")
506
+ Log.d(TAG, "[MAPPING] View: ${viewWidth.toInt()}x${viewHeight.toInt()}, Scale: $scale, Offset: ($offsetX, $offsetY)")
507
+ Log.d(TAG, "[MAPPING] TL: (${rectangle.topLeft.x}, ${rectangle.topLeft.y}) → " +
508
+ "Rotated: (${rotatePoint(rectangle.topLeft).x}, ${rotatePoint(rectangle.topLeft).y}) → " +
509
+ "Final: (${result.topLeft.x}, ${result.topLeft.y})")
540
510
 
541
511
  return result
542
512
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "10.35.0",
3
+ "version": "10.37.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",