Skip to content

fix white channel for "Rainbow" effect#5694

Open
chschu wants to merge 2 commits into
wled:mainfrom
chschu:bugfix/rainbow-white-channel
Open

fix white channel for "Rainbow" effect#5694
chschu wants to merge 2 commits into
wled:mainfrom
chschu:bugfix/rainbow-white-channel

Conversation

@chschu

@chschu chschu commented Jun 21, 2026

Copy link
Copy Markdown

This PR fixes an issue when using the "Rainbow" effect on RGBW LEDs:

  • The CRGBW instance allocated on the stack in Segment::color_wheel is not initialized, so all its color values may (and will) contain garbage.
  • The subsequent assignment from a CHSV32 instance calls hsv2rgb_rainbow, which doesn't clear the white value either.
  • So even if the white value of the primary color is zero, the "Rainbow" effect produces RGBW colors with a non-zero white value.
  • The final OR'ing with the primary color's white value in Segment::color_wheel produces (at least to a human eye) unexpected results.

The issue has been introduced in WLED v16.0.0 by the FastLED replacement in #4615.

The important part of the fix is to properly clear the white value in hsv2rgb_rainbow, because HSV only maps to RGB (not W). The line is already there, and I don't know why it had been commented out in the first place.

The change in Segment::color_wheel is merely cosmetic. Setting the white value produces the same result as OR'ing it to a (now guaranteed) zero value.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed white channel handling in color wheel calculations to properly derive from primary color values
    • Fixed white channel initialization in HSV to RGBW color space conversions to prevent uninitialized values

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

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: 9a1a4a27-9c5c-4c2d-9103-4e8225a6a8c6

📥 Commits

Reviewing files that changed from the base of the PR and between 221964e and 105f427.

📒 Files selected for processing (2)
  • wled00/FX_fcn.cpp
  • wled00/src/dependencies/fastled_slim/fastled_slim.cpp

Walkthrough

Two bug fixes for RGBW white channel handling: Segment::color_wheel() now assigns the white byte via a CRGBW struct member (rgb.w) instead of a bit-shift/OR expression, and hsv2rgb_rainbow explicitly zeroes rgbdata[3] in the isRGBW branch instead of leaving it as a commented-out/uninitialized value.

Changes

RGBW White Channel Fixes

Layer / File(s) Summary
hsv2rgb_rainbow white channel zero-initialization
wled00/src/dependencies/fastled_slim/fastled_slim.cpp
In the isRGBW branch, rgbdata[3] is now explicitly assigned 0, preventing the white channel from being uninitialized in RGBW HSV conversions.
color_wheel() CRGBW struct packing
wled00/FX_fcn.cpp
color_wheel() populates a CRGBW temporary from CHSV32(...), assigns rgb.w from W(getCurrentColor(0)), and returns rgb.color32 — replacing the previous bit-shift/OR approach for combining the white byte.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Possibly related PRs

  • wled/WLED#3681: Modifies Segment::color_wheel() in wled00/FX_fcn.cpp to change how the white channel is sourced from the current segment color and packed into the returned color32.
  • wled/WLED#4615: Touches both hsv2rgb_rainbow in fastled_slim.cpp and the CRGBW-based color_wheel() logic in FX_fcn.cpp, directly overlapping with both files changed here.

Suggested labels

bug

Suggested reviewers

  • DedeHai
  • TripleWhy
🚥 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 The title 'fix white channel for "Rainbow" effect' accurately describes the main change—fixing a white channel rendering issue in the Rainbow effect on RGBW LEDs.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

rgbdata[1] = g;
rgbdata[2] = r;
//rgbdata[3] = 0; // white
rgbdata[3] = 0; // white

@DedeHai DedeHai Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this was intentional, I can't recall why I commented it as it does not make sense to me now to split the two but do the same... maybe some conversion issue somewhere else

edit:
please revert this, I need to check what the proper way is, either remove the isRGBW or set it to zero

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

The other part of the PR fixes the issue as well, because now it simply overwrites the garbage value.

Comment thread wled00/FX_fcn.cpp
CRGBW rgb;
rgb = CHSV32(static_cast<uint16_t>(pos << 8), 255, 255);
return rgb.color32 | (w << 24); // add white channel
rgb.w = W(getCurrentColor(0)); // add white channel

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

good call, thanks for uncovering this. we changed this function a few times over so something must have gotten lost somewhere along the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants