Skip to content

Commit

Permalink
Patch 1.1.0
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
FulcrumOne committed Jun 16, 2024
1 parent 5e08682 commit 15f83d5
Show file tree
Hide file tree
Showing 15 changed files with 364 additions and 58 deletions.
2 changes: 1 addition & 1 deletion MijickCameraView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Pod::Spec.new do |s|
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.
DESC

s.version = '1.0.1'
s.version = '1.1.0'
s.ios.deployment_target = '14.0'
s.swift_version = '5.10'

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

<p align="center">
<a href="https://github.com/Mijick/CameraView-Demo" rel="nofollow">Try demo we prepared</a>
|
<a href="https://github.com/orgs/Mijick/projects/12" rel="nofollow">Roadmap</a>
|
<a href="https://github.com/Mijick/CameraView/issues/new" rel="nofollow">Propose a new feature</a>
</p>

<br>
Expand Down Expand Up @@ -204,6 +208,7 @@ struct CameraView: View {
.focusImage(.init(named: "icon-focus")!)
.focusImageColor(.blue)
.focusImageSize(120)
.changeCameraFilters([.init(name: "CISepiaTone")!])
}

(...)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Internal/Config/CameraConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct CameraConfig {
var appDelegate: MApplicationDelegate.Type? = nil

// MARK: Actions
var onImageCaptured: (Data) -> () = { _ in }
var onImageCaptured: (UIImage) -> () = { _ in }
var onVideoCaptured: (URL) -> () = { _ in }
var afterMediaCaptured: () -> () = {}
var onCloseController: () -> () = {}
Expand Down
12 changes: 12 additions & 0 deletions Sources/Internal/Extensions/AVCaptureVideoOrientation++.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import SwiftUI
import AVKit

// MARK: - To Angle
extension AVCaptureVideoOrientation {
func getAngle() -> Angle { switch self {
case .portrait: .degrees(0)
Expand All @@ -21,3 +22,14 @@ extension AVCaptureVideoOrientation {
default: .degrees(0)
}}
}

// MARK: - To UIImage.Orientation
extension AVCaptureVideoOrientation {
func toImageOrientation() -> UIImage.Orientation { switch self {
case .portrait: .downMirrored
case .landscapeLeft: .leftMirrored
case .landscapeRight: .rightMirrored
case .portraitUpsideDown: .upMirrored
default: .up
}}
}
30 changes: 30 additions & 0 deletions Sources/Internal/Extensions/AVVideoComposition++.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// AVVideoComposition++.swift of MijickCameraView
//
// Created by Tomasz Kurylik
// - Twitter: https://twitter.com/tkurylik
// - Mail: tomasz.kurylik@mijick.com
// - GitHub: https://github.com/FulcrumOne
//
// Copyright ©2024 Mijick. Licensed under MIT License.


import AVKit

// MARK: - Applying Filters
extension AVVideoComposition {
static func applyFilters(to asset: AVAsset, applyFiltersAction: @escaping (AVAsynchronousCIImageFilteringRequest) -> (), completionHandler: @escaping (AVVideoComposition?, (any Error)?) -> ()) {
if #available(iOS 16.0, *) { applyFiltersNewWay(asset, applyFiltersAction, completionHandler) }
else { applyFiltersOldWay(asset, applyFiltersAction, completionHandler) }
}
}
private extension AVVideoComposition {
@available(iOS 16.0, *)
static func applyFiltersNewWay(_ asset: AVAsset, _ applyFiltersAction: @escaping (AVAsynchronousCIImageFilteringRequest) -> (), _ completionHandler: @escaping (AVVideoComposition?, (any Error)?) -> ()) {
AVVideoComposition.videoComposition(with: asset, applyingCIFiltersWithHandler: applyFiltersAction, completionHandler: completionHandler)
}
static func applyFiltersOldWay(_ asset: AVAsset, _ applyFiltersAction: @escaping (AVAsynchronousCIImageFilteringRequest) -> (), _ completionHandler: @escaping (AVVideoComposition?, (any Error)?) -> ()) {
let composition = AVVideoComposition(asset: asset, applyingCIFiltersWithHandler: applyFiltersAction)
completionHandler(composition, nil)
}
}
23 changes: 23 additions & 0 deletions Sources/Internal/Extensions/CIImage++.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// CIImage++.swift of MijickCameraView
//
// Created by Tomasz Kurylik
// - Twitter: https://twitter.com/tkurylik
// - Mail: tomasz.kurylik@mijick.com
// - GitHub: https://github.com/FulcrumOne
//
// Copyright ©2024 Mijick. Licensed under MIT License.


import SwiftUI

extension CIImage {
func applyingFilters(_ filters: [CIFilter]) -> CIImage {
var ciImage = self
filters.forEach {
$0.setValue(ciImage, forKey: kCIInputImageKey)
ciImage = $0.outputImage ?? ciImage
}
return ciImage
}
}
35 changes: 35 additions & 0 deletions Sources/Internal/Extensions/FileManager++.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// FileManager++.swift of MijickCameraView
//
// Created by Tomasz Kurylik
// - Twitter: https://twitter.com/tkurylik
// - Mail: tomasz.kurylik@mijick.com
// - GitHub: https://github.com/FulcrumOne
//
// Copyright ©2024 Mijick. Licensed under MIT License.


import SwiftUI

// MARK: - Preparing place for video output
extension FileManager {
static func prepareURLForVideoOutput() -> URL? {
guard let fileUrl = createFileUrl() else { return nil }

clearPlaceIfTaken(fileUrl)
return fileUrl
}
}
private extension FileManager {
static func createFileUrl() -> URL? {
FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
.first?
.appendingPathComponent(videoPath)
}
static func clearPlaceIfTaken(_ url: URL) {
try? FileManager.default.removeItem(at: url)
}
}
private extension FileManager {
static var videoPath: String { "mijick-camera-view-video-output.mp4" }
}
25 changes: 25 additions & 0 deletions Sources/Internal/Extensions/UIImage.Orientation++.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// UIImage.Orientation++.swift of MijickCameraView
//
// Created by Tomasz Kurylik
// - Twitter: https://twitter.com/tkurylik
// - Mail: tomasz.kurylik@mijick.com
// - GitHub: https://github.com/FulcrumOne
//
// Copyright ©2024 Mijick. Licensed under MIT License.


import SwiftUI

extension UIImage.Orientation {
init(_ orientation: CGImagePropertyOrientation) { switch orientation {
case .down: self = .down
case .downMirrored: self = .downMirrored
case .left: self = .left
case .leftMirrored: self = .leftMirrored
case .right: self = .right
case .rightMirrored: self = .rightMirrored
case .up: self = .up
case .upMirrored: self = .upMirrored
}}
}
13 changes: 13 additions & 0 deletions Sources/Internal/Extensions/UIView++.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@

import SwiftUI

// MARK: - Adding to Parent
extension UIView {
func addToParent(_ view: UIView) {
view.addSubview(self)

translatesAutoresizingMaskIntoConstraints = false
leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0).isActive = true
rightAnchor.constraint(equalTo: view.rightAnchor, constant: 0).isActive = true
topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true
}
}

// MARK: - Blurring View
extension UIView {
func applyBlurEffect(style: UIBlurEffect.Style, animationDuration: Double) {
Expand Down
Loading

0 comments on commit 15f83d5

Please sign in to comment.