Repository navigation
fix(rgbw): default source = native LED gamut + D65; named-gamut opt-in - #2711
Conversation
#2710) Closes #2710. #2705 added the source-RGB → LED-XYZ transform with `kRgbwDefaultProfile` defaulting to Rec709/sRGB primaries + D65. That silently clipped saturated inputs to the sRGB sub-volume of the LED's native gamut — `RGB=(255,0,0)` on a typical SK6812 strip drove the LED red diode to ~70 % of its capability, leaving the rest unreachable through the public API. Flips the default to **native LED gamut + D65 white**: - `kRgbwDefaultProfile.input_xy_r/g/b` now mirror the profile's own LED `xy_r/g/b` (was sRGB), so saturated inputs hit the LED gamut at full saturation. - `input_xy_w` stays at D65 so neutral inputs land on a standard daylight white. - Same applies to `kRgbwwDefaultProfile` (RGBWW warm + cool paths). Adds a small opt-in API for users who explicitly want standard color-space input semantics: enum class InputGamut : u8 { Native, Rec709, Rec2020, DciP3D65, DciP3D60 }; void set_input_gamut(DiodeProfile* profile, InputGamut g) noexcept; void set_input_gamut(DiodeProfile* profile, InputGamut g, const float white_xy[2]) noexcept; Users with sRGB content (ambilight, video bridges) write one line at setup: `fl::set_input_gamut(&my_profile, fl::InputGamut::Rec709);`. The white-override overload covers niche cases like D50 photography workflow or D60 ACES theatrical mastering. Tests ===== - `default profile carries native-LED + D65 source space (#2710)` — asserts input_xy_* mirror xy_* and input_xy_w == D65. - `source matrix matches published sRGB->XYZ matrix (Rec709 opt-in)` — the existing sRGB matrix-derivation check now opts into Rec709 via set_input_gamut() before building M_src. - `set_input_gamut: Native copies LED primaries` — trashes input_xy_* then proves Native restores them from xy_*. - `set_input_gamut: named gamuts populate canonical primaries` — hits Rec709 / Rec2020 / DCI-P3 D65 / DCI-P3 D60 and asserts canonical primary + white-point values. - `set_input_gamut: white override honored` — covers the overload that takes a custom white (D50 in the test). - `set_input_gamut: null profile is a no-op` — defensive guard parity with `set_rgbw_colorimetric_profile(nullptr)`. Drive-by ======== Removes `compare_rgbw.py`, a one-off scratch comparison harness that slipped into master via #2709's squash-merge despite being deleted on the branch. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughSwitch default RGBW/RGBWW input chromaticities to native LED primaries with D65 white, add a public InputGamut enum and two set_input_gamut() overloads (including optional white override), implement cache invalidation for mutated profiles, remove compare_rgbw.py, and update/extend tests plus minor CI/test formatting tweaks. ChangesInput Gamut Colorimetric Defaults and API
Sequence DiagramsequenceDiagram
participant CFastLED
participant fl_set_input_gamut as fl::set_input_gamut
participant DiodeProfile
participant CacheInvalidator as invalidate_colorimetric_caches_for
CFastLED->>fl_set_input_gamut: call setInputGamut(profile, gamut[, white_xy])
fl_set_input_gamut->>DiodeProfile: mutate input_xy_r/g/b/w
fl_set_input_gamut->>CacheInvalidator: request cache invalidation for profile
CacheInvalidator->>ProfileCache: clear cached profile/LUT state
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/fl/gfx/rgbww.cpp.hpp (1)
53-84: ⚡ Quick winConsider guarding the native-primary duplication for RGBWW.
input_xy_r/g/bare hand-copied fromxy_r/g/bin both warm and cool paths. If the LED chromaticities are later retuned,input_xy_*can silently drift out of sync, since (unlikekRgbwDefaultProfile, which is covered by the test at Lines 252-272) there is no equivalent test assertingkRgbwwDefaultProfile.warm_path.input_xy_* == xy_*. A small static assertion or a dedicated test would lock the "native LED gamut" default contract in place.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/fl/gfx/rgbww.cpp.hpp` around lines 53 - 84, The warm_path and cool_path entries in kRgbwwDefaultProfile duplicate native-primary values (xy_r/g/b vs input_xy_r/g/b) which can drift; add a guard to ensure they remain identical by either adding compile-time static assertions or a unit test that compares kRgbwwDefaultProfile.warm_path.input_xy_r/g/b == kRgbwwDefaultProfile.warm_path.xy_r/g/b and the same for cool_path (and fail/build on mismatch). Locate kRgbwwDefaultProfile and implement assertions/tests referencing the struct members warm_path, cool_path, xy_r, xy_g, xy_b, input_xy_r, input_xy_g, input_xy_b to lock the native LED gamut contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/fl/gfx/rgbw.cpp.hpp`:
- Around line 234-268: set_input_gamut currently mutates profile->input_xy_* in
place but does not mark any cache invalid, so get_cache() /
rebuild_lut_if_stale() keep using the stale M_src/LUT; to fix, add a
cache-invalidation step inside set_input_gamut(DiodeProfile*, InputGamut, const
float[]) (and the two-arg overload) that updates a version/id on the profile
that the cache key reads (e.g. bump profile->cache_version or call
profile_invalidate_cache(profile)), and then update get_cache() /
rebuild_lut_if_stale() to include that version/id in their cache lookup so any
in-place changes to profile->input_xy_* will force cache recomputation of
M_src/LUT.
In `@src/fl/gfx/rgbw.h`:
- Around line 94-100: Change the public API for set_input_gamut(DiodeProfile*
profile, InputGamut g, const float white_xy[2]) to use fl::span<const float, 2>
for the white_xy parameter, update the header doc to remove the "must point"
wording, and update the implementation in set_input_gamut (and any callers) to
accept a span (no nullptr semantics) and rely on the existing 2-arg overload
set_input_gamut(DiodeProfile*, InputGamut) for the default/D65 behavior; ensure
the implementation checks span.size()==2 and handles missing span by calling the
2-arg overload.
---
Nitpick comments:
In `@src/fl/gfx/rgbww.cpp.hpp`:
- Around line 53-84: The warm_path and cool_path entries in kRgbwwDefaultProfile
duplicate native-primary values (xy_r/g/b vs input_xy_r/g/b) which can drift;
add a guard to ensure they remain identical by either adding compile-time static
assertions or a unit test that compares
kRgbwwDefaultProfile.warm_path.input_xy_r/g/b ==
kRgbwwDefaultProfile.warm_path.xy_r/g/b and the same for cool_path (and
fail/build on mismatch). Locate kRgbwwDefaultProfile and implement
assertions/tests referencing the struct members warm_path, cool_path, xy_r,
xy_g, xy_b, input_xy_r, input_xy_g, input_xy_b to lock the native LED gamut
contract.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f0edddb2-83e0-4c3d-9f83-1ed90b5cdefc
📒 Files selected for processing (5)
compare_rgbw.pysrc/fl/gfx/rgbw.cpp.hppsrc/fl/gfx/rgbw.hsrc/fl/gfx/rgbww.cpp.hpptests/fl/gfx/rgbw_colorimetric.cpp
💤 Files with no reviewable changes (1)
- compare_rgbw.py
bash lint reformatted three CI files during PR #2711 review work. No functional change — purely line-break/whitespace adjustments that ruff flagged as drift from the current format profile. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Three follow-ups from the CodeRabbit review: 1. **(major) Cache invalidation on in-place gamut mutation** — set_input_gamut() rewrites profile->input_xy_* in place, but the ColorimetricCacheHolder and LutStateHolder are keyed on (profile_ptr, cct). Without invalidation, the cache held stale M_src/LUT entries after a gamut switch on the currently active profile, producing deterministic wrong colors. Now the active per-process caches are evicted whenever set_input_gamut() mutates a profile that matches the cache key. No-op in the FASTLED_RGBW_COLORIMETRIC=0 build (no cache exists to invalidate). 2. **(contract) white_xy doc mismatch** — The header doc said the `white_xy` override "must point to a 2-float array" but the impl already accepted nullptr as "use the gamut's reference white" (equivalent to the 2-arg overload). Doc now matches behavior. Kept the raw-array signature instead of switching to fl::span<const float, 2> — the header sits low in the include graph and pulling fl/stl/span.h here would be a heavier change than the contract bug warrants; the 2-arg overload remains the recommended call site for the default-white path. 3. **(nitpick) RGBWW native-gamut guard** — Added an explicit test asserting kRgbwwDefaultProfile.warm_path / cool_path keep input_xy_* mirroring xy_* and input_xy_w pinned at D65. Symmetric to the existing assertion at rgbw_colorimetric.cpp:252-272; locks the native-LED-gamut contract on both warm and cool paths so future chromaticity retuning can't silently desync source from emitter. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Heads-up — PR #2715 just codified a Public Settings Pattern rule into
Two options, whichever is easier for you: Option A (preferred, cleanest history): fold the wrapper into this PR. Roughly: // src/FastLED.h, near setRgbwColorimetricProfile (which PR #2715 adds)
inline void setInputGamut(fl::DiodeProfile* profile, fl::InputGamut g) FL_NOEXCEPT {
fl::set_input_gamut(profile, g);
}
inline void setInputGamut(fl::DiodeProfile* profile, fl::InputGamut g,
const float white_xy[2]) FL_NOEXCEPT {
fl::set_input_gamut(profile, g, white_xy);
}Then update the PR body's "Opt-in API for named gamuts" example to read: FastLED.setInputGamut(&my_profile, fl::InputGamut::Rec709);…and the same in Option B: ship #2711 as-is and I'll open a follow-up to wrap it after merge. Slightly more churn but no extra work on your end. Either way the free function stays callable, so tests keep working unchanged. (Will need a tiny rebase against master after #2715 lands — |
…al setters Removes the grandfathered exceptions section from the Public Settings Pattern docs. Both names that were allowlisted in the initial commit of this PR were introduced after the policy itself was being defined, so neither was historically grandfathered: - `fl::set_rgbw_colorimetric_profile` is already wrapped on `CFastLED` (`CFastLED::setRgbwColorimetricProfile`) in this PR, so it no longer needs an exception. - `fl::set_input_gamut` (#2710) is introduced in PR #2711 without a `CFastLED` wrapper. The wrapper must be added before that PR merges. Updated files: - `.coderabbit.yaml` - `agents/docs/cpp-standards.md` - `.claude/agents/architecture-reviewer-agent.md` - `.claude/commands/code_review.md` Addresses CodeRabbit review on PR #2715. Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
@coderabbitai full review please — three follow-up commits (9e5831a, 79cf584) address all findings from your previous review:
|
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Fetch PR details and diff
gh pr view 2711 --repo FastLED/FastLED --json title,body,commits,files,state
echo "=== PR DIFF ==="
gh pr diff 2711 --repo FastLED/FastLEDLength of output: 49686
✅ Cache invalidation (
|
…attern `fl::set_input_gamut` (#2710) is a library-wide global setter. Under the Public Settings Pattern in agents/docs/cpp-standards.md, every public fl:: global setter must ship with a thin inline `CFastLED` wrapper that becomes the documented user-facing call site. The two-arg and three-arg overloads now have matching `CFastLED::setInputGamut` wrappers. Removes the implicit grandfathered exception this function was relying on in PR #2715 — that PR's follow-up commit explicitly dropped the allowlist, so this wrapper is now required before merge rather than deferred. Co-Authored-By: Claude Opus 4.7 <[email protected]>
CodeRabbit's findings against fc0703b were addressed in follow-up commits 9e5831a + 79cf584 — cache invalidation hook added to set_input_gamut, white_xy contract doc fixed, RGBWW native-gamut guard test added. CR's own status check is SUCCESS on the new HEAD; CI is 7/7 green. Dismissing the stale review since CR did not auto-update.
Codifies the long-implicit rule that new library-wide configuration setters must be exposed on the `CFastLED` god instance (e.g. `FastLED.setX(...)`) rather than as bare `fl::set_x(...)` free functions. The free function may exist for ADL / testability, but the documented call site is the god instance. Motivated by PR #2711, which added `fl::set_input_gamut(...)` as a free function only — following the unwrapped precedent of `fl::set_rgbw_colorimetric_profile`. Neither has a `FastLED.setX()` entry point, so users don't discover them. Both are now grandfathered exceptions; new code must wrap. Changes: - `agents/docs/cpp-standards.md`: New "Public Settings Pattern" section with rules, exemplar (`setPowerModel` → `set_power_model`), and a grandfathered allowlist. - `CLAUDE.md`: One-liner pointer in the task table and Code Standards section so agents see the rule on entry. - `.coderabbit.yaml`: `path_instructions` for `src/fl/**/*.h`, `src/FastLED.h`, and `src/fl/gfx/**` telling CodeRabbit to flag bare new `fl::set_* / enable_* / disable_* / use_*` declarations without a matching `CFastLED` wrapper as HIGH severity, with the grandfathered allowlist honored. - `.claude/agents/architecture-reviewer-agent.md`: API Surface check step gains a "Public Settings Pattern enforcement" subsection. - `.claude/commands/code_review.md`: New rule block before "SIGNED INTEGER OVERFLOW", plus a counter in the violations summary. - `src/FastLED.h`: Backfills `CFastLED::setRgbwColorimetricProfile()` and `getRgbwColorimetricProfile()` — thin `inline` delegators to the existing `fl::` free functions. `setInputGamut` is intentionally left for PR #2711 to add alongside its own free function (it isn't on master yet). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…al setters Removes the grandfathered exceptions section from the Public Settings Pattern docs. Both names that were allowlisted in the initial commit of this PR were introduced after the policy itself was being defined, so neither was historically grandfathered: - `fl::set_rgbw_colorimetric_profile` is already wrapped on `CFastLED` (`CFastLED::setRgbwColorimetricProfile`) in this PR, so it no longer needs an exception. - `fl::set_input_gamut` (#2710) is introduced in PR #2711 without a `CFastLED` wrapper. The wrapper must be added before that PR merges. Updated files: - `.coderabbit.yaml` - `agents/docs/cpp-standards.md` - `.claude/agents/architecture-reviewer-agent.md` - `.claude/commands/code_review.md` Addresses CodeRabbit review on PR #2715. Co-Authored-By: Claude Opus 4.7 <[email protected]>
* docs(cpp): enforce Public Settings Pattern for global setters Codifies the long-implicit rule that new library-wide configuration setters must be exposed on the `CFastLED` god instance (e.g. `FastLED.setX(...)`) rather than as bare `fl::set_x(...)` free functions. The free function may exist for ADL / testability, but the documented call site is the god instance. Motivated by PR #2711, which added `fl::set_input_gamut(...)` as a free function only — following the unwrapped precedent of `fl::set_rgbw_colorimetric_profile`. Neither has a `FastLED.setX()` entry point, so users don't discover them. Both are now grandfathered exceptions; new code must wrap. Changes: - `agents/docs/cpp-standards.md`: New "Public Settings Pattern" section with rules, exemplar (`setPowerModel` → `set_power_model`), and a grandfathered allowlist. - `CLAUDE.md`: One-liner pointer in the task table and Code Standards section so agents see the rule on entry. - `.coderabbit.yaml`: `path_instructions` for `src/fl/**/*.h`, `src/FastLED.h`, and `src/fl/gfx/**` telling CodeRabbit to flag bare new `fl::set_* / enable_* / disable_* / use_*` declarations without a matching `CFastLED` wrapper as HIGH severity, with the grandfathered allowlist honored. - `.claude/agents/architecture-reviewer-agent.md`: API Surface check step gains a "Public Settings Pattern enforcement" subsection. - `.claude/commands/code_review.md`: New rule block before "SIGNED INTEGER OVERFLOW", plus a counter in the violations summary. - `src/FastLED.h`: Backfills `CFastLED::setRgbwColorimetricProfile()` and `getRgbwColorimetricProfile()` — thin `inline` delegators to the existing `fl::` free functions. `setInputGamut` is intentionally left for PR #2711 to add alongside its own free function (it isn't on master yet). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(cpp): drop grandfathered allowlist; require wrapper for all global setters Removes the grandfathered exceptions section from the Public Settings Pattern docs. Both names that were allowlisted in the initial commit of this PR were introduced after the policy itself was being defined, so neither was historically grandfathered: - `fl::set_rgbw_colorimetric_profile` is already wrapped on `CFastLED` (`CFastLED::setRgbwColorimetricProfile`) in this PR, so it no longer needs an exception. - `fl::set_input_gamut` (#2710) is introduced in PR #2711 without a `CFastLED` wrapper. The wrapper must be added before that PR merges. Updated files: - `.coderabbit.yaml` - `agents/docs/cpp-standards.md` - `.claude/agents/architecture-reviewer-agent.md` - `.claude/commands/code_review.md` Addresses CodeRabbit review on PR #2715. Co-Authored-By: Claude Opus 4.7 <[email protected]> * feat(lint): enforce Public Settings Pattern for fl:: global setters (layer 5) (#2716) * feat(lint): enforce Public Settings Pattern for fl:: global setters Adds `PublicSettingsPatternChecker` (ci/lint_cpp/public_settings_pattern_checker.py) — layer 5 of the six-layer Public Settings Pattern enforcement plan introduced in PR #2715 / docs commit d51a8f6. What it checks: Every public free function declared at `namespace fl` root scope in `src/fl/**/*.h` whose name matches `^(set|enable|disable|use)_[a-z]` MUST have a matching `CFastLED::setX()` / `enableX()` / `disableX()` wrapper in `src/FastLED.h` that delegates to it. Carve-outs (NOT flagged): - Sub-namespaces (fl::detail::, fl::isr::, fl::colorimetric_detail::, …) - Anonymous namespaces - Class/struct member functions (per-object setters) - Function-pointer installers (set_rgb_2_rgbw_function, set_rgb_2_rgbww_function) - Per-object mutators: non-const ptr/ref to user-defined type as first param - Lines suppressed with `// nolint` or `// ok public_settings` Grandfathered allowlist (pre-rule offenders, not flagged): set_rgbw_colorimetric_profile, set_input_gamut (from #2715 description), enable_rgbw_colorimetric_lut, disable_rgbw_colorimetric_lut (#2545), set_rgbww_colorimetric_profile (#2558). Implementation notes: - Uses a per-`{` scope stack (not a simple brace counter) so that enum bodies, inline function definitions, and nested namespaces are all tracked correctly without false namespace pops. - FastLED.h is loaded once at `__init__` time for cross-file wrapper lookup. - 63 unit tests; `bash lint --cpp` passes clean on the full codebase. - Registered in the `fl` scope in run_all_checkers.py. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * fix(lint): annotate first_param list type in public_settings checker Pyright (--strict) flagged `first_param` as `list[Unknown]` since it's initialized as a bare `[]`. The list only ever holds str characters from iterating `params_raw` (a str), so the annotation is `list[str]`. Drive-by while reviewing the agent-generated PR #2716. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Sonnet 4.6 <[email protected]> * docs(cpp): align grandfathered allowlist text with checker CodeRabbit (#2715 thread on agents/docs/cpp-standards.md:262) flagged that the "No grandfathered offenders" wording contradicted the actual enforcement state: public_settings_pattern_checker.py still carries a small GRANDFATHERED_NAMES allowlist for legacy bare setters that have not yet received CFastLED wrappers (set_input_gamut, enable_rgbw_colorimetric_lut, disable_rgbw_colorimetric_lut, set_rgbww_colorimetric_profile). Reconcile the policy text in cpp-standards.md, architecture-reviewer- agent.md, and code_review.md to describe the transitional allowlist explicitly: strict for *new* code, shrinking allowlist for legacy names, entries removed as wrappers land. The behavior of the rule is unchanged; only the documentation matches reality now. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Closes #2710.
#2705 added the source-RGB → LED-XYZ transform with
kRgbwDefaultProfiledefaulting to Rec709/sRGB primaries + D65. That silently clipped saturated inputs to the sRGB sub-volume of the LED's native gamut —RGB=(255,0,0)on a typical SK6812 strip drove the LED red diode to ~70 % of its capability, leaving the rest unreachable through the public API. Users had no indication this was happening; they expected FastLED to drive their LEDs at full saturation as it always has.Behavior change
kRgbwDefaultProfile.input_xy_r/g/bnow mirror the profile's own LEDxy_r/g/b(was sRGB), so saturated inputs hit the LED gamut at full saturation.input_xy_wstays at D65 so neutral inputs land on a standard daylight white. Same applies tokRgbwwDefaultProfile(RGBWW warm + cool paths).Net effect for users on the default profile:
RGB=(255,0,0)RGB=(255,255,255)RGB=(0,0,255)Opt-in API for named gamuts
Users with sRGB content (ambilight, video bridges) write one line at setup:
fl::set_input_gamut(&my_profile, fl::InputGamut::Rec709);The new enum + setter:
The white-override overload covers niche cases like D50 photography workflow or any custom calibration target.
Tests
fl_gfx_rgbw_colorimetricadds:default profile carries native-LED + D65 source space (#2710)— assertsinput_xy_*mirrorxy_*andinput_xy_w == D65.source matrix matches published sRGB->XYZ matrix (Rec709 opt-in)— existing sRGB matrix-derivation check now opts into Rec709 viaset_input_gamut()first.set_input_gamut: Native copies LED primaries— trashesinput_xy_*, then proves Native restores them fromxy_*.set_input_gamut: named gamuts populate canonical primaries— hits Rec709 / Rec2020 / DCI-P3 D65 / DCI-P3 D60 and asserts canonical primary + white values.set_input_gamut: white override honored— covers the overload (D50 in the test).set_input_gamut: null profile is a no-op.Drive-by
Removes
compare_rgbw.py, a one-off scratch comparison harness that slipped into master via #2709's squash-merge despite being deleted on the branch.Test plan
bash lintcleanbash test --cpp --cleanpasses 308/308 including the 6 new gamut-API cases🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Changes
Bug Fixes / Reliability
Chores
Tests