Search guides and the APICtrl K
  1. API reference
  2. Native GUI

gfx/colour.h

Colour, and blending.

#include <sonore/gfx/colour.h>
On this page

Design notes

Premultiplied, and why that decision is load-bearing

A colour is stored as four separate 8-bit channels, but everything the rasteriser composites is PREMULTIPLIED: the colour channels already carry their alpha. That is not an optimisation, it is the only way the arithmetic stays correct.

Compositing two half-transparent layers with straight alpha requires a divide per pixel to recover the colour, and where alpha is zero there is nothing to recover -- so a fully transparent pixel has no defined colour and blending through it drags whatever garbage was in the channels into the result. Premultiplied has no such case: zero alpha means zero everywhere, and over is one multiply and one add per channel.

So Colour is the type a caller writes, and PremulColour is the type the rasteriser blends. The conversion is explicit and one-directional at the point of use, because a premultiplied value that gets treated as straight is a picture that looks washed out in a way nobody can locate.

Types 2

Straight (non-premultiplied) 8-bit RGBA: what a caller writes.

Premultiplied 8-bit RGBA: what the rasteriser blends.

Functions 8

↑↓ to move↵ to openEvery public name in the headers, and every guide