Skip to content

feat(rgbw): expose LutInterp choice + LUT memory accessor + error-floor tests - #2721

Merged
zackees merged 3 commits into
masterfrom
feat/rgbw-lut-interp-and-error-floor
Jun 4, 2026
Merged

zackees merged 3 commits into
masterfrom
feat/rgbw-lut-interp-and-error-floor

Conversation

@zackees

@zackees zackees commented Jun 4, 2026 •

Copy link
Copy Markdown
Member

Closes #2720.

Summary

Adds the missing public surface around the colorimetric LUT path so users can trade memory for accuracy from outside the library — and locks the LUT's accuracy budget down with explicit regression tests.

Public API additions (fl:: namespace)

enum class RgbwLutInterp : u8 {
    Bilinear = 0,   // 8 B/cell (4x i16)
    Hermite  = 1,   // 24 B/cell (4x i16 value + 4x dx + 4x dy)
};

bool enable_rgbw_colorimetric_lut(int grid_n, RgbwLutInterp interp) noexcept;
bool enable_rgbw_colorimetric_lut(int grid_n) noexcept;  // existing — forwards to Hermite

constexpr unsigned long rgbw_colorimetric_lut_memory_bytes(
    int grid_n, RgbwLutInterp interp) noexcept;

The existing single-arg overload is preserved (forwards to Hermite), so this is source-compatible with everyone who is already on the LUT path.

LutStateHolder now keys its rebuild check on (profile, cct, grid_n, interp), so changing interp triggers an automatic rebuild on the next colorimetric call exactly like changing grid_n does.

Memory cost (matches the new accessor)

grid_n Bilinear (8 B/cell) Hermite (24 B/cell)
8 512 1 536
16 2 048 6 144
32 8 192 24 576
64 32 768 98 304

Tests added

In tests/fl/gfx/rgbw_colorimetric.cpp:

  • LUT memory accessor matches stride math — FL_STATIC_ASSERTs for every (interp, N) cell in the table above, plus the grid_n=0 degenerate case. Pins the byte-cost contract at compile time.
  • LUT error floor: Bilinear N=16 — <= 48 LSB max per-channel delta.
  • LUT error floor: Bilinear N=32 — <= 24 LSB.
  • LUT error floor: Hermite N=16 — <= 40 LSB (set just inside the Bilinear N=16 budget so a Hermite regression that silently degrades to bilinear-equivalent error gets caught).
  • LUT error floor: Hermite N=32 — <= 16 LSB (default-quality config — what most users will get from the no-arg enable_rgbw_colorimetric_lut(N)).
  • LUT error floor: monotonicity in grid size — refining the Hermite grid from N=16 to N=32 must not regress max delta beyond 4 LSB of slack.

The error-floor harness sweeps 7³−1 = 342 in-gamut RGB samples through dispatch in two passes (LUT disabled → closed-form; LUT enabled → interpolated) and compares max per-channel byte delta. Thresholds are deliberately generous against current behavior (typically 2–3× headroom) so the tests don't flap on minor numerical adjustments, but tighten the moment something seriously regresses (wrong basis, wrong stride, sign-flipped slope, off-by-one cell indexing, lost quantization precision).

Doc refresh

The comment on enable_rgbw_colorimetric_lut claimed bilinear default + quoted bilinear byte counts. Since #2707 made Hermite the actual default, the comment was wrong for everyone on the LUT path. New comment tables both interps explicitly.

Drive-by

Fixes a pre-existing IWYU violation in src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp (FreeRTOS headers needed IWYU pragma: begin_keep / end_keep wrappers) — surfaced by bash lint on a clean tree.

Test plan

  • bash lint clean
  • bash test fl_gfx_rgbw_colorimetric --cpp passes all error-floor cases (5 new) + memory accessor case (1 new) + all pre-existing cases
  • CI green
  • CodeRabbit review addressed

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added selectable interpolation modes for RGBW colorimetric lookup tables and a memory estimator to preview LUT storage needs per configuration.
  • Tests
    • Expanded automated tests with regression, error‑floor and monotonicity checks to validate LUT accuracy across interpolation modes and grid sizes.

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

coderabbitai Bot commented Jun 4, 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: d074be63-d5bb-4935-b5f2-213109993074

📥 Commits

Reviewing files that changed from the base of the PR and between 8151ed1 and b8c8a87.

📒 Files selected for processing (2)
  • src/fl/gfx/rgbw.h
  • tests/fl/gfx/rgbw_colorimetric.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/fl/gfx/rgbw.h
  • tests/fl/gfx/rgbw_colorimetric.cpp

📝 Walkthrough

Walkthrough

This PR extends the RGBW colorimetric LUT to support a selectable interpolation (Bilinear or Hermite), records the requested interp in LUT state, includes interp in rebuild staleness checks, adds a constexpr memory-size helper, and adds LUT vs closed-form error-floor regression tests.

Changes

RGBW Colorimetric LUT Interpolation Selection

Layer / File(s) Summary
Public API contracts and memory helper
src/fl/gfx/rgbw.h
RgbwLutInterp enum (Bilinear, Hermite), new enable_rgbw_colorimetric_lut(grid_n, interp) overload with updated docs, and constexpr rgbw_colorimetric_lut_memory_bytes(grid_n, interp) helper.
Internal state and rebuild staleness logic
src/fl/gfx/rgbw.cpp.hpp
LutStateHolder stores requested_interp; to_internal_interp() maps the public enum; rebuild_lut_if_stale() includes interp in up-to-date checks and forwards it to build_lut().
Enable/disable function wiring and delegation
src/fl/gfx/rgbw.cpp.hpp
New enable_rgbw_colorimetric_lut(grid_n, interp) clamps grid_n, records interp, forces rebuild; single-arg overload forwards to Hermite; disable resets interp; non-colorimetric stub updated to accept interp.
LUT error-floor regression test suite
tests/fl/gfx/rgbw_colorimetric.cpp
lut_error_floor helpers and tests that probe link presence, sweep sample RGBs comparing closed-form vs LUT outputs, assert rgbw_colorimetric_lut_memory_bytes() via FL_STATIC_ASSERT, enforce per-channel byte-delta thresholds for Bilinear/Hermite at N=16/32, and check Hermite monotonicity.

Sequence Diagram

sequenceDiagram
  participant Dev as Developer
  participant API as enable_rgbw_colorimetric_lut
  participant State as LutStateHolder
  participant Rebuild as rebuild_lut_if_stale
  participant Builder as build_lut
  Dev->>API: call enable_rgbw_colorimetric_lut(grid_n, interp)
  API->>State: store requested_interp, clamp grid_n, mark stale
  Rebuild->>State: check profile, CCT override, grid_n, requested_interp
  alt up-to-date
    Rebuild->>Builder: skip build (up-to-date)
  else stale
    Rebuild->>Builder: build_lut(..., to_internal_interp(requested_interp))
    Builder->>State: update LUT table and built markers
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2552: Related prior work on the RGBW colorimetric LUT lifecycle and builder.
  • FastLED/FastLED#2554: Overlaps at LUT generation/lookup hardening and degenerate-state handling.
  • FastLED/FastLED#2707: Prior Hermite-vs-bilinear interpolation support that this PR exposes and validates via API and tests.

Poem

"🐰 I nudge the LUT to Hermite or Bilinear light,
Hopping through grids both large and slight.
I count the bytes, I test the sweep,
So colors stay true while bunnies sleep. ✨"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.41% 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 accurately and concisely summarizes the main changes: exposing LUT interpolation choice, adding a memory accessor function, and including error-floor tests.
Linked Issues check ✅ Passed The PR fully addresses all four objectives from issue #2720: exposing RgbwLutInterp choice in public API with backward-compatible single-arg overload, providing rgbw_colorimetric_lut_memory_bytes() accessor, adding comprehensive error-floor regression tests for both interpolation modes, and updating documentation with corrected memory costs.
Out of Scope Changes check ✅ Passed All changes align with stated objectives; the ESP32 IWYU pragma fix is a minor drive-by improvement mentioned in PR objectives, and no out-of-scope functionality changes were introduced.

✏️ 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 feat/rgbw-lut-interp-and-error-floor
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feat/rgbw-lut-interp-and-error-floor

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Infer (1.2.0)
tests/fl/gfx/rgbw_colorimetric.cpp

tests/fl/gfx/rgbw_colorimetric.cpp:19:10: fatal error: 'test.h' file not found
19 | #include "test.h"
| ^~~~~~~~
1 error generated.
tests/fl/gfx/rgbw_colorimetric.cpp:1039:5-12: ERROR translating statement 'ReturnStmt'
Aborting translation of method 'lut_error_floor::sample_sweep' in file 'tests/fl/gfx/rgbw_colorimetric.cpp': "Assert_failure src/clang/cAst_utils.ml:249:53"
Uncaught Internal Error: "Assert_failure src/clang/cAst_utils.ml:249:53"
Error backtrace:
Raised at ClangFrontend__CAst_utils.get_decl_from_typ_ptr in file "src/clang/cAst_utils.ml", line 249, characters 53-65
Called from ClangFrontend__CTrans.CTrans_funct.get_destructor_decl_ref in file "src/clang/cTrans.ml", line 658, characters 12-59
Called from ClangFrontend__CTrans.CTrans_funct.destructor_calls.(fun) in file "src/clang/cTrans.ml", line 2048, characters 12-69
Called from Base__List.rev_filter_map.loop in file "src/list.ml", line 944, characters 13-17
Called from Base__List.filter_map in file "sr

... [truncated 2200 characters] ...

line 4784, characters 10-1023
Called from ClangFrontend__CTrans.CTrans_funct.instruction in file "src/clang/cTrans.ml" (inlined), line 4765, characters 38-71
Called from ClangFrontend__CTrans.CTrans_funct.exec_with_node_creation in file "src/clang/cTrans.ml" (inlined), line 104, characters 20-38
Called from ClangFrontend__CTrans.CTrans_funct.get_clang_stmt_trans in file "src/clang/cTrans.ml" (inlined), line 5395, characters 4-69
Called from ClangFrontend__CTrans.CTrans_funct.get_custom_stmt_trans in file "src/clang/cTrans.ml", line 5401, characters 8-55
Called from ClangFrontend__CTrans.CTrans_funct.exec_trans_instrs.exec_trans_instrs_rev in file "src/clang/cTrans.ml" (inlined), line 5365, characters 28-54
Called from ClangFrontend__CTrans.CTrans_funct.exec_trans_instrs in file "src/clang/


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.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 4, 2026

@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/rgbw.h`:
- Around line 153-163: The helper rgbw_colorimetric_lut_memory_bytes currently
uses the raw grid_n, causing mismatches with the runtime clamp; update this
function to clamp grid_n to the same [4, 256] range used by
enable_rgbw_colorimetric_lut() before computing the size so callers budget
correctly for small (<4) or large (>256) inputs, then compute bytes using the
clamped value and the existing interp check (RgbwLutInterp::Hermite vs others).

In `@tests/fl/gfx/rgbw_colorimetric.cpp`:
- Around line 1021-1035: sample_sweep produces wrapped low values for r/g/b==6
because r * 42 + 15 overflows u8; update Sample assignment in sample_sweep so
the arithmetic is done in an int and then clamped to 0–255 before casting to u8
(e.g. compute val = r*42 + 15 in int, val = std::min(val, 255), then cast/set
s.r/s.g/s.b) to ensure the high-end samples produce ~255 instead of wrapping to
11.
🪄 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: 2e694efa-6948-4a58-9313-41b8f6e75528

📥 Commits

Reviewing files that changed from the base of the PR and between cf80f80 and 8151ed1.

📒 Files selected for processing (4)
  • src/fl/gfx/rgbw.cpp.hpp
  • src/fl/gfx/rgbw.h
  • src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp
  • tests/fl/gfx/rgbw_colorimetric.cpp

Comment thread src/fl/gfx/rgbw.h Resolved
Comment thread tests/fl/gfx/rgbw_colorimetric.cpp Resolved
zackees and others added 2 commits June 3, 2026 17:59
- 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]>
… form

#2718 also touched the FreeRTOS-include block in lcd_spi/channel_driver_lcd_clockless.cpp.hpp
and picked the inline `// IWYU pragma: keep` form (cleaner than the
`begin_keep`/`end_keep` wrapper this branch had added as a drive-by).
Taking master's resolution; both forms satisfy the same lint check and
master is the canonical style.
@zackees
zackees merged commit 7bbb414 into master Jun 4, 2026
6 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 4, 2026
@zackees
zackees deleted the feat/rgbw-lut-interp-and-error-floor branch August 21, 2026 19:15
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.

feat(rgbw): expose LUT interp choice + add error-floor test + memory accessor

1 participant