Skip to content

fix(rgbw): native topology authority for strict + boosted solvers (#2748) - #2749

Merged
zackees merged 1 commit into
masterfrom
fix/2748-rgbw-native-topology-authority
Jun 4, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/2748-rgbw-native-topology-authority

Conversation

@zackees

@zackees zackees commented Jun 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #2748. The strict sub-gamut solver was routing every input — even pure native single-channel and outer-edge (dual-channel) inputs — through the W-containing sub-gamut inverses, pulling W and unrelated channels into the output in violation of the reference math model's strict topology rules.

The verifier session linked from the issue showed:

(R, 0, 0)            -> (R, 0, 0, W>0)        instead of (R, 0, 0, 0)
(0, G, G)  full cyan -> (0, G', B', W>0)      instead of (0, G, G, 0)
cyan value-ramp      -> SAME (24029, 65535, 38635) for all values
                                              instead of scaling linearly

What changed

  • New header-inline helpers in src/fl/gfx/rgbw_colorimetric.h:

    • is_native_input_gamut(p) — detects when source primaries match the LED's native primaries
    • count_active_channels(s_r, s_g, s_b) — LSB-eps classifier
  • src/fl/gfx/rgbw_colorimetric.cpp.hpp:

    • solve_strict_subgamut short-circuits native 1- and 2-channel inputs to the matching LED channels with W=0
    • solve_wx_overdrive (kRGBWColorimetricBoosted) inherits the same guard — W overdrive is not legal on edge-locked topologies

Three-channel (interior) inputs still flow through the existing sub-gamut solver where W participation is correct and intentional. Non-native input gamuts (Rec.709 / Rec.2020 / DCI-P3) bypass the guard so out-of-hull projection (#2708) still applies — covered by an explicit regression test.

Legal native topologies (per the reference math model)

single  : R, G, B            (W = 0, two other channels = 0)
outer   : RG, RB, BG         (W = 0, third channel = 0)
triple  : RGW, RBW, BGW      (interior — existing sub-gamut routing applies)

Test plan

  • bash test rgbw_colorimetric --cpp — full TU passes (224+ new assertions)
  • bash test --cpp — all 226 tests pass, no regressions
  • bash lint — clean

New reproducer tests in tests/fl/gfx/rgbw_colorimetric.cpp:

  • native pure-R / G / B single-channel topology preservation
  • native cyan / yellow / magenta outer-edge topology preservation
  • cyan value-ramp linearity (the collapse case from the report)
  • native single-channel ramp linearity
  • 3-channel interior inputs still use sub-gamut routing
  • non-native (Rec.709) inputs bypass the guard
  • public dispatch round-trip through kRGBWColorimetric and kRGBWColorimetricBoosted
  • is_native_input_gamut / count_active_channels helper coverage

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced RGBW color processing to correctly handle single and dual-channel native color inputs (such as pure red, green, blue, and cyan/magenta/yellow), ensuring proper color accuracy and topology preservation for these specific input types.

)

The strict sub-gamut solver routed every input — even pure native single-
channel and outer-edge (dual-channel) inputs — through the W-containing
sub-gamut inverses, pulling W and unrelated channels into the output in
violation of the reference math model's strict topology rules. The
verifier session in #2748 showed:

  (R, 0, 0) -> (R, 0, 0, W>0)        instead of (R, 0, 0, 0)
  (0, G, G) cyan -> (0, G', B', W>0) instead of (0, G, G, 0)
  cyan value-ramp -> SAME tuple      instead of scaling linearly

Add an `is_native_input_gamut()` predicate plus `count_active_channels()`
in `rgbw_colorimetric.h`. In `solve_strict_subgamut` and `solve_wx_overdrive`,
short-circuit 1- and 2-channel native inputs to the matching LED channels
with W = 0, preserving the legal native topology set:

  single  : R, G, B
  outer   : RG, RB, BG  (W = 0, edge-locked)
  triple  : RGW, RBW, BGW  (interior — existing sub-gamut routing applies)

Three-channel (interior) inputs still flow through the sub-gamut solver
where W participation is correct and intentional.

Non-native input gamuts (Rec.709, Rec.2020, DCI-P3) bypass the guard so
out-of-hull projection (#2708) still applies — verified by an explicit
regression test using sRGB red on a wider-gamut LED panel.

Reproducer tests cover:
  * native pure-R / G / B single-channel topology
  * native cyan / yellow / magenta outer-edge topology
  * value-ramp linearity (the cyan-collapse case from the report)
  * 3-channel interior inputs still hit sub-gamut routing
  * non-native input bypasses the guard
  * public-API round-trip through kRGBWColorimetric and
    kRGBWColorimetricBoosted dispatch

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: b05ca97f-55b5-4c5c-b4f2-95320e5b97ca

📥 Commits

Reviewing files that changed from the base of the PR and between 8d1e04e and d444766.

📒 Files selected for processing (3)
  • src/fl/gfx/rgbw_colorimetric.cpp.hpp
  • src/fl/gfx/rgbw_colorimetric.h
  • tests/fl/gfx/rgbw_colorimetric.cpp

📝 Walkthrough

Walkthrough

This PR implements native topology authority fast-paths for the RGBW colorimetric solver to address issue #2748. It adds native input gamut detection and early-return guards to prevent single- and dual-channel native inputs from being routed through W-containing sub-gamut inverses, preserving strict topology rules defined for the native gamut.

Changes

Native Topology Authority Fix

Layer / File(s) Summary
Native gamut detection helpers
src/fl/gfx/rgbw_colorimetric.h
is_native_input_gamut() compares profile input primaries against LED-measured primaries under tight epsilon, and count_active_channels() counts non-zero RGB inputs to classify topology as single-, dual-, or three-channel.
Native topology fast-paths in solvers
src/fl/gfx/rgbw_colorimetric.cpp.hpp
solve_strict_subgamut and solve_wx_overdrive each add an early-return guard: when native input gamut with ≤2 active channels is detected, RGB channels are clamped to [0,1], W forced to 0, and return early to bypass sub-gamut routing.
Reference implementation and test coverage
tests/fl/gfx/rgbw_colorimetric.cpp
fastled_mirror::strict_subgamut reference implementation mirrors the native guard; new test suite validates single-channel purity (R/G/B), dual-channel edges (cyan/yellow/magenta), value ramps (linear scaling and monotonicity), non-native gamut bypass, public dispatch preservation (standard and boosted modes), and unit tests for both helper functions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • FastLED/FastLED#2545: The PR's DiodeProfile helper additions and native-topology fast-path directly extend the colorimetric RGBW solver work.
  • FastLED/FastLED#2710: Both PRs modify how DiodeProfile input primaries determine whether native-topology fast-paths activate.
  • FastLED/FastLED#2706: Both PRs affect solve_strict_subgamut and the WX overdrive/LP solver paths.

Possibly related PRs

  • FastLED/FastLED#2554: Both modify the strict subgamut solver's W handling; this PR adds native ≤2-channel early-return, while #2554 updates barycentric containment for CCT-shifted whites.
  • FastLED/FastLED#2552: This PR extends colorimetric solver implementations introduced by #2552 by adding native-input fast-path guards to solve_strict_subgamut and solve_wx_overdrive.
  • FastLED/FastLED#2711: PR #2711 changes RGBW profile input primaries to native LED gamut, which is exactly what this PR's is_native_input_gamut() guards rely on to activate the solver fast-paths.

Poem

🐰 A rabbit hops through RGBW light,
With native channels burning bright—
No W shall steal a single shade,
When R, G, B alone have played.
Topology preserved with care,
Fast-paths swift through colorspace fair! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% 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 describes the main change: adding native topology authority guards to strict and boosted RGBW solvers to address issue #2748.
Linked Issues check ✅ Passed All coding objectives from issue #2748 are met: native topology authority is enforced for 1/2-channel inputs, sub-gamut solver is preserved for 3-channel, non-native gamuts bypass the guard, and comprehensive tests validate the fixes.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #2748: two helper functions, guards in two solver routines, and tests covering native topology enforcement with no unrelated modifications.

✏️ 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/2748-rgbw-native-topology-authority

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:1055: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.

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.

RGBW FastLED Implementation Divergences, bug report, & proposed fixes with pseudocode

1 participant