tomnz / button-shim-go

Go library for Pimoroni's Button SHIM
https://shop.pimoroni.com/products/button-shim
MIT License
3 stars 1 forks source link

Take advantage of the LED's brightness setting #2

Open tomnz opened 6 years ago

tomnz commented 6 years ago

The APA102 LED on the shim supports 32 brightness levels. However, we currently always use the maximum brightness level, and dim by lowering the individual RGB values. Due to the gamma, this results in visible value snapping at low brightness levels. We should be able to do better.

There is some related discussion here: https://github.com/pimoroni/button-shim/issues/3

The crux of the issue seems to be that using the brightness level basically bypasses the gamma curve - so e.g. RGB of [127, 63, 0] at brightness 31 could look different to [255, 127, 0] at brightness 15. In my opinion the loss of accuracy is worth it to support smoother color changes at low brightness. At the least, we offer control of it over to the client.

thediveo commented 6 years ago

Aren't the brightness levels controlling the PWM in the LED hardware? So these are at this time linear, correct? Also, the LED hardware does PWM on the RGB values, if I'm correct (but I might be mistaken). But the lib applies gamma correction to the RGB values, but not to the brightness ... or am I mistaken here? So we would basically use a brightness range of 0..255 instead of 0..31, and then apply gamma correction in combination with mapping to the 0..31 range.

tomnz commented 6 years ago

I think the discussion in the linked ticket by Gadgetoid describes it better than I can.

I actually really like the approach that the periph.io APA102 driver took with this - where we use brightness 31 as much as possible, and only take advantage of the APA102 brightness when displaying really dim colors. This is partially due to the gamma issue, but also the much lower frequency on the brightness PWM, which produces visual artifacts. I think we should use the same approach here.