public final class ColorMatrixBlend

  1. Object
  2. ColorMatrixBlend

Reference implementation of Graphics.colorMatrixRegion over an ARGB buffer.

Every pixel p (channels in 0..1) becomes p + (clamp(M * p + offset) - p) * k, where k = amount * shape * mask:

  • shape is the anti-aliased coverage of a rounded rectangle filling the region, clamp(0.5 - sdf, 0, 1) at the pixel centre, with corner radius cornerRadius (a negative radius makes a capsule; zero covers the whole rectangle);
  • mask is the alpha of the optional mask sampled at the same relative position (nearest pixel), which is how vibrant content is drawn: the mask holds the glyphs, and each glyph pixel takes its colour from the matrix applied to what lies behind it.

The destination alpha is kept. Ports without a native path (JavaSE, the JavaScript port, iOS off-screen images) call this; the Metal shader cn1_fs_colormatrix mirrors it.

Methods

public static void apply(int[] argb, int w, int h, float[] matrix, int[] mask, int maskW, int maskH, float cornerRadius, float amount)Applies the blend in place.

Inherited methods

Method details

apply

public static void apply(int[] argb, int w, int h, float[] matrix, int[] mask, int maskW, int maskH, float cornerRadius, float amount)
Applies the blend in place.

Parameters

argb int[]
the destination region, w * h pixels, row major
w int
region width in pixels
h int
region height in pixels
matrix float[]
12 floats, rows r, g, b of [r, g, b, offset] in 0..1 units
mask int[]
the mask pixels (ARGB, alpha used), or null for no mask
maskW int
mask width in pixels
maskH int
mask height in pixels
cornerRadius float
corner radius in region pixels, negative for a capsule
amount float
overall strength 0..1