Alpha channel (source code)

= Alpha channel

An \b[alpha channel] stores an additional value for each <pixel> that controls its contribution when images are combined by <alpha compositing>. In a common normalized convention, $\alpha=0$ makes the source <pixel> fully transparent and $\alpha=1$ makes it fully opaque. An <alpha channel> can describe partial coverage as well as transparency; its meaning includes the compositing rule, rather than merely a fourth color component. <PNG> represents its explicit <alpha channel> with 8-bit or 16-bit values, with zero fully transparent and the maximum value fully opaque.<Portable Network Graphics (PNG) Specification (Third Edition) by Mark Adler and others>[§6.2, Alpha representation]{ref}

For source color $C_s$ and an opaque background color $C_b$, the source-over rule in <Linear-light RGB> is
$$
C_{\mathrm{out}}=\alpha C_s+(1-\alpha)C_b.
$$
For an original example, a red source $C_s=(1,0,0)$ at $\alpha=1/4$ over a blue background $C_b=(0,0,1)$ produces $(1/4,0,3/4)$. These are linear color components; applying the same arithmetic directly to nonlinear display codes generally gives a different physical mixture.<Portable Network Graphics (PNG) Specification (Third Edition) by Mark Adler and others>[§13.16, Alpha channel processing; compositing and gamma correction]{ref}

Storage conventions matter too. With straight alpha the stored color remains $C_s$; with <premultiplied alpha> it is $\alpha C_s$. The red source in the example is therefore stored as either $(1,0,0,1/4)$ or $(1/4,0,0,1/4)$. Using the first formula on an already premultiplied color would multiply its source contribution by alpha twice. <PNG> explicitly uses non-premultiplied color samples.<Portable Network Graphics (PNG) Specification (Third Edition) by Mark Adler and others>[§6.2, unassociated alpha]{ref}