@carviz/capacitor-camera-preview 7.2.1 → 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,7 +94,7 @@ 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
100
 
@@ -544,66 +544,38 @@ extension CameraController: AVCaptureVideoDataOutputSampleBufferDelegate {
544
544
  // Clear the completion block to avoid capturing multiple frames for one request
545
545
  self.sampleBufferCaptureCompletionBlock = nil
546
546
 
547
- // Convert sample buffer to UIImage
548
- 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 {
549
549
  DispatchQueue.main.async {
550
550
  completion(nil, CameraControllerError.unknown)
551
551
  }
552
552
  return
553
553
  }
554
554
 
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
-
563
- let context = CIContext()
564
-
565
- guard let cgImage = context.createCGImage(ciImage, from: ciImage.extent) else {
566
- DispatchQueue.main.async {
567
- completion(nil, CameraControllerError.unknown)
568
- }
569
- return
570
- }
571
-
572
- let image = UIImage(cgImage: cgImage, scale: 1.0, orientation: .up)
573
-
574
555
  // Call completion on main queue
575
556
  DispatchQueue.main.async {
576
557
  completion(image, nil)
577
558
  }
578
559
  }
579
560
 
580
- private func transformForVideoOrientation(_ orientation: AVCaptureVideoOrientation, pixelBuffer: CVPixelBuffer) -> CGAffineTransform {
581
- let bufferWidth = CGFloat(CVPixelBufferGetWidth(pixelBuffer))
582
- let bufferHeight = CGFloat(CVPixelBufferGetHeight(pixelBuffer))
561
+ private func imageFromSampleBuffer(_ sampleBuffer: CMSampleBuffer) -> UIImage? {
562
+ guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
563
+ return nil
564
+ }
583
565
 
584
- var transform = CGAffineTransform.identity
566
+ // Use CIImage for YUV to RGB conversion, but ensure we get the full extent
567
+ let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
568
+ let context = CIContext()
585
569
 
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
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)
572
+
573
+ guard let cgImage = context.createCGImage(ciImage, from: rect) else {
574
+ return nil
604
575
  }
605
576
 
606
- return transform
577
+ // Create UIImage with proper orientation
578
+ return UIImage(cgImage: cgImage, scale: 1.0, orientation: .up)
607
579
  }
608
580
  }
609
581
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carviz/capacitor-camera-preview",
3
- "version": "7.2.1",
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",