color-d 0.2.0 – type-safe color math (Oklab/OKLCH, gamut mapping, linear alpha) for D
alex-1974
alex.leisser at gmail.com
Sun Oct 4 08:52:40 UTC 2026
Hi all,
I've released color-d 0.2.0, a small, allocation-free
color-mathematics library for D. It is @safe pure nothrow @nogc
throughout and usable in CTFE.
The idea: the color space is part of the type, and every step is
explicit. Encoded and linear sRGB are different types,
conversions never clip silently, and there is no default gamut
mapper.
```dlang
import color;
const display =
SRgbd(0.82, 0.25, 0.12)
.toLinear.toXyzD65.toOklab.toOklch
.withLightness(0.70).withChroma(0.16)
.gamutMapRayTraceToLinearSRgb
.toSRgb;
```
What's in it: sRGB/linear/XYZ D65/Oklab/OKLCH, CIELAB and
CIEDE2000, straight and premultiplied alpha with linear-light
compositing, interpolation with hue-path control, CSS Color 4
gamut mapping (Local MINDE, Ray Trace), WCAG 2 contrast, CVD
simulation (Brettel, Viénot, Machado), and packed SRgb8/SRgba8
with hex interop.
What it is not: no HSL/HSV, wide-gamut spaces or CSS parser yet,
and no theme or palette policy. The API is pre-1.0 and may still
change.
It targets DMD 2.112/2.113 and LDC 1.42/1.43 on Linux x86-64.
Feedback on other platforms is very welcome.
Docs: [github pages](https://alex-1974.github.io/color-d/)
Repo: [github](https://github.com/alex-1974/color-d)
DUB:
> dependency "color-d" version="~>0.2.0"
Feedback, issues and use cases are welcome.
More information about the Digitalmars-d-announce
mailing list