Skip to content

Color pipeline P7: gamut mapping and device solve (incl. RGBW) #4041

Closed

Description

@zackees

Phase P7 of the color pipeline implementation (see parent issue). Independently mergeable.

Scope

Gamut mapping and the device solve — including the ≥4-emitter case.

  • Host-side optimizer implements the reference objective: hue-preserving chroma compression in OKLCh (A3); exact in-gamut preservation within numeric budget, neutral/white-point preservation, explicit luminance-vs-chroma tradeoff, continuity under animation (§4).
  • Embedded per-pixel path: matrix + clamp/compress, optionally LUT-backed with measured error bounds vs the host optimizer. Iterative optimization (incl. existing nnls3) restricted to profile/cache build at host/setup — a structural test enforces it never runs per-pixel (A3/B11 rule).
  • Device solve consumes the emitter profile (chromaticities, response compensation); RGBW/RGBWW uses the deterministic allocation policy (C3): default white-preferred, per-profile RGB-preferred override, W included in the gamut volume the mapper targets, continuous in the input.
  • Comparison study (§4, closes the survey): clipping vs max-normalization vs OKLCh compression vs constrained solve — pick the smallest algorithm meeting the A1 budget on embedded hardware, documented in the phase report.

Decisions implemented

A3, C3, §4 objective, B11 (per-pixel restriction half).

Acceptance criteria owned

  • In-gamut vectors preserve chromaticity; neutral ramps remain neutral; out-of-gamut mapping is continuous and meets the hue/luminance objective.

Dependencies

P5 (reference optimizer + vectors), P6 (working-domain core to plug into).

Deliverables

Host optimizer (tooling), embedded mapper + solve stage, LUT generation path, continuity/preservation test suite, algorithm-selection report.

Activity

  1. 12 remaining items

  2. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    The connectivity assumption is false, with a witness (#4267)

    Your comment above closed both of P7's evidence gaps and left connectivity as the one thing sampling could not supply:

    The connectivity claim is still empirical. The report's option 2, an analytic bound for the primaries FastLED ships, is not supplied by any amount of sampling. Worth stating plainly since the search's validity rests on it.

    Took option 2. It does not give a bound — it gives a counterexample.

    The ray never needed sampling

    docs/color-reference-method.md already says an inverse-OKLab fixed-lightness, fixed-hue ray is cubic in chroma. Writing that out, each drive along the ray is d_i(c) = sum_j K_ij (p_j + q_j c)^3 — an ordinary cubic. So {c : 0 <= d_i(c) <= 1} follows from the real roots of d_i and d_i - 1, exactly. No gap can hide between two samples, however narrow.

    At lightness 0.5, hue 264.06 degrees

    feasible chroma [0, 0.29443] and [0.34575, 0.34644]
    bisection returns 0.29443
    actually reachable 0.34644
    given up 0.0520 — 17.6%

    Checked three ways before believing it: the intervals agree with the study's own is_feasible path; the far island's LMS response is positive on all three cones; and re-rendering its drives (0.000005, 0.000214, 0.097553) through the forward matrix returns L=0.500000 C=0.346092 h=264.0600. A deep blue at a tenth of full drive, not an artefact.

    Why 8.4 million sampled evaluations walked past it

    • The wedge runs 264.06 to 264.20 degrees — 0.14 degrees wide, present at every lightness from 0.05 to 0.75 — and contains no multiple of the 3 degrees the dense sweep steps by.
    • Handed the exact hue, a 401-sample chroma scan still reports one interval: the far island is 0.00069 wide against a 0.00125 step. Density is not the fix. Whatever the step, some ray's island is thinner.

    What it costs

    0.04% of hues. Inside the wedge an out-of-gamut target above 0.34644 chroma maps to 0.29443 — under-saturated, hue exact, still in gamut. A quality loss in a sliver, not a correctness failure, and I am not proposing a mapper change for it.

    Two consequences that are worth more than the defect:

    1. test_feasible_chroma_is_one_interval_for_this_device still passes and is kept unchanged. That is now the finding rather than the reassurance — a sampled grid reports connectivity on a device that does not have it.
    2. The wide-hull zeros need re-reading. That identical sweep at that identical density reported a clean zero here too. The exact method does not carry over to four emitters, because a white emitter makes feasibility a linear program rather than one cubic per drive, so connectivity above three emitters is still genuinely open rather than answered.
  3. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    The #4245 fix broke this phase's continuity criterion, and #4283 repairs it

    Reporting this against my own change rather than waiting for it to be found.

    P7's acceptance criterion asks that out-of-gamut mapping be continuous. I checked #4271 against that criterion — not against the tests I wrote for it — and it fails.

    Before #4245, every above-cap target clamped to the neutral cap, so a rising lightness ramp went flat there: continuous, if dim. #4245 made the answer track the requested lightness while a feasible chroma interval could be found, then drop all the way back to the cap as soon as the probes stopped landing. Along hue 300 at chroma 0.10:

    requested L emitted L chroma drives
    1.360 1.360 0.40 0.71, 1.00, 0.57
    1.365 1.118 0.10 0.32, 0.89, 0.16

    0.91 in summed drive — 234 eight-bit codes, against the ~1 code the mapper's other paths stay inside. The existing continuity case measures its worst boundary crossing at 0.80 codes and reasons explicitly about staying under one; it did not catch this because its only cap-crossing path is a neutral ramp, where the interval search never activates.

    #4283 bisects lightness down to the highest reachable one instead, so the answer lands on the edge of the region rather than past it. Worst step becomes 1–3 codes across the same sweeps, and the fix goes into all three mappers since all three carried the same fallback.

    For the phase

    With this, P7's own evidence is complete: the wide-hull gaps are measured (#4250), connectivity is settled with a witness rather than a sample (#4267), #4245 is fixed (#4271) and now continuous across the boundary it introduced (#4283). What remains is the dependency you named — P6 (#4040), whose PR #4200 is parked on the bloat-ratchet decision, now that the ratchet's own policy is settled (#4274).

  4. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    The last empty cell in the criterion grid — and it found something (#4293)

    With P6 merged, this phase's dependency is satisfied and I went back over the criterion against the tree rather than trusting the earlier "evidence is complete". Three mappers × four parts left one cell empty: RGBW's hue was checked only above the neutral cap, where the walk-down chooses the lightness. The other way out of the hull — a target inside the cap whose chroma the four emitters cannot reach — had no hue coverage on that mapper, and it is a different code path.

    Writing the case turned up an asymmetry. RGBWW holds hue under 0.02 on five xy chromaticities. On the identical five, RGBW does not:

    target xy hue divergence
    (0.70, 0.28) 0.00018
    (0.18, 0.72) 0.00174
    (0.10, 0.03) 0.00025
    (0.55, 0.42) 0.02610
    (0.08, 0.55) 0.00309

    That is about 1.5° of OKLab hue on one target, against near-zero on its four neighbours and against RGBWW's sub-0.02 on the same input.

    What I could and could not pin down

    chromaCandidateXyz scales a and b by a single factor, which preserves hue exactly — so the mapper's own candidate is on the ray by construction, and the divergence arises after it: in the four-emitter allocation, or in the quantisation between the two.

    I did not separate those. The experiment that would is an in-gamut target, where mapAndAllocateRgbwQ16 returns the plain allocation and any divergence is the allocator's alone — and all five targets in this corpus are outside the four-emitter hull, so it cannot run it. A corpus with in-gamut RGBW targets would settle it in one measurement.

    I did rule out the cheap explanation: it is not a low-chroma artefact. The outlier's mapped chroma is 0.198 against a target of 0.210, so the hue angle is well determined rather than noise on a near-grey.

    On closing this phase

    The criterion's four parts now have coverage on all three mappers, and #4283's continuity work is merged. What I would not do yet is call it closed on the strength of that table: the 0.026 is inside no stated tolerance, because P7 does not give one. #4156 R7 asked for "the exact luminance-versus-chroma objective and tie-breaks" to be written down, and this is what that gap looks like in practice — there is no number to say whether 1.5° passes.

    So the outstanding item for P7 as I see it is a stated hue tolerance, not more tests. With one, this measurement either passes or names a defect; without one it is just a number in a test.

  5. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    The last open question on this phase is answered — it is the allocation (#4304)

    My comment above measured 0.026 of OKLab hue divergence on RGBW at (0.55, 0.42) and said what I could not pin down:

    chromaCandidateXyz scales a and b by a single factor, which preserves hue exactly — so the mapper's own candidate is on the ray by construction, and the divergence arises after it: in the four-emitter allocation, or in the quantisation between the two. I did not separate those. The experiment that would is an in-gamut target … and all five targets in this corpus are outside the four-emitter hull, so it cannot run it.

    I built a corpus that can. It is the allocation, and the mechanism is exact rather than statistical.

    The measurement

    At (0.55, 0.41), Y = 0.5 — one step in y from the outlier, and inside the four-emitter hull, so mapAndAllocateRgbwQ16 returns the plain allocation and no compression happens — solveRgbDrivesQ16 returns blue = −62 raw. allocateEmitterDrivesQ16 accepts a drive down to -kWhiteSlack (64) as a rounding allowance, reports the target reachable, and clamps blue to 0.

    reproduced from XYZ error hue divergence
    the solve's own drives (blue = −62) 5.3e-05 0
    what the allocator returns (blue = 0) 0.0158 0.026

    So the solve is essentially exact and the quantisation is innocent. The clamp is the whole anomaly, and it is the same 0.026 the out-of-gamut case records.

    Why so much colour for 62 drive units: the test device's blue primary is xy = (0.15, 0.06) normalised to Y = 1, so its Z column is 13.17 — one drive unit of blue is thirteen of Z. The clamp costs 0.0125 in Z against a target Z of 0.0488, a 26% error in the smallest component and about 1.5° of OKLab hue.

    That also explains the asymmetry I reported: RGBWW holds under 0.02 on the identical five targets because its second white emitter changes which drive goes negative.

    Extent

    Over the 291 in-gamut targets on a coarse grid of the xy plane at Y = 0.5: worst 0.0197 at (0.56, 0.40), median 6.9e-05, only 6 above 0.005. The allocator is accurate nearly everywhere and wrong in a small orange-yellow region — exactly where blue solves just below zero.

    What this means for closing P7

    I said before I would not call this closed on the strength of the criterion table alone, because "the 0.026 is inside no stated tolerance, because P7 does not give one". That is still true, but the reason it mattered has changed: the number is no longer unexplained. It is a named defect in allocateEmitterDrivesQ16 with a measured mechanism, filed as #4303, and it is not a property of the gamut mapper this phase owns — the mapper's candidate is on the hue ray by construction, which is now demonstrated rather than argued.

    So P7's criterion has coverage on all three mappers in all four parts, and the one anomalous cell is attributed to a different component. I think that closes this phase's work, with #4303 carrying what remains. I am not closing it myself — the tolerance question (should P7 state a hue bound at all?) is still yours, and #4304 only supplies the evidence.

    Pinned so it cannot drift

    #4304 adds two cases: the mechanism, and the extent. Both carry vacuity guards — the in-gamut count is pinned at 291, and the mechanism case fails if the clamped and honest reproductions ever converge. Removing the clamp fails both plus the existing hue case; setting kWhiteSlack to 0 makes the target rejected outright.

  6. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    The 0.026 anomaly is gone, and this is the remark the bound asked for (#4313)

    The RGBW hue case bracketed its outlier from below on purpose, with a message saying that if the divergence ever vanished, someone should find out what changed and record it here rather than let the evidence be absorbed. It fired:

    WARN: RGBW hue divergence at (0.55, 0.42) improved to 0.00 from the 0.026 recorded here.
    That is good news, not a failure: find what changed, note it on FastLED#4041, and re-pin this bound.
    

    What changed: #4303, the defect #4304 traced this to. allocateEmitterDrivesQ16 sized its feasibility slack in drive space and paid it in colour — one drive unit of an emitter is that emitter's XYZ column, and this device's blue carries a Z of 13.17, so 64 raw units bought thirteen times the colour error on blue as on green. #4313 divides the allowance by each column's peak: green keeps 64, red gets 33, blue gets 5.

    Measured over 291 in-gamut targets on the xy plane at Y = 0.5:

    before after
    worst OKLab hue divergence 0.0197 0.0034
    above 0.005 6 0
    above 0.010 2 0
    reported reachable 291 283

    The five targets in this phase's hue case now all hold one bound at 0.005, worst measured 0.0000.

    What that means for P7

    The reason I would not call this phase closed was that the 0.026 sat inside no stated tolerance and was unexplained. It is now explained, fixed, and measured — and it was never a property of the gamut mapper this phase owns. chromaCandidateXyz scales a and b by one factor, so the mapper's candidate is on the hue ray by construction; the divergence arose entirely in the allocation after it.

    So P7's criterion has coverage on all three mappers in all four parts, with no unexplained cell. I am still not closing it — whether P7 should state a hue tolerance at all is yours, and #4313 supplies evidence rather than a decision.

    The 8 targets the fix stops reporting as reachable are not lost; the mapper compresses them into the hull. That count is pinned so the cost stays visible.

  7. moved this from Triage to Done in FastLED Trackeron Sep 19, 2026
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