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
- func saveImageAsJPEG(_ image: UIImage) -> URL? {
1259
- let cameraTransform = getCameraTransformString(from: ReplateCameraView.arView.session)
1260
-
1261
- guard let imageData = image.jpegData(compressionQuality: 1),
1262
- let source = CGImageSourceCreateWithData(imageData as CFData, nil) else {
1263
- return nil
1264
- }
1265
-
1266
- let temporaryDirectoryURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
1267
- let uniqueFilename = "image_\(Date().timeIntervalSince1970).jpg"
1268
- let fileURL = temporaryDirectoryURL.appendingPathComponent(uniqueFilename)
1269
-
1270
- guard let imageProperties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [CFString: Any] else {
1271
- return nil
1272
- }
1273
-
1274
- var mutableMetadata = imageProperties
1275
- mutableMetadata[kCGImagePropertyExifDictionary] = [
1276
- kCGImagePropertyExifUserComment: cameraTransform
1277
- ]
1278
-
1279
- guard let destination = CGImageDestinationCreateWithURL(
1280
- fileURL as CFURL,
1281
- kUTTypeJPEG,
1282
- 1,
1283
- nil
1284
- ) else {
1285
- return nil
1286
- }
1287
-
1288
- CGImageDestinationAddImageFromSource(
1289
- destination,
1290
- source,
1291
- 0,
1292
- mutableMetadata as CFDictionary
1293
- )
1294
-
1295
- guard CGImageDestinationFinalize(destination) else {
1296
- return nil
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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "replate-camera",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Camera component for Replate Manager",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",