Repository navigation
fix(rgbw): source RGB color space + differentiated boosted solver + Hermite LUT - #2707
Conversation
…+ Hermite LUT Closes #2705. Closes #2706. #2705 — Source RGB → LED XYZ transform ===================================== The colorimetric solvers (added in #2545) previously interpreted the input RGB triple as native-emitter drive coordinates, so `RGB=(255,255,255)` targeted the native-gamut sum chromaticity rather than any standard white point. D65-based verifiers could never match the implementation. Adds input_xy_r/g/b/w to DiodeProfile (defaults: Rec709/sRGB primaries + D65 white). build_profile_cache constructs an M_src 3×3 matrix via the classic CIE primary-matrix derivation; solvers now compute `X_t = M_src · source_rgb` so RGB=(255,255,255) actually means D65 white in CIE coordinates. Legacy zero-initialized profiles (input_xy_w[1]==0) fall back to the device-emitter projection for backward compat. #2706 — Differentiated boosted solver ===================================== The previous solve_wx_lp was `max w s.t. (a - w*d) >= 0`, which produces the *same vertex of the feasible polytope* as the strict sub-gamut solver — bit-identical output for every in-gamut target. Replaced with solve_wx_overdrive(overdrive_ratio): computes the strict-vertex w and then pushes W past it by ρ ∈ [0,1] (default 0.5), accepting chromaticity drift toward W in exchange for higher luminance. kRGBWColorimetricBoosted now produces genuinely different output from kRGBWColorimetric for any in-gamut target, with W ≥ strict-vertex W. LUT upgrade — value+slope Hermite interpolation =============================================== Per-cell storage of (value, ∂/∂t_x, ∂/∂t_y) per RGBW channel enables bicubic Hermite interp (no fxy cross term). 3× larger per cell vs. bilinear, but typically reaches comparable error at ~half the grid edge length — small LUTs (N=8..16) become viable for memory-constrained targets. Bilinear remains selectable via `build_lut(cache, n, Bilinear)`. Tests ===== - Default profile carries Rec709/sRGB + D65 fields with expected values. - M_src·(1,1,1) lands on D65 at Y=1.0. - M_src·(1,0,0), etc. preserve source primary chromaticities. - Constructed M_src matches the published linear-sRGB → XYZ (D65) matrix. - Singular source primaries are rejected. - Boosted dispatch ≠ strict dispatch for in-gamut inputs (probe via the LUT enable API; skipped when the lib was built without colorimetric). - Boosted W ≥ strict W (overdrive monotonicity). - Hermite basis evaluates to expected node values + symmetry checks. - Stride constants match storage layout. All 308 unit tests pass. bash lint clean (also addressed pre-existing Teensy audio_input + unity-build lint findings from 223f13f that were blocking C++ linter on master). 🤖 Generated with [Claude Code](https://claude.com/claude-code) 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: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds source-input chromaticities and a cached source→XYZ matrix, uses that matrix in colorimetric XYZ computation when available, replaces the LP white solver with an overdrive-parameterized solver, adds Hermite LUT interpolation, updates default profiles to sRGB-D65, and adds tests plus minor CI/platform tweaks. ChangesRGBW Colorimetric Solver Enhancement
Build System and Platform Infrastructure
🎯 3 (Moderate) | ⏱️ ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant ProfileCache
participant Solver
participant LUT
participant LED
Client->>ProfileCache: provide DiodeProfile input_xy_* → build_source_matrix -> M_src (cached)
Client->>Solver: request RGB→RGBW (s_r,s_g,s_b)
Solver->>ProfileCache: read has_source_space, M_src
ProfileCache-->>Solver: M_src (or none)
Solver->>LUT: lookup or build_lut (interp) for target XYZ
LUT-->>Solver: sampled RGBW (or evaluate Hermite)
Solver->>LED: output RGBW drives
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 |
The Azure Ubuntu apt mirror was returning 404 on liblzma-dev_5.6.1+really5.4.5-1ubuntu0.2_amd64.deb (a transient package the mirror metadata referenced before the mirror finished syncing). Running apt-get update first refreshes the cached package index so the install step doesn't pin to a missing version, eliminating the spurious CI failures on the test / build matrix. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/rgbww.cpp.hpp`:
- Around line 61-64: compute_eta_from_input currently reconstructs
chromaticities using warm_path.xy_r/xy_g/xy_b (emitter space) so eta is biased
to the LED emitter gamut; update compute_eta_from_input (and the similar logic
used around the other eta derivations) to derive chromaticities from input_xy_r,
input_xy_g, input_xy_b or by applying the source-space matrix used by the
colorimetric solver (i.e., convert source-space XY to the same space the solver
uses) so eta is computed in source-space/D65 like the rest of the colorimetric
solve, not emitter-space; ensure all references to warm_path.xy_* are replaced
or conditioned to use input_xy_* / source-space matrix conversion when computing
eta.
In `@tests/fl/gfx/rgbw_colorimetric.cpp`:
- Around line 421-446: The test currently redefines local lambdas
h00/h01/h10/h11 instead of exercising the production Hermite implementation;
replace the local lambdas with calls to the real Hermite basis functions (or the
helper that computes them) from the header under test and/or create a small LUT
and call lookup_lut() to produce an interpolated RGBW sample, then assert the
returned RGBW values (and derivative behavior) rather than comparing the local
lambdas' values. Ensure you reference the production symbols (the Hermite basis
functions used by lookup_lut() and the lookup_lut() function itself) in the
assertions so the test fails on regressions.
🪄 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: a735dc1d-bb26-468c-9381-6f419b19aacc
📒 Files selected for processing (9)
src/fl/gfx/rgbw.cpp.hppsrc/fl/gfx/rgbw.hsrc/fl/gfx/rgbw_colorimetric.cpp.hppsrc/fl/gfx/rgbw_colorimetric.hsrc/fl/gfx/rgbww.cpp.hppsrc/platforms/arm/teensy/_build.cpp.hppsrc/platforms/arm/teensy/audio_input_teensy.hsrc/platforms/arm/teensy/audio_input_teensy_config.htests/fl/gfx/rgbw_colorimetric.cpp
1. RGBWW eta derivation respects source-space (CodeRabbit major)
`compute_eta_from_input` previously reconstructed the input chromaticity
from the warm path's *emitter* primaries, so even with the new
`input_xy_*` defaults the warm/cool split was biased toward the LED gamut
instead of the intended sRGB/D65 source gamut. Now uses `M_src` (built
from the warm path's `input_xy_*`) to project the input into the source
color space; falls back to the legacy emitter projection only when the
profile leaves `input_xy_w[1]` zero (the `DiodeProfile{}` default).
2. Hermite test exercises production code (CodeRabbit major)
Test cases previously redefined the Hermite basis as local lambdas, so a
regression in the production basis (or in lookup_lut's call into it)
would not be caught. Extracted a single `hermite_basis(t, out)` inline
helper into `rgbw_colorimetric.h`; `lookup_lut` and both test cases now
call exactly the same evaluator. Added a second test that reconstructs a
linear function f(t) = a + b·t through the basis to catch swaps in the
h10/h11 derivative slots.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e808e07b-2a8f-4f73-81eb-a371d90cbe84
📒 Files selected for processing (4)
src/fl/gfx/rgbw_colorimetric.cpp.hppsrc/fl/gfx/rgbw_colorimetric.hsrc/fl/gfx/rgbww.cpp.hpptests/fl/gfx/rgbw_colorimetric.cpp
🚧 Files skipped from review as they are similar to previous changes (3)
- tests/fl/gfx/rgbw_colorimetric.cpp
- src/fl/gfx/rgbw_colorimetric.h
- src/fl/gfx/rgbw_colorimetric.cpp.hpp
CodeRabbit #2707 (heavy lift): `compute_eta_from_input` runs on the per-pixel RGBWW path, so the previous `build_source_matrix()` + `invert3x3()` call re-derived the 3x3 source-space matrix for every non-black pixel in both strict and boosted modes. `input_xy_*` is profile-level data — the matrix is invariant until the active profile's source primaries change — so the rebuild adds large avoidable cost on MCU targets. Adds an EtaSourceMatrixCache held behind a lazy Singleton<T>. The cache snapshots the eight input_xy_* floats; if all eight match on the next call, the cached M_src is reused (no math) — otherwise the matrix is rebuilt and the snapshot updated. Falls back to the legacy emitter-space projection only when the profile leaves input_xy_w[1] zero (the DiodeProfile{} default). Hot path is now: 8 float compares (cache hit) + matvec3 + ratio compute. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…or tests (#2721) * feat(rgbw): expose LutInterp choice + LUT memory accessor + error-floor tests (#2720) Adds the missing public surface around the colorimetric LUT path so users can trade memory for accuracy from outside the library: - `enum class fl::RgbwLutInterp { Bilinear, Hermite }` — new public type. - `enable_rgbw_colorimetric_lut(grid_n, interp)` overload; the single-arg overload preserves source compatibility and forwards to Hermite. - `rgbw_colorimetric_lut_memory_bytes(grid_n, interp)` constexpr accessor so callers can size their RAM/flash budget at compile time. LutStateHolder now keys cache validity on the requested interp in addition to (profile, cct, grid_n), so switching interp triggers an automatic rebuild on the next colorimetric call. Test coverage: - `LUT memory accessor matches stride math` — `FL_STATIC_ASSERT`s for Bilinear/Hermite at N ∈ {8, 16, 32, 64} plus the zero-grid degenerate case, pinning the byte-cost contract. - `LUT error floor: Bilinear N=16/32` — asserts max per-channel byte delta between the LUT path and the closed-form solver across a 7³ RGB sweep stays under a generous budget. - `LUT error floor: Hermite N=16/32` — same harness, tighter budget at N=32 (the default-quality config). - `LUT error floor: monotonicity in grid size` — refining the grid must not regress the worst-case error. Drive-by: refresh the stale doc comment on `enable_rgbw_colorimetric_lut` (it described the bilinear default + bilinear byte counts, but the actual default has been Hermite since #2707 — the new comment tables both). Also fixes a pre-existing IWYU violation in `lcd_spi/channel_driver_lcd_clockless.cpp.hpp` flagged by the linter (FreeRTOS headers wrapped in `IWYU pragma: begin_keep`/ `end_keep`). Closes #2720. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(rgbw): address CodeRabbit review feedback - Clamp grid_n to [4, 256] in rgbw_colorimetric_lut_memory_bytes() to match the runtime clamp in enable_rgbw_colorimetric_lut(), so callers budget the correct RAM/flash footprint for grid_n < 4 or > 256. - Fix u8 overflow in sample_sweep(): r*42+15 wrapped from 267 to 11 at r=6, dropping full-scale coverage from the error-floor suite. Replace with a bucket() lambda that maps step v in [0,6] to [15, 255]. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Closes #2705
Closes #2706
Summary
Single PR addressing #2705 (no target white point) and #2706 (boosted LP is bit-identical to strict sub-gamut), plus a LUT upgrade per follow-up feedback. All gated behind the existing
FASTLED_RGBW_COLORIMETRICflag.#2705 — Source RGB → LED XYZ transform
The colorimetric solvers added in #2545 interpreted the input RGB triple as native-emitter drive coordinates.
RGB=(255,255,255)targeted the native-gamut sum chromaticity (e.g. ~xy(0.20, 0.23) for the default SK6812 profile), not D65 or any standard white point — so D65-based verifiers could never match the implementation.Fix:
DiodeProfilegainsinput_xy_r/g/b/w(defaults: Rec709/sRGB primaries + D65).build_profile_cacheconstructs anM_src3×3 matrix via the classic CIE primary-matrix derivation; solvers now computeX_t = M_src · source_rgb.RGB=(255,255,255)now actually means D65 white at Y=1.0.Legacy zero-initialized profiles (
input_xy_w[1] == 0) fall back to the device-emitter projection, preserving the old behavior forDiodeProfile{}-style aggregate inits.#2706 — Differentiated boosted solver
The old
solve_wx_lpwasmax w s.t. (a − w·d) ≥ 0, which finds the same vertex of the same feasible polytope assolve_strict_subgamut— guaranteed bit-identical output for every in-gamut target. The "wx_lp_legacy" gist spec is faithful, but the resulting mode was redundant.Fix:
solve_wx_overdrive(overdrive_ratio)computes the strict-vertexwand then pushes W past it byρ ∈ [0, 1](default 0.5), accepting chromaticity drift toward W in exchange for higher luminance.kRGBWColorimetricBoostednow produces genuinely different output fromkRGBWColorimetricfor any in-gamut target, withW_boosted ≥ W_strict. Atρ = 0the behavior collapses to the strict vertex; atρ = 1W is driven to 1.0.LUT upgrade — value + slope (bicubic Hermite)
Per follow-up reviewer feedback ("LUTs must be small and allow different error levels — store position + slope"). Per-grid-point storage of
(value, ∂/∂t_x, ∂/∂t_y)for each RGBW channel enables bicubic Hermite interpolation (no fxy cross term). 3× the per-cell memory vs. bilinear, but typically reaches comparable error at ~½ the grid edge length — small LUTs (N=8..16) become viable for memory-constrained targets.build_lut(cache, n, LutInterp::Bilinear)remains available for users who prefer the original.Tests
fl_gfx_rgbw_colorimetricadds:M_src·(1,1,1)lands on D65 at Y=1.0.M_src·(1,0,0)etc. preserve source primary chromaticities.M_srcmatches the published linear-sRGB → XYZ (D65) matrix.false.Verification
Test plan
bash lint)bash test --cpp)🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Chores