Harbeth
Animated | Still |
---|---|
Harbeth is a tiny set of utils and extensions over Apple's Metal framework dedicated to make your Swift GPU code much cleaner and let you prototype your pipelines faster.
English | 简体中文
Features
- Support more platform system, macOS and iOS.
- High performance quickly add filters at these sources:
- UIImage, NSImage, CIImage, CGImage, CMSampleBuffer, CVPixelBuffer.
- The built-in filters is roughly divided into the following modules:
- Customized filter and use operator chain add filter at sources.
- Setup
MetalPerformanceShaders
filters and also compatible forCoreImage
filters. - Camera capture and video to add filter special effects.
- Video source processing video file.
100+
kinds of built-in filters are currently available.✌️
A total of Requirements
iOS Target | macOS Target | Xcode Version | Swift Version |
---|---|---|---|
iOS 10.0+ | macOS 10.13+ | Xcode 10.0+ | Swift 5.0+ |
Usage
🚗 Original code.
lazy var ImageView: UIImageView = {
let imageView = UIImageView(image: originImage)
imageView.layer.borderColor = R.color("background2")?.cgColor
imageView.layer.borderWidth = 0.5
return imageView
}()
ImageView.image = originImage
🎷 Code zero intrusion add filter function.
let filter1 = C7ColorMatrix4x4(matrix: Matrix4x4.Color.sepia)
let filter2 = C7Granularity(grain: 0.8)
let filter3 = C7SoulOut(soul: 0.7)
let filters = [filter1, filter2, filter3]
// Use:
let dest = BoxxIO.init(element: originImage, filters: filters)
// Synchronize do something..
ImageView.image = try? dest.output()
// Asynchronous do something..
dest.transmitOutput(success: { [weak self] image in
DispatchQueue.main.async {
self?.ImageView.image = image
}
})
// OR Use:
ImageView.image = try? originImage.makeGroup(filters: filters)
// OR Use Operator:
ImageView.image = originImage ->> filter1 ->> filter2 ->> filter3
Camera
📸 Camera capture generates pictures.
// Add an edge detection filter:
let filter = C7EdgeGlow(lineColor: .red)
// Generate camera collector:
let camera = C7CollectorCamera.init(delegate: self)
camera.captureSession.sessionPreset = AVCaptureSession.Preset.hd1280x720
camera.filters = [filter]
extension CameraViewController: C7CollectorImageDelegate {
func preview(_ collector: C7Collector, fliter image: C7Image) {
// do something..
}
}
Video
📺 Local video or Network video are simply apply with filters.🙄 For details, See PlayerViewController.- You can also extend this by using BoxxIO to filter the collected
CVPixelBuffer
.
lazy var video: C7CollectorVideo = {
let videoURL = URL.init(string: "Link")!
let asset = AVURLAsset.init(url: videoURL)
let playerItem = AVPlayerItem.init(asset: asset)
let player = AVPlayer.init(playerItem: playerItem)
let video = C7CollectorVideo.init(player: player, delegate: self)
let filter = C7ColorMatrix4x4(matrix: Matrix4x4.Color.sepia)
video.filters = [filter]
return video
}()
self.video.play()
extension PlayerViewController: C7CollectorImageDelegate {
func preview(_ collector: C7Collector, fliter image: C7Image) {
// do something..
}
}
CocoaPods
- If you want to import Metal module, you need in your Podfile:
pod 'Harbeth'
- If you want to import OpenCV image module, you need in your Podfile:
pod 'OpencvQueen'
Swift Package Manager
Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
Xcode 11+ is required to build Harbeth using Swift Package Manager.
To integrate Harbeth into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift
:
dependencies: [
.package(url: "https://github.com/yangKJ/Harbeth.git", branch: "master"),
]
Remarks
The general process is almost like this, the Demo is also written in great detail, you can check it out for yourself.
🎷 Tip: If you find it helpful, please help me with a star. If you have any questions or needs, you can also issue.
Thanks.
🎇
About the author
🎷 E-mail address: [email protected]🎷 🎸 GitHub address: yangKJ🎸
Buy me a coffee or support me on GitHub.
License
Harbeth is available under the MIT license. See the LICENSE file for more info.