@carviz/capacitor-camera-preview 7.2.0 → 7.2.2

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.
@@ -94,9 +94,14 @@ class CameraController: NSObject {
94
94
 
95
95
  // Configure video data output for sample capture
96
96
  self.videoDataOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "videoQueue"))
97
- self.videoDataOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)]
97
+ self.videoDataOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange)]
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 {
@@ -534,30 +544,38 @@ extension CameraController: AVCaptureVideoDataOutputSampleBufferDelegate {
534
544
  // Clear the completion block to avoid capturing multiple frames for one request
535
545
  self.sampleBufferCaptureCompletionBlock = nil
536
546
 
537
- // Convert sample buffer to UIImage
538
- guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
547
+ // Convert sample buffer to UIImage using a more direct approach
548
+ guard let image = self.imageFromSampleBuffer(sampleBuffer) else {
539
549
  DispatchQueue.main.async {
540
550
  completion(nil, CameraControllerError.unknown)
541
551
  }
542
552
  return
543
553
  }
544
554
 
555
+ // Call completion on main queue
556
+ DispatchQueue.main.async {
557
+ completion(image, nil)
558
+ }
559
+ }
560
+
561
+ private func imageFromSampleBuffer(_ sampleBuffer: CMSampleBuffer) -> UIImage? {
562
+ guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
563
+ return nil
564
+ }
565
+
566
+ // Use CIImage for YUV to RGB conversion, but ensure we get the full extent
545
567
  let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
546
568
  let context = CIContext()
547
569
 
548
- guard let cgImage = context.createCGImage(ciImage, from: ciImage.extent) else {
549
- DispatchQueue.main.async {
550
- completion(nil, CameraControllerError.unknown)
551
- }
552
- return
553
- }
570
+ // Make sure we use the full extent of the image
571
+ let rect = CGRect(x: 0, y: 0, width: ciImage.extent.width, height: ciImage.extent.height)
554
572
 
555
- let image = UIImage(cgImage: cgImage)
556
-
557
- // Call completion on main queue
558
- DispatchQueue.main.async {
559
- completion(image, nil)
573
+ guard let cgImage = context.createCGImage(ciImage, from: rect) else {
574
+ return nil
560
575
  }
576
+
577
+ // Create UIImage with proper orientation
578
+ return UIImage(cgImage: cgImage, scale: 1.0, orientation: .up)
561
579
  }
562
580
  }
563
581
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carviz/capacitor-camera-preview",
3
- "version": "7.2.0",
3
+ "version": "7.2.2",
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",