Repository navigation
fix(rgbw): address CodeRabbit findings from #2552 - #2554
Conversation
Three correctness/robustness fixes for the colorimetric path, all from CodeRabbit review of the original PR #2552: 1. Check invert3x3 return values in build_profile_cache (CRITICAL) A degenerate DiodeProfile (colinear primaries, near-zero luminance, etc.) silently produced garbage matrices and corrupted every subsequent color conversion. build_profile_cache now captures the four invert3x3 returns and FL_WARN_ONCEs when any sub-gamut matrix inversion fails. 2. Persist effective W chromaticity in ProfileCache (MAJOR) When cct_override was applied, cache->P_W was rebuilt from the shifted white point, but solve_strict_subgamut / solve_strict_subgamut_xy still did their barycentric routing against cache.profile->xy_w. That made CCT-shifted whites fall in the wrong sub-gamut while the matrix solve used the right one. ProfileCache now carries an xy_w[2] field that the solvers route against; build_profile_cache populates it with the effective (post-shift) chromaticity. 3. Harden build_lut / lookup_lut against invalid inputs (MAJOR) build_lut(grid_n) used to divide by N-1 unconditionally and allocate with signed-int product (overflow risk for negative N). It now bails to an empty LutTable on grid_n < 2 and computes the allocation size as size_t. lookup_lut now zero-fills out_rgbw and early-returns when the LUT is empty/unbuilt or has a zero xy span. Skipped from the review: - "Replace raw new/delete with RAII" — already done; the merged PR uses fl::unique_ptr throughout. - "Use new(std::nothrow)" — same; no bare allocations remain. - "Test name doesn't match assertions" — already fixed in the merged PR by renaming and removing the misleading equality claim. - "Replace raw array parameters with fl::span" — genuine refactor that would touch every function signature in the public header. Deferred to a dedicated pass. Co-Authored-By: Claude Opus 4.7 <[email protected]>
📝 WalkthroughWalkthroughThe PR hardens the RGBW colorimetric solver pipeline by storing the effective W chromaticity (accounting for CCT overrides) in ChangesRGBW Colorimetric Robustness Improvements
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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.
🧹 Nitpick comments (1)
src/fl/gfx/rgbw_colorimetric.cpp.hpp (1)
43-59: 💤 Low valueDuplicate comment block.
Lines 43-46 and 51-54 convey the same message about singular matrix inversion leaving garbage output. Consider removing one of them.
♻️ Suggested fix
- // Inverting a singular matrix leaves the destination with whatever - // invert3x3 wrote — solvers reading it would silently produce garbage. - // Warn once if any inversion fails so the user knows their profile has - // degenerate primaries (colinear chromaticities, near-zero luminance, etc). const bool ok_rgb = invert3x3(P_RGB, cache->P_RGB_inv); const bool ok_rgw = invert3x3(P_RGW, cache->P_RGW_inv); const bool ok_rbw = invert3x3(P_RBW, cache->P_RBW_inv); const bool ok_bgw = invert3x3(P_BGW, cache->P_BGW_inv);🤖 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/rgbw_colorimetric.cpp.hpp` around lines 43 - 59, The file contains a duplicated explanatory comment about singular matrix inversion adjacent to the invert3x3 calls (see invert3x3(P_RGB,...), invert3x3(P_RGW,...), invert3x3(P_RBW,...), invert3x3(P_BGW,...) and the subsequent FL_WARN_ONCE call); remove the redundant paragraph so only one clear comment remains describing that invert3x3 can leave garbage on failure and that FL_WARN_ONCE reports degenerate primaries, keeping the comment that is closest/most relevant to the invert3x3 calls and the if (!(ok_rgb && ok_rgw && ok_rbw && ok_bgw)) warning check.
🤖 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.
Nitpick comments:
In `@src/fl/gfx/rgbw_colorimetric.cpp.hpp`:
- Around line 43-59: The file contains a duplicated explanatory comment about
singular matrix inversion adjacent to the invert3x3 calls (see
invert3x3(P_RGB,...), invert3x3(P_RGW,...), invert3x3(P_RBW,...),
invert3x3(P_BGW,...) and the subsequent FL_WARN_ONCE call); remove the redundant
paragraph so only one clear comment remains describing that invert3x3 can leave
garbage on failure and that FL_WARN_ONCE reports degenerate primaries, keeping
the comment that is closest/most relevant to the invert3x3 calls and the if
(!(ok_rgb && ok_rgw && ok_rbw && ok_bgw)) warning check.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2e7ce70c-19b3-4d98-9329-cf12faa64d15
📒 Files selected for processing (2)
src/fl/gfx/rgbw_colorimetric.cpp.hppsrc/fl/gfx/rgbw_colorimetric.h
…e8 (#2568) Generalizes the 16-lane BF1 win from #2559 to all PARLIO Wave8 lane counts. Same algebraic identity (output_bit = M0_p XOR (input_bit AND D_p)), adapted to each lane count's output packing format: 16-lane: 8 symbols × 8 pulses × 2 bytes (low lanes, high lanes) ← #2559 8-lane: 8 symbols × 8 pulses × 1 byte (8 lanes per pulse) 4-lane: 8 symbols × 4 bytes (2 pulses/byte, 4 lanes/nibble) 2-lane: 8 symbols × 2 bytes (4 pulses/byte, 2 lanes bit-interleaved) Each kernel: 1. Pre-computes per-pulse D_p / M0_p masks from chipset constants W0/W1 (extracted from byte_lut[0x00/0xFF].symbols[0] at the API boundary). 2. Bit-transposes input lane bytes to per-symbol "column" bytes. For 16- and 8-lane, uses the existing `spread_transpose16_symbol` / `spread_transpose8_symbol` primitives. For 4-lane, uses spreadA/spreadB with shifted-OR across 4 lanes (8 ops). For 2-lane, direct bit extraction (16 ops — tiny workload). 3. Emits the output bytes using `output = M0_p_mask XOR (col AND D_p_mask)`, packed per the lane-count's output layout. ### Measured on ESP32-P4 v1.3 (256 LEDs/lane, WS2812B Wave8, 5 iters) lanes | total_us | show_us | wait_us | notes 2 | 9 994 | 2 559 | 7 434 | encode << TX, TX-bound 4 | 10 244 | 2 917 | 7 326 | encode << TX, TX-bound 8 | 12 243 | 4 701 | 7 541 | encode < TX, TX-bound 16 | 12 312 | 10 677 | 1 635 | eager-queue → TX overlaps with show() All 4 lane counts complete cleanly (completed=1, channels_ok=1, no hangs). For 2/4/8 lanes the frame is already TX-bound, so BF1's win is primarily **reduced CPU usage** (encode time drops ~5× per the 16-lane scaling) — freeing cycles for animation logic. For 16 lanes the win is both reduced CPU and reduced frame time (because encode was previously > TX). ### Engine dispatch `ParlioEngine::populateDmaBuffer` 2/4/8-lane Wave8 branches now call `wave8Transpose_{2,4,8}_bf1` instead of `wave8Transpose_{2,4,8}`. Bit- identical output for any Wave8 chipset/timing. ### Test plan - [x] Host bit-exactness: 1 000 random seeds × 5 timings for each of the 3 new BF1 kernels (= 15 000 inputs × 16/32/64 output bytes each), bit- for-bit equality vs the existing byte_lut path. Source in tests/fl/ channels/wave8.cpp. - [ ] Host `bash test wave8` skipped — pre-existing rgbw linker error on master (undefined `fl::rgb_2_rgbw_colorimetric` from #2545/#2554) blocks the shared fastled.dll build. BF1-specific cases compile cleanly. - [x] Device (ESP32-P4 v1.3): boot-time validation cycles each lane count through 5 back-to-back show() calls. All pass cleanly. - [x] `bash lint --cpp` clean. Refs #2548, #2559. Co-authored-by: Claude Opus 4.7 <[email protected]>
…lock (#2589) Two CodeRabbit follow-ups for src/fl/gfx/rgbw_colorimetric.cpp.hpp: - B1: build_profile_cache warned on invert3x3 failure but still wrote garbage matrices into cache->P_*_inv. Downstream matvec3() then produced undefined output. Zero-init each failed matrix so output is deterministic (zero) on degenerate profiles. - B7: lines 43-46 and 51-54 were near-identical comment blocks about degenerate primaries. Removed the second block. Addresses CodeRabbit findings B1 (originally #2552) and B7 (#2554) per meta #2580.
Summary
Follow-up to #2552 addressing three actionable CodeRabbit findings (correctness + robustness; no API surface change).
1. Check
invert3x3return values inbuild_profile_cache(🔴 critical)A degenerate
DiodeProfile(colinear primaries, near-zero luminance, etc.) used to silently produce garbage matrices and corrupt every subsequent color conversion. Now we capture the fourinvert3x3returns and emitFL_WARN_ONCEif any sub-gamut matrix inversion fails.2. Persist effective W chromaticity in
ProfileCache(🟠 major)When
cct_overridewas applied,cache->P_Wwas rebuilt from the shifted white point — butsolve_strict_subgamut/solve_strict_subgamut_xystill did their barycentric routing againstcache.profile->xy_w. CCT-shifted whites would fall in the wrong sub-gamut while the matrix solve used the right one.ProfileCachenow carries anxy_w[2]field;build_profile_cachepopulates it with the effective (post-shift) chromaticity and the solvers route against it.3. Harden
build_lut/lookup_lutagainst invalid inputs (🟠 major)build_lut(grid_n)used to divide byN-1unconditionally and computed allocation size in signedint(overflow risk for negativeN). Now bails to an emptyLutTablewhengrid_n < 2and usessize_tarithmetic.lookup_lutnow zero-fillsout_rgbwand early-returns when the LUT is empty/unbuilt or has a zero xy span.Not addressed in this PR
new/deletewith RAII" — already done in feat(rgbw): colorimetric solvers + LUT + CCT + RGBCCT (full #2545) #2552; the merged code usesfl::unique_ptrthroughout.new(std::nothrow)" — same; no bare allocations remain.fl::span" — genuine refactor that would touch every function signature in the public header. Deferred to a dedicated pass.Test plan
fl_gfx_rgbw_colorimetrictest suite: 14/14 passing (existing coverage; no new tests required — the fixes harden internal paths that aren't directly callable from tests under the_build-only include rule)🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Logging