@carviz/capacitor-camera-preview 7.2.1 → 7.2.3
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(
|
|
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
|
|
|
@@ -311,8 +311,41 @@ class CameraController: NSObject {
|
|
|
311
311
|
return
|
|
312
312
|
}
|
|
313
313
|
|
|
314
|
-
//
|
|
315
|
-
|
|
314
|
+
// Capture the preview layer content directly - this mimics what the user sees
|
|
315
|
+
DispatchQueue.main.async {
|
|
316
|
+
guard let image = self.capturePreviewLayerAsImage() else {
|
|
317
|
+
completion(nil, CameraControllerError.unknown)
|
|
318
|
+
return
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// Apply the same orientation fix as the regular capture function
|
|
322
|
+
let orientationFixedImage = image.fixedOrientation() ?? image
|
|
323
|
+
completion(orientationFixedImage, nil)
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
private func capturePreviewLayerAsImage() -> UIImage? {
|
|
328
|
+
// Ensure we're on the main thread
|
|
329
|
+
assert(Thread.isMainThread)
|
|
330
|
+
|
|
331
|
+
// Get the preview layer bounds
|
|
332
|
+
let bounds = previewLayer.bounds
|
|
333
|
+
|
|
334
|
+
// Create a graphics context
|
|
335
|
+
UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.main.scale)
|
|
336
|
+
guard let context = UIGraphicsGetCurrentContext() else {
|
|
337
|
+
UIGraphicsEndImageContext()
|
|
338
|
+
return nil
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// Render the preview layer into the context
|
|
342
|
+
previewLayer.render(in: context)
|
|
343
|
+
|
|
344
|
+
// Get the image from the context
|
|
345
|
+
let image = UIGraphicsGetImageFromCurrentImageContext()
|
|
346
|
+
UIGraphicsEndImageContext()
|
|
347
|
+
|
|
348
|
+
return image
|
|
316
349
|
}
|
|
317
350
|
|
|
318
351
|
func getSupportedFlashModes() throws -> [String] {
|
|
@@ -538,72 +571,8 @@ extension CameraController: AVCapturePhotoCaptureDelegate {
|
|
|
538
571
|
|
|
539
572
|
extension CameraController: AVCaptureVideoDataOutputSampleBufferDelegate {
|
|
540
573
|
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
|
|
541
|
-
//
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
// Clear the completion block to avoid capturing multiple frames for one request
|
|
545
|
-
self.sampleBufferCaptureCompletionBlock = nil
|
|
546
|
-
|
|
547
|
-
// Convert sample buffer to UIImage
|
|
548
|
-
guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
|
|
549
|
-
DispatchQueue.main.async {
|
|
550
|
-
completion(nil, CameraControllerError.unknown)
|
|
551
|
-
}
|
|
552
|
-
return
|
|
553
|
-
}
|
|
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
|
-
// Call completion on main queue
|
|
575
|
-
DispatchQueue.main.async {
|
|
576
|
-
completion(image, nil)
|
|
577
|
-
}
|
|
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
|
|
574
|
+
// We don't actually need to process video frames anymore since we're using preview layer capture
|
|
575
|
+
// This method is kept for compatibility but does nothing
|
|
607
576
|
}
|
|
608
577
|
}
|
|
609
578
|
|
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.3",
|
|
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",
|