Skip to content

Commit 15f83d5

Browse files
committed
Patch 1.1.0
KNOWN ISSUES: - It is highly recommended that the rotation lock be set, as there is currently a problem with camera rotation. The bug will be fixed in upcoming updates feat: - Added ability to apply filters to photos and videos (#11) - Format of captured image was changed to UIImage (#10)
1 parent 5e08682 commit 15f83d5

15 files changed

+364
-58
lines changed

MijickCameraView.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Pod::Spec.new do |s|
55
CameraView is a free and open-source library dedicated for SwiftUI that allows you to create fully customisable camera view in no time. Keep your code clean.
66
DESC
77

8-
s.version = '1.0.1'
8+
s.version = '1.1.0'
99
s.ios.deployment_target = '14.0'
1010
s.swift_version = '5.10'
1111

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
<p align="center">
2020
<a href="https://github.com/Mijick/CameraView-Demo" rel="nofollow">Try demo we prepared</a>
21+
|
22+
<a href="https://github.com/orgs/Mijick/projects/12" rel="nofollow">Roadmap</a>
23+
|
24+
<a href="https://github.com/Mijick/CameraView/issues/new" rel="nofollow">Propose a new feature</a>
2125
</p>
2226

2327
<br>
@@ -204,6 +208,7 @@ struct CameraView: View {
204208
.focusImage(.init(named: "icon-focus")!)
205209
.focusImageColor(.blue)
206210
.focusImageSize(120)
211+
.changeCameraFilters([.init(name: "CISepiaTone")!])
207212
}
208213

209214
(...)

Sources/Internal/Config/CameraConfig.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct CameraConfig {
2121
var appDelegate: MApplicationDelegate.Type? = nil
2222

2323
// MARK: Actions
24-
var onImageCaptured: (Data) -> () = { _ in }
24+
var onImageCaptured: (UIImage) -> () = { _ in }
2525
var onVideoCaptured: (URL) -> () = { _ in }
2626
var afterMediaCaptured: () -> () = {}
2727
var onCloseController: () -> () = {}

Sources/Internal/Extensions/AVCaptureVideoOrientation++.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import SwiftUI
1313
import AVKit
1414

15+
// MARK: - To Angle
1516
extension AVCaptureVideoOrientation {
1617
func getAngle() -> Angle { switch self {
1718
case .portrait: .degrees(0)
@@ -21,3 +22,14 @@ extension AVCaptureVideoOrientation {
2122
default: .degrees(0)
2223
}}
2324
}
25+
26+
// MARK: - To UIImage.Orientation
27+
extension AVCaptureVideoOrientation {
28+
func toImageOrientation() -> UIImage.Orientation { switch self {
29+
case .portrait: .downMirrored
30+
case .landscapeLeft: .leftMirrored
31+
case .landscapeRight: .rightMirrored
32+
case .portraitUpsideDown: .upMirrored
33+
default: .up
34+
}}
35+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// AVVideoComposition++.swift of MijickCameraView
3+
//
4+
// Created by Tomasz Kurylik
5+
// - Twitter: https://twitter.com/tkurylik
6+
// - Mail: tomasz.kurylik@mijick.com
7+
// - GitHub: https://github.com/FulcrumOne
8+
//
9+
// Copyright ©2024 Mijick. Licensed under MIT License.
10+
11+
12+
import AVKit
13+
14+
// MARK: - Applying Filters
15+
extension AVVideoComposition {
16+
static func applyFilters(to asset: AVAsset, applyFiltersAction: @escaping (AVAsynchronousCIImageFilteringRequest) -> (), completionHandler: @escaping (AVVideoComposition?, (any Error)?) -> ()) {
17+
if #available(iOS 16.0, *) { applyFiltersNewWay(asset, applyFiltersAction, completionHandler) }
18+
else { applyFiltersOldWay(asset, applyFiltersAction, completionHandler) }
19+
}
20+
}
21+
private extension AVVideoComposition {
22+
@available(iOS 16.0, *)
23+
static func applyFiltersNewWay(_ asset: AVAsset, _ applyFiltersAction: @escaping (AVAsynchronousCIImageFilteringRequest) -> (), _ completionHandler: @escaping (AVVideoComposition?, (any Error)?) -> ()) {
24+
AVVideoComposition.videoComposition(with: asset, applyingCIFiltersWithHandler: applyFiltersAction, completionHandler: completionHandler)
25+
}
26+
static func applyFiltersOldWay(_ asset: AVAsset, _ applyFiltersAction: @escaping (AVAsynchronousCIImageFilteringRequest) -> (), _ completionHandler: @escaping (AVVideoComposition?, (any Error)?) -> ()) {
27+
let composition = AVVideoComposition(asset: asset, applyingCIFiltersWithHandler: applyFiltersAction)
28+
completionHandler(composition, nil)
29+
}
30+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// CIImage++.swift of MijickCameraView
3+
//
4+
// Created by Tomasz Kurylik
5+
// - Twitter: https://twitter.com/tkurylik
6+
// - Mail: tomasz.kurylik@mijick.com
7+
// - GitHub: https://github.com/FulcrumOne
8+
//
9+
// Copyright ©2024 Mijick. Licensed under MIT License.
10+
11+
12+
import SwiftUI
13+
14+
extension CIImage {
15+
func applyingFilters(_ filters: [CIFilter]) -> CIImage {
16+
var ciImage = self
17+
filters.forEach {
18+
$0.setValue(ciImage, forKey: kCIInputImageKey)
19+
ciImage = $0.outputImage ?? ciImage
20+
}
21+
return ciImage
22+
}
23+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// FileManager++.swift of MijickCameraView
3+
//
4+
// Created by Tomasz Kurylik
5+
// - Twitter: https://twitter.com/tkurylik
6+
// - Mail: tomasz.kurylik@mijick.com
7+
// - GitHub: https://github.com/FulcrumOne
8+
//
9+
// Copyright ©2024 Mijick. Licensed under MIT License.
10+
11+
12+
import SwiftUI
13+
14+
// MARK: - Preparing place for video output
15+
extension FileManager {
16+
static func prepareURLForVideoOutput() -> URL? {
17+
guard let fileUrl = createFileUrl() else { return nil }
18+
19+
clearPlaceIfTaken(fileUrl)
20+
return fileUrl
21+
}
22+
}
23+
private extension FileManager {
24+
static func createFileUrl() -> URL? {
25+
FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
26+
.first?
27+
.appendingPathComponent(videoPath)
28+
}
29+
static func clearPlaceIfTaken(_ url: URL) {
30+
try? FileManager.default.removeItem(at: url)
31+
}
32+
}
33+
private extension FileManager {
34+
static var videoPath: String { "mijick-camera-view-video-output.mp4" }
35+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// UIImage.Orientation++.swift of MijickCameraView
3+
//
4+
// Created by Tomasz Kurylik
5+
// - Twitter: https://twitter.com/tkurylik
6+
// - Mail: tomasz.kurylik@mijick.com
7+
// - GitHub: https://github.com/FulcrumOne
8+
//
9+
// Copyright ©2024 Mijick. Licensed under MIT License.
10+
11+
12+
import SwiftUI
13+
14+
extension UIImage.Orientation {
15+
init(_ orientation: CGImagePropertyOrientation) { switch orientation {
16+
case .down: self = .down
17+
case .downMirrored: self = .downMirrored
18+
case .left: self = .left
19+
case .leftMirrored: self = .leftMirrored
20+
case .right: self = .right
21+
case .rightMirrored: self = .rightMirrored
22+
case .up: self = .up
23+
case .upMirrored: self = .upMirrored
24+
}}
25+
}

Sources/Internal/Extensions/UIView++.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@
1111

1212
import SwiftUI
1313

14+
// MARK: - Adding to Parent
15+
extension UIView {
16+
func addToParent(_ view: UIView) {
17+
view.addSubview(self)
18+
19+
translatesAutoresizingMaskIntoConstraints = false
20+
leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0).isActive = true
21+
rightAnchor.constraint(equalTo: view.rightAnchor, constant: 0).isActive = true
22+
topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
23+
bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true
24+
}
25+
}
26+
1427
// MARK: - Blurring View
1528
extension UIView {
1629
func applyBlurEffect(style: UIBlurEffect.Style, animationDuration: Double) {

0 commit comments

Comments
 (0)