SPColorMatrixFilter Class Reference
Inherits from | SPFragmentFilter : NSObject |
Declared in | SPColorMatrixFilter.h |
Overview
The SPColorMatrixFilter class lets you apply a 4x5 matrix transformation on the RGBA color and alpha values of every pixel in the input image to produce a result with a new set of RGBA color and alpha values. It allows saturation changes, hue rotation, luminance to alpha, and various other effects.
The class contains several convenience methods for frequently used color adjustments. All those methods change the current matrix, which means you can easily combine them in one filter:
// create an inverted filter with 50% saturation and 180° hue rotation
SPColorMatrixFilter* filter = [[SPColorMatrixFilter alloc] init]
[filter invert];
[filter adjustSaturation:-0.5];
[filter adjustHue:1.0];
If you want to gradually animate one of the predefined color adjustments, either reset the matrix after each step, or use an identical adjustment value for each step; the changes will add up.
Tasks
Initialization
-
– initWithMatrix:
Initialize a color matrix filter with a color matrix. Designated initializer.
-
– init
Initialize a color matrix filter with an identity color matrix.
-
+ colorMatrixFilterWithMatrix:
Factory method.
-
+ colorMatrixFilter
Factory method.
Methods
-
– invert
Inverts the colors of the filtered objects.
-
– adjustSaturation:
Changes the saturation. Typical values are in the range(-1, 1). Values above zero will raise, values below zero will reduce the saturation. ‘-1’ will produce a grayscale image.
-
– adjustContrast:
Changes the contrast. Typical values are in the range(-1, 1). Values above zero will raise, values below zero will reduce the contrast.
-
– adjustBrightness:
Changes the brightness. Typical values are in the range(-1, 1). Values above zero will make the image brighter, values below zero will make it darker.
-
– adjustHue:
Changes the hue of the image. Typical values are in the range(-1, 1).
Matrix Manipulation
-
– reset
Changes the filter matrix back to the identity matrix.
-
– concatColorMatrix:
Concatenates the current matrix with another one.
Properties
-
colorMatrix
The color matrix object used to apply the filter.
property
Class Methods
Instance Methods
adjustBrightness:
Changes the brightness. Typical values are in the range(-1, 1). Values above zero will make the image brighter, values below zero will make it darker.
- (void)adjustBrightness:(float)brightness
Discussion
Changes the brightness. Typical values are in the range(-1, 1). Values above zero will make the image brighter, values below zero will make it darker.
Declared In
SPColorMatrixFilter.h
adjustContrast:
Changes the contrast. Typical values are in the range(-1, 1). Values above zero will raise, values below zero will reduce the contrast.
- (void)adjustContrast:(float)contrast
Discussion
Changes the contrast. Typical values are in the range(-1, 1). Values above zero will raise, values below zero will reduce the contrast.
Declared In
SPColorMatrixFilter.h
adjustHue:
Changes the hue of the image. Typical values are in the range(-1, 1).
- (void)adjustHue:(float)hue
Discussion
Changes the hue of the image. Typical values are in the range(-1, 1).
Declared In
SPColorMatrixFilter.h
adjustSaturation:
Changes the saturation. Typical values are in the range(-1, 1). Values above zero will raise, values below zero will reduce the saturation. ‘-1’ will produce a grayscale image.
- (void)adjustSaturation:(float)saturation
Discussion
Changes the saturation. Typical values are in the range(-1, 1). Values above zero will raise, values below zero will reduce the saturation. ‘-1’ will produce a grayscale image.
Declared In
SPColorMatrixFilter.h
concatColorMatrix:
Concatenates the current matrix with another one.
- (void)concatColorMatrix:(SPColorMatrix *)colorMatrix
Discussion
Concatenates the current matrix with another one.
Declared In
SPColorMatrixFilter.h
init
Initialize a color matrix filter with an identity color matrix.
- (instancetype)init
Discussion
Initialize a color matrix filter with an identity color matrix.
Declared In
SPColorMatrixFilter.h
initWithMatrix:
Initialize a color matrix filter with a color matrix. Designated initializer.
- (instancetype)initWithMatrix:(SPColorMatrix *)colorMatrix
Discussion
Initialize a color matrix filter with a color matrix. Designated initializer.
Declared In
SPColorMatrixFilter.h