Repository navigation
feat(rgbw): expose LutInterp choice + LUT memory accessor + error-floor tests - #2721
Conversation
…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]>
|
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 (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis 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. ChangesRGBW Colorimetric LUT Interpolation Selection
Sequence DiagramsequenceDiagram
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
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)
⚔️ Resolve merge conflicts
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.cpptests/fl/gfx/rgbw_colorimetric.cpp:19:10: fatal error: 'test.h' file not found ... [truncated 2200 characters] ... line 4784, characters 10-1023 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
🤖 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
📒 Files selected for processing (4)
src/fl/gfx/rgbw.cpp.hppsrc/fl/gfx/rgbw.hsrc/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpptests/fl/gfx/rgbw_colorimetric.cpp
- 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.
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)The existing single-arg overload is preserved (forwards to
Hermite), so this is source-compatible with everyone who is already on the LUT path.LutStateHoldernow keys its rebuild check on(profile, cct, grid_n, interp), so changinginterptriggers an automatic rebuild on the next colorimetric call exactly like changinggrid_ndoes.Memory cost (matches the new accessor)
grid_nTests 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 thegrid_n=0degenerate case. Pins the byte-cost contract at compile time.LUT error floor: Bilinear N=16—<= 48LSB max per-channel delta.LUT error floor: Bilinear N=32—<= 24LSB.LUT error floor: Hermite N=16—<= 40LSB (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—<= 16LSB (default-quality config — what most users will get from the no-argenable_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_lutclaimed 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 neededIWYU pragma: begin_keep/end_keepwrappers) — surfaced bybash linton a clean tree.Test plan
bash lintcleanbash test fl_gfx_rgbw_colorimetric --cpppasses all error-floor cases (5 new) + memory accessor case (1 new) + all pre-existing cases🤖 Generated with Claude Code
Summary by CodeRabbit