Skip to content

fix(rgbw): source RGB color space + differentiated boosted solver + Hermite LUT - #2707

Merged
zackees merged 4 commits into
masterfrom
fix/rgbw-source-space-and-overdrive-2705-2706
Jun 3, 2026
Merged

zackees merged 4 commits into
masterfrom
fix/rgbw-source-space-and-overdrive-2705-2706

Conversation

@zackees

@zackees zackees commented Jun 3, 2026 •

Copy link
Copy Markdown
Member

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_COLORIMETRIC flag.

#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: DiodeProfile gains input_xy_r/g/b/w (defaults: Rec709/sRGB primaries + D65). 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. 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 for DiodeProfile{}-style aggregate inits.

#2706 — Differentiated boosted solver

The old solve_wx_lp was max w s.t. (a − w·d) ≥ 0, which finds the same vertex of the same feasible polytope as solve_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-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_boosted ≥ W_strict. At ρ = 0 the behavior collapses to the strict vertex; at ρ = 1 W 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_colorimetric adds:

  • 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 return false.
  • 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.
  • LUT stride constants match storage layout.

Verification

bash lint              # clean (also fixed pre-existing Teensy audio_input lint findings on master)
bash test --cpp        # 308/308 passed

Test plan

  • Lint passes (bash lint)
  • All unit tests pass (bash test --cpp)
  • Default profile has populated source-space fields
  • M_src matches published sRGB→XYZ (D65) matrix
  • Boosted output differs from strict for in-gamut targets
  • CI green
  • CodeRabbit review addressed

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added source color‑space support for more accurate RGBW/RGBWW color interpretation and default profiles using D65/sRGB‑Rec709 primaries.
    • Introduced Hermite interpolation option (now the default) for smoother color lookup tables and selectable interpolation modes.
  • Bug Fixes

    • Improved fallback when source chromaticity is missing or degenerate.
    • Refined boosted white-channel computation for more consistent behavior vs strict mode.
  • Tests

    • Added coverage for source‑space mapping, LUT/Hermite math, and boosted‑vs‑strict comparisons.
  • Chores

    • Made Linux CI package install more reliable by refreshing APT indexes.

…+ 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]>
@coderabbitai

coderabbitai Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

Review 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: Pro

Run ID: f65e0c97-9e9a-464e-aed8-7575a737bf98

📥 Commits

Reviewing files that changed from the base of the PR and between cde5bcd and 8d2833e.

📒 Files selected for processing (1)
  • src/fl/gfx/rgbww.cpp.hpp

📝 Walkthrough

Walkthrough

This 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.

Changes

RGBW Colorimetric Solver Enhancement

Layer / File(s) Summary
Source-space contract, types, and helpers
src/fl/gfx/rgbw.h, src/fl/gfx/rgbw_colorimetric.h
DiodeProfile adds input_xy_* fields; build_source_matrix() added; ProfileCache gains M_src and has_source_space; LutInterp, strides, and hermite_basis added.
Profile cache construction with source matrix and fallback
src/fl/gfx/rgbw_colorimetric.cpp.hpp
build_profile_cache() computes and caches M_src when non-degenerate; zeroes it and clears has_source_space to force legacy fallback on degeneracy.
Strict subgamut solver integration with source-space matrix
src/fl/gfx/rgbw_colorimetric.cpp.hpp, src/fl/gfx/rgbw.cpp.hpp
Strict solver and LUT path compute target XYZ via cache.M_src·[s_r,s_g,s_b] when available; otherwise use legacy P_R/P_G/P_B accumulation.
Overdrive ratio parameterization and W-channel boost logic
src/fl/gfx/rgbw_colorimetric.h, src/fl/gfx/rgbw_colorimetric.cpp.hpp
Replace solve_wx_lp() with solve_wx_overdrive(..., overdrive_ratio, ...); compute strict feasible W, clamp, and apply overdrive_ratio (default constant introduced).
LUT interpolation mode support: Hermite derivative computation and bicubic evaluation
src/fl/gfx/rgbw_colorimetric.h, src/fl/gfx/rgbw_colorimetric.cpp.hpp
build_lut(cache, grid_n, interp) stores interp, chooses stride (Hermite adds derivative channels), computes finite-difference derivatives; lookup_lut() evaluates Hermite bicubic using derivatives or previous bilinear path.
Default profile updates with source chromaticity values
src/fl/gfx/rgbw.cpp.hpp, src/fl/gfx/rgbww.cpp.hpp
Update default input_xy_* to Rec709/sRGB primaries with D65 white; RGBW/RGBWW codepaths now use cached source-space matrix when present; boosted path calls solve_wx_overdrive.
Test coverage for source-space matrix, boosted solver, and Hermite LUT
tests/fl/gfx/rgbw_colorimetric.cpp
Add tests for build_source_matrix() correctness, boosted vs strict behavior (overdrive), Hermite basis properties, and LUT stride layout.

Build System and Platform Infrastructure

Layer / File(s) Summary
Teensy audio input include organization
src/platforms/arm/teensy/_build.cpp.hpp, src/platforms/arm/teensy/audio_input_teensy.h, src/platforms/arm/teensy/audio_input_teensy_config.h
Move conditional Teensy audio include before unity-build marker; add is_teensy.h include and a clarifying comment in the config header.
CI apt-get update before libunwind install
.github/workflows/template_example_test.yml, .github/workflows/template_unit_test.yml
Run sudo apt-get update before installing libunwind-dev on Linux runners to avoid failures from stale mirror metadata.

🎯 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
Loading

Possibly Related Issues

Possibly Related PRs

Poem

A rabbit hops through sRGB skies,
Matrices clutched with curious eyes,
Hermite curves and overdrive hum,
White finds its place, the LEDs come,
Solver sings—colors bloom—hippity-thump! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.79% which is insufficient. The required threshold is 80.00%. 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 concisely captures the three main changes: source RGB color space, differentiated boosted solver, and Hermite LUT interpolation—all primary objectives of the PR.
Linked Issues check ✅ Passed The PR implementation directly addresses both linked issues: #2705 (source RGB→LED-XYZ transform via input_xy_* and M_src matrix with fallback), #2706 (differentiated boosted solver via solve_wx_overdrive with overdrive_ratio achieving W_boosted ≥ W_strict). Tests validate source-space correctness and boosted vs. strict divergence.
Out of Scope Changes check ✅ Passed All changes are scoped to RGBW colorimetric modeling (DiodeProfile input primaries, M_src transform, solve_wx_overdrive, Hermite LUT, RGBWW eta caching) and supporting CI workflow fixes (APT cache refresh). No unrelated features or design shifts detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rgbw-source-space-and-overdrive-2705-2706

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 and usage tips.

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]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 223f13f and dbc7b07.

📒 Files selected for processing (9)
  • src/fl/gfx/rgbw.cpp.hpp
  • src/fl/gfx/rgbw.h
  • src/fl/gfx/rgbw_colorimetric.cpp.hpp
  • src/fl/gfx/rgbw_colorimetric.h
  • src/fl/gfx/rgbww.cpp.hpp
  • src/platforms/arm/teensy/_build.cpp.hpp
  • src/platforms/arm/teensy/audio_input_teensy.h
  • src/platforms/arm/teensy/audio_input_teensy_config.h
  • tests/fl/gfx/rgbw_colorimetric.cpp

Comment thread src/fl/gfx/rgbww.cpp.hpp Resolved
Comment thread tests/fl/gfx/rgbw_colorimetric.cpp Resolved
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]>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between dc6664b and cde5bcd.

📒 Files selected for processing (4)
  • src/fl/gfx/rgbw_colorimetric.cpp.hpp
  • src/fl/gfx/rgbw_colorimetric.h
  • src/fl/gfx/rgbww.cpp.hpp
  • tests/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

Comment thread src/fl/gfx/rgbww.cpp.hpp Resolved
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]>
@zackees
zackees merged commit 6cd4a07 into master Jun 3, 2026
11 checks passed
@zackees
zackees deleted the fix/rgbw-source-space-and-overdrive-2705-2706 branch June 3, 2026 20:00
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 3, 2026
zackees added a commit that referenced this pull request Jun 4, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

1 participant