react-native-rectangle-doc-scanner 10.35.0 → 10.36.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,74 +457,23 @@ 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
+ // Simple fit-center scaling like Camera2 did
461
+ // The image analysis coordinates are in the image's coordinate space (imageWidth x imageHeight)
462
+ // We just need to scale and center them to the view, matching how Camera2 worked.
463
463
 
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
482
- 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(
493
- point.y,
494
- imageWidth - point.x
495
- )
496
- else -> point // 0 degrees, no rotation
497
- }
498
- }
499
-
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
- }
511
-
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()
464
+ val scaleX = viewWidth / imageWidth.toFloat()
465
+ val scaleY = viewHeight / imageHeight.toFloat()
515
466
  val scale = scaleX.coerceAtMost(scaleY) // Fit (preserve aspect ratio)
516
467
 
517
- val scaledWidth = rotatedImageWidth * scale
518
- val scaledHeight = rotatedImageHeight * scale
468
+ val scaledWidth = imageWidth * scale
469
+ val scaledHeight = imageHeight * scale
519
470
  val offsetX = (viewWidth - scaledWidth) / 2f
520
471
  val offsetY = (viewHeight - scaledHeight) / 2f
521
472
 
522
- // Transform coordinates: rotate first, then scale and center
523
473
  fun transformPoint(point: org.opencv.core.Point): org.opencv.core.Point {
524
- val rotated = rotatePoint(point)
525
474
  return org.opencv.core.Point(
526
- rotated.x * scale + offsetX,
527
- rotated.y * scale + offsetY
475
+ point.x * scale + offsetX,
476
+ point.y * scale + offsetY
528
477
  )
529
478
  }
530
479
 
@@ -535,8 +484,11 @@ class CameraController(
535
484
  transformPoint(rectangle.bottomRight)
536
485
  )
537
486
 
538
- Log.d(TAG, "[MAPPING] Original TL: (${rectangle.topLeft.x}, ${rectangle.topLeft.y}) " +
539
- "Transformed: (${result.topLeft.x}, ${result.topLeft.y})")
487
+ Log.d(TAG, "[MAPPING] Simple fit-center: Image ${imageWidth}x${imageHeight}, " +
488
+ "View ${viewWidth.toInt()}x${viewHeight.toInt()}, Scale: $scale, " +
489
+ "Offset: ($offsetX, $offsetY)")
490
+ Log.d(TAG, "[MAPPING] TL: (${rectangle.topLeft.x}, ${rectangle.topLeft.y}) → " +
491
+ "(${result.topLeft.x}, ${result.topLeft.y})")
540
492
 
541
493
  return result
542
494
  }
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.36.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",