Composite Operations

The CompositeOperation type represents the Porter-Duff operators, or the modes of generalized alpha compositing.

The general form of the Porter-Duff equation is:

    αo = αsrc × Fa + αb × Fb
    co = αsrc × Fa × Csrc + αb × Fb × Cb
    Co = co / αo

where:

  • αo is the output alpha
  • αsrc and αb are the source alpha and backdrop alpha
  • Fa and Fb are defined by the operator in use
  • co is the output color pre-multiplied with the output alpha αo
  • Csrc and Cb are the source color and backdrop color
  • Co is the output color

Note that the "destination" means the "backdrop", not the "output" in this context.

The following two images are used as examples below.

Destination (backdrop)Source
destinationsource

clear

Result
clear

copy

Result
copy

destination

Result
destination

source-over

ResultSVG
source-oversource-over_svg

destination-over

ResultSVG
destination-overdestination-over_svg

source-in

ResultSVG
source-insource-in_svg

destination-in

ResultSVG
destination-indestination-in_svg

source-out

ResultSVG
source-outsource-out_svg

destination-out

ResultSVG
destination-outdestination-out_svg

source-atop

ResultSVG
source-atopsource-atop_svg

destination-atop

ResultSVG
destination-atopdestination-atop_svg

xor

ResultSVG
xorxor_svg

lighter

ResultSVG
lighterlighter_svg
Warning

If and only if αo is constant 1, you can specify an opaque Color to the backdrop, i.e. the first argument of blend. For example, CompositeSourceOver can be used with opaque backdrops, since αo is 1 regardless of αsrc. In contrast, CompositeSourceOut cannot be used with opaque backdrops because the output will be transparent, resulting in an error.