Repository navigation
Description
Summary
When a source RGB input maps to a target chromaticity that falls outside the LED's 4-emitter convex hull, the strict sub-gamut solver returns (0, 0, 0, 0) instead of projecting to the nearest in-hull point. The math-model gist's §3 specifies a constrained NNLS projection ("Builder and verifier must use the same projection — this is a correctness requirement") that FastLED has not yet implemented.
Surfaced by a side-by-side comparison against the Python reference (https://gist.github.com/JChalka/cebc5a018066cae05d98cf9088c3b3b9):
| Input | FastLED | Reference | Δ |
|---|---|---|---|
| sRGB pure blue | (0, 0, 0, 0) |
(26, 0, 242, 0) |
(+26, 0, +242, 0) |
All other in-hull test cases (D65 white, red, green, cyan, magenta, yellow, mid grey, etc.) match the reference within ±16/255 — only out-of-hull cases black out.
Root cause
solve_strict_subgamut in src/fl/gfx/rgbw_colorimetric.cpp.hpp iterates the three sub-gamut triangles (RGW / RBW / BGW). When none of them contain the target xy (barycentric check at lines 105-112), the function returns false, and the dispatch in rgbw.cpp.hpp:303-309 falls back to rgb_2_rgbw_exact — which itself can't represent a chromaticity outside the LED hull and zeroes the W contribution incorrectly. Net result for the sRGB-blue case is (0,0,0,0).
The reference, by contrast, runs _strict_project_target_xyz_to_led_hull(target_xyz) first (lines 2148-… of xy_target_rgbw_model.py), which uses non-negative least squares (NNLS) to find the closest in-hull XYZ before routing into a sub-gamut.
Why this matters
- Standard color spaces routinely escape the LED hull. sRGB's blue primary at xy(0.15, 0.06) is barely outside the SK6812-class LED's RBW triangle. Anything saturated and short-wavelength (pure blue, deep violet) blacks out.
- Verification fails on these inputs. The user's D65-targeted verification tool reports
(0,0,0,0)from FastLED vs. real RGBW values from the spec, masking the actual chromaticity reproduction quality of everything else. - The fallback is wrong.
rgb_2_rgbw_exactwas designed for in-gamut inputs — for an out-of-hull target it produces a chromaticity excursion that's worse than the NNLS projection.
Proposed fix
- Implement constrained NNLS in
colorimetric_detail(small enough to inline; 4-variable non-negative quadratic with 3 equality constraints). Apply toX_tbefore triangle routing if a target chromaticity is flagged out-of-hull by an initial barycentric scan. - Add a test case asserting sRGB pure blue produces a non-zero RGBW with reconstructed chromaticity close to the LED hull's blue boundary (not the original sRGB blue).
- The boosted (
solve_wx_overdrive) path needs the same projection — currently it tolerates out-of-hull targets via residual clamping, but the chromaticity drift is uncontrolled.
References
- Parent: feat(rgbw): sub-gamut white-extraction algorithm for chromaticity-accurate RGBW output #2545
- Implementing PR for input color space + boosted differentiation: fix(rgbw): source RGB color space + differentiated boosted solver + Hermite LUT #2707
- Math model spec: https://gist.github.com/JChalka/915603d7930b7216d5c5aae834ec2ea9 (§3)
- Reference implementation: https://gist.github.com/JChalka/cebc5a018066cae05d98cf9088c3b3b9 (
_strict_project_target_xyz_to_led_hull) - Comparison harness producing the above table lives in
compare_rgbw.py(uncommitted) — fetches the gist, drives FastLED's algorithm (faithfully mirrored in Python), and prints the side-by-side delta.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
fix(rgbw): NNLS out-of-hull projection (#2708) + flip in-test contract
fix(rgbw): NNLS out-of-hull projection (#2708) + in-test ground truth (…
fix(rgbw): native topology authority for strict + boosted solvers (#2748