apply inverse gamma to segment brightness for better color preservation#5343
apply inverse gamma to segment brightness for better color preservation#5343
Conversation
WalkthroughThe change modifies the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fun fact - I am experimenting in WLEDMM with moving gamma corrections to bus driver level, to exploit HUB75 with 10bits per color. I ran into the same observation that you made: if effects run in "no-gamma space", then segment brightness (segment::opacity) requires inverse gamma to look the same as with previous WLED versions. |
FYI these were not meant to behave the same, one is brightness the other is opacity. Opacity with single segment behaves similarly as brightness but is not brightness.
This is the only correct way of handling gamma and I've made that a few days back in my fork. BTW don't forget that gamma may not always be applied always. |
to make global brightness slider and segment brightness slider behave the same, the segment brightness needs to be gamma-inverted when using gamma for color correction.
the reason being (wigh g = gamma)
global brightness:
(color)^g * brightnesssegment brightness:
(color * brightness)^gusing
brightness^(1/g)results in(color * brightness^(1/g) )^g = color^g * brightnessi.e. the same as with global brightness.The way WLED handles gamma is not mathematically correct but is an approximation and a good compromise (I ran A LOT of tests on that before setteling for the way it is currently done). The correct way would actually be to do
(color * brightness)^gbut the issue is that that results in color loss. To make it work would require to scale colors to 16bit, apply brightness, then apply gamma, then scale back to 8bit, which is much slower and does only gain "linearity" in brightness scaling which was never really a thing in WLED.Fixes #5342
Summary by CodeRabbit
Release Notes