I have try this:
CIFilter *dodgeFilter = [CIFilter filterWithName:@"CIColorDodgeBlendMode"];
to replace:
GPUImageDivideBlendFilter *divideBlendFilter = [[GPUImageDivideBlendFilter alloc] init];
but the effects are not same.
Also—and I know this doesn't relate to the question, but I feel like this should be pointed out—the kernel code has one thing backwards, specifically, the premultiply-related functions. Unpremultiply any sampler (or color) object when working with the alpha channel independently from the remaining three; recombine them with premultiply when you have the finished product. Do neither if you are not changing or mixing or otherwise using two sampler (or color) objects in your calculations.
Builtin filter
Have you tried with
CIDivideBlendMode
?Custom filter
I thought it would be fun to try to create a custom
CIFilter
based on an existing GPUImageFilter now that iOS8 allows us to do so. This should allow to translate anyGPUImageFilter
to itsCIFilter
counterpart.Before starting it's worth checking out What You Need to Know Before Writing a Custom Filter and Core Image Kernel Language Reference
We'll start by writing our custom kernel which will be very similar to the
GPUImageDivideBlendFilter
shader. The one exception is the control flow part that seems unsupported in the Core Image Kernel language which we'll workaround using the*_branch1
and*_branch2
multipliers.Creating a CIFilter is simple:
Create a new
ImageDivideBlendFilter.cikernel
(your custom filter kernel) file to your Xcode project:Add the interface and implementation for your filter
We're ready to use our newly created custom filter in our application
Builtin and custom filter produce the same result.
Edit: Swift version
I made a sample project available on Github https://github.com/tcamin/CustomCoreImageFilteringDemo that shows how to make CIFiltering in Swift.