Premultiplied alpha (source code)

= Premultiplied alpha

= Associated alpha
{synonym}

With \b[premultiplied alpha], a stored colour triple already includes its <alpha channel> multiplier: $c=\alpha C$, where $C$ is the corresponding <straight alpha> colour. The alpha value itself is retained. This is also called associated alpha. For $\alpha>0$, recover $C=c/\alpha$; at zero alpha the multiplication loses the original colour. <PNG> uses unassociated samples rather than this convention.<Portable Network Graphics (PNG) Specification (Third Edition) by Mark Adler and others>[§6.2, Alpha representation; §12.3, conversion from associated data]{ref}

For an original <Linear-light RGB> example, red $C=(1,0,0)$ with $\alpha=1/4$ becomes the stored quadruple $(1/4,0,0,1/4)$. The <source-over compositing> contribution of this sample is already $(1/4,0,0)$. Multiplying its first three entries by alpha again would make the red contribution $1/16$ instead of $1/4$.

<Premultiplied alpha> also makes a useful <linear interpolation> example transparent. Let sample A be opaque red, $(C_A,\alpha_A)=((1,0,0),1)$, and sample B be fully transparent blue, $(C_B,\alpha_B)=((0,0,1),0)$. Their premultiplied quadruples are $(1,0,0,1)$ and $(0,0,0,0)$. Averaging them gives
$$
(c,\alpha)=( (1/2,0,0),1/2).
$$
Placed over black, this contributes $(1/2,0,0)$. Averaging the straight colour triples and alphas separately would instead give $C=(1/2,0,1/2)$, $\alpha=1/2$, contributing $(1/4,0,1/4)$ over black. That blue contribution came from colour attached to a fully transparent sample. The calculation explains how an interpolation convention can create a coloured fringe.

The multiplication convention and the <color space> are separate choices. The example uses <Linear-light RGB> throughout. A file decoder, texture sampler and <alpha compositing> stage must agree on both the colour encoding and whether the samples use <straight alpha> or <premultiplied alpha>.