Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2651,19 +2651,18 @@ static void twinklefox_base(bool cat)
if (SEGMENT.speed > 100) SEGENV.aux0 = 3 + ((255 - SEGMENT.speed) >> 3);
else SEGENV.aux0 = 22 + ((100 - SEGMENT.speed) >> 1);

// Set up the background color, "bg".
// Set up the background color, "bg". Note: using gamma invert for brightness as the FX was written without any gamma correction, it will dim down too much now
CRGBW bg = SEGCOLOR(1);
unsigned bglight = bg.getAverageLight();
unsigned bglight = bg.getRGBaverage();
if (bglight > 64) {
bg = color_fade(bg, 16, true); // very bright, so scale to 1/16th
bg = color_fade(bg, gamma8inv(16), true); // very bright, so scale to 1/16th
} else if (bglight > 16) {
bg = color_fade(bg, 64, true); // not that bright, so scale to 1/4th
bg = color_fade(bg, gamma8inv(64), true); // not that bright, so scale to 1/4
} else {
bg = color_fade(bg, 86, true); // dim, scale to 1/3rd.
bg = color_fade(bg, gamma8inv(86), true); // dim, scale to 1/3rd
}
bg = gamma32inv(bg); // need to invert gamma as the FX was written without any gamma correction and it will dim down too much otherwise

unsigned backgroundBrightness = bg.getAverageLight();
bglight = bg.getRGBaverage(); // update after scaling

for (unsigned i = 0; i < SEGLEN; i++) {

Expand All @@ -2680,8 +2679,8 @@ static void twinklefox_base(bool cat)
// on the "brightness = f( time )" idea.
CRGBW c = twinklefox_one_twinkle(myclock30, myunique8, cat);

unsigned cbright = c.getAverageLight();
int deltabright = cbright - backgroundBrightness;
unsigned cbright = c.getRGBaverage();
int deltabright = cbright - bglight;
Comment thread
softhack007 marked this conversation as resolved.
if (deltabright >= 32 || (bg==0)) {
// If the new pixel is significantly brighter than the background color,
// use the new color.
Expand Down
5 changes: 5 additions & 0 deletions wled00/colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ struct CRGBW {
uint8_t getAverageLight() const {
return (r + g + b + w) >> 2;
}

// get the average of the R, G, B values
uint8_t getRGBaverage() const {
return ((r + g + b) * 21846) >> 16; // x*21846>>16 is equal to "divide by 3"
}
};

inline CHSV32::CHSV32(const CRGBW& rgb) {
Expand Down
Loading