Skip to content

test(gfx): pin where P7's RGBW hue divergence comes from — a clamped drive - #4304

Merged
zackees merged 1 commit into
masterfrom
test/p7-rgbw-hue-divergence-source
Sep 10, 2026
Merged

zackees merged 1 commit into
masterfrom
test/p7-rgbw-hue-divergence-source

Conversation

@zackees

@zackees zackees commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Closes the last open question on P7 (#4041). Defect it uncovered: #4303.

What was open

RGBW mapper preserves hue while compressing chroma measured 0.026 of OKLab hue
divergence on one target and said plainly that it could not tell whether the
four-emitter allocation or the Q16 quantisation produced it — every target in that
corpus is outside the hull, so the chroma-halving search always runs first. Its own note
names the experiment that would settle it: an in-gamut target, where
mapAndAllocateRgbwQ16 returns the plain allocation untouched.

This runs it.

The answer

It is the allocation, and the mechanism is exact.

At (0.55, 0.41), Y = 0.5 — one step in y from the outlier, and inside the four-emitter
hull — 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

The solve is essentially exact, so neither the matrix nor the quantisation is the source.
The clamp is the whole anomaly — the same 0.026 the existing case records on its own
target.

Why 62 drive units cost that much colour: this device's blue primary sits at
xy = (0.15, 0.06) normalised to Y = 1, so its Z column is 13.17 — one drive unit of
blue is thirteen units of Z. The clamp is worth 0.0125 in Z against a target Z of 0.0488.
kWhiteSlack's comment sizes it as "a quarter of one code at 8-bit output", which is true
in drive space and is not the space the cost is paid in. That mismatch is #4303.

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 of 291 above 0.005. Accurate nearly everywhere,
wrong in a small orange-yellow region — where blue solves just below zero. Neither a
coincidence nor a pervasive fault.

Guards

Both cases carry vacuity guards, because both could otherwise pass by measuring nothing:
the in-gamut count is pinned at 291 (a grid that found none would satisfy every bound
below it), and the mechanism case fails if the clamped and honest reproductions ever
converge.

Mutation-checked:

mutation result
remove the clamp (rgb[i] = drive unclamped below zero) both new cases fail, and so does the existing hue case
kWhiteSlack 64 → 0 the target is rejected outright, so the new case's FL_REQUIRE fails — it really does depend on the slack accepting it

Scope

Test-only. No src/ change: fixing the slack means either carrying the forward matrix in
WhiteAllocationQ16 or choosing a new tolerance for a shipped colour path, and that is a
design call with four candidate directions — written up on #4303 rather than picked here.
This establishes what P7 asked and leaves a baseline for whichever is taken.

The note in the existing case that said the source was undetermined is now wrong, so it is
corrected to point at the new case.

303/303 unit + 84/84 examples, bash lint clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

Summary by CodeRabbit

  • Tests
    • Expanded RGBW gamut-mapping coverage with new in-gamut target cases.
    • Added validation isolating allocator behavior from hue mapping.
    • Added a grid sweep to identify the limited orange-yellow region where hue divergence occurs.
    • Clarified test documentation regarding divergence caused by clamping a negative blue drive.

…drive

"RGBW mapper preserves hue while compressing chroma" measured 0.026 of OKLab
hue divergence on one target and said it could not tell whether the
four-emitter allocation or the Q16 quantisation produced it, because every
target in that corpus needs compressing first. Its note names the experiment
that would settle it: an in-gamut target, where `mapAndAllocateRgbwQ16`
returns the plain allocation untouched.

Run. It is the allocation, and the mechanism is exact.

At (0.55, 0.41), Y = 0.5 -- one step in y from the outlier, and inside the
four-emitter hull -- `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 neither the matrix nor the quantisation is the source; the solve is
essentially exact. The clamp is the whole anomaly, and it is the same 0.026
the existing case records.

Why 62 raw units of drive cost that much colour: this device's blue primary
sits at xy = (0.15, 0.06) normalised to Y = 1, so its Z column is 13.17 and
one drive unit of blue is thirteen units of Z. The clamp is worth 0.0125 in
Z against a target Z of 0.0488. `kWhiteSlack`'s own comment sizes it as "a
quarter of one code at 8-bit output", which is true in drive space and is not
the space the cost is paid in.

Extent, so this is read as neither a coincidence nor a pervasive fault: over
the 291 in-gamut targets on a coarse grid of the xy plane at Y = 0.5, the
worst divergence is 0.0197 at (0.56, 0.40), the median is 6.9e-05, and only 6
exceed 0.005. The allocator is accurate nearly everywhere and wrong in a
small orange-yellow region -- where blue solves just below zero.

Both cases carry vacuity guards: the in-gamut count is pinned at 291, and the
mechanism case fails if the clamped and honest reproductions ever agree.

Mutation-checked:
- Removing the clamp fails both new cases and the existing hue case.
- `kWhiteSlack` 64 -> 0 makes the target rejected outright, so the new case's
  `FL_REQUIRE` fails -- it does depend on the slack accepting it.

The slack being sized in the wrong space is a defect in its own right and is
filed separately; this only establishes what P7 asked.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: d3271048-4c5d-43e4-9fe2-21edf5a051a1

📥 Commits

Reviewing files that changed from the base of the PR and between 15a19f9 and a80c916.

📒 Files selected for processing (1)
  • tests/fl/gfx/gamut_map.cpp

Included review availability: Your plan provides up to 8 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The RGBW gamut tests now identify negative blue-drive clamping as the source of the 0.026 OKLab hue divergence. They add a focused reproduction and a grid sweep that bounds the affected in-gamut region.

Changes

RGBW allocator divergence characterization

Layer / File(s) Summary
Allocator divergence tests
tests/fl/gfx/gamut_map.cpp
The test comments identify allocation clamping as the cause of the divergence. A focused in-gamut case compares unclamped and clamped reproduction results. A 291-target sweep measures the maximum divergence and counts affected targets.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to a80c9

This test-only change documents and bounds the RGBW hue divergence without changing production behavior. It is mergeable with normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: tests pin the source of P7's RGBW hue divergence to a clamped drive.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/p7-rgbw-hue-divergence-source

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zackees
zackees merged commit d7d279e into master Sep 10, 2026
6 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 10, 2026
zackees added a commit that referenced this pull request Sep 10, 2026
…fect (#4303) (#4314)

* fix(gfx): size the allocator's feasibility slack in colour, not in drive units (#4303)

`allocateEmitterDrivesQ16` let each RGB drive fall 64 raw units outside
[0, 1] before refusing, then clamped it -- returning "reachable" and an
allocation that reproduces a different colour. The constant's own comment
sized it as "a quarter of one code at 8-bit output", which is true in drive
space and is not the space the cost is paid in.

One drive unit of an emitter is that emitter's XYZ column. The corpus
device's blue sits at xy = (0.15, 0.06), putting its Z at 13.17, so the same
64 units bought thirteen times the colour error there as on green. At
(0.55, 0.41) -- inside the hull, needing no compression -- blue solved to -62
and was clamped to 0: 0.0125 off in Z against a target Z of 0.0488, 26%, and
0.026 of OKLab hue.

Direction 2 of the four the issue lists, implemented and measured. The slack
is divided by each column's peak component at bind time, so the colour cost
of the allowance is the same on every channel: green keeps 64, red gets 33,
blue gets 5. No per-pixel work and no new matrix.

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

| | before | after |
|---|---:|---:|
| worst OKLab hue divergence | 0.0197 | **0.0034** |
| targets above 0.005 | 6 | **0** |
| targets above 0.010 | 2 | **0** |
| targets reported reachable | 291 | 283 |

The 8 are the cost, and they are not lost: the gamut mapper compresses them
into the hull instead of the allocator answering them wrongly. Pinned, so
that cost is visible and cannot grow unnoticed.

Three cases change, which is what they were built for. The RGBW hue case
bracketed its outlier from below with a message saying that if the anomaly
vanished, someone should find out why and re-pin -- it fired, and this is
that. It now holds one bound for all five targets. The mechanism case #4304
added becomes a regression guard on the mechanism rather than a record of the
defect. The extent case measures the absence with the same grid that measured
the presence.

The two-white RGBWW path is deliberately untouched. Its slack is still
uniform, because the defect was measured on the single-white allocation and
RGBWW holds hue under 0.02 on the same five targets that gave RGBW its 0.026
-- so it may not have the same problem, and scaling on a guess would be
changing a shipped colour path without evidence.

303/303 unit + 84/84 examples, `bash lint` clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

* fix(gfx): cap the scaled slack, and make four headers self-contained

Review on #4313 asked whether `scaled` could overflow an i32 for a tiny
emitter luminance. It cannot -- `buildRgbSolveMatrixQ16`'s coefficient guard
refuses the profile first, measured at a luminance of 4.6e-5 and below, and
UBSan is silent on everything it accepts.

Chasing that found something the review did not name and I had missed. The
scaling *divides* by the column peak, so a dim emitter -- small column --
wants a **larger** slack. At a luminance of 1e-4 the three channels came out
at 330000, 640000 and 48608 raw units. 640000 is nearly ten in drive space,
so `drive > 65536 + 640000` accepts any drive at all and clamps it: the exact
defect this change exists to remove, an order of magnitude worse, for every
dim profile.

The slack now only ever narrows. 64 is the ceiling and the column decides how
far below it each channel sits. The corpus device is unaffected -- green sits
exactly at 64 and the others below -- so every measurement in this PR stands.
A case pins it, with a guard that dim profiles actually reach the slack
rather than all being refused earlier, and mutation-checked by removing the
ceiling: 66, 128 and 3300 against a bound of 64.

Also, from trying to write a standalone probe: `white_allocation.h` did not
compile as a translation unit's only include, spelling `EmitterProfile`
unqualified so it resolved only after some other header pulled in the `using`.
`gamut_map.h` had it too, and `colorimetric_response.h` was already fine. That
is the second and third instance after `device_solve.h`, so the
self-containment test now lists the group rather than taking them one incident
at a time -- which is how `gamut_map.h` turned up.

303/303 unit + 84/84 examples, `bash lint` clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

* test(gfx): the two-white allocator does not share the single-white defect (#4303)

The question #4303 was left with after #4313 fixed the single-white path.

It does not. The defect is accepting a target whose RGB solve wants a drive
outside [0, 1], clamping it, and reporting the target reachable.
`allocateTwoWhiteDrivesQ16` never accepts one, so its uniform slack never
decides feasibility and cannot buy a colour error.

The vacuity guard is the part that makes that worth saying. On the same grid,
670 targets *do* have a solve wanting an out-of-range drive -- all 670 are
refused. Without pinning that, "never accepts one" would hold just as well
over an empty set and would be a property of the corpus rather than of the
allocator. Worst OKLab hue divergence over the 283 it accepts is 0.00096,
against the single-white path's 0.0197 before #4313 and 0.0034 after.

Why it holds is measured, not reasoned, because the first explanation was
wrong. `kTwoWhiteBoundSlack` is half the final check's tolerance, so the
bounds admit less than the check accepts -- true, and not the reason: making
them equal changes nothing. Raising the slack instead:

    64 (shipped)   0 accepted with an out-of-range solve
    128            0
    256            0
    512            0
    1024           3
    2048           5
    4096          11

So 64 sits a factor of eight below where the behaviour changes. A comfortable
margin rather than a structural guarantee, which is the useful thing to know
before widening it.

303/303 unit + 84/84 examples, `bash lint` clean. Test-only; the src change
this builds on is #4313.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@zackees
zackees deleted the test/p7-rgbw-hue-divergence-source branch November 5, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant