Messed upped the formatting in my previous answer. Here is the full code again:
func applyFilterChain(_ image: CIImage) -> CIImage {
// Create a filter (Photo effect)
let colorFilter: CIFilter = CIFilter(name: "CIPhotoEffectProcess", parameters: [kCIInputImageKey: image])!
// Apply second filter (Bloom) onto resulting image of first filter
let bloomImage: CIImage = colorFilter.outputImage!.applyingFilter("CIBloom", parameters: [kCIInputRadiusKey: 10.0, kCIInputIntensityKey: 1.0])
// Apply third filter (Exposure) from seconds filtered CIImage result
let exposeImage: CIImage = bloomImage.applyingFilter("CIExposureAdjust", parameters: [kCIInputEVKey: 1.0])
return exposeImage
}
Post
Replies
Boosts
Views
Activity
On the Apple documentation archive there is a section under the Core Image Programming Guide about 'Chaining Filters for Complex Effects'. It explains why chaining multiple filters should be done as follows to increase efficiency.[https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/CoreImaging/ci_tasks/ci_tasks.html]
Filter chain example in Swift:
// Create a filter (Photo effect)
let colorFilter: CIFilter = CIFilter(name: "CIPhotoEffectProcess", parameters: [kCIInputImageKey: image])!
// Apply second filter (Bloom) onto resulting image of first filter
let bloomImage: CIImage = colorFilter.outputImage!.applyingFilter("CIBloom", parameters: [kCIInputRadiusKey: 10.0, kCIInputIntensityKey: 1.0])
// Apply third filter (Exposure) from second's filtered CIImage result
let exposeImage: CIImage = bloomImage.applyingFilter("CIExposureAdjust", parameters: [kCIInputEVKey: 1.0])
return exposeImage
}
Please do note that the arrangement of the order of the chain affects the final image output. So putting 'filter A' before 'filter B' will result in something different opposed to 'filter A' after 'filter B'.