replate-camera 0.6.1 → 0.7.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.
|
@@ -705,7 +705,7 @@ class ReplateCameraController: NSObject {
|
|
|
705
705
|
|
|
706
706
|
// Configuration Constants
|
|
707
707
|
private static let MIN_DISTANCE: Float = 0.15
|
|
708
|
-
private static let MAX_DISTANCE: Float = 0.
|
|
708
|
+
private static let MAX_DISTANCE: Float = 0.65
|
|
709
709
|
private static let ANGLE_THRESHOLD: Float = 0.6
|
|
710
710
|
private static let TARGET_IMAGE_SIZE = CGSize(width: 2048, height: 1556)
|
|
711
711
|
private static let MIN_AMBIENT_INTENSITY: CGFloat = 650
|
|
@@ -978,7 +978,7 @@ class ReplateCameraController: NSObject {
|
|
|
978
978
|
let uiImage = UIImage(cgImage: cgImage)
|
|
979
979
|
let rotatedImage = uiImage.rotate(radians: .pi / 2)
|
|
980
980
|
|
|
981
|
-
guard let savedURL =
|
|
981
|
+
guard let savedURL = saveImageAsPNG(rotatedImage) else {
|
|
982
982
|
callbackHandler.reject(.processingError)
|
|
983
983
|
return
|
|
984
984
|
}
|
|
@@ -1328,6 +1328,56 @@ class ReplateCameraController: NSObject {
|
|
|
1328
1328
|
|
|
1329
1329
|
return fileURL
|
|
1330
1330
|
}
|
|
1331
|
+
|
|
1332
|
+
func saveImageAsPNG(_ image: UIImage) -> URL? {
|
|
1333
|
+
// Convert UIImage to PNG data
|
|
1334
|
+
guard let imageData = image.pngData(),
|
|
1335
|
+
let source = CGImageSourceCreateWithData(imageData as CFData, nil) else {
|
|
1336
|
+
return nil
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
// Define temporary file URL
|
|
1340
|
+
let temporaryDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
|
1341
|
+
let uniqueFilename = "image_\(Date().timeIntervalSince1970).png"
|
|
1342
|
+
let fileURL = temporaryDirectoryURL.appendingPathComponent(uniqueFilename)
|
|
1343
|
+
|
|
1344
|
+
// Retrieve existing image properties
|
|
1345
|
+
guard let imageProperties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [CFString: Any] else {
|
|
1346
|
+
return nil
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
// Add metadata (including a user comment with transform JSON)
|
|
1350
|
+
var mutableMetadata = imageProperties
|
|
1351
|
+
mutableMetadata[kCGImagePropertyPNGDictionary] = [
|
|
1352
|
+
kCGImagePropertyPNGComment: getTransformJSON(session: ReplateCameraView.arView.session)
|
|
1353
|
+
]
|
|
1354
|
+
|
|
1355
|
+
// Create destination for PNG file
|
|
1356
|
+
guard let destination = CGImageDestinationCreateWithURL(
|
|
1357
|
+
fileURL as CFURL,
|
|
1358
|
+
kUTTypePNG,
|
|
1359
|
+
1,
|
|
1360
|
+
nil
|
|
1361
|
+
) else {
|
|
1362
|
+
return nil
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
// Add image with metadata to destination
|
|
1366
|
+
CGImageDestinationAddImageFromSource(
|
|
1367
|
+
destination,
|
|
1368
|
+
source,
|
|
1369
|
+
0,
|
|
1370
|
+
mutableMetadata as CFDictionary
|
|
1371
|
+
)
|
|
1372
|
+
|
|
1373
|
+
// Finalize image creation
|
|
1374
|
+
guard CGImageDestinationFinalize(destination) else {
|
|
1375
|
+
return nil
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
return fileURL
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1331
1381
|
|
|
1332
1382
|
func getTransformJSON(session: ARSession) -> String {
|
|
1333
1383
|
let transform = session.currentFrame?.camera.transform ?? simd_float4x4()
|