The opacity value used to blend between the original and transformed colors.
This value controls how much of the color transformation is applied:
The current color transformation matrix of the filter.
This 5x4 matrix transforms RGBA color and alpha values of each pixel. The matrix is stored as a 20-element array in row-major order.
Converts the display object to pure black and white using a luminance-based threshold.
This method applies a matrix transformation that removes all color information and reduces the image to just black and white values based on the luminance of each pixel. The transformation uses standard luminance weightings: 30% red, 60% green, and 10% blue.
When true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
Adjusts the brightness of a display object.
The brightness adjustment works by multiplying the RGB channels by a scalar value while keeping the alpha channel unchanged. Values below 1 darken the image, while values above 1 brighten it.
The brightness multiplier to apply. Values between 0-1 darken the image (0 being black), while values > 1 brighten it (2.0 would make it twice as bright)
When true, the new matrix is multiplied with the current one instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
// Create a new color matrix filter
const colorMatrix = new ColorMatrixFilter();
// Darken the image to 50% brightness
colorMatrix.brightness(0.5, false);
// Chain with other effects by using multiply
colorMatrix
.brightness(1.2, true) // Brighten by 20%
.saturate(1.1, true); // Increase saturation by 10%
Applies a stylized brown-tinted effect to the display object.
This method applies a matrix transformation that creates a rich, warm brown tone with enhanced contrast and subtle color shifts.
When true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
We don't know exactly what it does, kind of gradient map, but funny to play with!
Tone values.
Tone values.
Tone values, example: 0xFFE580
Tone values, example: 0xFFE580
if true, current matrix and matrix are multiplied. If false, just set the current matrix with matrix
const colorMatrix = new ColorMatrixFilter();
// Create sepia-like effect with custom colors
colorMatrix.colorTone(
0.3, // Moderate desaturation
0.2, // Moderate toning
0xFFE580, // Warm highlight color
0x338000, // Dark green shadows
false
);
// Chain with other effects
colorMatrix
.colorTone(0.2, 0.15, 0xFFE580, 0x338000, true)
.brightness(1.1, true); // Slightly brighten
Adjusts the contrast of the display object by modifying the separation between dark and bright values.
This method applies a matrix transformation that affects the difference between dark and light areas in the image. Increasing contrast makes shadows darker and highlights brighter, while decreasing contrast brings shadows up and highlights down, reducing the overall dynamic range.
The contrast adjustment value. Range is 0 to 1, where: - 0 represents minimum contrast (flat gray) - 0.5 represents normal contrast - 1 represents maximum contrast
When true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
Completely removes color information from the display object, creating a grayscale version.
This is a convenience method that calls saturate(-1)
internally. The transformation preserves
the luminance of the original image while removing all color information.
Converts the display object to grayscale by applying a weighted matrix transformation.
The grayscale effect works by setting equal RGB values for each pixel based on the scale parameter, effectively removing color information while preserving luminance.
The intensity of the grayscale effect. Value between 0-1, where: - 0 produces black - 0.5 produces 50% grey - 1 produces white
When true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
Converts the display object to greyscale by applying a weighted matrix transformation.
The greyscale effect works by setting equal RGB values for each pixel based on the scale parameter, effectively removing color information while preserving luminance.
The intensity of the greyscale effect. Value between 0-1, where: - 0 produces black - 0.5 produces 50% grey - 1 produces white
When true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
Adjusts the hue of the display object by rotating the color values around the color wheel.
This method uses an optimized matrix transformation that accurately rotates the RGB color space around its luminance axis. The implementation is based on RGB cube rotation in 3D space, providing better results than traditional matrices with magic luminance constants.
The angle of rotation in degrees around the color wheel: - 0 = no change - 90 = rotate colors 90° clockwise - 180 = invert all colors - 270 = rotate colors 90° counter-clockwise
When true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
Applies a Kodachrome color effect that simulates the iconic film stock.
This method applies a matrix transformation that recreates the distinctive look of Kodachrome film, known for its rich, vibrant colors and excellent image preservation qualities. The effect emphasizes reds and blues while producing deep, true blacks.
When true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
Applies a psychedelic color effect that creates dramatic color shifts.
This method applies a matrix transformation that produces vibrant colors through channel mixing and amplification. Creates an effect reminiscent of color distortions in psychedelic art.
When true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
Creates a negative effect by inverting all colors in the display object.
This method applies a matrix transformation that inverts the RGB values of each pixel while preserving the alpha channel. The result is similar to a photographic negative.
When true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
Applies a night vision effect to the display object.
This method applies a matrix transformation that simulates night vision by enhancing certain color channels while suppressing others, creating a green-tinted effect similar to night vision goggles.
The intensity of the night effect (0-1): - 0 produces no effect - 0.1 produces a subtle night vision effect (default) - 1 produces maximum night vision effect
When true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
Applies a vintage Polaroid camera effect to the display object.
This method applies a matrix transformation that simulates the distinctive look of Polaroid instant photographs, characterized by slightly enhanced contrast, subtle color shifts, and a warm overall tone.
When true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
Predator effect
Erase the current matrix by setting a new independent one
how much the predator feels his future victim
if true, current matrix and matrix are multiplied. If false, just set the current matrix with matrix
Resets the color matrix filter to its default state.
This method resets all color transformations by setting the matrix back to its identity state. The identity matrix leaves colors unchanged, effectively removing all previously applied effects.
Adjusts the saturation of the display object by modifying color separation.
This method applies a matrix transformation that affects the intensity of colors. Increasing saturation makes colors more vivid and intense, while decreasing saturation moves colors toward grayscale.
The saturation adjustment value. Range is -1 to 1, where: - -1 produces grayscale - 0 represents no change - 1 produces maximum saturation
Optional
multiply: booleanWhen true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
Applies a sepia tone effect to the display object, creating a warm brown tint reminiscent of vintage photographs.
This method applies a matrix transformation that converts colors to various shades of brown while preserving the original luminance values.
When true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
Applies a Technicolor-style effect that simulates the early color motion picture process.
This method applies a matrix transformation that recreates the distinctive look of the Technicolor process. The effect produces highly saturated colors with a particular emphasis on reds, greens, and blues.
When true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
Sets each channel on the diagonal of the color matrix to apply a color tint.
This method provides a way to tint display objects using the color matrix filter, similar to the tint property available on Sprites and other display objects. The tint is applied by scaling the RGB channels of each pixel.
The color to use for tinting, this can be any valid color source.
Optional
multiply: booleanWhen true, the new tint matrix is multiplied with the current matrix instead of replacing it. This allows for combining tints with other color effects.
Swaps the red and blue color channels in the display object.
This method applies a matrix transformation that exchanges the red and blue color values while keeping the green channel and alpha unchanged.
When true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
Applies a vintage photo effect that simulates old photography techniques.
This method applies a matrix transformation that creates a nostalgic, aged look with muted colors, enhanced warmth, and subtle vignetting.
When true, the new matrix is multiplied with the current matrix instead of replacing it. This allows for cumulative effects when calling multiple color adjustments.
The ColorMatrixFilter class lets you apply color transformations to display objects using a 5x4 matrix. The matrix transforms the RGBA color and alpha values of every pixel to produce a new set of values.
The class provides convenient methods for common color adjustments like brightness, contrast, saturation, and various photo filter effects.
Example
Common use cases:
Author
Clément Chenebault clement@goodboydigital.com