gfx/colour.h
Colour, and blending.
#include <sonore/gfx/colour.h>- 2types
- 8other declarations
- Guides: The native editor
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
- fn
inline PremulColour over(PremulColour src, PremulColour dst, uint8_t coverage = 255)gfx::over · colour.h:173srcoverdst, both premultiplied. - fn
inline Colour background()0x0D1014: the window's ground.gfx::palette::background · colour.h:192 - fn
inline Colour panel()0x131922: a control's body.gfx::palette::panel · colour.h:194 - fn
inline Colour outline()0x26313F: edges and tracks.gfx::palette::outline · colour.h:196 - fn
inline Colour text()0xDCE5EE: text.gfx::palette::text · colour.h:198 - fn
inline Colour dimText()0x7D8B9C: secondary and disabled text.gfx::palette::dimText · colour.h:200 - fn
inline Colour accent()0x4EA3FF: a control's value, focus, selection.gfx::palette::accent · colour.h:202 - fn
inline Colour warning()0xE5A13A: something destructive, such as a close button being pressed.gfx::palette::warning · colour.h:204