Skip to content

Conversation

@blazoncek
Copy link
Collaborator

@blazoncek blazoncek commented Jun 20, 2025

fixes #4734

Summary by CodeRabbit

  • New Features

    • Improved color temperature (CCT) handling for lighting effects, now supporting per-pixel CCT control for more precise and dynamic color rendering.
  • Bug Fixes

    • Enhanced memory management to ensure proper cleanup of resources used for per-pixel CCT data.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 20, 2025

"""

Walkthrough

The changes introduce a per-pixel CCT (Correlated Color Temperature) buffer to the WS2812FX class. CCT values are now tracked and set for each pixel during output, replacing the previous segment-level approach. This involves memory management for the new buffer and updates to blending and output logic to ensure accurate per-pixel CCT handling.

Changes

Files Change Summary
wled00/FX.h Added private member _pixelCCT to WS2812FX, initialized and freed in constructor/destructor; updated size comment.
wled00/FX_fcn.cpp Reworked CCT handling: removed segment-level CCT setting, added allocation and use of per-pixel _pixelCCT buffer, updated blending and show logic for per-pixel CCT assignment.

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Correct handling of CCT so warm/cool LEDs respond to CCT slider as expected (#4734)
Ensure CCT is not ignored and is applied per pixel as needed for analog RGB+CCT strips (#4734)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were found. All modifications directly relate to implementing per-pixel CCT handling as required by the linked issue.
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
wled00/FX_fcn.cpp (1)

1321-1321: Consider using a more descriptive variable name.

The variable cct could be renamed to segmentCCT or currentSegmentCCT for better clarity.

-  uint8_t       cct        = topSegment.currentCCT();
+  uint8_t       segmentCCT = topSegment.currentCCT();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f00c95 and e2fd155.

📒 Files selected for processing (2)
  • wled00/FX.h (4 hunks)
  • wled00/FX_fcn.cpp (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: wled_build / Build Environments (usermods)
  • GitHub Check: wled_build / Build Environments (esp32_wrover)
  • GitHub Check: wled_build / Build Environments (esp32s3_4M_qspi)
  • GitHub Check: wled_build / Build Environments (esp32dev_V4)
  • GitHub Check: wled_build / Build Environments (lolin_s2_mini)
  • GitHub Check: wled_build / Build Environments (esp32_eth)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_16MB_opi)
  • GitHub Check: wled_build / Build Environments (esp32c3dev)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_8MB_opi)
  • GitHub Check: wled_build / Build Environments (esp32dev)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full_compat)
  • GitHub Check: wled_build / Build Environments (esp8266_2m)
  • GitHub Check: wled_build / Build Environments (nodemcuv2_160)
  • GitHub Check: wled_build / Build Environments (esp8266_2m_160)
  • GitHub Check: wled_build / Build Environments (esp8266_2m_compat)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full_160)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full)
  • GitHub Check: wled_build / Build Environments (nodemcuv2)
  • GitHub Check: wled_build / Build Environments (nodemcuv2_compat)
  • GitHub Check: wled_build / Test cdata.js
🔇 Additional comments (6)
wled00/FX.h (2)

805-805: Comment update is accurate.

The class size increase from 104 to 108 bytes correctly reflects the addition of the 4-byte pointer member on ESP32.


832-832: Proper memory management for the new CCT buffer pointer.

The _pixelCCT pointer is correctly initialized to nullptr in the constructor and properly freed in the destructor.

Also applies to: 861-861

wled00/FX_fcn.cpp (4)

1394-1394: Correct implementation of per-pixel CCT assignment.

The CCT values are properly assigned to the buffer with appropriate null checks, and the implementation correctly handles mirrored pixels in 2D segments.

Also applies to: 1406-1409, 1481-1481, 1486-1486


1619-1631: Well-optimized per-pixel CCT implementation.

The code efficiently handles per-pixel CCT by:

  • Only updating CCT when the value changes between pixels
  • Properly saving and restoring the global CCT value
  • Correctly handling the cctFromRgb case

1632-1633: Proper cleanup of CCT buffer.

The buffer is correctly freed and the pointer is set to nullptr, preventing use-after-free issues.


1597-1633: Potential memory leak if show() is called recursively.

If show() can be called recursively (e.g., through the _callback on line 1612), the CCT buffer would be allocated multiple times but only freed once, causing a memory leak. Consider adding a guard to prevent recursive allocation.

#!/bin/bash
# Check if show() can be called recursively through callbacks
ast-grep --pattern 'void show() {
  $$$
}'

# Search for potential recursive calls to show() in callback functions
rg -A 5 "show_callback.*=.*show"
rg -A 10 "_callback.*show\(\)"

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
wled00/FX_fcn.cpp (1)

1594-1600: Consider persistent CCT buffer allocation for better performance.

Allocating and freeing the CCT buffer on every show() call could impact performance, especially at high frame rates. Consider keeping the buffer allocated and only reallocating when the strip size changes.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e2fd155 and 10d1098.

📒 Files selected for processing (1)
  • wled00/FX_fcn.cpp (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (19)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_8MB_opi)
  • GitHub Check: wled_build / Build Environments (usermods)
  • GitHub Check: wled_build / Build Environments (esp32s3_4M_qspi)
  • GitHub Check: wled_build / Build Environments (esp32_wrover)
  • GitHub Check: wled_build / Build Environments (esp32dev)
  • GitHub Check: wled_build / Build Environments (esp32_eth)
  • GitHub Check: wled_build / Build Environments (esp32c3dev)
  • GitHub Check: wled_build / Build Environments (esp8266_2m_160)
  • GitHub Check: wled_build / Build Environments (esp32s3dev_16MB_opi)
  • GitHub Check: wled_build / Build Environments (nodemcuv2)
  • GitHub Check: wled_build / Build Environments (lolin_s2_mini)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full_compat)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full_160)
  • GitHub Check: wled_build / Build Environments (esp32dev_V4)
  • GitHub Check: wled_build / Build Environments (esp8266_2m_compat)
  • GitHub Check: wled_build / Build Environments (nodemcuv2_compat)
  • GitHub Check: wled_build / Build Environments (esp01_1m_full)
  • GitHub Check: wled_build / Build Environments (nodemcuv2_160)
  • GitHub Check: wled_build / Build Environments (esp8266_2m)
🔇 Additional comments (4)
wled00/FX_fcn.cpp (4)

1321-1321: Per-pixel CCT implementation looks correct.

The CCT value is properly obtained from the segment and consistently applied to all pixels, including mirrored variants. The null checks for _pixelCCT ensure safe operation when CCT buffer allocation fails.

Also applies to: 1394-1409, 1481-1487


1619-1631: Efficient per-pixel CCT application during output.

The implementation efficiently tracks CCT changes between pixels and only calls setSegmentCCT when necessary. The original CCT value is properly preserved and restored for ABL adjustments.


1632-1633: Proper cleanup of CCT buffer.

Good practice to free the buffer and set the pointer to nullptr, preventing use-after-free issues.


1594-1596: Verify architectural change from segment-level to per-pixel CCT.

The comment mentions that "WLED doesn't handle CCT on pixel level but on Segment level instead", but this implementation adds per-pixel CCT support. Please confirm this architectural change is intentional and aligns with the PR objectives for fixing CCT issues.

@blazoncek blazoncek merged commit 66869f8 into main Jun 24, 2025
42 checks passed
@blazoncek blazoncek deleted the CCT-fix branch June 24, 2025 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CCT information is ignored in 0.16-alpha

2 participants