replate-camera 0.4.1 → 0.5.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.
|
@@ -1255,49 +1255,59 @@ class ReplateCameraController: NSObject {
|
|
|
1255
1255
|
return context.createCGImage(ciImage, from: ciImage.extent)
|
|
1256
1256
|
}
|
|
1257
1257
|
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
return fileURL
|
|
1258
|
+
func saveImageAsJPEG(_ image: UIImage) -> URL? {
|
|
1259
|
+
let cameraTransform = getCameraTransformString(from: ReplateCameraView.arView.session)
|
|
1260
|
+
let gravityVector = getGravityVectorString(from: ReplateCameraView.arView.session)
|
|
1261
|
+
|
|
1262
|
+
guard let imageData = image.jpegData(compressionQuality: 1),
|
|
1263
|
+
let source = CGImageSourceCreateWithData(imageData as CFData, nil) else {
|
|
1264
|
+
return nil
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
let temporaryDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
|
|
1268
|
+
let uniqueFilename = "image_\(Date().timeIntervalSince1970).jpg"
|
|
1269
|
+
let fileURL = temporaryDirectoryURL.appendingPathComponent(uniqueFilename)
|
|
1270
|
+
|
|
1271
|
+
guard let imageProperties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [CFString: Any] else {
|
|
1272
|
+
return nil
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
var mutableMetadata = imageProperties
|
|
1276
|
+
mutableMetadata[kCGImagePropertyExifDictionary] = [
|
|
1277
|
+
kCGImagePropertyExifUserComment: "\(cameraTransform ?? "")|\(gravityVector)"
|
|
1278
|
+
]
|
|
1279
|
+
|
|
1280
|
+
guard let destination = CGImageDestinationCreateWithURL(
|
|
1281
|
+
fileURL as CFURL,
|
|
1282
|
+
kUTTypeJPEG,
|
|
1283
|
+
1,
|
|
1284
|
+
nil
|
|
1285
|
+
) else {
|
|
1286
|
+
return nil
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
CGImageDestinationAddImageFromSource(
|
|
1290
|
+
destination,
|
|
1291
|
+
source,
|
|
1292
|
+
0,
|
|
1293
|
+
mutableMetadata as CFDictionary
|
|
1294
|
+
)
|
|
1295
|
+
|
|
1296
|
+
guard CGImageDestinationFinalize(destination) else {
|
|
1297
|
+
return nil
|
|
1300
1298
|
}
|
|
1299
|
+
|
|
1300
|
+
return fileURL
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
func getGravityVectorString(from session: ARSession) -> String? {
|
|
1304
|
+
guard let currentFrame = session.currentFrame else {
|
|
1305
|
+
return nil
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
let gravityVector = currentFrame.camera.eulerAngles // gravity vector is in Euler angles (x, y, z)
|
|
1309
|
+
return "\(gravityVector.x),\(gravityVector.y),\(gravityVector.z)"
|
|
1310
|
+
}
|
|
1301
1311
|
|
|
1302
1312
|
func getCameraTransformString(from session: ARSession) -> String? {
|
|
1303
1313
|
guard let currentFrame = session.currentFrame else {
|