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 alphaFa
andFb
are defined by the operator in useco
is the output color pre-multiplied with the output alphaαo
Csrc
andCb
are the source color and backdrop colorCo
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 |
---|---|
![]() | ![]() |
clear
Result |
---|
![]() |
ColorBlendModes.CompositeOperations.CompositeClear
— ConstantCompositeClear
A basic Porter-Duff operator with the fractional terms Fa = 0; Fb = 0
. The composite result is completely transparent.
copy
Result |
---|
![]() |
ColorBlendModes.CompositeOperations.CompositeCopy
— ConstantCompositeCopy
A basic Porter-Duff operator with the fractional terms Fa = 1; Fb = 0
. The composite result is the copy of source.
Even if the source alpha is zero, the color components are not cleared.
destination
Result |
---|
![]() |
ColorBlendModes.CompositeOperations.CompositeDestination
— ConstantCompositeDestination
A basic Porter-Duff operator with the fractional terms Fa = 0; Fb = 1
. The composite result is the copy of destination (backdrop).
Even if the destination alpha is zero, the color components are not cleared.
source-over
Result | SVG |
---|---|
![]() |
ColorBlendModes.CompositeOperations.CompositeSourceOver
— ConstantCompositeSourceOver
A basic Porter-Duff operator with the fractional terms Fa = 1; Fb = 1 - αsrc
. This means the simple alpha compositing.
destination-over
Result | SVG |
---|---|
![]() |
ColorBlendModes.CompositeOperations.CompositeDestinationOver
— ConstantCompositeDestinationOver
A basic Porter-Duff operator with the fractional terms Fa = 1 - αb; Fb = 1
.
source-in
Result | SVG |
---|---|
![]() |
ColorBlendModes.CompositeOperations.CompositeSourceIn
— ConstantCompositeSourceIn
A basic Porter-Duff operator with the fractional terms Fa = αb; Fb = 0
.
destination-in
Result | SVG |
---|---|
![]() |
ColorBlendModes.CompositeOperations.CompositeDestinationIn
— ConstantCompositeDestinationIn
A basic Porter-Duff operator with the fractional terms Fa = 0; Fb = αsrc
.
source-out
Result | SVG |
---|---|
![]() |
ColorBlendModes.CompositeOperations.CompositeSourceOut
— ConstantCompositeSourceOut
A basic Porter-Duff operator with the fractional terms Fa = 1 - αb; Fb = 0
.
destination-out
Result | SVG |
---|---|
![]() |
ColorBlendModes.CompositeOperations.CompositeDestinationOut
— ConstantCompositeDestinationOut
A basic Porter-Duff operator with the fractional terms Fa = 0; Fb = 1 - αsrc
.
source-atop
Result | SVG |
---|---|
![]() |
ColorBlendModes.CompositeOperations.CompositeSourceAtop
— ConstantCompositeSourceAtop
A basic Porter-Duff operator with the fractional terms Fa = αb; Fb = 1 - αsrc
.
destination-atop
Result | SVG |
---|---|
![]() |
ColorBlendModes.CompositeOperations.CompositeDestinationAtop
— ConstantCompositeDestinationAtop
A basic Porter-Duff operator with the fractional terms Fa = 1 - αsrc; Fb = αb
.
xor
Result | SVG |
---|---|
![]() |
ColorBlendModes.CompositeOperations.CompositeXor
— ConstantCompositeXor
A basic Porter-Duff operator with the fractional terms Fa = 1 - αb; Fb = 1 - αsrc
.
lighter
Result | SVG |
---|---|
![]() |
ColorBlendModes.CompositeOperations.CompositeLighter
— ConstantCompositeLighter
A basic Porter-Duff operator with the fractional terms Fa = 1; Fb = 1
.
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.