Class ColorMatrixBlend

java.lang.Object
com.codename1.ui.plaf.ColorMatrixBlend

public final class ColorMatrixBlend extends Object

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.

  • Method Summary

    Modifier and Type
    Method
    Description
    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.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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: the destination region, w * h pixels, row major

      • w: region width in pixels

      • h: region height in pixels

      • matrix: 12 floats, rows r, g, b of [r, g, b, offset] in 0..1 units

      • mask: the mask pixels (ARGB, alpha used), or null for no mask

      • maskW: mask width in pixels

      • maskH: mask height in pixels

      • cornerRadius: corner radius in region pixels, negative for a capsule

      • amount: overall strength 0..1