The 2D layer · function

unpackRgba

A packed 0xRRGGBBAA token as the four floats a node's background and tint are: the colour decoded from sRGB to the linear light the renderer draws in, the coverage as it is.

Explained in Sprites and tilemaps.

function unpackRgba(packed: number, out: Float32Array): Float32Array
import { unpackRgba } from '@driftengine/ui2d';

Parameters

ParameterTypeDescription
packednumber
outFloat32Array

In depth

Decoded, because a hex colour is a display colour wherever one is written, CSS included, and the renderer grades everything it draws: read as linear, 0x336699 came out as 0x7caacb under the default outputTransform, every panel a washed-out version of the one picked. What it gives up is a token meant as an amount rather than a look, which a colour token is not. A renderer asked for outputTransform: 'none' draws these darker than picked, as it does every colour.

Two of this package's own APIs did not meet: a theme token is one number and a UiNode colour is a Float32Array, so every consumer wrote the same four shifts. The editor found it by being the first thing to build widgets on both, which is what a consumer outside packages/ is for.

>>> rather than >>, because a token with red at or above 0x80 has the sign bit set and an arithmetic shift returns it negative — a red that turns the whole colour into a large negative number, which is exactly the shape of bug that survives review.