Skip to content

Commit 3bc728e

Browse files
committed
fix low brightness gradient "jumpyness"
during testing at low brightness I noticed that gradients can be "jumping" in colors quite wildly, turning a smooth gradient into a flickering mess. This is due to the color hue preservation being inaccurate and a bit too aggressive. This can be seen for example using a gradient palette and "Running" FX. Removing the hue preservation completely fixes it but leaves color artefacts for example visible in PS Fire at very low brightness: the bright part of the flames gets a pink hue. This change is a compromise to fix both problems to a "good enough" state
1 parent 7f1f986 commit 3bc728e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

wled00/colors.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@ uint32_t IRAM_ATTR color_fade(uint32_t c1, uint8_t amount, bool video) {
7272
// video scaling: make sure colors do not dim to zero if they started non-zero unless they distort the hue
7373
uint8_t r = byte(c1>>16), g = byte(c1>>8), b = byte(c1), w = byte(c1>>24); // extract r, g, b, w channels
7474
uint8_t maxc = (r > g) ? ((r > b) ? r : b) : ((g > b) ? g : b); // determine dominant channel for hue preservation
75-
uint8_t quarterMax = maxc >> 2; // note: using half of max results in color artefacts
76-
addRemains = r && r > quarterMax ? 0x00010000 : 0;
77-
addRemains |= g && g > quarterMax ? 0x00000100 : 0;
78-
addRemains |= b && b > quarterMax ? 0x00000001 : 0;
79-
addRemains |= w ? 0x01000000 : 0;
75+
addRemains = r && (r<<5) > maxc ? 0x00010000 : 0; // note: setting color preservation threshold too high results in flickering and
76+
addRemains |= g && (g<<5) > maxc ? 0x00000100 : 0; // jumping colors in low brightness gradients. Multiplying the color preserves
77+
addRemains |= b && (b<<5) > maxc ? 0x00000001 : 0; // better accuracy than dividing the maxc. Shifting by 5 is a good compromise
78+
addRemains |= w ? 0x01000000 : 0; // i.e. remove color channel if <13% of max
8079
}
8180
const uint32_t TWO_CHANNEL_MASK = 0x00FF00FF;
8281
uint32_t rb = (((c1 & TWO_CHANNEL_MASK) * amount) >> 8) & TWO_CHANNEL_MASK; // scale red and blue

0 commit comments

Comments
 (0)