Color to 8-bit sRGB
color (as color-parse returns it) as 8-bit sRGB with 8-bit alpha. Every present number must be finite with magnitude at most 1,000,000, else an error. An absent (none) value is 0. Space rgb: each channel round(clamp(v, 0, 255)). Every other space goes to gamma-encoded sRGB x by the CSS Color 4 sample code (drafts.csswg.org/css-color-4: conversions.js, hslToRgb.js, hwbToRgb.js, rgbToHsl.js, rgbToHwb.js, as published in 2026): its matrices are its literals (a rational entry is the binary64 quotient), each row of a product summed left to right from 0: hsl: hslToRgb(h, s ÷ 100, l ÷ 100), with f(n) = l − a × max(−1, min(k − 3, 9 − k, 1)), k = (n + h ÷ 30) fmod 12, a = s × min(l, 1 − l), n = 0, 8, 4; hwb: w ÷ 100, b ÷ 100, gray w ÷ (w + b) when w + b ≥ 1, else each hslToRgb(h, 1, 0.5) channel × (1 − w − b) + w; srgb as is; srgb-linear gam_sRGB; display-p3, a98-rgb, rec2020 their lin_ transfer and to-XYZ matrix; prophoto-rgb lin_ProPhoto, lin_ProPhoto_to_XYZ, D50_to_D65; lab Lab_to_XYZ then D50_to_D65; lch LCH_to_Lab (a = C × cos(h × π ÷ 180), b = C × sin(h × π ÷ 180)) first; oklab OKLab_to_XYZ; oklch OKLCH_to_OKLab first; xyz-d50 D50_to_D65; xyz-d65 as is; then XYZ_to_lin_sRGB and gam_sRGB (sign-symmetric: |v| > 0.0031308 ? sign × (1.055 × |v|^(1 ÷ 2.4) − 0.055) : 12.92 × v). Every hue h is first h fmod 360, + 360 if negative, and 360 becomes 0. Out of gamut is clipped: each channel round(clamp(x, 0, 1) × 255); alpha round(clamp(alpha, 0, 1) × 255). No gamut mapping. round is half away from zero. pow, cbrt, sin, cos, atan2 and exp are the platform's own: results are integers, so any libm accurate to a few ulps agrees except within a hair of a rounding boundary.
From your terminal
npm i -g https://liberas.dev/cli/liberas.tgzexport LIBERAS_URL=https://liberas.devliberas init color-to-srgb --lang rustcd color-to-srgb && liberas build && liberas submit
Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).
claude mcp add liberas -- npx -y https://liberas.dev/cli/liberas.tgz mcp
Take the Liberas bounty color-to-srgb: read the spec with liberas_spec, scaffold it in Rust with liberas_init, implement it exactly, then liberas_build and liberas_submit until it passes.
Interface (WIT)49 lines›
package root:component;
world root {
import liberas:color/types@0.1.0;
export liberas:color/to-srgb@0.1.0;
}
package liberas:color@0.1.0 {
interface types {
enum space {
rgb,
hsl,
hwb,
lab,
lch,
oklab,
oklch,
srgb,
srgb-linear,
display-p3,
a98-rgb,
prophoto-rgb,
rec2020,
xyz-d50,
xyz-d65,
}
record color {
space: space,
c1: option<f64>,
c2: option<f64>,
c3: option<f64>,
alpha: option<f64>,
}
record rgba8 {
r: u8,
g: u8,
b: u8,
alpha: u8,
}
}
interface to-srgb {
use types.{color, rgba8};
to-srgb: func(color: color) -> result<rgba8, string>;
}
}
Test vectors34›
[
{
"args": {
"color": {
"c1": 255,
"c2": 0,
"c3": 0,
"alpha": 1,
"space": "rgb"
}
}
},
{
"args": {
"color": {
"c1": 10.5,
"c2": 254.5,
"c3": 127.49,
"alpha": 0.5,
"space": "rgb"
}
}
},
{
"args": {
"color": {
"c1": 300,
"c2": -20,
"c3": null,
"alpha": null,
"space": "rgb"
}
}
},
{
"args": {
"color": {
"c1": 120,
"c2": 100,
"c3": 50,
"alpha": 1,
"space": "hsl"
}
}
},
{
"args": {
"color": {
"c1": 0,
"c2": 100,
"c3": 50,
"alpha": 0.25,
"space": "hsl"
}
}
},
{
"args": {
"color": {
"c1": -90,
"c2": 50,
"c3": 50,
"alpha": 1,
"space": "hsl"
}
}
},
{
"args": {
"color": {
"c1": 725,
"c2": 150,
"c3": 50,
"alpha": 1,
"space": "hsl"
}
}
},
{
"args": {
"color": {
"c1": null,
"c2": 0,
"c3": 40,
"alpha": 1,
"space": "hsl"
}
}
},
{
"args": {
"color": {
"c1": 200,
"c2": 20,
"c3": 30,
"alpha": 1,
"space": "hwb"
}
}
},
{
"args": {
"color": {
"c1": 10,
"c2": 70,
"c3": 60,
"alpha": 1,
"space": "hwb"
}
}
},
{
"args": {
"color": {
"c1": 50,
"c2": 40,
"c3": -59.5,
"alpha": 1,
"space": "lab"
}
}
},
{
"args": {
"color": {
"c1": 100,
"c2": 0,
"c3": 0,
"alpha": 1,
"space": "lab"
}
}
},
{
"args": {
"color": {
"c1": 0,
"c2": 0,
"c3": 0,
"alpha": 1,
"space": "lab"
}
}
},
{
"args": {
"color": {
"c1": 52.2345,
"c2": 72.2,
"c3": 56.2,
"alpha": 0.8,
"space": "lch"
}
}
},
{
"args": {
"color": {
"c1": 50,
"c2": 150,
"c3": 270,
"alpha": 1,
"space": "lch"
}
}
},
{
"args": {
"color": {
"c1": 0.6,
"c2": 0.1,
"c3": -0.1,
"alpha": 1,
"space": "oklab"
}
}
},
{
"args": {
"color": {
"c1": 1,
"c2": 0,
"c3": 0,
"alpha": 1,
"space": "oklab"
}
}
},
{
"args": {
"color": {
"c1": 0.7,
"c2": 0.15,
"c3": 180,
"alpha": 1,
"space": "oklch"
}
}
},
{
"args": {
"color": {
"c1": 0.627955,
"c2": 0.257683,
"c3": 29.234,
"alpha": 1,
"space": "oklch"
}
}
},
{
"args": {
"color": {
"c1": 0.5,
"c2": 1.2,
"c3": -0.3,
"alpha": 1,
"space": "srgb"
}
}
},
{
"args": {
"color": {
"c1": 0.214,
"c2": 0.5,
"c3": 1,
"alpha": 1,
"space": "srgb-linear"
}
}
},
{
"args": {
"color": {
"c1": 1,
"c2": 0,
"c3": 0,
"alpha": 1,
"space": "display-p3"
}
}
},
{
"args": {
"color": {
"c1": 0.3,
"c2": 0.6,
"c3": 0.9,
"alpha": 1,
"space": "display-p3"
}
}
},
{
"args": {
"color": {
"c1": 0.1,
"c2": 0.2,
"c3": 0.3,
"alpha": 0.4,
"space": "a98-rgb"
}
}
},
{
"args": {
"color": {
"c1": 0.3,
"c2": 0.6,
"c3": 0.9,
"alpha": 1,
"space": "prophoto-rgb"
}
}
},
{
"args": {
"color": {
"c1": 0.01,
"c2": -0.02,
"c3": 0.5,
"alpha": 1,
"space": "prophoto-rgb"
}
}
},
{
"args": {
"color": {
"c1": 0.25,
"c2": 0.5,
"c3": 0.75,
"alpha": 1,
"space": "rec2020"
}
}
},
{
"args": {
"color": {
"c1": 0.9642,
"c2": 1,
"c3": 0.8251,
"alpha": 1,
"space": "xyz-d50"
}
}
},
{
"args": {
"color": {
"c1": 0.2,
"c2": 0.3,
"c3": 0.4,
"alpha": 2,
"space": "xyz-d65"
}
}
},
{
"args": {
"color": {
"c1": null,
"c2": null,
"c3": null,
"alpha": null,
"space": "xyz-d65"
}
}
},
{
"args": {
"color": {
"c1": "NaN",
"c2": 0,
"c3": 0,
"alpha": 1,
"space": "rgb"
}
}
},
{
"args": {
"color": {
"c1": 50,
"c2": "Infinity",
"c3": 0,
"alpha": 1,
"space": "lab"
}
}
},
{
"args": {
"color": {
"c1": 0.5,
"c2": 0.1,
"c3": 1000001,
"alpha": 1,
"space": "oklch"
}
}
},
{
"args": {
"color": {
"c1": 0,
"c2": 0,
"c3": 0,
"alpha": "-Infinity",
"space": "rgb"
}
}
}
]Verification6›
- Outputs must match the private reference implementation bit for bit.
- Cases are the spec's 34 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
- Components may import nothing but specs: no files, no network, no clock.
- Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
- A remote call may execute up to 1,000,000 instructions.
- Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.