FrameworkComputer / inputmodule-rs

Framework Laptop 16 Input Module SW/FW
MIT License
223 stars 24 forks source link

ledmatrix: gamma correction for smoother brightness ramps #99

Open cbiffle opened 5 months ago

cbiffle commented 5 months ago

The brightness values sent to the LED controller actually control a PWM duty cycle. LEDs emit light roughly in proportion to the PWM duty cycle, but human vision perceives brightness on an exponential curve -- generally it takes 2x the physical luminous flux for the eye to perceive something as one step brighter.

As a result, brightness ramps (like the one generated by --all-brightnesses) were rapidly brightening to what appeared to be max, and then flattening.

This change adds gamma correction, which maps the linear input brightness values to a non-linear function of PWM duty cycles, causing the ramp to look far more ramp-y.

The gamma value I've chosen here is arguably a preference, I messed with output on a PVT panel until I found something that looked approximately right.

Photo of a panel with the firmware from main (left) vs this change (right): PXL_20240320_171617774

cbiffle commented 5 months ago

FWIW, I'm not at all sure that I hooked the gamma correction at the right points in the code --- definitely open to guidance if you'd like it moved!

cbiffle commented 5 months ago

It's also worth calling out that gamma correction makes all mid-range brightnesses look dimmer (by design!). So it might be good to increase the default brightness multiplier (currently 51 on PVT looks like?) to something higher. I'm happy to find a value that matches the approximate intensity of the original firmware if you'd like.

Maxfojtik commented 2 months ago

This change reminds me of what FastLED does. Great idea and work. Can I use this code in my fork of the repo?