Skip to content

CCT (color white balance support) - #2285

Merged
Aircoookie merged 20 commits into
masterfrom
CCT-support
Nov 30, 2021
Merged

Aircoookie merged 20 commits into
masterfrom
CCT-support

Conversation

@blazoncek

Copy link
Copy Markdown
Contributor

@blazoncek
blazoncek requested a review from Aircoookie October 22, 2021 05:22
Introduced color mangling macros.
Minor optimizations/fixes.
@blazoncek
blazoncek marked this pull request as ready for review October 27, 2021 12:00
@blazoncek

Copy link
Copy Markdown
Contributor Author

Any progress on this @Aircoookie ?

@Aircoookie

Copy link
Copy Markdown
Member

Not yet 😅

Comment thread wled00/FX.cpp Resolved
Comment thread wled00/FX_fcn.cpp Resolved
Comment thread wled00/FX_fcn.cpp Resolved
Comment thread wled00/FX.h Resolved
Comment thread wled00/bus_manager.h Resolved
Comment thread wled00/bus_manager.h Resolved
Comment thread wled00/data/settings_leds.htm Resolved
Comment thread wled00/json.cpp Outdated

usermods.readFromJsonState(root);

int8_t ledmap = root[F("ledmap")] | -1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice to have. But it would be better to store the ledmap number in a var and load the map after the JSON request. Otherwise it will create a second JSON buffer, which will in the best case not work and in the worst case crash on ESP8266. As an alternative, the JSON buffer could be reused by giving deserializeMap a pointer to the doc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It does if you click in UI rapidly (or have multiple clients) but loads nice from playlist or preset.
But then...
... there is a single JSON buffer PR. 😁 Which now works flawlessly on my installs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Won't work in single buffer since the doc will be locked, so it has to be re-used. Might as well implement that immediately :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed that part I missed when moving code into single JSON branch from my fork.
It has been fixed now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It can be removed here since correct implementation is in single JSON buffer.

Comment thread wled00/led.cpp Resolved
Comment thread wled00/wled.h Outdated
#define WLED_ENABLE_MQTT // saves 12kb
#endif
#define WLED_ENABLE_ADALIGHT // saves 500b only
//#define WLED_ENABLE_ADALIGHT // saves 500b only (uses GPIO3 (RX) for serial)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't sneak this in 😉 Serial is important and must be enabled by default.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if (pinManager.isPinAllocated(3)) return; in wled_serial.cpp already 100% takes care of it. Should also perhaps rename it to WLED_ENABLE_SERIAL later since it now handles not only Adalight, but also Serial JSON, tpm2.net, and most importantly now Improv.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry. This was not intentional.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no worries :)

Comment thread wled00/xml.cpp Resolved
@Aircoookie

Aircoookie commented Nov 18, 2021 •

Copy link
Copy Markdown
Member

Found some old notes of mine, thought I'd share. Seems like your implementation aligns pretty well with approach 1!


CCT Notes / WLED white management:

Case 1: Only RGB busses
-> Show RGB color wheel and colortemp slider. Slider will convert to RGB value (implemented)

Case 2: At least one bus with white channel
-> Same as RGB only, but the white channel is either set manually with an extra slider or derived from RGB using the "Auto calculate white" setting (implemented)
-> White channel is fully supported in effects

Case 3: Only White / CCT busses:
Consider hiding RGB color wheel and only show single white slider and if CCT, colortemp slider

Case 4: At least one RGB bus and at least one CCT bus (or RGBCCT bus)
-> Approach 1:
Extra colortemp slider. It blends the output of the single white channel to both the cold and warm white output.
There can be a setting to set whether blending should be linear or additive (medium CCT would either be 50% warm 50% cold or 100% warm 100% cold)
Advantages:
Granular CCT control independent of RGB (depending on auto white setting)
Likely to offer best performance
Disadvantages:
Extra var, two color temperature sliders (one for the RGB color, one for CCT) could confuse the user*
Effects can only affect total white brightness, but not the color temperature, it will stay fixed at the temp assigned by the user, no per-pixel CCT control

-> Approach 2:
Extend auto calculate white code to calculate a color temperature from the RGB color (in addition to the already calculated total white %)
Advantages:
Effects, palettes, live sources, ... can easily change the color temperature on a per-LED basis
No added complexity for user in both API and UI
Disadvantages:
Possibly hard/computationally slow to approximate a Kelvin value from RGB
Potential for subpar color precision (e.g. less saturated RGB colors being overpowered by a too-bright white light)

*just one color temp slider could be used, which would affect the RGB color for RGB(W) setups and CCT for RGBCCT setups

@Aircoookie

Aircoookie commented Nov 18, 2021 •

Copy link
Copy Markdown
Member

Performance results
(ESP32, 4x 512 SK6812, effects 0-18 and 37-117)

Average FPS:
0.13.0-b5: 37.0
CCT-support: 35.7
CCT + auto WB: 10.9
CCT + auto WB performance improvement: 31.1

Auto WB performance (allowCCT) is abysmal as expected. I love the feature though and would like to keep it. Luckily I can think the code can be optimized so that the expensive colorKtoRGB only has to run once per show per segment and not once per show per pixel 👍 since the K value doesn't change for each pixel (only for the bus and/or segment), we won't have to calculate it individually, but can simply store its result RGBW color and apply it to the RGB color.
Another problem is that getPixelColor() will degrade much more quickly since it will obviously return the corrected color. Double buffering could have the potential to fix that in the future.

@blazoncek

Copy link
Copy Markdown
Contributor Author

Yeah...
Someone could argue that WB on a very large LED count is "not recommended". 😉

Approach 2 IMO isn't good since CCT may vary according to pixel color which is not what should be expected.

Th disadvantage of two temp. sliders for Approach 1 don't seem to make sense to me. Why would you want 2 sliders?
I intentionally removed color picker temperature slider since "temperature" is not supposed to change (internal) RGB values (white should be white [255,255,255]) but just the output (as it should with WW + CW strips, you only have brightness and "balance" between W & C, otherwise you're better off with just two white channels).
This aligns well with double buffer approach IMO.

@Aircoookie

Copy link
Copy Markdown
Member

Approach 2 would in fact be the only thing that makes sense if 5 channel addressable is ever available - please chip makers - make that a thing!
Otherwise pixel color is in 99% of cases == segment color, as PWM busses are only a single pixel. I will give it a try tomorrow, think I have found a quite accurate and fast way to map from RGB -> Kelvin and we could add it as an extra option.

You are correct, 2 sliders would only make sense if you want to set the RGB color to a Kelvin value and independently control channel 4 & 5 CCT. For RGB and RGBW busses, I think a single slider that sets the color temperature directly is more intuitive than having to set the RGB color to #ffffff first. I see the application of WB correction more for actual correction rather than selection (e.g. the person on the forum recently with the nice new kitchen counters who used different kinds of strips)

On that note, managed to improve WB performance to 31 fps avg! Tradeoff is 6 extra bytes of memory.

Comment thread wled00/data/index.js
d.getElementById('picker').style.display = ccfg.picker ? "block":"none";
d.getElementById('vwrap').style.display = ccfg.picker ? "block":"none";
d.getElementById('kwrap').style.display = ccfg.picker ? "block":"none";
d.getElementById('vwrap').style.display = ccfg.picker ? "block":"none";

@Aircoookie Aircoookie Nov 27, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!
These indentations were indeed horrible if you use a tab size >2. I prefer tab size 2 for my editor, since it makes indentations more compact. Github uses a default of 8 (!), so my code rendered fine in my VS Code, but horribly in the web view and (I assume) VS Code with tab size 4.
I had the option enabled though in VS Code which inserted 2 spaces instead of a tab, which is bad, since it essentially forces tab size 2 upon everyone, but only for the lines I edited recently. Turned that off now, we should replace all indentations with spaces with tab indentations. That way indentations should render correctly no matter what tab size you prefer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

https://softwareengineering.stackexchange.com/questions/57/tabs-versus-spaces-what-is-the-proper-indentation-character-for-everything-in-e 😅
No "100% correct" way as it seems.
Let's go with the style proposed by Peter Boughton:

Use tabs to indent the start of the line, one tab per indent level, and let everyone pick how wide they want that to be.

Use spaces if you're lining up characters within a line, so they always line up regardless of tab size.

Revert auto white to global setting
Rounded /settings buttons by blazoncek
Removed obsolete script from /settings
(to be implemented in #2336 )
@Aircoookie

Copy link
Copy Markdown
Member

Codacy is a bit buggy, it doesn't let me disable the PR check at all... perhaps I need to remove it from the repo entirely, though it is useful on occasion.

Ready to merge IMO 🎉

Comment thread wled00/bus_manager.h Resolved
Comment thread wled00/FX_fcn.cpp

WS2812FX* WS2812FX::instance = nullptr;
int16_t Bus::_cct = -1; No newline at end of file
int16_t Bus::_cct = -1;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I do not like this at this place.
Perhaps moving it to util.cpp at the beginning or converting bus_manager.h into .cpp & .h combo.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Agreed, me neither. Should really make a bus_manager.cpp, though I dislike it for two reasons. a) Too many files and b) always have to change/add functions in two places.

Comment thread wled00/bus_manager.h
}
}

void setSegmentCCT(int16_t cct, bool allowWBCorrection = false) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are hijacking bus manager?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would not call it hijacking :) more setting a value that applies globally for all busses. Essentially it is a BusManager::setPixelColor(), just separately for just CCT. The alternatives would be 1) passing it as part of setPixelColor() like you implemented initially, which I liked, but increased complexity (two setPixelColor() methods) and 2) having it as a global var that can be modified from all parts of WLED, running the risk to unintentionally setting an invalid value since all the checks run by setSegmentCCT would need to be implemented in strip.service() which is less clean imo.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah! Ok, I thought it was linked to segment as seen in strip.

@blazoncek

blazoncek commented Nov 28, 2021 •

Copy link
Copy Markdown
Contributor Author

You are making my life hard with all those changes in UI.
Will need to take time and absorb all changes. You could help by adding a few more comments on what certain change does (especially blending and FX changes).

@blazoncek blazoncek mentioned this pull request Nov 29, 2021
@Aircoookie

Copy link
Copy Markdown
Member

Sorry about that. I will definitely go over index.js when I have time and add comments for a lot of things. The current "already minified" code style is still from the time where we didn't have cdata.js and it needs to go.

UI Changes in this PR are:

  • Picker version updated
  • Picker sets RGB, V (value) and Kelvin sliders
  • RGB, V and Kelvin sliders directly update picker oninput
  • Unified style of all sliders (replaces native iro.js value + kelvin sliders)
  • Kelvin (sliderK) slider is hidden if CCT
  • CCT slider (sliderA) is hidden if not CCT

Makes slider updates easier overall since everything (but white channel) is managed by the picker color.

@blazoncek

Copy link
Copy Markdown
Contributor Author

While you're at it, add

  void setStatusPixel(uint32_t c) {
    if (_skip && canShow()) {
      for (uint8_t i=0; i<_skip; i--) PolyBus::setPixelColor(_busPtr, _iType, i, c, _colorOrder);
      PolyBus::show(_busPtr, _iType);
    }
  }

just in front of BusDigital::setPixelColor() and

  void setStatusPixel(uint32_t c) {
    for (uint8_t i = 0; i < numBusses; i++) busses[i]->setStatusPixel(c);
  }

just in front of BusManager::setPixelColor().

Then we can use sacrificial pixel in handleStatusLed(). 😉

@blazoncek

Copy link
Copy Markdown
Contributor Author

BTW, I don't like color picker sliders except for V. 😁

@Aircoookie

Copy link
Copy Markdown
Member

Status pixel is a good idea, will add that.

Don't have a use for RGB sliders personally either, some people like them though. Kelvin is great though for non-CCT strips, trying to dial in a non-greenish and non-pinkish RGB "white" of your desired temperature using the picker wheel alone is an absolute pain (of course WB correction can fix that too - but it does not allow e.g. separate BG colors)

@Aircoookie
Aircoookie merged commit f6e5b67 into master Nov 30, 2021
@Aircoookie
Aircoookie deleted the CCT-support branch November 30, 2021 22:41
@lucaf86 lucaf86 mentioned this pull request Dec 20, 2021
1 task done
aenertia pushed a commit to aenertia/WLED that referenced this pull request Aug 18, 2026
CCT (color white balance support)
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.

2 participants