Packagestarling.filters
Classpublic class ColorMatrixFilter
InheritanceColorMatrixFilter Inheritance FragmentFilter Inheritance Object

The ColorMatrixFilter 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
      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
 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
 Inheritedmode : String
The filter mode, which is one of the constants defined in the "FragmentFilterMode" class.
FragmentFilter
 InheritedoffsetX : Number
Use the x-offset to move the filter output to the right or left.
FragmentFilter
 InheritedoffsetY : Number
Use the y-offset to move the filter output to the top or bottom.
FragmentFilter
 Inheritedresolution : Number
The resolution of the filter texture.
FragmentFilter
Protected Properties
 PropertyDefined By
 InheritedbaseTextureID : int
The ID (sampler) of the input texture (containing the output of the previous pass).
FragmentFilter
 InheritedmarginX : Number
The x-margin will extend the size of the filter texture along the x-axis.
FragmentFilter
 InheritedmarginY : Number
The y-margin will extend the size of the filter texture along the y-axis.
FragmentFilter
 InheritedmvpConstantID : int
The ID of the first register of the modelview-projection constant (a 4x4 matrix).
FragmentFilter
 InheritednumPasses : int
The number of passes the filter is applied.
FragmentFilter
 InheritedtexCoordsAtID : int
The ID of the vertex buffer attribute that stores the texture coordinates.
FragmentFilter
 InheritedvertexPosAtID : int
The ID of the vertex buffer attribute that stores the vertex position.
FragmentFilter
Public Methods
 MethodDefined By
  
ColorMatrixFilter(matrix:Vector.<Number> = null)
Creates a new ColorMatrixFilter instance with the specified matrix.
ColorMatrixFilter
  
Changes the brightness.
ColorMatrixFilter
  
Changes the contrast.
ColorMatrixFilter
  
Changes the hue of the image.
ColorMatrixFilter
  
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>):ColorMatrixFilter
Concatenates the current matrix with another one.
ColorMatrixFilter
 Inherited
dispose():void
Disposes the filter (programs, buffers, textures).
FragmentFilter
  
Inverts the colors of the filtered objects.
ColorMatrixFilter
 Inherited
render(object:DisplayObject, support:RenderSupport, parentAlpha:Number):void
Applies the filter on a certain display object, rendering the output into the current render target.
FragmentFilter
  
Changes the filter matrix back to the identity matrix.
ColorMatrixFilter
  
tint(color:uint, amount:Number = 1.0):ColorMatrixFilter
Tints the image in a certain color, analog to what can be done in Flash Pro.
ColorMatrixFilter
Protected Methods
 MethodDefined By
 Inherited
activate(pass:int, context:Context3D, texture:Texture):void
Subclasses must override this method and use it to activate their fragment- and vertex-programs.
FragmentFilter
 Inherited
assembleAgal(fragmentShader:String = null, vertexShader:String = null):Program3D
Assembles fragment- and vertex-shaders, passed as Strings, to a Program3D.
FragmentFilter
 Inherited
Subclasses must override this method and use it to create their fragment- and vertex-programs.
FragmentFilter
 Inherited
deactivate(pass:int, context:Context3D, texture:Texture):void
This method is called directly after 'context.drawTriangles'.
FragmentFilter
Protected Constants
 ConstantDefined By
 InheritedPMA : Boolean = true
All filter processing is expected to be done with premultiplied alpha.
FragmentFilter
 InheritedSTD_FRAGMENT_SHADER : String = tex oc, v0, fs0 <2d, clamp, linear, mipnone>
The standard fragment shader code.
FragmentFilter
 InheritedSTD_VERTEX_SHADER : String
The standard vertex shader code.
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):ColorMatrixFilter

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

Returns
ColorMatrixFilter
adjustContrast()method 
public function adjustContrast(value:Number):ColorMatrixFilter

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

Returns
ColorMatrixFilter
adjustHue()method 
public function adjustHue(value:Number):ColorMatrixFilter

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

Parameters

value:Number

Returns
ColorMatrixFilter
adjustSaturation()method 
public function adjustSaturation(sat:Number):ColorMatrixFilter

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

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

Concatenates the current matrix with another one.

Parameters

matrix:Vector.<Number>

Returns
ColorMatrixFilter
invert()method 
public function invert():ColorMatrixFilter

Inverts the colors of the filtered objects.

Returns
ColorMatrixFilter
reset()method 
public function reset():ColorMatrixFilter

Changes the filter matrix back to the identity matrix.

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

Tints the image in a certain color, analog to what can be done in Flash Pro.

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).

Returns
ColorMatrixFilter