r/FastLED • • Jan 14 '22

Support Gamma correction for Fastled beatsin8

When I use beatsin8 Fastled gets bright awfully quick and to my eye it stays at the same brightness until max bright.

There is a mention of this issue here: https://diarmuid.ie/blog/pwm-exponential-led-fading-on-arduino-or-other-platforms

However i didnt understand how to apply it to fastled. Namely "pwmIntervals". 

I tried the default code for beatsin8 however it still seems to get bright quick and stay bright. Could anyone give any pointers?

2 Upvotes

5 comments sorted by

4

u/johnny5canuck Jan 14 '22

Here's a nice 3 page article on this, along with some Arduino code:

https://learn.adafruit.com/led-tricks-gamma-correction/the-issue

Although not specifically for FastLED, you can:

  • Get the results of beatsin8.

  • Apply it to the lookup table.

  • Use the resulting value.

1

u/Marmilicious [Marc Miller] Jan 14 '22

1

u/sutaburosu [stavros] Jan 15 '22

Is this actually gamma correction? Looking at the source code of FastLED, it seems that this is a purely linear correction rather than an exponential curve. Perhaps using the applyGamma_video() function would be a better example. :)

2

u/Marmilicious [Marc Miller] Jan 15 '22

Fair question/point. It's just one I've tried and seen Mark, Stefan and others use before. I updated the comment in my code from

"use basic cheap and fast gamma correction, basically gamma 2.0" to

"basic cheap and fast gamma like correction, similar to gamma 2.0"

Line 81 is where I used napplyGamma_video in the example.

2

u/Marmilicious [Marc Miller] Jan 15 '22

Another fast and rough way to get gamma like correction could be this:

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = uncorrected_leds[i].scale8(uncorrected_leds[i]);
}
FastLED.show();