replate-camera 0.7.1 → 0.8.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.
|
@@ -707,7 +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:
|
|
710
|
+
private static let TARGET_IMAGE_SIZE = CGSize(width: 2048, height: 1556)
|
|
711
711
|
private static let MIN_AMBIENT_INTENSITY: CGFloat = 650
|
|
712
712
|
|
|
713
713
|
// Callbacks
|
|
@@ -968,25 +968,34 @@ class ReplateCameraController: NSObject {
|
|
|
968
968
|
|
|
969
969
|
private func processAndSaveImage(_ pixelBuffer: CVPixelBuffer, callbackHandler: SafeCallbackHandler) {
|
|
970
970
|
let ciImage = CIImage(cvImageBuffer: pixelBuffer)
|
|
971
|
-
|
|
971
|
+
|
|
972
972
|
guard let resizedImage = resizeImage(ciImage, to: Self.TARGET_IMAGE_SIZE),
|
|
973
973
|
let cgImage = cgImage(from: resizedImage) else {
|
|
974
974
|
callbackHandler.reject(.processingError)
|
|
975
975
|
return
|
|
976
976
|
}
|
|
977
|
-
|
|
977
|
+
|
|
978
978
|
let uiImage = UIImage(cgImage: cgImage)
|
|
979
979
|
let rotatedImage = uiImage.rotate(radians: .pi / 2)
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
980
|
+
|
|
981
|
+
// Save the image in the background
|
|
982
|
+
DispatchQueue.global(qos: .userInitiated).async {
|
|
983
|
+
guard let savedURL = self.saveImageAsPNG(rotatedImage) else {
|
|
984
|
+
DispatchQueue.main.async {
|
|
985
|
+
callbackHandler.reject(.processingError)
|
|
986
|
+
}
|
|
987
|
+
return
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
// Call the callback on the main thread
|
|
991
|
+
DispatchQueue.main.async {
|
|
992
|
+
callbackHandler.resolve(savedURL.absoluteString)
|
|
993
|
+
}
|
|
984
994
|
}
|
|
985
|
-
|
|
986
|
-
callbackHandler.resolve(savedURL.absoluteString)
|
|
987
995
|
}
|
|
988
996
|
|
|
989
997
|
|
|
998
|
+
|
|
990
999
|
func resizeImage(_ image: CIImage, to targetSize: CGSize) -> CIImage? {
|
|
991
1000
|
guard let scaleFilter = CIFilter(name: "CILanczosScaleTransform") else { return nil }
|
|
992
1001
|
|