MetalImage is an iOS image and video processing framework built on Apple Metal.
It follows the chaining style of GPUImage, but replaces the OpenGL ES rendering path with Metal and ships a large set of filters, blend modes, and image-processing operators.
- Metal-based rendering pipeline for camera, image, and intermediate texture processing
- Chainable node model built around
MetalImageOutput->MetalImageInput - Real-time camera processing via
MetalImageVideoCamera - On-screen rendering via
MetalImageView/MetalImageDebugView - Static image processing via
MetalImagePicture - Rich built-in filters, including:
- Color adjustment:
MIBrightnessFilter,MIContrastFilter,MISaturationFilter,MILookupFilter - Image processing:
MIGaussianBlurFilter,MIBilateralFilter,MIMedianFilter,MICannyEdgeDetectionFilter - Blend filters:
MIOverlayBlendFilter,MIScreenBlendFilter,MIAlphaBlendFilter - Effects:
MISwirlFilter,MIPixellateFilter,MIVignetteFilter,MIKuwaharaFilter - Matrix helpers:
MetalMatrixMult,BlasMatrixMult
- Color adjustment:
All public headers are exported through:
#import <MetalImage/MetalImage.h>| Item | Requirement |
|---|---|
| Platform | iOS |
| Deployment target | iOS 9.0+ |
| Hardware | Metal-capable physical device |
| Architecture | arm64 device runtime |
| Camera features | Require camera permission and supported hardware |
The framework does not support the iOS Simulator.
MetalImage.xcodeproj Xcode project
Framework/MetalImage/ Framework root
Framework/MetalImage/MetalImage/Color/ Color-related filters
Framework/MetalImage/MetalImage/ImageProcessing/
Blur, edge detection, morphology, transforms
Framework/MetalImage/MetalImage/Blend/ Blend filters
Framework/MetalImage/MetalImage/Effects/ Stylized and distortion effects
Framework/MetalImage/MetalImage/Matrix/ Matrix acceleration helpers
Example/MetalImageDemo/ Demo app sources and assets
MetalImageShader Metal shader library target
This repository now separates the reusable framework code from the runnable example:
Framework/MetalImage/: headers, sources, resources, and framework plistExample/MetalImageDemo/: app entry, UI, assets, and example plist
You can integrate MetalImage in two ways:
- Swift Package Manager
- In Xcode, choose Add Package Dependencies...
- Use this repository URL
- Link the
MetalImageproduct to your iOS app target
- Open the sample project
- Open
MetalImage.xcodeproj - Select the
MetalImageDemoscheme and a physical iOS device - Build and run
- Open
SwiftPM support is source-based and packages the framework's Metal shaders with the target. Camera-based features still require NSCameraUsageDescription, and runtime use still targets Metal-capable iOS devices rather than the simulator.
#import <MetalImage/MetalImage.h>
UIImage *image = [UIImage imageNamed:@"sample"];
MetalImagePicture *source = [[MetalImagePicture alloc] initWithImage:image];
MIBrightnessFilter *brightness = [[MIBrightnessFilter alloc] init];
brightness.brightness = 0.1;
MIGaussianBlurFilter *blur = [[MIGaussianBlurFilter alloc] init];
blur.radius = 4;
MetalImageView *renderView = [[MetalImageView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:renderView];
[source addTarget:brightness];
[brightness addTarget:blur];
[blur addTarget:renderView];
[source processImage];#import <MetalImage/MetalImage.h>
MetalImageView *renderView = [[MetalImageView alloc] initWithFrame:self.view.bounds];
renderView.fillMode = kMetalImageFillModePreserveAspectRatio;
[self.view addSubview:renderView];
MetalImageVideoCamera *camera =
[[MetalImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset1280x720
cameraPosition:AVCaptureDevicePositionFront];
camera.outputImageOrientation = UIInterfaceOrientationPortrait;
camera.horizontallyMirrorFrontFacingCamera = YES;
MIBilateralFilter *bilateral = [[MIBilateralFilter alloc] init];
MIMedianFilter *median = [[MIMedianFilter alloc] init];
[camera addTarget:bilateral];
[bilateral addTarget:median];
[median addTarget:renderView];
[camera startCameraCapture];For filters derived from MetalImageTwoInputFilter such as MILookupFilter, use addTarget:atTextureLocation: to bind the secondary texture input.
| Type | Role |
|---|---|
MetalImageOutput |
Upstream node that produces textures |
MetalImageInput |
Consumer protocol for downstream nodes |
MetalImageFilter |
Base class for most single-input filters |
MetalImageTwoInputFilter |
Base class for blend / LUT / dual-texture filters |
MetalImageFilterGroup |
Composite pipeline wrapper |
MetalImagePicture |
Static image source |
MetalImageVideoCamera |
Camera frame source |
MetalImageView |
Final display view |
- The demo app shows the intended real-time filter-chain usage.
MetalImageDebugViewcan be used when you need a debug-oriented render target.- Most filters map one-to-one to a
.metalshader file in the repository, which makes extension straightforward.
Feng Shi
redpark@qq.com
MIT. See LICENSE.