Skip to content

fix(rgbw): normalize colorimetric endpoints - #3252

Merged
zackees merged 1 commit into
masterfrom
fix/3231-rgbw-endpoint-scaling
Jul 28, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/3231-rgbw-endpoint-scaling

Conversation

@zackees

@zackees zackees commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Normalize strict RGBW sub-gamut endpoints before applying source value so split-channel energy no longer caps the final output.
  • Make LUT lookup use source RGB value against normalized endpoint cells.
  • Extract shared colorimetric primitives into colorimetric_response.h and add an RGB-only cache/solve shape for the follow-up plumbing.
  • Refresh RGBW colorimetric tests for endpoint scaling, native dual-edge topology, and RGB-only helper coverage.

Tests

  • python test.py --unit rgbw_colorimetric --no-interactive
  • python test.py --unit rgbw_colorimetric --no-interactive --debug
  • python test.py --unit rgbw --no-interactive
  • git diff --check

Closes #3231

Summary by CodeRabbit

Release Notes

  • New Features

    • Added an RGB-family colorimetric response layer with reusable caching to speed up source-to-output conversions.
    • Introduced an RGB-specific colorimetric profile/compatibility alias for smoother integration.
  • Bug Fixes

    • Improved RGBW colorimetric scaling by consistently using the maximum source channel value.
    • Refined strict sub-gamut solving and LUT interpolation for more consistent normalization and endpoint behavior.
  • Tests

    • Added tests for source-space vs no-source-space behavior and stricter RGBW endpoint/normalization regressions.
    • Expanded solver and monotonicity assertions for tighter output validation.

@coderabbitai

coderabbitai Bot commented Jun 18, 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: d10b449d-bc9b-46f4-95b3-9da98ab24a24

📥 Commits

Reviewing files that changed from the base of the PR and between 643478c and 69ab69c.

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

📝 Walkthrough

Walkthrough

Introduces colorimetric_response.h with shared RGB colorimetric cache and solver primitives. Updates rgbw_colorimetric.h/cpp.hpp to delegate to this module and rename the Y_t parameter to source_value, correcting the endpoint normalization convention. Updates test implementations and assertions to validate the changes and cover issue #3231 endpoint scaling.

Changes

RGBW Colorimetric Shared RGB Solver Extraction and Source Value Convention

Layer / File(s) Summary
New colorimetric_response.h: RGB solver primitives and cache
src/fl/gfx/colorimetric_response.h
Adds a header-only module under fl::colorimetric_response with EmitterProfile (R/G/B chromaticities, luminance, optional source-space), RgbColorimetricProfile alias, RgbColorimetricCache (precomputed primary XYZ, matrix inverse, source matrix, has_source_space flag), build_rgb_colorimetric_cache (populates cache), rgb_source_to_XYZ (maps source RGB to XYZ), and solve_rgb_colorimetric (maps source RGB → XYZ → device RGB with clamping/normalization).
RGBW header: delegate to colorimetric_response.h and rename parameters
src/fl/gfx/rgbw_colorimetric.h
Includes and re-exports RGB colorimetric symbols from colorimetric_response.h into fl::colorimetric_detail. Renames the third parameter of solve_strict_subgamut_xy and lookup_lut from Y_t to source_value.
RGBW solver: source_value normalization and endpoint scaling
src/fl/gfx/rgbw_colorimetric.cpp.hpp, src/fl/gfx/rgbw.cpp.hpp
Changes strict subgamut normalization threshold to m > 1e-9f. Fixes chromaticity-to-XYZ to use Y=1.0f then scale by source_value / m. Updates Hermite and bilinear LUT branches to compute normalized endpoint then multiply by source_value. In rgbw.cpp.hpp, switches LUT fast path argument from X_t[1] to max(s_r, s_g, s_b).
Test: RGB cache behavior validation
tests/fl/gfx/rgbw_colorimetric.cpp
Adds two new test cases validating RGB colorimetric cache: one checks RGB passthrough when has_source_space is false; another checks finite, range-bounded output when source-space is enabled.
Test: mirror helpers and cache builder for source-space support
tests/fl/gfx/rgbw_colorimetric.cpp
Updates fastled_mirror::build_cache to normalize and scale M_src using inverse-transform evaluation on source white. Adds helpers: zero4, normalize4_if_needed, source_rgb_to_XYZ, native single-channel identity, and native dual-edge fixed-topology least-squares solver.
Test: solver path updates for source_value normalization
tests/fl/gfx/rgbw_colorimetric.cpp
Updates fastled_mirror::strict_subgamut and reference::strict_with_projection to use value=max(s_r,s_g,s_b) with 1e-9f epsilon, restrict native topology to 1-2 channels, compute X_t via source_rgb_to_XYZ, scale triangle outputs by value, and apply normalize4_if_needed.
Test: assertion refinements and monotonic checks
tests/fl/gfx/rgbw_colorimetric.cpp
Relaxes cyan/yellow/magenta native dual-edge assertions from exact equality to positivity+max checks (e.g., max(G,B) ≈ 1.0). Extends dual-channel ramp test to assert strict monotonic increase for both edge channels.
Test: Issue #3231 endpoint scaling regression
tests/fl/gfx/rgbw_colorimetric.cpp
Adds regression test for issue #3231 validating that RGBW output scales from the input RGB endpoint (not intermediate split energy), with W ≈ 1.0, active channels positive, and dominant budget ≤ 1.0.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant solve_strict_subgamut_xy
  participant xyY_to_XYZ
  participant nnls3
  Caller->>solve_strict_subgamut_xy: xy_t[], source_value
  solve_strict_subgamut_xy->>xyY_to_XYZ: x, y, Y=1.0f
  xyY_to_XYZ-->>solve_strict_subgamut_xy: XYZ
  solve_strict_subgamut_xy->>nnls3: M_out, XYZ
  nnls3-->>solve_strict_subgamut_xy: t[] (normalized solution)
  solve_strict_subgamut_xy->>solve_strict_subgamut_xy: scale t[] by source_value/m
  solve_strict_subgamut_xy-->>Caller: out_rgbw[]
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related issues

  • #3231: Directly addresses the sub-gamut endpoint scaling follow-up, including the deterministic regression test and source-value normalization convention change.

Possibly related PRs

  • FastLED/FastLED#2552: Introduced the original solve_strict_subgamut_xy and lookup_lut functions that this PR renames parameters and changes scaling convention for.
  • FastLED/FastLED#2752: Fixed native dual-edge solving and the 3-channel value/chroma separation in the same strict subgamut solver paths being modified here.
  • FastLED/FastLED#3256: Extends the new colorimetric_response.h shared layer introduced in this PR with additional RGB emitter profile functionality.

Poem

🐇 A matrix spun in a brand-new home,
colorimetric_response has room to roam.
Y_t is gone, source_value reigns,
endpoints scale right — no clipping pains!
The rabbit hops on, with tests aligned,
and issue three-two-three-one: fully defined. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 32.14% 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 clearly and concisely summarizes the main change: normalizing colorimetric endpoints in the RGBW system to fix output scaling.
Linked Issues check ✅ Passed The PR addresses both objectives from issue #3231: endpoint scaling fix and shared colorimetric solver extraction with RGB support, implementing all acceptance criteria.
Out of Scope Changes check ✅ Passed All changes directly support the PR objectives: colorimetric endpoint normalization, shared solver extraction, and test coverage for the fix.

✏️ 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/3231-rgbw-endpoint-scaling

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.

@JChalka

JChalka commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

I'm already handling all of this, I can't continue to be helpful if we're actively touching the same code causing problems that would need to be resolved at merge time

@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

🤖 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/colorimetric_response.h`:
- Line 18: Array parameters declared as `float out[2]` or `float out[3]` in
functions like cct_to_xy, xyY_to_XYZ, and others throughout the file decay to
pointers and do not enforce extent, violating the coding guidelines. Replace all
such decayed array parameters with either `fl::span<float, N>` (where N is 2 or
3 as appropriate) or array references `float (&out)[N]` depending on the API
requirements. This applies to all function parameters matching the pattern `T
value[N]` throughout the file at the specified line numbers.
🪄 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: 165ff422-e031-47d1-931a-fb7ac2d1212d

📥 Commits

Reviewing files that changed from the base of the PR and between 851c7e7 and 7c8f729.

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

Comment thread src/fl/gfx/colorimetric_response.h Outdated
// Krystek's outputs are (u, v) in the CIE 1960 UCS; convert to xy via the
// standard 1960->xy formulas. Reference: Krystek, "An algorithm to calculate
// correlated color temperature", Color Research & Application, 1985.
inline void cct_to_xy(int cct, float out[2]) FL_NOEXCEPT {

@coderabbitai coderabbitai Bot Jun 19, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Decayed array parameter: float out[2] does not enforce extent.

Per coding guidelines, function parameters spelled as T value[N] decay to pointers and the declared extent is not enforced. For non-ISR APIs, use fl::span<float, 2> or an array reference float (&out)[2].

This issue affects multiple functions in this file:

  • Line 18: cct_to_xy(..., float out[2])
  • Line 33: xyY_to_XYZ(..., float out[3])
  • Line 44, 65, 71-72, 104-106, 131-132: similar patterns

As per coding guidelines, "Do not allow function parameters spelled as T value[N] or T value[]" — replacements should use fl::span<T, N> or array references.

🤖 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/colorimetric_response.h` at line 18, Array parameters declared as
`float out[2]` or `float out[3]` in functions like cct_to_xy, xyY_to_XYZ, and
others throughout the file decay to pointers and do not enforce extent,
violating the coding guidelines. Replace all such decayed array parameters with
either `fl::span<float, N>` (where N is 2 or 3 as appropriate) or array
references `float (&out)[N]` depending on the API requirements. This applies to
all function parameters matching the pattern `T value[N]` throughout the file at
the specified line numbers.

Source: Coding guidelines

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Acknowledged — deferring on the same basis as PR #3256: the decayed-array signatures (float out[N]) flagged here are the established style across colorimetric_response.h and rgbw_colorimetric.h on master. The new RGB cache/solver helpers I just rebased in (build_rgb_colorimetric_cache, rgb_source_to_XYZ, solve_rgb_colorimetric) intentionally match that style so the fl::span<T, N> migration can land as a single atomic pass over both files (per the PR 2 of #3255 plan agreed on #3256). No new decayed signatures unique to this PR remain.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@zackees, understood — keeping the pattern consistent until the atomic fl::span<T, N> migration lands makes sense. I'll note the plan so it isn't re-flagged in interim PRs.

Would you like me to open a tracking issue for the fl::span<float, N> migration pass over colorimetric_response.h and rgbw_colorimetric.h (and any other colorimetric helpers in that directory) to make sure it stays on the radar for PR 2 of #3255?


🧠 Learnings used
Learnt from: zackees
Repo: FastLED/FastLED PR: 3256
File: src/fl/gfx/colorimetric_response.cpp.hpp:14-24
Timestamp: 2026-06-19T02:25:59.632Z
Learning: In the FastLED/FastLED repository, `FASTLED_RGBW_COLORIMETRIC` is an already-established build-gate macro. During review, do not flag new/added files that only reference/reuse this existing guard for unity-build consistency as a violation of the “new-macro-prefix” rule. Only flag when code introduces a genuinely new macro (or a new/renamed guard) rather than reusing this pre-existing `FASTLED_RGBW_COLORIMETRIC` macro.

@zackees
zackees force-pushed the fix/3231-rgbw-endpoint-scaling branch from 7c8f729 to 643478c Compare June 19, 2026 00:15
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 19, 2026
@zackees
zackees force-pushed the fix/3231-rgbw-endpoint-scaling branch from 643478c to 69ab69c Compare June 19, 2026 07:51
@zackees
zackees force-pushed the fix/3231-rgbw-endpoint-scaling branch from 69ab69c to 663fe6e Compare July 27, 2026 17:58
@zackees

zackees commented Jul 27, 2026

Copy link
Copy Markdown
Member Author

Rebased onto master (was conflicting since June 18) and revalidated locally.

Conflict resolution: two overlapping renames. This PR renames the LUT/subgamut parameter Y_t → source_value (its actual semantic change: the value is a source value, not a luminance Y); master separately renamed the macro FL_NOEXCEPT → FL_NO_EXCEPT. Both sides kept — new param name, new macro spelling — in solve_strict_subgamut_xy() and lookup_lut() across rgbw_colorimetric.h and rgbw_colorimetric.cpp.hpp.

The rebase also auto-merged this PR's new src/fl/gfx/colorimetric_response.h cleanly, but that file was written against the old macro and still carried 3 FL_NOEXCEPT uses. Since FL_NOEXCEPT no longer exists anywhere on master, those would have been a hard compile failure that the textual merge could not surface — renamed them too.

Validation on the rebased branch:

  • bash test --cpp — 355/355 pass
  • bash test rgbw_colorimetric — pass
  • bash lint — fully green

🤖 Generated with Claude Code

Fixes #3231

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees force-pushed the fix/3231-rgbw-endpoint-scaling branch from 663fe6e to a5f03ad Compare July 28, 2026 04:15
@zackees
zackees merged commit fab494d into master Jul 28, 2026
11 checks passed
@zackees
zackees deleted the fix/3231-rgbw-endpoint-scaling branch July 28, 2026 04:15
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jul 28, 2026
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.

fix(rgbw_colorimetric): track post-#2748 endpoint scaling and shared solver follow-ups

2 participants