Straight alpha (source code)

= Straight alpha

= Unassociated alpha
{synonym}

With \b[straight alpha], colour samples are stored independently of their <alpha channel> value. The same convention is called unassociated alpha. For a normalized colour triple $C$ and alpha $\alpha$, the stored pair is $(C,\alpha)$; <premultiplied alpha> instead stores $(\alpha C,\alpha)$. The PNG specification requires the unassociated convention.<Portable Network Graphics (PNG) Specification (Third Edition) by Mark Adler and others>[§6.2, Alpha representation]{ref}

For an original <Linear-light RGB> colour $C=(0.2,0.6,0.8)$ and alpha $1/4$, the straight-alpha quadruple is $(0.2,0.6,0.8,0.25)$. The corresponding premultiplied quadruple is $(0.05,0.15,0.2,0.25)$. Both describe the same source contribution when interpreted correctly. Raising alpha to $1/2$ can leave the straight colour triple unchanged, while its premultiplied counterpart must become $(0.1,0.3,0.4)$.

For <source-over compositing> against an opaque black background, the first sample contributes $(0.05,0.15,0.2)$. The stored straight colour is therefore not already its final contribution. At zero alpha, a straight-alpha representation can retain arbitrary colour components while the source contributes no colour to this operation. Multiplying by zero discards those components.

<Unpremultiplication> recovers the straight colour by dividing premultiplied colour by alpha when alpha is nonzero. It cannot recover a colour erased at zero alpha, and finite-precision errors become significant near zero. If a premultiplied component has absolute rounding error at most $\delta$, exact division by a fixed alpha magnifies that bound to $\delta/\alpha$. At $\alpha=1/100$, a component error $10^{-4}$ can therefore become $10^{-2}$. These are original error bounds, rather than a measured decoder defect.

The alpha convention and the <color space> remain separate specifications. For light-linear arithmetic, decode nonlinear colour samples before forming their light contributions. PNG documents both compositing and conversion from associated data, including handling zero alpha.<Portable Network Graphics (PNG) Specification (Third Edition) by Mark Adler and others>[§12.3, conversion from associated data; §13.16, alpha channel processing]{ref}