@carviz/capacitor-camera-preview 7.2.0 → 7.2.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.
|
@@ -97,6 +97,11 @@ class CameraController: NSObject {
|
|
|
97
97
|
self.videoDataOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)]
|
|
98
98
|
if captureSession.canAddOutput(self.videoDataOutput) {
|
|
99
99
|
captureSession.addOutput(self.videoDataOutput)
|
|
100
|
+
|
|
101
|
+
// Set the video orientation to match the preview layer
|
|
102
|
+
if let connection = self.videoDataOutput.connection(with: .video) {
|
|
103
|
+
connection.videoOrientation = self.previewLayer.connection?.videoOrientation ?? .portrait
|
|
104
|
+
}
|
|
100
105
|
}
|
|
101
106
|
|
|
102
107
|
captureSession.startRunning()
|
|
@@ -222,6 +227,11 @@ class CameraController: NSObject {
|
|
|
222
227
|
|
|
223
228
|
previewLayer.connection?.videoOrientation = videoOrientation
|
|
224
229
|
photoOutput.connections.forEach { $0.videoOrientation = videoOrientation }
|
|
230
|
+
|
|
231
|
+
// Also update video data output orientation
|
|
232
|
+
if let connection = videoDataOutput.connection(with: .video) {
|
|
233
|
+
connection.videoOrientation = videoOrientation
|
|
234
|
+
}
|
|
225
235
|
}
|
|
226
236
|
|
|
227
237
|
public func switchCameras() throws {
|
|
@@ -542,7 +552,14 @@ extension CameraController: AVCaptureVideoDataOutputSampleBufferDelegate {
|
|
|
542
552
|
return
|
|
543
553
|
}
|
|
544
554
|
|
|
545
|
-
|
|
555
|
+
// Create CIImage from pixel buffer
|
|
556
|
+
var ciImage = CIImage(cvPixelBuffer: pixelBuffer)
|
|
557
|
+
|
|
558
|
+
// Apply orientation correction based on video orientation
|
|
559
|
+
let videoOrientation = connection.videoOrientation
|
|
560
|
+
let transform = self.transformForVideoOrientation(videoOrientation, pixelBuffer: pixelBuffer)
|
|
561
|
+
ciImage = ciImage.transformed(by: transform)
|
|
562
|
+
|
|
546
563
|
let context = CIContext()
|
|
547
564
|
|
|
548
565
|
guard let cgImage = context.createCGImage(ciImage, from: ciImage.extent) else {
|
|
@@ -552,13 +569,42 @@ extension CameraController: AVCaptureVideoDataOutputSampleBufferDelegate {
|
|
|
552
569
|
return
|
|
553
570
|
}
|
|
554
571
|
|
|
555
|
-
let image = UIImage(cgImage: cgImage)
|
|
572
|
+
let image = UIImage(cgImage: cgImage, scale: 1.0, orientation: .up)
|
|
556
573
|
|
|
557
574
|
// Call completion on main queue
|
|
558
575
|
DispatchQueue.main.async {
|
|
559
576
|
completion(image, nil)
|
|
560
577
|
}
|
|
561
578
|
}
|
|
579
|
+
|
|
580
|
+
private func transformForVideoOrientation(_ orientation: AVCaptureVideoOrientation, pixelBuffer: CVPixelBuffer) -> CGAffineTransform {
|
|
581
|
+
let bufferWidth = CGFloat(CVPixelBufferGetWidth(pixelBuffer))
|
|
582
|
+
let bufferHeight = CGFloat(CVPixelBufferGetHeight(pixelBuffer))
|
|
583
|
+
|
|
584
|
+
var transform = CGAffineTransform.identity
|
|
585
|
+
|
|
586
|
+
switch orientation {
|
|
587
|
+
case .portrait:
|
|
588
|
+
// No rotation needed for portrait
|
|
589
|
+
break
|
|
590
|
+
case .portraitUpsideDown:
|
|
591
|
+
// Rotate 180 degrees
|
|
592
|
+
transform = transform.translatedBy(x: bufferWidth, y: bufferHeight)
|
|
593
|
+
transform = transform.rotated(by: .pi)
|
|
594
|
+
case .landscapeRight:
|
|
595
|
+
// Rotate 90 degrees clockwise
|
|
596
|
+
transform = transform.translatedBy(x: bufferHeight, y: 0)
|
|
597
|
+
transform = transform.rotated(by: .pi / 2)
|
|
598
|
+
case .landscapeLeft:
|
|
599
|
+
// Rotate 90 degrees counter-clockwise
|
|
600
|
+
transform = transform.translatedBy(x: 0, y: bufferWidth)
|
|
601
|
+
transform = transform.rotated(by: -.pi / 2)
|
|
602
|
+
@unknown default:
|
|
603
|
+
break
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
return transform
|
|
607
|
+
}
|
|
562
608
|
}
|
|
563
609
|
|
|
564
610
|
extension CameraController: UIGestureRecognizerDelegate {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carviz/capacitor-camera-preview",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.1",
|
|
4
4
|
"description": "Fork of the capacitor-community/camera-preview plugin focusing on high resolution photos without bloating up the code.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/plugin.cjs.js",
|