added some minor fixes

-fastled flags
-gamma correction
-pass by reference instead of pointer
This commit is contained in:
Damian Schneider 2024-01-28 14:19:46 +01:00
parent e114b842ba
commit f5ed757780
4 changed files with 19 additions and 10 deletions

View File

@ -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
}

View File

@ -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]);
}

View File

@ -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);

View File

@ -177,6 +177,8 @@ using PSRAMDynamicJsonDocument = BasicJsonDocument<PSRAM_Allocator>;
#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"