Commit efdf690e authored by Rasmus Villemoes's avatar Rasmus Villemoes Committed by Lee Jones

backlight: pwm_bl: Fix cie1913 comments and constant

The "break-even" point for the two formulas is L==8, which is also
what the code actually implements. [Incidentally, at that point one
has Y=0.008856, not 0.08856].

Moreover, all the sources I can find say the linear factor is 903.3
rather than 902.3, which makes sense since then the formulas agree at
L==8, both yielding the 0.008856 figure to four significant digits.
Signed-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
Reviewed-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
parent 349ee122
...@@ -156,8 +156,8 @@ static const struct backlight_ops pwm_backlight_ops = { ...@@ -156,8 +156,8 @@ static const struct backlight_ops pwm_backlight_ops = {
* *
* The CIE 1931 lightness formula is what actually describes how we perceive * The CIE 1931 lightness formula is what actually describes how we perceive
* light: * light:
* Y = (L* / 902.3) if L* ≤ 0.08856 * Y = (L* / 903.3) if L* ≤ 8
* Y = ((L* + 16) / 116)^3 if L* > 0.08856 * Y = ((L* + 16) / 116)^3 if L* > 8
* *
* Where Y is the luminance, the amount of light coming out of the screen, and * Where Y is the luminance, the amount of light coming out of the screen, and
* is a number between 0.0 and 1.0; and L* is the lightness, how bright a human * is a number between 0.0 and 1.0; and L* is the lightness, how bright a human
...@@ -170,9 +170,15 @@ static u64 cie1931(unsigned int lightness, unsigned int scale) ...@@ -170,9 +170,15 @@ static u64 cie1931(unsigned int lightness, unsigned int scale)
{ {
u64 retval; u64 retval;
/*
* @lightness is given as a number between 0 and 1, expressed
* as a fixed-point number in scale @scale. Convert to a
* percentage, still expressed as a fixed-point number, so the
* above formulas can be applied.
*/
lightness *= 100; lightness *= 100;
if (lightness <= (8 * scale)) { if (lightness <= (8 * scale)) {
retval = DIV_ROUND_CLOSEST_ULL(lightness * 10, 9023); retval = DIV_ROUND_CLOSEST_ULL(lightness * 10, 9033);
} else { } else {
retval = int_pow((lightness + (16 * scale)) / 116, 3); retval = int_pow((lightness + (16 * scale)) / 116, 3);
retval = DIV_ROUND_CLOSEST_ULL(retval, (scale * scale)); retval = DIV_ROUND_CLOSEST_ULL(retval, (scale * scale));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment