CompositeMode Enum

How a paint is combined with the pixels it is drawn on: the compositing operators of Porter and Duff.

public enum CompositeMode

Remarks

An operator gives the result where the shape covers a pixel entirely, from the paint (the source) and the pixel (the destination). With the alphas as and ad as fractions of one, each operator has two factors Fa and Fb: the result has the alpha Fa as + Fb ad, and its color multiplied by its alpha is Fa as source + Fb ad destination. A pixel that a shape covers in part is, for that part, the result of the operator, and for the rest what it was: a pixel the shape does not touch is never changed, whatever the operator.

The arithmetic is exact, on the stored sample values, and rounded to nearest with ties upward, as for CompositeMode.SourceOver. A pixel whose alpha becomes zero becomes transparent black; a pixel that was fully transparent and stays so is not written. A pixel format without alpha is opaque before and after: its pixels get the color the result would have over black (the color multiplied by the alpha the result would have).

Fields

NameValueDescription
SourceOver0The paint is drawn over the pixel (Fa = 1, Fb = 1 - as). This is the default.
Source1The paint replaces the pixel, alpha included (Fa = 1, Fb = 0): a transparent paint erases.
DestinationOver2The paint is drawn behind the pixel: it shows where the pixel is transparent (Fa = 1 - ad, Fb = 1).
SourceIn3The paint replaces the pixel, with its alpha multiplied by the alpha of the pixel (Fa = ad, Fb = 0).
DestinationIn4The pixel is kept where the paint is opaque: its alpha is multiplied by the alpha of the paint (Fa = 0, Fb = as). The color of the paint is not used.
SourceOut5The paint replaces the pixel, and only shows where the pixel was transparent (Fa = 1 - ad, Fb = 0).
DestinationOut6The pixel is erased where the paint is opaque: its alpha is multiplied by one minus the alpha of the paint (Fa = 0, Fb = 1 - as). The color of the paint is not used.
SourceAtop7The paint is drawn over the pixel, which keeps its alpha (Fa = ad, Fb = 1 - as).
DestinationAtop8The pixel is drawn over the paint, and the result has the alpha of the paint (Fa = 1 - ad, Fb = as).
Xor9The paint and the pixel each show where the other one is transparent (Fa = 1 - ad, Fb = 1 - as).
Clear10The pixel is erased (Fa = 0, Fb = 0). Neither the color nor the alpha of the paint is used: only the shape counts.
Plus11The paint is added to the pixel (Fa = 1, Fb = 1), and the result is clipped to one: its alpha is min(as + ad, 1), and its color multiplied by its alpha min(as source + ad destination, 1), for each color. Light added to light: plus-lighter of CSS, lighter of the HTML canvas, lighter of feComposite.