There's More Than One RGBA

Well, believe it or not, there is more than one RGBA. Maybe this is old news for you or maybe you hear this for the first time like me. I’m not in any way specialized in computer graphics, not even frontend development. Nevertheless, I must have heard and used RGBA a million times before. It’s just one of these prevalent concepts. All the more was I surprised when I heard of Premultiplied Alpha and Non-Premultiplied Alpha. And maybe you are just about to learn something new today too…

An RGBA value of RGBA(0.2, 0.5, 0.4, 0.5) has 2 different interpretations. I stumbled across this while building an Intcode VM visualization with dvui. DVUI uses exclusively premultiplied RGBA. And apparently this is actually quite common once you dig a little deeper into graphics libraries and the like.

In premultiplied RGBA the color values are multiplied by the Alpha channel, while in non-premultiplied RGBA they are not. It’s as simple as that.

So a Non-Premultiplied RGBA

RGBA(0.4, 1.0, 0.8, 0.5)

simply becomes a Premultiplied RBA

RGBA(0.2, 0.5, 0.4, 0.5)

With no transparency (i.e. an alpha value of 1.0) there is no difference between the two. With some transparency (alpha < 1.0) and without additional context you don’t know which of these you got. Nigel Taos’s blog post provides an a bit more explanations if you want.

Now you may think ok so what, it’s just a different notation because people couldn’t agree on a single format. Someone came up with this, someone else with that, now we have two. But in fact this little transformation has an surprising amount of depth. For some further reading these posts provide peek into the consequences of this rather unassuming multiplication:

https://github.com/dtrebilco/PreMulAlpha
https://developer.nvidia.com/content/alpha-blending-pre-or-not-pre