Skip to content

bug(rgbw): out-of-hull source colors return (0,0,0,0) — missing NNLS projection (gist §3) #2708

Closed

Description

@zackees

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

  1. 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.
  2. 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.
  3. The fallback is wrong. rgb_2_rgbw_exact was 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

  1. Implement constrained NNLS in colorimetric_detail (small enough to inline; 4-variable non-negative quadratic with 3 equality constraints). Apply to X_t before triangle routing if a target chromaticity is flagged out-of-hull by an initial barycentric scan.
  2. 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).
  3. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions