Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ledmatrix: gamma correction for smoother brightness ramps #99

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

cbiffle
Copy link

@cbiffle cbiffle commented Mar 20, 2024

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 added 2 commits March 20, 2024 10:17
This costs ~256 bytes of flash (once referenced). I've tried to keep the
generated code readable.
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.
@cbiffle cbiffle marked this pull request as ready for review March 20, 2024 17:30
@cbiffle
Copy link
Author

cbiffle commented Mar 20, 2024

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
Copy link
Author

cbiffle commented Mar 20, 2024

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
Copy link

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

@xeruf
Copy link

xeruf commented Nov 4, 2024

Would appreciate progress on this change! I also noticed this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants