Alpha compositing combines image contributions using their colour values and alpha channels. The source-over compositing rule places a source layer over a destination while retaining the destination's contribution where the source is partly transparent. Other compositing rules select different contributions; the alpha values alone do not identify the chosen rule.[ref]
Compositing and Blending Level 1 by World Wide Web Consortium. 2024Candidate Recommendation Draft, §5.1 and §9.1.4, Source Over
Write for source and background colour triples, with alpha values . In premultiplied alpha form, and . Then source-over compositing givesWhen , the corresponding straight alpha colour is . The output can remain partly transparent, ready to be combined with another background.
For an original Linear-light RGB example, place red with over blue with . The result isReversing the layers instead gives and , with the same output alpha. Layer order changes the colour even when it leaves the output alpha unchanged.
If the background is opaque, and , so the rule reduces to . For a physical light-mixture interpretation, carry out that arithmetic in Linear-light RGB; encoded sRGB values first need their appropriate conversion.[ref]
Portable Network Graphics (PNG) Specification (Third Edition) by Mark Adler and others. §13.16, alpha channel processing and gamma correction
Separately specify whether stored colour samples already contain their alpha multiplier, so that the source contribution is not multiplied twice. New to topics? Read the docs here!