CIFilter
An image processor that produces an image by manipulating one or more input images or by generating new image data.
Declaration
class CIFilterMentioned in
Overview
The CIFilter class produces a CIImage object as output. Typically, a filter takes one or more images as input. Some filters, however, generate an image based on other types of input parameters. The parCIFilter swift.class` object are set and retrieved through the use of key-value pairs.
You use the CIFilter object in conjunction with other Core Image classes, such as CIImage, CIContext, and CIColor, to take advantage of the built-in Core Image filters when processing images, creating filter generators, or writing custom filters.
CIFilter objects are mutable, and thus cannot be shared safely among threads. Each thread must create its own CIFilter objects, but you can pass a filter’s immutable input and output CIImage objects between threads.
To get a quick overview of how to set up and use Core Image filters, see Core Image Programming Guide.
Create type-safe filters
Core Image provides methods that create type-safe CIFilter instances. Use these filters to avoid run-time errors that can occur when relying on Core Image’s string-based API.
To use the type-safe API, import CoreImage.CIFilterBuiltins:
#import <CoreImage/CoreImage.h>
#import <CoreImage/CIFilterBuiltins.h>The type-safe approach returns a non-optional filter. Because the returned filter conforms to the relevant protocol—for example, CIFalseColor in the case of falseColor()—the parameters are available as properties. The following creates and applies a false color filter:
- (CIImage *) falseColorImage:(CIImage*) inputImage {
CIFilter<CIFalseColor> *falseColorFilter = CIFilter.falseColorFilter;
falseColorFilter.color0 = [CIColor colorWithRed:1 green:1 blue:0];
falseColorFilter.color1 = [CIColor colorWithRed:0 green:0 blue:1];
falseColorFilter.inputImage = inputImage;
return falseColorFilter.outputImage;
}The false color filter maps luminance to a color ramp of two colors:
[Image]
Subclassing notes
You can subclass CIFilter in order to create custom filter effects:
By chaining together two or more built-in Core Image filters
By using an image-processing kernel that you write
Regardless of whether your subclass provides its effect by chaining filters or implementing its own kernel, you should:
Declare any input parameters as properties whose names are prefixed with
input, such asinputImage.Override the setDefaults() methods to provide default values for any input parameters you’ve declared.
Implement an
outputImagemethod to create a newCIImagewith your filter’s effect.
The CIFilter class automatically manages input parameters when archiving, copying, and deallocating filters. For this reason, your subclass must obey the following guidelines to ensure proper behavior:
Store input parameters in instance variables whose names are prefixed with
input.
Don’t use auto-synthesized instance variables, because their names are automatically prefixed with an underscore. Instead, synthesize the property manually. For example:
@synthesize inputMyParameter;
If using manual reference counting, don’t release input parameter instance variables in your dealloc method implementation. The dealloc implementation in the
CIFilterclass uses Key-value coding to automatically set the values of all input parameters tonil.
Topics
Creating a filter
Configuring type-safe filters
CIFilterProtocolBlur FiltersColor Adjustment FiltersColor Effect FiltersComposite OperationsConvolution FiltersDistortion FiltersGenerator FiltersGeometry Adjustment FiltersGradient FiltersHalftone Effect FiltersReduction FiltersSharpening FiltersStylizing FiltersTile Effect FiltersTransition Filters
Accessing registered filters
Registering a filter
Getting filter parameters and attributes
Setting default values
Applying a filter
Getting localized information for registered filters
localizedName(forFilterName:)localizedName(forCategory:)localizedDescription(forFilterName:)localizedReferenceDocumentation(forFilterName:)
Creating a configuration view for a filter
Applying system tone mapping modes
Constants
Filter Attribute KeysData Type AttributesVector Quantity AttributesColor Attribute KeysImage Attribute KeysFilter Category KeysOptions for Applying a FilterUser Interface Control OptionsUser Interface OptionsFilter Parameter KeysRAW Image Options
Deprecated
init(CVPixelBuffer:properties:options:)init(imageData:options:)init(imageURL:options:)CIRAWFilterOptionserializedXMP(from:inputImageExtent:)filterArray(fromSerializedXMP:inputImageExtent:error:)supportedRawCameraModels()
Type methods
Initializers
Type Methods
areaAverageMaximumRed()blurredRoundedRectangleGenerator()distanceGradientFromRedMask()roundedQRCodeGenerator()signedDistanceGradientFromRedMask()systemToneMap()