Class Compositor

java.lang.Object
com.codename1.art.Compositor

public final class Compositor extends Object

Software compositing of ARGB pixel arrays.

Uses the formulas of the W3C Compositing and Blending specification: the blended color is mixed with the layer's color by the backdrop's alpha, then composited source-over. Pixels are non-premultiplied 0xAARRGGBB ints, as Image.getRGB returns them.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The scratch space blend(int, int, BlendMode, float, double[]) needs, in doubles.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    blend(int src, int dst, BlendMode mode, float opacity)
    Composites one pixel and returns the result.
    static int
    blend(int src, int dst, BlendMode mode, float opacity, double[] scratch)
    Blends one pixel without allocating, for loops over many pixels.
    static void
    composite(int[] src, int[] dst, BlendMode mode, float opacity)
    Composites src over dst in place.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SCRATCH

      public static final int SCRATCH
      The scratch space blend(int, int, BlendMode, float, double[]) needs, in doubles.
      See Also:
  • Method Details

    • composite

      public static void composite(int[] src, int[] dst, BlendMode mode, float opacity)

      Composites src over dst in place.

      Parameters
      • src: the layer's pixels
      • dst: the backdrop, overwritten with the result; same length as src
      • mode: how colors combine
      • opacity: the layer's opacity, 0 to 1, applied on top of each pixel's own alpha
    • blend

      public static int blend(int src, int dst, BlendMode mode, float opacity)

      Composites one pixel and returns the result.

      Parameters
      • src: the layer's pixel
      • dst: the backdrop pixel
      • mode: how colors combine
      • opacity: the layer's opacity, 0 to 1
    • blend

      public static int blend(int src, int dst, BlendMode mode, float opacity, double[] scratch)

      Blends one pixel without allocating, for loops over many pixels.

      Parameters
      • src: the layer's pixel
      • dst: the backdrop pixel
      • mode: how colors combine
      • opacity: the layer's opacity, 0 to 1
      • scratch: at least SCRATCH doubles, reused across calls
      Returns

      the composited pixel