### Configuring Harbeth Performance and HarbethIO Source: https://context7.com/yangkj/harbeth/llms.txt Covers global device configuration for memory and concurrency, as well as HarbethIO settings for real-time processing. Includes examples for enabling double buffering and handling output results. ```swift import Harbeth Device.setMemoryLimitMB(256) Device.setMaxConcurrentRenderTasks(4) Device.setEnablePerformanceMonitor(true) var dest = HarbethIO(element: image, filters: filters) dest.enableDoubleBuffer = true dest.transmitOutputRealTimeCommit = true dest.bufferPixelFormat = .bgra8Unorm dest.mirrored = true dest.createDestTexture = true dest.transmitOutput { result in switch result { case .success(let output): DispatchQueue.main.async { self.imageView.image = output } case .failure(let error): print("Error: \(error)") } } if let stats = PerformanceMonitor.shared.getStatistics() { print("Average processing time: \(stats.averageTime)ms") } ``` -------------------------------- ### SwiftUI Integration with HarbethView Source: https://context7.com/yangkj/harbeth/llms.txt Shows how to use HarbethView for native SwiftUI image filtering with state-driven updates. Includes examples for basic filter application and advanced configuration using HarbethViewInput. ```swift import SwiftUI import Harbeth struct FilteredImageView: View { @State private var brightness: Float = 0.0 @State private var saturation: Float = 1.0 @State private var blur: Float = 0.0 let sourceImage = UIImage(named: "photo")! var body: some View { VStack { // HarbethView with dynamic filters HarbethView( image: sourceImage, filters: [ C7Brightness(brightness: brightness), C7Saturation(saturation: saturation), C7GaussianBlur(radius: blur) ] ) { image in image .resizable() .aspectRatio(contentMode: .fit) .cornerRadius(12) .shadow(radius: 5) } .frame(height: 300) // Interactive controls VStack(spacing: 16) { HStack { Text("Brightness") Slider(value: $brightness, in: -1...1) } HStack { Text("Saturation") Slider(value: $saturation, in: 0...2) } HStack { Text("Blur") Slider(value: $blur, in: 0...20) } } .padding() } } } // Using HarbethViewInput for more control struct AdvancedFilterView: View { let sourceImage = UIImage(named: "photo")! var body: some View { var input = HarbethViewInput(image: sourceImage) input.filters = [ C7ColorMatrix4x4(matrix: Matrix4x4.Color.sepia), C7Vignette(start: 0.3, end: 0.8) ] input.asynchronousProcessing = true input.placeholder = sourceImage return HarbethView(input: input) { image in image .resizable() .scaledToFit() } } } ``` -------------------------------- ### Install Harbeth via CocoaPods Source: https://github.com/yangkj/harbeth/blob/master/README.md Add the Harbeth dependency to your Podfile to integrate the library into your project. ```ruby pod 'Harbeth' ``` -------------------------------- ### Install Harbeth via Swift Package Manager Source: https://github.com/yangkj/harbeth/blob/master/README.md Add the Harbeth package to your Package.swift file dependencies to manage the library using Swift Package Manager. ```swift dependencies: [ .package(url: "https://github.com/yangKJ/Harbeth.git", branch: "master"), ] ``` -------------------------------- ### CoreImage Filter Integration with Harbeth in Swift Source: https://context7.com/yangkj/harbeth/llms.txt Illustrates how to use CoreImage filters within the Harbeth framework, enabling the combination of Metal-based Harbeth filters and CoreImage filters in a single processing chain. Includes examples for various CoreImage adjustments. ```swift import Harbeth // CoreImage brightness adjustment let ciBrightness = CIBrightness(brightness: 0.2) // CoreImage color controls let ciColorControls = CIColorControls( brightness: 0.1, contrast: 1.1, saturation: 1.2 ) // CoreImage Gaussian blur let ciGaussianBlur = CIGaussianBlur(radius: 10.0) // CoreImage exposure let ciExposure = CIExposure(ev: 0.5) // CoreImage photo effects let ciPhotoEffect = CIPhotoEffect(style: .noir) // CoreImage highlight adjustment let ciHighlight = CIHighlight(highlight: 0.8) // CoreImage shadows let ciShadows = CIShadows(shadows: 0.5) // CoreImage sharpening let ciSharpen = CISharpen(sharpness: 0.5) // CoreImage vignette let ciVignette = CIVignette(intensity: 0.5, radius: 1.0) // Mix CoreImage and Metal filters in same chain let mixedImage = originalImage ->> CIColorControls(brightness: 0.05, contrast: 1.1, saturation: 1.1) ->> C7GaussianBlur(radius: 2.0) // Metal filter ->> CIVignette(intensity: 0.3, radius: 1.2) ``` -------------------------------- ### Apply Artistic Stylization Effects Source: https://context7.com/yangkj/harbeth/llms.txt Provides examples of transforming images into artistic styles including oil painting, cartoon, and glitch effects. These filters are useful for creating unique visual aesthetics. ```swift import Harbeth let oilPainting = C7OilPainting(radius: 3, levels: 10) let toonFilter = C7Toon(threshold: 0.2, quantizationLevels: 10.0) let shiftGlitch = C7ShiftGlitch(time: 0.5, maxJitter: 0.03, enableGlitch: true, enableShift: true) let artisticImage = originalImage ->> C7Kuwahara(radius: 5) ->> C7Saturation(saturation: 1.3) ->> C7Contrast(contrast: 1.1) ``` -------------------------------- ### Configure and Process Images with HarbethIO Source: https://github.com/yangkj/harbeth/blob/master/README.md Demonstrates how to initialize HarbethIO with custom properties such as pixel format and double buffering, and how to execute image processing synchronously or asynchronously. ```swift // Custom configuration var dest = HarbethIO(element: image, filters: [filter1, filter2]) dest.bufferPixelFormat = .rgba8Unorm dest.enableDoubleBuffer = true _ = try? dest.output() // Asynchronous processing with custom configuration var dest = HarbethIO(element: image, filters: [filter1, filter2]) dest.transmitOutputRealTimeCommit = true dest.transmitOutput { result in switch result { case .success(let output): // Handle successful output case .failure(let error): // Handle error } } ``` -------------------------------- ### Implementing Custom Filters with C7FilterProtocol Source: https://context7.com/yangkj/harbeth/llms.txt Shows how to create a custom filter by implementing the C7FilterProtocol and defining a corresponding Metal kernel function. This allows for specialized image processing logic using custom shader parameters. ```swift import Harbeth import Metal public struct MyCustomFilter: C7FilterProtocol { public static let range: ParameterRange = .init(min: 0.0, max: 1.0, value: 0.5) @ZeroOneRange public var intensity: Float = range.value public var customValue: Float = 1.0 public var modifier: ModifierEnum { return .compute(kernel: "MyCustomKernel") } public var factors: [Float] { return [intensity, customValue] } public init(intensity: Float = range.value, customValue: Float = 1.0) { self.intensity = intensity self.customValue = customValue } } let customFilter = MyCustomFilter(intensity: 0.7, customValue: 0.3) let customResult = originalImage ->> customFilter ``` ```metal #include using namespace metal; kernel void MyCustomKernel( texture2d outputTexture [[texture(0)]], texture2d inputTexture [[texture(1)]], constant float *intensity [[buffer(0)]], constant float *customValue [[buffer(1)]], uint2 gid [[thread_position_in_grid]]) { half4 color = inputTexture.read(gid); half4 result = color * half(*intensity) + half(*customValue); outputTexture.write(result, gid); } ``` -------------------------------- ### Apply Edge Detection and Detail Enhancement Filters Source: https://context7.com/yangkj/harbeth/llms.txt Demonstrates how to use Harbeth's sharpening, edge detection, and sketch filters. These filters allow for precise control over image sharpness and artistic effects using a chainable operator syntax. ```swift import Harbeth let sharpenFilter = C7Sharpen(sharpness: 0.5) let edgeAwareSharpen = C7EdgeAwareSharpen(sharpness: 0.5, threshold: 0.1) let detailEnhancer = C7DetailEnhancer(intensity: 0.5) let clarityFilter = C7Clarity(clarity: 0.5) let sobelEdge = C7Sobel(edgeStrength: 1.0) let cannyEdge = C7Canny(threshold: 0.1, upperThreshold: 0.4) let edgeGlow = C7EdgeGlow(intensity: 1.0) let sketchFilter = C7Sketch(intensity: 1.0) let thresholdSketch = C7ThresholdSketch(threshold: 0.25) let crosshatch = C7Crosshatch(crossHatchSpacing: 0.03, lineWidth: 0.003) let grainFilter = C7Granularity(grain: 0.5) let sharpImage = originalImage ->> C7Clarity(clarity: 0.3) ->> C7EdgeAwareSharpen(sharpness: 0.4, threshold: 0.1) ->> C7DetailEnhancer(intensity: 0.2) ``` -------------------------------- ### Utility Filters Source: https://context7.com/yangkj/harbeth/llms.txt Demonstrates the usage of various utility filters for image manipulation, including highlight/shadow adjustment, levels, chroma keying, vignette, haze, and opacity. ```APIDOC ## Utility Filters Utility filters provide specialized adjustments for highlights, shadows, levels, chroma keying, and other practical image manipulation tasks. ### Highlight and Shadow Adjustment ```swift import Harbeth let highlightShadow = C7HighlightShadow(shadows: 0.5, highlights: 0.5) ``` ### Separate Highlight Control ```swift let highlightFilter = C7Highlights(highlights: 0.7) ``` ### Separate Shadow Control ```swift let shadowFilter = C7Shadows(shadows: 0.3) ``` ### Levels Adjustment ```swift let levelsFilter = C7Levels( minInput: 0.0, maxInput: 1.0, minOutput: 0.1, maxOutput: 0.9, gamma: 1.0 ) ``` ### Luminance Threshold ```swift let thresholdFilter = C7LuminanceThreshold(threshold: 0.5) ``` ### Chroma Key ```swift let chromaKey = C7ChromaKey( thresholdSensitivity: 0.4, smoothing: 0.1, colorToReplace: .green ) ``` ### Vignette Effect ```swift let vignetteFilter = C7Vignette(start: 0.3, end: 0.8, color: .black) ``` ### Haze Effect ```swift let hazeFilter = C7Haze(distance: 0.2, slope: 0.0) ``` ### Opacity Adjustment ```swift let opacityFilter = C7Opacity(opacity: 0.8) ``` ### Fade Effect ```swift let fadeFilter = C7Fade(intensity: 0.3) ``` ### Applying Utility Adjustments ```swift let enhancedImage = originalImage ->> C7HighlightShadow(shadows: 0.4, highlights: 0.6) ->> C7Levels(minInput: 0.05, maxInput: 0.95, gamma: 1.1) ->> C7Vignette(start: 0.4, end: 0.9) ``` ``` -------------------------------- ### Matrix-Based Color Transformations in Swift Source: https://context7.com/yangkj/harbeth/llms.txt Shows how to apply 4x4 matrix transformations for advanced color effects using `C7ColorMatrix4x4`. This includes common presets like sepia, grayscale, and color inversion, as well as custom transformations and color grading. These filters are powerful for achieving specific aesthetic looks. ```swift import Harbeth // Sepia tone (vintage brown effect) let sepiaFilter = C7ColorMatrix4x4(matrix: Matrix4x4.Color.sepia) // Grayscale conversion let grayFilter = C7ColorMatrix4x4(matrix: Matrix4x4.Color.gray) // Black and white based on human eye sensitivity let bwFilter = C7ColorMatrix4x4(matrix: Matrix4x4.Color.blackAndWhite) // Color inversion (negative) let invertFilter = C7ColorMatrix4x4(matrix: Matrix4x4.Color.invert) // Nostalgic/vintage effect let nostalgicFilter = C7ColorMatrix4x4(matrix: Matrix4x4.Color.nostalgic) // Warm color tone let warmFilter = C7ColorMatrix4x4(matrix: Matrix4x4.Color.warm) // Cool color tone let coolFilter = C7ColorMatrix4x4(matrix: Matrix4x4.Color.cool) // Polaroid color effect let polaroidFilter = C7ColorMatrix4x4(matrix: Matrix4x4.Color.polaroid) // Vibrance enhancement let vibranceMatrix = C7ColorMatrix4x4(matrix: Matrix4x4.Color.vibrance) // Custom matrix with intensity control var customFilter = C7ColorMatrix4x4(matrix: Matrix4x4.Color.sepia, intensity: 0.7) // Rotate colors around blue axis let blueRotate = C7ColorMatrix4x4(matrix: Matrix4x4.Color.axix_blue_rotate(30.0)) // Apply vintage film look let vintageImage = originalImage ->> C7ColorMatrix4x4(matrix: Matrix4x4.Color.nostalgic) ->> C7Granularity(grain: 0.4) ->> C7Vignette(start: 0.4, end: 0.9) ``` -------------------------------- ### Utilizing Metal Performance Shaders (MPS) for Image Processing Source: https://context7.com/yangkj/harbeth/llms.txt Demonstrates how to apply highly optimized MPS filters like Gaussian blur, median filters, and Canny edge detection. These filters leverage Apple's hardware-accelerated shaders for maximum GPU efficiency. ```swift import Harbeth let mpsGaussianBlur = MPSGaussianBlur(sigma: 10.0) let mpsBoxBlur = MPSBoxBlur(kernelWidth: 5, kernelHeight: 5) let mpsMedian = MPSMedian(diameter: 3) let mpsCanny = MPSCanny() let mpsHistogram = MPSHistogram() let fastBlurredImage = originalImage ->> MPSGaussianBlur(sigma: 15.0) ``` -------------------------------- ### Apply Blend Modes with Harbeth Source: https://context7.com/yangkj/harbeth/llms.txt Demonstrates how to apply various blend modes such as multiply, screen, and overlay to combine images. It also shows how to update filter parameters dynamically and use the operator syntax for chaining. ```swift import Harbeth let overlayImage = UIImage(named: "overlay")! let normalBlend = C7Blend(with: .normal, image: overlayImage, intensity: 0.5) let multiplyBlend = C7Blend(with: .multiply, image: overlayImage, intensity: 1.0) let updatedBlend = normalBlend.updateBlend(.overlay).updateIntensity(0.6) let blendedImage = baseImage ->> C7Blend(with: .overlay, image: textureImage, intensity: 0.5) ``` -------------------------------- ### Apply Color Adjustment Filters in Swift Source: https://context7.com/yangkj/harbeth/llms.txt Demonstrates how to use various color adjustment filters such as brightness, contrast, saturation, exposure, vibrance, hue, white balance, and HSL. These filters modify fundamental color properties of an image. They can be applied individually or chained for combined effects. ```swift import Harbeth // Brightness: -1.0 to 1.0, default 0.0 let brightnessFilter = C7Brightness(brightness: 0.3) // Contrast: 0.0 to 2.0, default 1.0 let contrastFilter = C7Contrast(contrast: 1.4) // Saturation: 0.0 (grayscale) to 2.0 (highly saturated), default 1.0 let saturationFilter = C7Saturation(saturation: 1.3) // Exposure: -10.0 to 10.0, default 0.0 let exposureFilter = C7Exposure(exposure: 1.5) // Vibrance: -1.2 to 1.2, intelligent saturation preserving skin tones let vibranceFilter = C7Vibrance(vibrance: 0.6) // Hue rotation: 0 to 360 degrees let hueFilter = C7Hue(hue: 45.0) // White balance adjustment let whiteBalanceFilter = C7WhiteBalance(temperature: 5500, tint: 0.0) // HSL adjustment for precise color control let hslFilter = C7HSL(hue: 0.0, saturation: 1.2, lightness: 0.1) // Apply combined color adjustments let colorCorrectedImage = originalImage ->> C7Brightness(brightness: 0.1) ->> C7Contrast(contrast: 1.2) ->> C7Saturation(saturation: 1.1) ->> C7Vibrance(vibrance: 0.3) ``` -------------------------------- ### Implement Professional Color Grading with LUTs Source: https://context7.com/yangkj/harbeth/llms.txt Shows how to apply 2D lookup tables and 3D CUBE files to images. It includes methods for loading resources from bundles or URLs and chaining color adjustments. ```swift import Harbeth let lutImage = UIImage(named: "lut_vintage")! let lookupFilter = C7LookupTable(image: lutImage, intensity: 1.0) let cubeFilter = C7ColorCube(cubeName: "cinematic", bundle: .main, intensity: 1.0) if let cubeURL = Bundle.main.url(forResource: "film_stock", withExtension: "cube") { let urlCubeFilter = C7ColorCube(cubeURL: cubeURL, intensity: 0.8) let gradedImage = originalImage ->> urlCubeFilter } let adjustedCube = cubeFilter.updateIntensity(0.7) if let resource = C7ColorCube.Resource.readCubeResource("vintage_film", bundle: .main) { let reusableFilter = C7ColorCube(cubeResource: resource, intensity: 0.9) } let highQualityLUT = C7LookupTable512x512(image: lutImage, intensity: 1.0) let colorGradedImage = originalImage ->> C7ColorCube(cubeName: "hollywood", intensity: 0.8) ->> C7Contrast(contrast: 1.05) ->> C7Vignette(start: 0.5, end: 1.0) ``` -------------------------------- ### Chain Filters Using Operator Chaining Source: https://github.com/yangkj/harbeth/blob/master/README.md Illustrates an expressive method for applying filters by chaining them together using the '->>' operator. This allows for a more readable and intuitive way to apply a sequence of image transformations. ```swift // Chain filters with intuitive operators ImageView.image = originImage ->> filter1 ->> filter2 ->> filter3 ``` -------------------------------- ### Image Extension Method - `make(filters:)` Source: https://context7.com/yangkj/harbeth/llms.txt The `make(filters:)` extension method provides a concise way to apply filters directly on image objects like UIImage or NSImage. ```APIDOC ## Image Extension Method - `make(filters:)` ### Description The `make(filters:)` extension method provides the most concise way to apply filters directly on image objects. ### Method Extension method on image types (e.g., UIImage, NSImage) ### Endpoint N/A (Extension method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **filters** ([C7FilterProtocol]) - Required - An array of filters to apply to the image. ### Request Example ```swift import Harbeth // Direct extension method on UIImage/NSImage let filters: [C7FilterProtocol] = [ C7Brightness(brightness: 0.1), C7Vibrance(vibrance: 0.5), C7Granularity(grain: 0.3) ] // Apply filters directly to image if let processedImage = try? originalImage.make(filters: filters) { imageView.image = processedImage } // Single filter application if let vintageImage = try? photo.make(filters: [ C7ColorMatrix4x4(matrix: Matrix4x4.Color.nostalgic) ]) { displayImage(vintageImage) } ``` ### Response #### Success Response (200) - **processedImage** (UIImage/NSImage) - The processed image object. #### Response Example ```json { "example": "UIImage object after applying multiple filters" } ``` ``` -------------------------------- ### Image Extension Method for Filters (Swift) Source: https://context7.com/yangkj/harbeth/llms.txt Shows the concise `make(filters:)` extension method available on image objects (like UIImage/NSImage) for applying a list of filters directly. This provides a streamlined approach for image manipulation. ```swift import Harbeth // Direct extension method on UIImage/NSImage let filters: [C7FilterProtocol] = [ C7Brightness(brightness: 0.1), C7Vibrance(vibrance: 0.5), C7Granularity(grain: 0.3) ] // Apply filters directly to image if let processedImage = try? originalImage.make(filters: filters) { imageView.image = processedImage } // Single filter application if let vintageImage = try? photo.make(filters: [ C7ColorMatrix4x4(matrix: Matrix4x4.Color.nostalgic) ]) { displayImage(vintageImage) } ``` -------------------------------- ### HarbethIO: Core Image Processing Engine (Swift) Source: https://context7.com/yangkj/harbeth/llms.txt Demonstrates the use of the `HarbethIO` struct for applying filters to images and video frames. It covers both synchronous and asynchronous processing, including options for enabling double buffering and real-time output transmission for video streams. Input can be various image types like MTLTexture, UIImage, CIImage, etc. ```swift import Harbeth // Basic synchronous processing let brightnessFilter = C7Brightness(brightness: 0.3) let contrastFilter = C7Contrast(contrast: 1.2) let saturationFilter = C7Saturation(saturation: 1.1) let filters: [C7FilterProtocol] = [brightnessFilter, contrastFilter, saturationFilter] let dest = HarbethIO(element: originalImage, filters: filters) // Synchronous output - blocks until processing is complete if let processedImage = try? dest.output() { imageView.image = processedImage } // Or use filtered() which returns original on failure let safeResult = dest.filtered() // Asynchronous processing for better performance var asyncDest = HarbethIO(element: originalImage, filters: filters) asyncDest.enableDoubleBuffer = true // Better memory efficiency for 4+ filters asyncDest.transmitOutputRealTimeCommit = true // For camera/video streams asyncDest.transmitOutput { switch result { case .success(let image): DispatchQueue.main.async { self.imageView.image = image } case .failure(let error): print("Processing failed: \(error)") } } ``` -------------------------------- ### Harbeth Utility Filters in Swift Source: https://context7.com/yangkj/harbeth/llms.txt Demonstrates the usage of various utility filters in Harbeth for image adjustments like highlight/shadow control, levels mapping, chroma keying, vignette, haze, and opacity. These filters can be chained for complex image processing. ```swift import Harbeth // Highlight and shadow adjustment let highlightShadow = C7HighlightShadow(shadows: 0.5, highlights: 0.5) // Separate highlight control let highlightFilter = C7Highlights(highlights: 0.7) // Separate shadow control let shadowFilter = C7Shadows(shadows: 0.3) // Levels adjustment (input/output range mapping) let levelsFilter = C7Levels( minInput: 0.0, maxInput: 1.0, minOutput: 0.1, maxOutput: 0.9, gamma: 1.0 ) // Luminance threshold (high contrast B&W) let thresholdFilter = C7LuminanceThreshold(threshold: 0.5) // Chroma key (green screen removal) let chromaKey = C7ChromaKey( thresholdSensitivity: 0.4, smoothing: 0.1, colorToReplace: .green ) // Vignette effect (darkened edges) let vignetteFilter = C7Vignette(start: 0.3, end: 0.8, color: .black) // Haze effect (foggy atmosphere) let hazeFilter = C7Haze(distance: 0.2, slope: 0.0) // Opacity adjustment let opacityFilter = C7Opacity(opacity: 0.8) // Fade effect let fadeFilter = C7Fade(intensity: 0.3) // Apply utility adjustments let enhancedImage = originalImage ->> C7HighlightShadow(shadows: 0.4, highlights: 0.6) ->> C7Levels(minInput: 0.05, maxInput: 0.95, gamma: 1.1) ->> C7Vignette(start: 0.4, end: 0.9) ``` -------------------------------- ### Apply Filters Synchronously with HarbethIO Source: https://github.com/yangkj/harbeth/blob/master/README.md Demonstrates synchronous image processing using HarbethIO by applying a series of filters (ColorMatrix, Granularity, SoulOut) to an origin image. The output is then assigned to an ImageView. This method is recommended for batch processing. ```swift let filter1 = C7ColorMatrix4x4(matrix: Matrix4x4.Color.sepia) let filter2 = C7Granularity(grain: 0.8) let filter3 = C7SoulOut(soul: 0.7) let filters = [filter1, filter2, filter3] // Synchronous processing let dest = HarbethIO(element: originImage, filters: filters) ImageView.image = try? dest.output() ``` -------------------------------- ### Apply Filters Directly Using Image Extension Source: https://github.com/yangkj/harbeth/blob/master/README.md Shows the most concise way to apply filters to an image using a direct extension method. This approach applies a predefined array of filters to an image and updates the ImageView with the processed result. ```swift // Apply filters directly to image ImageView.image = try? originImage.make(filters: filters) ``` -------------------------------- ### SwiftUI Integration with HarbethView Source: https://context7.com/yangkj/harbeth/llms.txt Explains how to use `HarbethView` for integrating Harbeth filters into SwiftUI applications, enabling dynamic filter application and state-driven updates. ```APIDOC ## SwiftUI Integration with HarbethView `HarbethView` provides native SwiftUI support for applying filters to images with state-driven updates and declarative syntax. ### Basic HarbethView Usage ```swift import SwiftUI import Harbeth struct FilteredImageView: View { @State private var brightness: Float = 0.0 @State private var saturation: Float = 1.0 @State private var blur: Float = 0.0 let sourceImage = UIImage(named: "photo")! var body: some View { VStack { HarbethView( image: sourceImage, filters: [ C7Brightness(brightness: brightness), C7Saturation(saturation: saturation), C7GaussianBlur(radius: blur) ] ) { // Image modifiers image .resizable() .aspectRatio(contentMode: .fit) .cornerRadius(12) .shadow(radius: 5) } .frame(height: 300) // Interactive controls VStack(spacing: 16) { HStack { Text("Brightness") Slider(value: $brightness, in: -1...1) } HStack { Text("Saturation") Slider(value: $saturation, in: 0...2) } HStack { Text("Blur") Slider(value: $blur, in: 0...20) } } .padding() } } } ``` ### Advanced HarbethView with Input Object ```swift import SwiftUI import Harbeth struct AdvancedFilterView: View { let sourceImage = UIImage(named: "photo")! var body: some View { var input = HarbethViewInput(image: sourceImage) input.filters = [ C7ColorMatrix4x4(matrix: Matrix4x4.Color.sepia), C7Vignette(start: 0.3, end: 0.8) ] input.asynchronousProcessing = true input.placeholder = sourceImage return HarbethView(input: input) { image .resizable() .scaledToFit() } } } ``` ``` -------------------------------- ### Apply Image Filters with Harbeth on macOS Source: https://github.com/yangkj/harbeth/blob/master/README.md Demonstrates how to apply a chain of image filters (brightness, contrast, saturation) to an NSImage using the Harbeth framework in Swift. It utilizes HarbethIO for processing and handles asynchronous operations for large images, updating an NSImageView upon completion. Error handling for the filter process is also included. ```swift import Cocoa import Harbeth class ImageProcessingViewController: NSViewController { @IBOutlet weak var imageView: NSImageView! func applyFilter(to image: NSImage) { // Create filter chain let filters: [C7FilterProtocol] = [ C7Brightness(brightness: 0.1), C7Contrast(contrast: 1.2), C7Saturation(saturation: 1.1) ] // Process image using HarbethIO let dest = HarbethIO(element: image, filters: filters) // Asynchronous processing for large images dest.transmitOutput { [weak self] result in switch result { case .success(let output): DispatchQueue.main.async { self?.imageView.image = output } case .failure(let error): print("Filter application failed: \(error)") } } } } ``` -------------------------------- ### SwiftUI Image Filtering with HarbethView Source: https://github.com/yangkj/harbeth/blob/master/README.md Demonstrates how to use `HarbethView` in SwiftUI to apply real-time image filters. It takes a `UIImage` as input and a list of `CIHighlight` and `C7WaterRipple` filters, with adjustable intensity via a `Slider`. The output image can be further customized with standard SwiftUI modifiers. ```swift import SwiftUI import Harbeth struct FilteredImageView: View { @State private var inputImage: UIImage = UIImage(named: "sample")! @State private var intensity: Float = 0.5 var body: some View { VStack { HarbethView(image: inputImage, filters: [ CIHighlight(highlight: intensity), C7WaterRipple(ripple: intensity), ]) { image in image .resizable() .aspectRatio(contentMode: .fit) .cornerRadius(12) .shadow(radius: 5) } Slider(value: $intensity, in: 0...1) .padding() } .padding() } } ``` -------------------------------- ### Perform Asynchronous Image Processing Source: https://github.com/yangkj/harbeth/blob/master/README.md Demonstrates asynchronous image processing using HarbethIO with a completion handler. This method is suitable for large images or real-time scenarios to prevent blocking the main thread. The processed image is updated on the main thread upon successful completion. ```swift let dest = HarbethIO(element: sourceImage, filters: filters) dest.transmitOutput { [weak self] result in switch result { case .success(let image): DispatchQueue.main.async { self?.imageView.image = image } case .failure(let error): print("Processing failed: \(error)") } } ``` -------------------------------- ### CoreImage Integration Source: https://context7.com/yangkj/harbeth/llms.txt Illustrates how Harbeth integrates with CoreImage filters, enabling the combination of Metal and CoreImage processing within a single filter chain. ```APIDOC ## CoreImage Integration Harbeth seamlessly integrates with CoreImage filters, allowing you to combine Metal and CoreImage processing in the same filter chain. ### CoreImage Filter Examples ```swift import Harbeth // CoreImage brightness adjustment let ciBrightness = CIBrightness(brightness: 0.2) // CoreImage color controls let ciColorControls = CIColorControls( brightness: 0.1, contrast: 1.1, saturation: 1.2 ) // CoreImage Gaussian blur let ciGaussianBlur = CIGaussianBlur(radius: 10.0) // CoreImage exposure let ciExposure = CIExposure(ev: 0.5) // CoreImage photo effects let ciPhotoEffect = CIPhotoEffect(style: .noir) // CoreImage highlight adjustment let ciHighlight = CIHighlight(highlight: 0.8) // CoreImage shadows let ciShadows = CIShadows(shadows: 0.5) // CoreImage sharpening let ciSharpen = CISharpen(sharpness: 0.5) // CoreImage vignette let ciVignette = CIVignette(intensity: 0.5, radius: 1.0) ``` ### Mixing CoreImage and Metal Filters ```swift let mixedImage = originalImage ->> CIColorControls(brightness: 0.05, contrast: 1.1, saturation: 1.1) ->> C7GaussianBlur(radius: 2.0) // Metal filter ->> CIVignette(intensity: 0.3, radius: 1.2) ``` ``` -------------------------------- ### Implement Distortion and Warp Effects Source: https://context7.com/yangkj/harbeth/llms.txt Covers applying spatial transformations like water ripples, bulges, and pixelation. These filters allow for creative geometric manipulation of image textures. ```swift import Harbeth var waterRipple = C7WaterRipple(ripple: 0.5, boundary: 0.06) waterRipple.touchCenter = C7Point2D(x: 0.5, y: 0.5) let bulgeFilter = C7Bulge(radius: 0.5, scale: 0.5, center: C7Point2D.center) let pixelFilter = C7Pixellated(pixelWidth: 10, pixelHeight: 10) let distortedImage = originalImage ->> C7WaterRipple(ripple: 0.3) ->> C7Brightness(brightness: 0.05) ``` -------------------------------- ### Filter Chaining Operators (Swift) Source: https://context7.com/yangkj/harbeth/llms.txt Illustrates Harbeth's expressive filter chaining using the `->>` and `-->>>` operators. The `->>` operator applies a single filter, while `-->>>` applies an array of filters. This method supports chaining with various input types like CGImage, CIImage, and MTLTexture. ```swift import Harbeth // Single filter operator: ->> let sepiaImage = originalImage ->> C7ColorMatrix4x4(matrix: Matrix4x4.Color.sepia) // Chain multiple filters with ->> let styledImage = originalImage ->> C7Brightness(brightness: 0.2) ->> C7Contrast(contrast: 1.3) ->> C7GaussianBlur(radius: 5.0) ->> C7Vignette(start: 0.3, end: 0.8) // Array operator for batch processing: -->>> let filterStack: [C7FilterProtocol] = [ C7Exposure(exposure: 0.5), C7Saturation(saturation: 1.2), C7Sharpen(sharpness: 0.3) ] let enhancedImage = originalImage -->>> filterStack // Works with various input types let cgImageResult: CGImage = cgImage ->> C7Sepia(intensity: 0.8) let ciImageResult: CIImage = ciImage ->> C7GaussianBlur(radius: 10) let textureResult: MTLTexture = metalTexture ->> C7Brightness(brightness: 0.5) ``` -------------------------------- ### Blur Effects Filters Source: https://github.com/yangkj/harbeth/blob/master/README.md A collection of filters for applying various blur effects to images, including Gaussian, motion, and tilt-shift blurs. ```APIDOC ## Blur Effects Filters ### Description These filters provide various blurring techniques to smooth images, preserve edges, or simulate camera effects like motion or shallow depth of field. ### Method N/A (Library Class Methods) ### Parameters - **C7GaussianBlur** (float) - Blur radius - Applies standard Gaussian blur. - **C7MotionBlur** (float, float) - Radius and Angle - Simulates motion blur. - **C7TiltShift** (float, float) - Focus area and blur intensity - Simulates shallow depth of field. - **C7BilateralBlur** (float) - Blur radius - Blurs while preserving edges. ### Response Returns a processed image buffer with the applied blur effect. ``` -------------------------------- ### Color Adjustment Filters Source: https://github.com/yangkj/harbeth/blob/master/README.md A collection of filters for adjusting color properties such as brightness, contrast, saturation, and color space transformations. ```APIDOC ## Color Adjustment Filters ### Description These filters allow for precise color manipulation, including tonal curves, white balance, and channel-specific adjustments. ### Method N/A (Library Class Methods) ### Parameters - **C7Brightness** (float) - -1.0 to 1.0 - Adjusts overall brightness. - **C7Contrast** (float) - 0.0 to 2.0 - Adjusts image contrast. - **C7Saturation** (float) - 0.0 to 2.0 - Adjusts color intensity. - **C7Exposure** (float) - -10.0 to 10.0 - Simulates camera exposure. - **C7Temperature** (object) - Adjusts color temperature and tint. ### Response Returns a processed image buffer with the applied filter. ``` -------------------------------- ### Filter Chaining Operators Source: https://context7.com/yangkj/harbeth/llms.txt Harbeth provides intuitive operators (`->>` and `-->>>`) for chaining filters in expressive, readable code. ```APIDOC ## Filter Chaining Operators ### Description Harbeth provides intuitive operators for chaining filters in expressive, readable code. The `->>` operator applies a single filter, while `-->>>` applies an array of filters. ### Method Operator overloading for filter application ### Endpoint N/A (Operator) ### Parameters None ### Request Example ```swift import Harbeth // Single filter operator: ->> let sepiaImage = originalImage ->> C7ColorMatrix4x4(matrix: Matrix4x4.Color.sepia) // Chain multiple filters with ->> let styledImage = originalImage ->> C7Brightness(brightness: 0.2) ->> C7Contrast(contrast: 1.3) ->> C7GaussianBlur(radius: 5.0) ->> C7Vignette(start: 0.3, end: 0.8) // Array operator for batch processing: -->>> let filterStack: [C7FilterProtocol] = [ C7Exposure(exposure: 0.5), C7Saturation(saturation: 1.2), C7Sharpen(sharpness: 0.3) ] let enhancedImage = originalImage -->>> filterStack // Works with various input types let cgImageResult: CGImage = cgImage ->> C7Sepia(intensity: 0.8) let ciImageResult: CIImage = ciImage ->> C7GaussianBlur(radius: 10) let textureResult: MTLTexture = metalTexture ->> C7Brightness(brightness: 0.5) ``` ### Response #### Success Response (200) - **processedImage** (UIImage/NSImage/CIImage/CGImage/MTLTexture) - The image or video frame after applying the filter(s). #### Response Example ```json { "example": "UIImage object after applying sepia filter" } ``` ``` -------------------------------- ### Perform Geometric Transformations Source: https://context7.com/yangkj/harbeth/llms.txt Covers spatial operations such as resizing, rotating, flipping, and cropping. These filters utilize normalized coordinates and standard affine transforms to manipulate image geometry. ```swift import Harbeth let resizeFilter = C7Resize(width: 800, height: 600) let rotateFilter = C7Rotate(angle: Degree(45.0)) let horizontalFlip = C7Flip(horizontal: true, vertical: false) let verticalFlip = C7Flip(horizontal: false, vertical: true) let mirrorFilter = C7Mirror(horizontal: true) let cropFilter = C7Crop(origin: CGPoint(x: 0.1, y: 0.1), size: CGSize(width: 0.8, height: 0.8)) let transform = CGAffineTransform(scaleX: 0.5, y: 0.5).rotated(by: .pi / 4) let transformFilter = C7Transform(transform: transform) let transformedImage = originalImage ->> C7Resize(width: 1920, height: 1080) ->> C7Rotate(angle: Degree(15.0)) ->> C7Crop(origin: CGPoint(x: 0.05, y: 0.05), size: CGSize(width: 0.9, height: 0.9)) ``` -------------------------------- ### Blur Effects Source: https://context7.com/yangkj/harbeth/llms.txt Filters for applying various blur effects, including Gaussian, motion, zoom, and selective focus (tilt-shift). ```APIDOC ## Blur Effects ### Description Provides a variety of blur algorithms to achieve different artistic effects, from smooth blurs to selective focus. ### Parameters - **C7GaussianBlur** (Float) - Blur radius (0-100) - **C7MotionBlur** (Float, Float) - Radius and angle for motion blur - **C7TiltShift** (Float, Float, Float, Float) - Parameters for miniature effect (radius, top/bottom levels, falloff) ### Request Example let gaussianBlur = C7GaussianBlur(radius: 15.0) ``` -------------------------------- ### Apply Blur Effects in Swift Source: https://context7.com/yangkj/harbeth/llms.txt Illustrates the use of various blur filters available in Harbeth, including Gaussian, motion, zoom, bilateral, tilt-shift, and circle blurs. These filters are used to create different types of blur effects, from subtle smoothing to artistic distortions. They can be chained to achieve complex visual styles. ```swift import Harbeth // Gaussian blur: radius 0-100, default 10 let gaussianBlur = C7GaussianBlur(radius: 15.0) // Motion blur with direction let motionBlur = C7MotionBlur(radius: 10.0, angle: 45.0) // Zoom blur emanating from center let zoomBlur = C7ZoomBlur(blurSize: 5.0, center: C7Point2D(x: 0.5, y: 0.5)) // Bilateral blur preserving edges let bilateralBlur = C7BilateralBlur(radius: 8.0) // Tilt-shift for selective focus (miniature effect) let tiltShift = C7TiltShift( blurRadius: 10.0, topFocusLevel: 0.3, bottomFocusLevel: 0.7, focusFallOffRate: 0.2 ) // Circle blur effect let circleBlur = C7CircleBlur(radius: 12.0, center: C7Point2D.center) // Apply blur chain for dreamy effect let dreamyImage = originalImage ->> C7GaussianBlur(radius: 5.0) ->> C7Brightness(brightness: 0.1) ->> C7Saturation(saturation: 0.9) ```