From b3324d22f56eecdb24172d239c70e52a02191524 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Sun, 21 Nov 2021 23:46:44 +0100 Subject: [PATCH] allowCCT performance improvement --- wled00/FX.cpp | 2 +- wled00/FX.h | 2 +- wled00/colors.cpp | 31 ++++++++++++++++++------------- wled00/led.cpp | 1 - wled00/wled.h | 2 +- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index a2b6a959..d0767713 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -2614,7 +2614,7 @@ uint16_t WS2812FX::mode_glitter() -//each needs 11 bytes +//each needs 12 bytes //Spark type is used for popcorn, 1D fireworks, and drip typedef struct Spark { float pos; diff --git a/wled00/FX.h b/wled00/FX.h index 3b6bfab6..2195f6e5 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -247,7 +247,7 @@ class WS2812FX { // segment parameters public: - typedef struct Segment { // 30 (33 in memory?) bytes + typedef struct Segment { // 30 (32 in memory) bytes uint16_t start; uint16_t stop; //segment invalid if stop == 0 uint16_t offset; diff --git a/wled00/colors.cpp b/wled00/colors.cpp index 0377a198..e7e2b7d1 100644 --- a/wled00/colors.cpp +++ b/wled00/colors.cpp @@ -73,7 +73,7 @@ void colorKtoRGB(uint16_t kelvin, byte* rgb) //white spectrum to rgb, calc g = round(288.1221695283 * pow((temp - 60), -0.0755148492)); b = 255; } - //g += 15; //mod by Aircoookie, a bit less accurate but visibly less pinkish + //g += 12; //mod by Aircoookie, a bit less accurate but visibly less pinkish rgb[0] = (uint8_t) constrain(r, 0, 255); rgb[1] = (uint8_t) constrain(g, 0, 255); rgb[2] = (uint8_t) constrain(b, 0, 255); @@ -248,20 +248,25 @@ void colorRGBtoRGBW(byte* rgb) //rgb to rgbw (http://codewelt.com/rgbw). (RGBW_M // adjust RGB values based on color temperature in K (range [2800-10200]) (https://en.wikipedia.org/wiki/Color_balance) void colorBalanceFromKelvin(uint16_t kelvin, byte *rgb) { - byte rgbw[4] = {0,0,0,0}; - colorKtoRGB(kelvin, rgbw); // convert Kelvin to RGB - rgb[0] = ((uint16_t) rgbw[0] * rgb[0]) / 255; // correct R - rgb[1] = ((uint16_t) rgbw[1] * rgb[1]) / 255; // correct G - rgb[2] = ((uint16_t) rgbw[2] * rgb[2]) / 255; // correct B + uint32_t col = RGBW32(rgb[0], rgb[1], rgb[2], 0); + col = colorBalanceFromKelvin(kelvin, col); + rgb[0] = R(col); + rgb[1] = G(col); + rgb[2] = B(col); } +byte correctionRGB[4] = {0,0,0,0}; +uint16_t lastKelvin = 0; + uint32_t colorBalanceFromKelvin(uint16_t kelvin, uint32_t rgb) { - byte rgbw[4] = {0,0,0,0}; - colorKtoRGB(kelvin, rgbw); // convert Kelvin to RGB - rgbw[0] = ((uint16_t) rgbw[0] * R(rgb)) / 255; // correct R - rgbw[1] = ((uint16_t) rgbw[1] * G(rgb)) / 255; // correct G - rgbw[2] = ((uint16_t) rgbw[2] * B(rgb)) / 255; // correct B - rgbw[3] = W(rgb); + //remember so that slow colorKtoRGB() doesn't have to run for every setPixelColor() + if (lastKelvin != kelvin) colorKtoRGB(kelvin, correctionRGB); // convert Kelvin to RGB + lastKelvin = kelvin; + byte rgbw[4]; + rgbw[0] = ((uint16_t) correctionRGB[0] * R(rgb)) /255; // correct R + rgbw[1] = ((uint16_t) correctionRGB[1] * G(rgb)) /255; // correct G + rgbw[2] = ((uint16_t) correctionRGB[2] * B(rgb)) /255; // correct B + rgbw[3] = W(rgb); return colorFromRgbw(rgbw); -} +} \ No newline at end of file diff --git a/wled00/led.cpp b/wled00/led.cpp index 172fabbc..2c02d01a 100644 --- a/wled00/led.cpp +++ b/wled00/led.cpp @@ -30,7 +30,6 @@ void toggleOnOff() { briLast = bri; bri = 0; - //unloadPlaylist(); // no longer necessary } } diff --git a/wled00/wled.h b/wled00/wled.h index dbe9d338..ca3a6896 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -31,7 +31,7 @@ #ifndef WLED_DISABLE_MQTT #define WLED_ENABLE_MQTT // saves 12kb #endif -//#define WLED_ENABLE_ADALIGHT // saves 500b only (uses GPIO3 (RX) for serial) +#define WLED_ENABLE_ADALIGHT // saves 500b only (uses GPIO3 (RX) for serial) //#define WLED_ENABLE_DMX // uses 3.5kb (use LEDPIN other than 2) #ifndef WLED_DISABLE_LOXONE #define WLED_ENABLE_LOXONE // uses 1.2kb