diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 079ce7a86..d06a7baab 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -77,8 +77,8 @@ uint16_t Segment::_usedSegmentData = 0U; // amount of RAM all segments use for t uint16_t Segment::maxWidth = DEFAULT_LED_COUNT; uint16_t Segment::maxHeight = 1; -CRGBPalette16 Segment::_randomPalette = generateRandomPalette(&_randomPalette); -CRGBPalette16 Segment::_newRandomPalette = generateRandomPalette(&_randomPalette); +CRGBPalette16 Segment::_randomPalette = generateRandomPalette(_randomPalette); +CRGBPalette16 Segment::_newRandomPalette = generateRandomPalette(_randomPalette); unsigned long Segment::_lastPaletteChange = 0; // perhaps it should be per segment #ifndef WLED_DISABLE_MODE_BLEND @@ -223,7 +223,7 @@ CRGBPalette16 IRAM_ATTR &Segment::loadPalette(CRGBPalette16 &targetPalette, uint case 1: {//periodically replace palette with a random one unsigned long timeSinceLastChange = millis() - _lastPaletteChange; if (timeSinceLastChange > randomPaletteChangeTime * 1000U) { - _newRandomPalette = generateRandomPalette(&_randomPalette); + _newRandomPalette = generateRandomPalette(_randomPalette); _lastPaletteChange = millis(); handleRandomPalette(); // do a 1st pass of blend } diff --git a/wled00/colors.cpp b/wled00/colors.cpp index 8dcc735c3..49ae071d5 100644 --- a/wled00/colors.cpp +++ b/wled00/colors.cpp @@ -95,11 +95,11 @@ void setRandomColor(byte* rgb) *generates a random palette based on color theory */ -CRGBPalette16 generateRandomPalette(CRGBPalette16* basepalette) +CRGBPalette16 generateRandomPalette(CRGBPalette16 &basepalette) { CHSV palettecolors[4]; //array of colors for the new palette uint8_t keepcolorposition = random8(4); //color position of current random palette to keep - palettecolors[keepcolorposition] = rgb2hsv_approximate(basepalette->entries[keepcolorposition*5]); //read one of the base colors of the current palette + palettecolors[keepcolorposition] = rgb2hsv_approximate(basepalette.entries[keepcolorposition*5]); //read one of the base colors of the current palette palettecolors[keepcolorposition].hue += random8(20)-10; // +/- 10 randomness //generate 4 saturation and brightness value numbers //only one saturation is allowed to be below 200 creating mostly vibrant colors @@ -184,10 +184,17 @@ CRGBPalette16 generateRandomPalette(CRGBPalette16* basepalette) j++; } - return CRGBPalette16( palettecolors[0], - palettecolors[1], - palettecolors[2], - palettecolors[3]); + //apply gamma correction + CRGB RGBpalettecolors[4]; + for (int i = 0; i<4; i++) { + RGBpalettecolors[i] = (CRGB)palettecolors[i]; //convert to RGB + RGBpalettecolors[i] = gamma32((uint32_t)RGBpalettecolors[i]); + } + + return CRGBPalette16( RGBpalettecolors[0], + RGBpalettecolors[1], + RGBpalettecolors[2], + RGBpalettecolors[3]); } diff --git a/wled00/fcn_declare.h b/wled00/fcn_declare.h index ac68a6f8c..ff3718461 100644 --- a/wled00/fcn_declare.h +++ b/wled00/fcn_declare.h @@ -65,7 +65,7 @@ class NeoGammaWLEDMethod { uint32_t color_blend(uint32_t,uint32_t,uint16_t,bool b16=false); uint32_t color_add(uint32_t,uint32_t, bool fast=false); uint32_t color_fade(uint32_t c1, uint8_t amount, bool video=false); -CRGBPalette16 generateRandomPalette(CRGBPalette16* basepalette); +CRGBPalette16 generateRandomPalette(CRGBPalette16 &basepalette); inline uint32_t colorFromRgbw(byte* rgbw) { return uint32_t((byte(rgbw[3]) << 24) | (byte(rgbw[0]) << 16) | (byte(rgbw[1]) << 8) | (byte(rgbw[2]))); } void colorHStoRGB(uint16_t hue, byte sat, byte* rgb); //hue, sat to rgb void colorKtoRGB(uint16_t kelvin, byte* rgb); diff --git a/wled00/wled.h b/wled00/wled.h index a7023c6d8..5ac675757 100755 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -177,6 +177,8 @@ using PSRAMDynamicJsonDocument = BasicJsonDocument; #define PSRAMDynamicJsonDocument DynamicJsonDocument #endif +#define FASTLED_INTERNAL //remove annoying pragma messages +#define USE_GET_MILLISECOND_TIMER #include "FastLED.h" #include "const.h" #include "fcn_declare.h"