Skip to content

chore(api): take DiodeProfile by reference in set_input_gamut (#3234) - #3746

Merged
zackees merged 2 commits into
masterfrom
chore/3234-set-input-gamut-reference
Jul 28, 2026
Merged

zackees merged 2 commits into
masterfrom
chore/3234-set-input-gamut-reference

Conversation

@zackees

@zackees zackees commented Jul 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #3234.

Audit result: profile is required and mutated, so the nullable pointer advertised an optional argument that doesn't exist. Every call site already passed a real address (&copy internally, &p throughout the tests) — the if (profile == nullptr) return; was defensive, not a contract. And silently doing nothing is a poor answer to "you gave me no profile to configure": the caller gets no gamut applied and no signal.

So DiodeProfile* → DiodeProfile&.

What deliberately did not change

white_xy stays a pointer. It is genuinely optional — nullptr means "use the gamut's standard reference white" — so the nullable pointer is telling the truth there. The goal is matching the shape to the semantics, not removing pointers on principle.

Answering the issue's questions directly:

Question Answer
Is nullptr an intentional contract? No — defensive implementation detail, no caller relies on it
Should it become DiodeProfile&? Yes
Does any overload need const DiodeProfile&? No — every path mutates
Should a wrapper keep nullable behaviour? Yes, as a deprecated forwarder (below)

Migration — no sketch breaks

The pointer overloads are kept and marked FL_DEPRECATED, forwarding to the reference forms. Existing set_input_gamut(&profile, ...) calls keep compiling and get a pointed deprecation message.

The forwarders preserve the silent no-op on nullptr rather than dereferencing. A sketch that relied on that behaviour must not start crashing at the moment we deprecate it — the deprecation is the signal, not a segfault.

Testing

  • bash test --cpp — 357/357, including all 730 examples linking, so the new deprecation doesn't break example builds
  • bash lint — green
  • Two new tests: one asserting the pointer and reference paths produce identical output, one pinning the null no-op

Both use FL_DISABLE_WARNING(deprecated-declarations) locally so exercising the deprecated path doesn't add warning noise.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added reference-based APIs to configure input color gamut for RGBW colorimetric modes, with an optional white-point override.
  • Improvements
    • Updated gamut configuration so colorimetric results refresh immediately after changes.
    • Kept pointer-based configuration for compatibility, including null-pointer no-op behavior.
  • Bug Fixes
    • Ensured deprecated pointer overloads forward correctly and match reference overload results for valid profiles.
  • Tests
    • Expanded coverage to verify correct forwarding, deprecation behavior, and crash-free null handling.

Audit result: `profile` is required and mutated, so a nullable pointer
advertised an optional argument that does not exist. Every call site already
passed a real address (`&copy` internally, `&p` in tests) -- the
`if (profile == nullptr) return;` was defensive, and silently doing nothing
is a poor contract for "you gave me no profile to configure".

Adds reference overloads as the preferred form.

`white_xy` deliberately stays a POINTER. It is genuinely optional -- nullptr
means "use the gamut's standard reference white" -- so the nullable pointer
is telling the truth there. The point of this change is matching the shape to
the semantics, not removing pointers on principle.

Migration: the pointer overloads are kept, marked FL_DEPRECATED, forwarding
to the reference forms. Sketches calling `set_input_gamut(&profile, ...)`
keep compiling. The forwarders preserve the historical silent no-op on
nullptr rather than dereferencing -- a sketch relying on that must not start
crashing at the deprecation.

Tests cover both: that the pointer and reference paths produce identical
results, and that the null no-op still holds.

Validation: bash test --cpp 357/357 (incl. all 730 examples linking, so the
deprecation does not break example builds); bash lint green.

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 28, 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 Plus

Run ID: 4522340e-3a43-41d7-8fce-32241957b46b

📥 Commits

Reviewing files that changed from the base of the PR and between ad3a04a and 5f6f7dd.

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

📝 Walkthrough

Walkthrough

The set_input_gamut API adds DiodeProfile& overloads, deprecates pointer overloads while retaining null no-op behavior, updates profile construction, and migrates colorimetric tests to reference-based usage.

Changes

Input gamut API

Layer / File(s) Summary
Reference overload contract
src/fl/gfx/rgbw.h
Adds reference-based overloads, deprecates pointer overloads, and documents compatibility behavior.
Overload implementation and profile construction
src/fl/gfx/rgbw.cpp.hpp
Implements reference mutation, forwards guarded pointer calls, and applies gamut settings through the reference overload.
Colorimetric API validation
tests/fl/gfx/rgbw_colorimetric.cpp
Migrates gamut configuration calls and tests pointer compatibility, null no-op behavior, named gamuts, white overrides, and native-gamut checks.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed It clearly states the main API change: set_input_gamut now takes DiodeProfile by reference.
Linked Issues check ✅ Passed The PR audits the API, converts required mutation to DiodeProfile&, keeps deprecated nullable forwarders, and adds tests covering null and forwarding behavior.
Out of Scope Changes check ✅ Passed The added tests and deprecation shims support the API change and do not appear unrelated to the linked issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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 chore/3234-set-input-gamut-reference

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.

@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: 3

🤖 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 109-112: Replace the em dash in the deprecation comment above the
pointer overloads with ASCII punctuation such as "--" or "-"; keep the comment
text and behavior unchanged.
- Around line 106-107: Replace the decayed const float white_xy[2] parameter in
set_input_gamut’s declaration in src/fl/gfx/rgbw.h (lines 106-107) and its
implementation lambda in src/fl/gfx/rgbw.cpp.hpp (lines 246-250) with a nullable
extent-preserving representation that guarantees two floats when provided. Keep
the white override optional and update both sites consistently.

In `@tests/fl/gfx/rgbw_colorimetric.cpp`:
- Around line 419-435: Expand the assertions in the “set_input_gamut: deprecated
pointer overloads still work” test to compare both elements of all four
input_xy_r, input_xy_g, input_xy_b, and input_xy_w pairs between via_ptr and
via_ref, covering all eight mutated coordinates.
🪄 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 Plus

Run ID: 929a07b5-48cf-45c8-ad0b-d1e0ab089a7b

📥 Commits

Reviewing files that changed from the base of the PR and between fab494d and ad3a04a.

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

Comment thread src/fl/gfx/rgbw.h Resolved
Comment thread src/fl/gfx/rgbw.h Resolved
Comment on lines +419 to +435
FL_TEST_CASE("set_input_gamut: deprecated pointer overloads still work") {
// The pointer forms are kept so existing sketches calling
// set_input_gamut(&profile, ...) keep compiling (FastLED#3234). They must
// stay behaviourally identical to the reference forms.
DiodeProfile via_ptr = kRgbwDefaultProfile;
DiodeProfile via_ref = kRgbwDefaultProfile;

FL_DISABLE_WARNING_PUSH
FL_DISABLE_WARNING(deprecated-declarations)
set_input_gamut(&via_ptr, InputGamut::Rec2020);
FL_DISABLE_WARNING_POP
set_input_gamut(via_ref, InputGamut::Rec2020);

FL_CHECK_CLOSE(via_ptr.input_xy_r[0], via_ref.input_xy_r[0], 1e-9f);
FL_CHECK_CLOSE(via_ptr.input_xy_g[1], via_ref.input_xy_g[1], 1e-9f);
FL_CHECK_CLOSE(via_ptr.input_xy_w[0], via_ref.input_xy_w[0], 1e-9f);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Compare all mutated coordinates in the compatibility test.

Only 3 of the 8 input_xy_* floats are checked, so a forwarding regression in any omitted coordinate can pass unnoticed. Compare both elements of all four R/G/B/W pairs.

Example additions
+    FL_CHECK_CLOSE(via_ptr.input_xy_r[1], via_ref.input_xy_r[1], 1e-9f);
+    FL_CHECK_CLOSE(via_ptr.input_xy_g[0], via_ref.input_xy_g[0], 1e-9f);
+    FL_CHECK_CLOSE(via_ptr.input_xy_b[0], via_ref.input_xy_b[0], 1e-9f);
+    FL_CHECK_CLOSE(via_ptr.input_xy_b[1], via_ref.input_xy_b[1], 1e-9f);
+    FL_CHECK_CLOSE(via_ptr.input_xy_w[1], via_ref.input_xy_w[1], 1e-9f);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
FL_TEST_CASE("set_input_gamut: deprecated pointer overloads still work") {
// The pointer forms are kept so existing sketches calling
// set_input_gamut(&profile, ...) keep compiling (FastLED#3234). They must
// stay behaviourally identical to the reference forms.
DiodeProfile via_ptr = kRgbwDefaultProfile;
DiodeProfile via_ref = kRgbwDefaultProfile;
FL_DISABLE_WARNING_PUSH
FL_DISABLE_WARNING(deprecated-declarations)
set_input_gamut(&via_ptr, InputGamut::Rec2020);
FL_DISABLE_WARNING_POP
set_input_gamut(via_ref, InputGamut::Rec2020);
FL_CHECK_CLOSE(via_ptr.input_xy_r[0], via_ref.input_xy_r[0], 1e-9f);
FL_CHECK_CLOSE(via_ptr.input_xy_g[1], via_ref.input_xy_g[1], 1e-9f);
FL_CHECK_CLOSE(via_ptr.input_xy_w[0], via_ref.input_xy_w[0], 1e-9f);
}
FL_TEST_CASE("set_input_gamut: deprecated pointer overloads still work") {
// The pointer forms are kept so existing sketches calling
// set_input_gamut(&profile, ...) keep compiling (FastLED#3234). They must
// stay behaviourally identical to the reference forms.
DiodeProfile via_ptr = kRgbwDefaultProfile;
DiodeProfile via_ref = kRgbwDefaultProfile;
FL_DISABLE_WARNING_PUSH
FL_DISABLE_WARNING(deprecated-declarations)
set_input_gamut(&via_ptr, InputGamut::Rec2020);
FL_DISABLE_WARNING_POP
set_input_gamut(via_ref, InputGamut::Rec2020);
FL_CHECK_CLOSE(via_ptr.input_xy_r[0], via_ref.input_xy_r[0], 1e-9f);
FL_CHECK_CLOSE(via_ptr.input_xy_r[1], via_ref.input_xy_r[1], 1e-9f);
FL_CHECK_CLOSE(via_ptr.input_xy_g[0], via_ref.input_xy_g[0], 1e-9f);
FL_CHECK_CLOSE(via_ptr.input_xy_g[1], via_ref.input_xy_g[1], 1e-9f);
FL_CHECK_CLOSE(via_ptr.input_xy_b[0], via_ref.input_xy_b[0], 1e-9f);
FL_CHECK_CLOSE(via_ptr.input_xy_b[1], via_ref.input_xy_b[1], 1e-9f);
FL_CHECK_CLOSE(via_ptr.input_xy_w[0], via_ref.input_xy_w[0], 1e-9f);
FL_CHECK_CLOSE(via_ptr.input_xy_w[1], via_ref.input_xy_w[1], 1e-9f);
}
🤖 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 `@tests/fl/gfx/rgbw_colorimetric.cpp` around lines 419 - 435, Expand the
assertions in the “set_input_gamut: deprecated pointer overloads still work”
test to compare both elements of all four input_xy_r, input_xy_g, input_xy_b,
and input_xy_w pairs between via_ptr and via_ref, covering all eight mutated
coordinates.

- Spell the optional white-point override `const float*` instead of
  `const float[2]`. The array extent decayed to a pointer anyway, so it was
  an unenforced promise, and ci/tools/check_array_params.py bans the
  spelling. Nullability is the real contract, so the pointer now says what
  it means.
- Replace a non-ASCII em dash in the deprecation comment (7-bit ASCII rule).
- Compare all eight mutated coordinates in the pointer/reference
  equivalence test instead of a 3-coordinate sample, and add a case
  covering the 3-argument forwarder so a dropped white_xy is caught.

Co-Authored-By: Claude <[email protected]>
@zackees

zackees commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

All three addressed in 5f6f7dd.

1. Decayed white_xy[2] (Major) — fixed, though not the way suggested.

You were right that the extent was a false promise, and this repo actually has an explicit ratchet for it (ci/tools/check_array_params.py + array_param_baseline.txt), so the finding is backed by project policy rather than just style.

I didn't use a span/extent-preserving type, because that can't express the contract: nullptr genuinely means "use the gamut's standard reference white", and it's exercised by callers. No signature can encode both "exactly 2 floats" and "or null".

The ratchet bans the misleading array spelling, not pointers — so const float* white_xy satisfies it while keeping nullability honest. The length requirement stays in the comment, which is the only place it can live.

I left the lambda parameters alone: w is computed as white_xy != nullptr ? white_xy : kRec709.xy_w, so it's a pointer by construction and can't bind to a reference-to-array.

2. Em dash — fixed. Replaced with --.

3. Partial assertions — fixed. All eight coordinates now compared, plus a new case for the 3-argument forwarder, which had an extra argument to lose and no equivalence coverage at all.


Unrelated bug found while verifying this, being fixed separately: check_array_params.py and check_noexcept.py pass text=True to subprocess.run without an encoding, so clang-query's UTF-8 output is decoded with the locale codec. On Windows that raises in the reader thread, leaves stdout as None, and the check dies on None + str — meaning the array-param ratchet silently does not run for Windows contributors. That's why I couldn't get a straight answer out of it at first.

Validated: 357/357 with all examples linking, bash lint green.

@zackees
zackees merged commit 70002b8 into master Jul 28, 2026
11 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jul 28, 2026
@zackees
zackees deleted the chore/3234-set-input-gamut-reference 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.

chore(api): audit mutable pointer shape for set_input_gamut

1 participant