diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-09-16 11:07:46 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-09-16 11:07:46 +0200 |
| commit | 505c1e620497828ffb914e05dd76d9ab124f144a (patch) | |
| tree | 0d93162c4228dbee9e29c35e9f97f58daa5e3eef /Captura/Core Extensions | |
| parent | 5802c153cae64142d84e3cd5f762939501ee7e53 (diff) | |
Format the code
Diffstat (limited to 'Captura/Core Extensions')
| -rw-r--r-- | Captura/Core Extensions/CGImage+resize.swift | 16 | ||||
| -rw-r--r-- | Captura/Core Extensions/CVImageBuffer+cgImage.swift | 9 |
2 files changed, 15 insertions, 10 deletions
diff --git a/Captura/Core Extensions/CGImage+resize.swift b/Captura/Core Extensions/CGImage+resize.swift index 02aaa6e..9d1adaa 100644 --- a/Captura/Core Extensions/CGImage+resize.swift +++ b/Captura/Core Extensions/CGImage+resize.swift @@ -20,18 +20,22 @@ extension CGImage { func resize(by scale: CGFloat) -> CGImage? { let width = Int(CGFloat(self.width) / scale) let height = Int(CGFloat(self.height) / scale) - + let bitsPerComponent = self.bitsPerComponent let colorSpace = self.colorSpace ?? CGColorSpace(name: CGColorSpace.sRGB)! let bitmapInfo = self.bitmapInfo.rawValue - - guard let context = CGContext(data: nil, width: width, height: height, bitsPerComponent: bitsPerComponent, bytesPerRow: 0, space: colorSpace, bitmapInfo: bitmapInfo) else { - return nil + + guard + let context = CGContext( + data: nil, width: width, height: height, bitsPerComponent: bitsPerComponent, bytesPerRow: 0, + space: colorSpace, bitmapInfo: bitmapInfo) + else { + return nil } - + context.interpolationQuality = .high context.draw(self, in: CGRect(x: 0, y: 0, width: width, height: height)) - + return context.makeImage() } } diff --git a/Captura/Core Extensions/CVImageBuffer+cgImage.swift b/Captura/Core Extensions/CVImageBuffer+cgImage.swift index eb62e7a..ba98855 100644 --- a/Captura/Core Extensions/CVImageBuffer+cgImage.swift +++ b/Captura/Core Extensions/CVImageBuffer+cgImage.swift @@ -18,19 +18,20 @@ import Foundation import ReplayKit extension CVImageBuffer { - + private static let contextQueue = DispatchQueue(label: "com.example.contextQueue") static let sharedContext: CIContext = { - return CIContext() + return CIContext() }() - + var cgImage: CGImage? { var result: CGImage? CVImageBuffer.contextQueue.sync { let ciImage = CIImage(cvImageBuffer: self) let width = CVPixelBufferGetWidth(self) let height = CVPixelBufferGetHeight(self) - result = CVImageBuffer.sharedContext.createCGImage(ciImage, from: CGRect(x: 0, y: 0, width: width, height: height)) + result = CVImageBuffer.sharedContext.createCGImage( + ciImage, from: CGRect(x: 0, y: 0, width: width, height: height)) } return result } |