Packagestarling.filters
Classpublic class ColorMatrixFilter
InheritanceColorMatrixFilter Inheritance FragmentFilter Inheritance EventDispatcher Inheritance Object

The ColorMatrixFilter class lets you apply a 4x5 matrix transformation to the color and alpha values of every pixel in the input image to produce a result with a new set of color and alpha values. This 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
      var filter:ColorMatrixFilter = new ColorMatrixFilter();
      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.



Public Properties
 PropertyDefined By
 InheritedalwaysDrawToBackBuffer : Boolean
Indicates if the last filter pass is always drawn directly to the back buffer.
FragmentFilter
 InheritedantiAliasing : int
The anti-aliasing level.
FragmentFilter
 InheritedisCached : Boolean
[read-only] Indicates if the filter is cached (via the cache method).
FragmentFilter
  matrix : Vector.<Number>
A vector of 20 items arranged as a 4x5 matrix.
ColorMatrixFilter
 InheritednumPasses : int
[read-only] Indicates the number of rendering passes required for this filter.
FragmentFilter
 Inheritedpadding : Padding
Padding can extend the size of the filter texture in all directions.
FragmentFilter
 Inheritedresolution : Number
The resolution of the filter texture.
FragmentFilter
 InheritedtextureFormat : String
The format of the filter texture.
FragmentFilter
 InheritedtextureSmoothing : String
The smoothing mode of the filter texture.
FragmentFilter
Protected Properties
 PropertyDefined By
 Inheritedeffect : FilterEffect
[read-only] The effect instance returning the FilterEffect created via createEffect.
FragmentFilter
 InheritedindexData : IndexData
[read-only] The IndexData used to process the effect.
FragmentFilter
 InheritedmaintainResolutionAcrossPasses : Boolean
Indicates if the filter requires all passes to be processed with the exact same resolution.
FragmentFilter
 InheritedvertexData : VertexData
[read-only] The VertexData used to process the effect.
FragmentFilter
Public Methods
 MethodDefined By
  
ColorMatrixFilter(matrix:Vector.<Number> = null)
Creates a new ColorMatrixFilter instance with the specified matrix.
ColorMatrixFilter
 Inherited
addEventListener(type:String, listener:Function):void
Registers an event listener at a certain object.
EventDispatcher
  
adjustBrightness(value:Number):void
Changes the brightness.
ColorMatrixFilter
  
adjustContrast(value:Number):void
Changes the contrast.
ColorMatrixFilter
  
adjustHue(value:Number):void
Changes the hue of the image.
ColorMatrixFilter
  
adjustSaturation(sat:Number):void
Changes the saturation.
ColorMatrixFilter
 Inherited
cache():void
Caches the filter output into a texture.
FragmentFilter
 Inherited
clearCache():void
Clears the cached output of the filter.
FragmentFilter
  
concat(matrix:Vector.<Number>):void
Concatenates the current matrix with another one.
ColorMatrixFilter
  
concatValues(m0:Number, m1:Number, m2:Number, m3:Number, m4:Number, m5:Number, m6:Number, m7:Number, m8:Number, m9:Number, m10:Number, m11:Number, m12:Number, m13:Number, m14:Number, m15:Number, m16:Number, m17:Number, m18:Number, m19:Number):void
Concatenates the current matrix with another one, passing its contents directly.
ColorMatrixFilter
 Inherited
dispatchEvent(event:Event):void
Dispatches an event to all objects that have registered listeners for its type.
EventDispatcher
 Inherited
dispatchEventWith(type:String, bubbles:Boolean = false, data:Object = null):void
Dispatches an event with the given parameters to all objects that have registered listeners for the given type.
EventDispatcher
 Inherited
dispose():void
Disposes all resources that have been created by the filter.
FragmentFilter
 Inherited
hasEventListener(type:String, listener:Function = null):Boolean
If called with one argument, figures out if there are any listeners registered for the given event type.
EventDispatcher
  
invert():void
Inverts the colors of the filtered object.
ColorMatrixFilter
 Inherited
process(painter:Painter, helper:IFilterHelper, input0:Texture = null, input1:Texture = null, input2:Texture = null, input3:Texture = null):Texture
Does the actual filter processing.
FragmentFilter
 Inherited
removeEventListener(type:String, listener:Function):void
Removes an event listener from the object.
EventDispatcher
 Inherited
removeEventListeners(type:String = null):void
Removes all event listeners with a certain type, or all of them if type is null.
EventDispatcher
 Inherited
render(painter:Painter):void
Renders the filtered target object.
FragmentFilter
  
reset():void
Changes the filter matrix back to the identity matrix.
ColorMatrixFilter
  
tint(color:uint, amount:Number = 1.0):void
Tints the image in a certain color, analog to what can be done in Adobe Animate.
ColorMatrixFilter
Protected Methods
 MethodDefined By
 Inherited
Creates the effect that does the actual, low-level rendering.
FragmentFilter
 Inherited
Called when assigning a target display object.
FragmentFilter
 Inherited
Call this method when any of the filter's properties changes.
FragmentFilter
Events
 Event Summary Defined By
 InheritedDispatched when the settings change in a way that requires a redraw.FragmentFilter
 InheritedDispatched every frame on filters assigned to display objects connected to the stage.FragmentFilter
Property Detail
matrixproperty
matrix:Vector.<Number>

A vector of 20 items arranged as a 4x5 matrix.


Implementation
    public function get matrix():Vector.<Number>
    public function set matrix(value:Vector.<Number>):void
Constructor Detail
ColorMatrixFilter()Constructor
public function ColorMatrixFilter(matrix:Vector.<Number> = null)

Creates a new ColorMatrixFilter instance with the specified matrix.

Parameters
matrix:Vector.<Number> (default = null) — a vector of 20 items arranged as a 4x5 matrix.
Method Detail
adjustBrightness()method
public function adjustBrightness(value:Number):void

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.

Parameters

value:Number

adjustContrast()method 
public function adjustContrast(value:Number):void

Changes the contrast. Typical values are in the range (-1, 1). Values above zero will raise, values below zero will reduce the contrast.

Parameters

value:Number

adjustHue()method 
public function adjustHue(value:Number):void

Changes the hue of the image. Typical values are in the range (-1, 1).

Parameters

value:Number

adjustSaturation()method 
public function adjustSaturation(sat:Number):void

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.

Parameters

sat:Number

concat()method 
public function concat(matrix:Vector.<Number>):void

Concatenates the current matrix with another one.

Parameters

matrix:Vector.<Number>

concatValues()method 
public function concatValues(m0:Number, m1:Number, m2:Number, m3:Number, m4:Number, m5:Number, m6:Number, m7:Number, m8:Number, m9:Number, m10:Number, m11:Number, m12:Number, m13:Number, m14:Number, m15:Number, m16:Number, m17:Number, m18:Number, m19:Number):void

Concatenates the current matrix with another one, passing its contents directly.

Parameters

m0:Number
 
m1:Number
 
m2:Number
 
m3:Number
 
m4:Number
 
m5:Number
 
m6:Number
 
m7:Number
 
m8:Number
 
m9:Number
 
m10:Number
 
m11:Number
 
m12:Number
 
m13:Number
 
m14:Number
 
m15:Number
 
m16:Number
 
m17:Number
 
m18:Number
 
m19:Number

invert()method 
public function invert():void

Inverts the colors of the filtered object.

reset()method 
public function reset():void

Changes the filter matrix back to the identity matrix.

tint()method 
public function tint(color:uint, amount:Number = 1.0):void

Tints the image in a certain color, analog to what can be done in Adobe Animate.

Parameters

color:uint — the RGB color with which the image should be tinted.
 
amount:Number (default = 1.0) — the intensity with which tinting should be applied. Range (0, 1).