replate-camera 0.8.0 → 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,7 +707,8 @@ 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
|
+
// private static let TARGET_IMAGE_SIZE = CGSize(width: 2048, height: 1556)
|
|
711
|
+
private static let TARGET_IMAGE_SIZE = CGSize(width: 3072, height: 2304)
|
|
711
712
|
private static let MIN_AMBIENT_INTENSITY: CGFloat = 650
|
|
712
713
|
|
|
713
714
|
// Callbacks
|
|
@@ -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
|
|
@@ -968,16 +969,16 @@ class ReplateCameraController: NSObject {
|
|
|
968
969
|
|
|
969
970
|
private func processAndSaveImage(_ pixelBuffer: CVPixelBuffer, callbackHandler: SafeCallbackHandler) {
|
|
970
971
|
let ciImage = CIImage(cvImageBuffer: pixelBuffer)
|
|
971
|
-
|
|
972
|
+
|
|
972
973
|
guard let resizedImage = resizeImage(ciImage, to: Self.TARGET_IMAGE_SIZE),
|
|
973
974
|
let cgImage = cgImage(from: resizedImage) else {
|
|
974
975
|
callbackHandler.reject(.processingError)
|
|
975
976
|
return
|
|
976
977
|
}
|
|
977
|
-
|
|
978
|
+
|
|
978
979
|
let uiImage = UIImage(cgImage: cgImage)
|
|
979
980
|
let rotatedImage = uiImage.rotate(radians: .pi / 2)
|
|
980
|
-
|
|
981
|
+
|
|
981
982
|
// Save the image in the background
|
|
982
983
|
DispatchQueue.global(qos: .userInitiated).async {
|
|
983
984
|
guard let savedURL = self.saveImageAsPNG(rotatedImage) else {
|
|
@@ -986,7 +987,7 @@ class ReplateCameraController: NSObject {
|
|
|
986
987
|
}
|
|
987
988
|
return
|
|
988
989
|
}
|
|
989
|
-
|
|
990
|
+
|
|
990
991
|
// Call the callback on the main thread
|
|
991
992
|
DispatchQueue.main.async {
|
|
992
993
|
callbackHandler.resolve(savedURL.absoluteString)
|
|
@@ -1337,30 +1338,30 @@ class ReplateCameraController: NSObject {
|
|
|
1337
1338
|
|
|
1338
1339
|
return fileURL
|
|
1339
1340
|
}
|
|
1340
|
-
|
|
1341
|
+
|
|
1341
1342
|
func saveImageAsPNG(_ image: UIImage) -> URL? {
|
|
1342
1343
|
// Convert UIImage to PNG data
|
|
1343
1344
|
guard let imageData = image.pngData(),
|
|
1344
1345
|
let source = CGImageSourceCreateWithData(imageData as CFData, nil) else {
|
|
1345
1346
|
return nil
|
|
1346
1347
|
}
|
|
1347
|
-
|
|
1348
|
+
|
|
1348
1349
|
// Define temporary file URL
|
|
1349
1350
|
let temporaryDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
|
1350
1351
|
let uniqueFilename = "image_\(Date().timeIntervalSince1970).png"
|
|
1351
1352
|
let fileURL = temporaryDirectoryURL.appendingPathComponent(uniqueFilename)
|
|
1352
|
-
|
|
1353
|
+
|
|
1353
1354
|
// Retrieve existing image properties
|
|
1354
1355
|
guard let imageProperties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [CFString: Any] else {
|
|
1355
1356
|
return nil
|
|
1356
1357
|
}
|
|
1357
|
-
|
|
1358
|
+
|
|
1358
1359
|
// Add metadata (including a user comment with transform JSON)
|
|
1359
1360
|
var mutableMetadata = imageProperties
|
|
1360
1361
|
mutableMetadata[kCGImagePropertyPNGDictionary] = [
|
|
1361
1362
|
kCGImagePropertyPNGComment: getTransformJSON(session: ReplateCameraView.arView.session)
|
|
1362
1363
|
]
|
|
1363
|
-
|
|
1364
|
+
|
|
1364
1365
|
// Create destination for PNG file
|
|
1365
1366
|
guard let destination = CGImageDestinationCreateWithURL(
|
|
1366
1367
|
fileURL as CFURL,
|
|
@@ -1370,7 +1371,7 @@ class ReplateCameraController: NSObject {
|
|
|
1370
1371
|
) else {
|
|
1371
1372
|
return nil
|
|
1372
1373
|
}
|
|
1373
|
-
|
|
1374
|
+
|
|
1374
1375
|
// Add image with metadata to destination
|
|
1375
1376
|
CGImageDestinationAddImageFromSource(
|
|
1376
1377
|
destination,
|
|
@@ -1378,12 +1379,12 @@ class ReplateCameraController: NSObject {
|
|
|
1378
1379
|
0,
|
|
1379
1380
|
mutableMetadata as CFDictionary
|
|
1380
1381
|
)
|
|
1381
|
-
|
|
1382
|
+
|
|
1382
1383
|
// Finalize image creation
|
|
1383
1384
|
guard CGImageDestinationFinalize(destination) else {
|
|
1384
1385
|
return nil
|
|
1385
1386
|
}
|
|
1386
|
-
|
|
1387
|
+
|
|
1387
1388
|
return fileURL
|
|
1388
1389
|
}
|
|
1389
1390
|
|