replate-camera 0.7.1 → 0.8.1

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.
@@ -594,7 +594,7 @@ class ReplateCameraView: UIView, ARSessionDelegate {
594
594
  print("Error when sending feedback")
595
595
  }
596
596
  }
597
-
597
+
598
598
  func startDeviceMotionUpdates() {
599
599
  ReplateCameraView.motionManager.deviceMotionUpdateInterval = 0.1 // Update interval in seconds
600
600
  ReplateCameraView.motionManager.startDeviceMotionUpdates(to: .main) { (deviceMotion, error) in
@@ -707,6 +707,7 @@ class ReplateCameraController: NSObject {
707
707
  private static let MIN_DISTANCE: Float = 0.15
708
708
  private static let MAX_DISTANCE: Float = 0.65
709
709
  private static let ANGLE_THRESHOLD: Float = 0.6
710
+ // private static let TARGET_IMAGE_SIZE = CGSize(width: 2048, height: 1556)
710
711
  private static let TARGET_IMAGE_SIZE = CGSize(width: 3072, height: 2304)
711
712
  private static let MIN_AMBIENT_INTENSITY: CGFloat = 650
712
713
 
@@ -909,12 +910,12 @@ class ReplateCameraController: NSObject {
909
910
  callbackHandler.reject(.notInRange)
910
911
  return
911
912
  }
912
-
913
+
913
914
  guard let frame = ReplateCameraView.arView?.session.currentFrame else {
914
915
  callbackHandler.reject(.captureError)
915
916
  return
916
917
  }
917
-
918
+
918
919
  // Check lighting conditions
919
920
  if let lightEstimate = frame.lightEstimate {
920
921
  guard lightEstimate.ambientIntensity >= Self.MIN_AMBIENT_INTENSITY else {
@@ -922,7 +923,7 @@ class ReplateCameraController: NSObject {
922
923
  return
923
924
  }
924
925
  }
925
-
926
+
926
927
  self.updateSpheres(
927
928
  deviceTargetInfo: deviceTargetInfo,
928
929
  cameraTransform: deviceTargetInfo.transform
@@ -978,15 +979,24 @@ class ReplateCameraController: NSObject {
978
979
  let uiImage = UIImage(cgImage: cgImage)
979
980
  let rotatedImage = uiImage.rotate(radians: .pi / 2)
980
981
 
981
- guard let savedURL = saveImageAsPNG(rotatedImage) else {
982
- callbackHandler.reject(.processingError)
983
- return
984
- }
982
+ // Save the image in the background
983
+ DispatchQueue.global(qos: .userInitiated).async {
984
+ guard let savedURL = self.saveImageAsPNG(rotatedImage) else {
985
+ DispatchQueue.main.async {
986
+ callbackHandler.reject(.processingError)
987
+ }
988
+ return
989
+ }
985
990
 
986
- callbackHandler.resolve(savedURL.absoluteString)
991
+ // Call the callback on the main thread
992
+ DispatchQueue.main.async {
993
+ callbackHandler.resolve(savedURL.absoluteString)
994
+ }
995
+ }
987
996
  }
988
997
 
989
998
 
999
+
990
1000
  func resizeImage(_ image: CIImage, to targetSize: CGSize) -> CIImage? {
991
1001
  guard let scaleFilter = CIFilter(name: "CILanczosScaleTransform") else { return nil }
992
1002
 
@@ -1328,30 +1338,30 @@ class ReplateCameraController: NSObject {
1328
1338
 
1329
1339
  return fileURL
1330
1340
  }
1331
-
1341
+
1332
1342
  func saveImageAsPNG(_ image: UIImage) -> URL? {
1333
1343
  // Convert UIImage to PNG data
1334
1344
  guard let imageData = image.pngData(),
1335
1345
  let source = CGImageSourceCreateWithData(imageData as CFData, nil) else {
1336
1346
  return nil
1337
1347
  }
1338
-
1348
+
1339
1349
  // Define temporary file URL
1340
1350
  let temporaryDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
1341
1351
  let uniqueFilename = "image_\(Date().timeIntervalSince1970).png"
1342
1352
  let fileURL = temporaryDirectoryURL.appendingPathComponent(uniqueFilename)
1343
-
1353
+
1344
1354
  // Retrieve existing image properties
1345
1355
  guard let imageProperties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [CFString: Any] else {
1346
1356
  return nil
1347
1357
  }
1348
-
1358
+
1349
1359
  // Add metadata (including a user comment with transform JSON)
1350
1360
  var mutableMetadata = imageProperties
1351
1361
  mutableMetadata[kCGImagePropertyPNGDictionary] = [
1352
1362
  kCGImagePropertyPNGComment: getTransformJSON(session: ReplateCameraView.arView.session)
1353
1363
  ]
1354
-
1364
+
1355
1365
  // Create destination for PNG file
1356
1366
  guard let destination = CGImageDestinationCreateWithURL(
1357
1367
  fileURL as CFURL,
@@ -1361,7 +1371,7 @@ class ReplateCameraController: NSObject {
1361
1371
  ) else {
1362
1372
  return nil
1363
1373
  }
1364
-
1374
+
1365
1375
  // Add image with metadata to destination
1366
1376
  CGImageDestinationAddImageFromSource(
1367
1377
  destination,
@@ -1369,12 +1379,12 @@ class ReplateCameraController: NSObject {
1369
1379
  0,
1370
1380
  mutableMetadata as CFDictionary
1371
1381
  )
1372
-
1382
+
1373
1383
  // Finalize image creation
1374
1384
  guard CGImageDestinationFinalize(destination) else {
1375
1385
  return nil
1376
1386
  }
1377
-
1387
+
1378
1388
  return fileURL
1379
1389
  }
1380
1390
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replate-camera",
3
- "version": "0.7.1",
3
+ "version": "0.8.1",
4
4
  "description": "Camera component for Replate Manager",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",