Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ColorMatrixFilter

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

Hierarchy

Index

Constructors

constructor

Properties

alwaysDrawToBackBuffer

alwaysDrawToBackBuffer: boolean

Indicates if the last filter pass is always drawn directly to the back buffer.

Per default, the filter tries to automatically render in a smart way: objects that are currently moving are rendered to the back buffer, objects that are static are rendered into a texture first, which allows the filter to be drawn directly from the render cache in the next frame (in case the object remains static).

However, this fails when filters are added to an object that does not support the render cache, or to a container with such a child (e.g. a Sprite3D object or a masked display object). In such a case, enable this property for maximum performance.

@default false

antiAliasing

antiAliasing: number

The anti-aliasing level. This is only used for rendering the target object into a texture, not for the filter passes. 0 - none, 4 - maximum. @default 0

colorEffect

colorEffect: ColorMatrixEffect

isCached

isCached: boolean

Indicates if the filter is cached (via the cache method).

Protected maintainResolutionAcrossPasses

maintainResolutionAcrossPasses: boolean

Indicates if the filter requires all passes to be processed with the exact same resolution.

Some filters must use the same resolution for input and output; e.g. the blur filter is very sensitive to changes of pixel / texel sizes. When the filter is used as part of a filter chain, or if its last pass is drawn directly to the back buffer, such a filter produces artifacts. In that case, the filter author must set this property to true.

@default false

matrix

matrix: Vector<number>

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

padding

padding: Padding

Padding can extend the size of the filter texture in all directions. That's useful when the filter "grows" the bounds of the object in any direction.

resolution

resolution: number

The resolution of the filter texture. "1" means stage resolution, "0.5" half the stage resolution. A lower resolution saves memory and execution time, but results in a lower output quality. Values greater than 1 are allowed; such values might make sense for a cached filter when it is scaled up. @default 1

textureFormat

textureFormat: string

The format of the filter texture. @default BGRA

textureSmoothing

textureSmoothing: string

The smoothing mode of the filter texture. @default bilinear

Methods

Protected addEventListener

  • addEventListener(type: string, listener: Function): void

adjustBrightness

  • 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

    Returns void

adjustContrast

  • 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

    Returns void

adjustHue

  • adjustHue(value: number): void

adjustSaturation

  • 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

    Returns void

cache

  • cache(): void
  • Caches the filter output into a texture.

    An uncached filter is rendered every frame (except if it can be rendered from the global render cache, which happens if the target object does not change its appearance or location relative to the stage). A cached filter is only rendered once; the output stays unchanged until you call cache again or change the filter settings.

    Beware: you cannot cache filters on 3D objects; if the object the filter is attached to is a Sprite3D or has a Sprite3D as (grand-) parent, the request will be silently ignored. However, you can cache a 2D object that has 3D children!

    Returns void

clearCache

  • clearCache(): void

concat

  • concat(matrix: Vector<number>): void

concatValues

  • 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

    Returns void

dispatchEvent

  • dispatchEvent(event: Event): void
  • Dispatches an event to all objects that have registered listeners for its type. If an event with enabled 'bubble' property is dispatched to a display object, it will travel up along the line of parents, until it either hits the root object or someone stops its propagation manually.

    Parameters

    Returns void

dispatchEventWith

  • dispatchEventWith(type: string, bubbles?: boolean, data?: any): void

dispose

  • dispose(): void

Protected get_alwaysDrawToBackBuffer

  • get_alwaysDrawToBackBuffer(): boolean

Protected get_antiAliasing

  • get_antiAliasing(): number

Protected get_colorEffect

Protected get_isCached

  • get_isCached(): boolean

Protected get_maintainResolutionAcrossPasses

  • get_maintainResolutionAcrossPasses(): boolean

Protected get_matrix

  • get_matrix(): Vector<number>

Protected get_padding

Protected get_resolution

  • get_resolution(): number

Protected get_textureFormat

  • get_textureFormat(): string

Protected get_textureSmoothing

  • get_textureSmoothing(): string

hasEventListener

  • hasEventListener(type: string, listener?: any): boolean

invert

  • invert(): void

process

  • Does the actual filter processing. This method will be called with up to four input textures and must return a new texture (acquired from the helper) that contains the filtered output. To to do this, it configures the FilterEffect (provided via createEffect) and calls its render method.

    In a standard filter, only input0 will contain a texture; that's the object the filter was applied to, rendered into an appropriately sized texture. However, filters may also accept multiple textures; that's useful when you need to combine the output of several filters into one. For example, the DropShadowFilter uses a BlurFilter to create the shadow and then feeds both input and shadow texture into a CompositeFilter.

    Never create or dispose any textures manually within this method; instead, get new textures from the provided helper object, and pass them to the helper when you do not need them any longer. Ownership of both input textures and returned texture lies at the caller; only temporary textures should be put into the helper.

    Parameters

    Returns Texture

Protected removeEventListener

  • removeEventListener(type: string, listener: Function): void

removeEventListeners

  • removeEventListeners(type?: string): void

render

reset

  • reset(): void

Protected set_alwaysDrawToBackBuffer

  • set_alwaysDrawToBackBuffer(value: boolean): boolean

Protected set_antiAliasing

  • set_antiAliasing(value: number): number

Protected set_maintainResolutionAcrossPasses

  • set_maintainResolutionAcrossPasses(value: boolean): boolean

Protected set_matrix

  • set_matrix(value: Vector<number>): Vector<number>

Protected set_padding

Protected set_resolution

  • set_resolution(value: number): number

Protected set_textureFormat

  • set_textureFormat(value: string): string

Protected set_textureSmoothing

  • set_textureSmoothing(value: string): string

tint

  • tint(color: number, amount?: number): void
  • Tints the image in a certain color, analog to what can be done in Adobe Animate.

    @param color the RGB color with which the image should be tinted. @param amount the intensity with which tinting should be applied. Range (0, 1).

    Parameters

    • color: number
    • Optional amount: number

    Returns void

Generated using TypeDoc