What is premultiplied alpha?

Premultiplied alpha is a way of storing a pixel where the red, green and blue values have already been multiplied by the alpha value, which simplifies blending and filtering.

By · Updated

Explained in more detail

In a premultiplied (or "associated") alpha image, the color values are stored already scaled by opacity. A pure red pixel at 50% opacity is stored as roughly (128, 0, 0, 128) instead of (255, 0, 0, 128). The original color is recovered by dividing the color values by alpha.

Rendering systems like this because the math for compositing one image over another becomes simpler, and because scaling or blurring behaves correctly. When a transparent pixel with a black or white hidden color value sits next to an opaque colored pixel, straight alpha filtering can bleed that hidden color into the edge and produce a dark or light outline. Premultiplied data avoids that, since fully transparent pixels are always (0, 0, 0, 0) and contribute nothing.

The cost is precision. At low alpha, many different original colors collapse into nearly the same stored values, so a round trip from straight to premultiplied and back can change color values slightly. Fully transparent pixels lose their color entirely.

Canvas implementations may work with premultiplied values internally. The HTML Standard notes that, because of the conversion to and from premultiplied alpha, pixels written with putImageData that are not fully opaque may read back from getImageData with different values. That is why a read-modify-write round trip can shift the color of very low-alpha pixels.

The PNG specification defines its alpha as unassociated (straight), so a decoder that needs premultiplied data converts on load. Check a format's own specification before assuming which kind it stores.

Related terms

Try it in Triim

Sources

Part of the Triim image terms glossary, by Rocco Bombardieri.