ARMEBS4  revision-26.06.2015
lightness_to_pwm.c
2 
3 /**
4  * \brief Table for converting percentage of lightness# into PWM ratio
5  *
6  * #lightness = human eye perceived luminance
7  *
8  * Here we use the formula provided in CIE 1931.
9  *
10  * Y = (L* / 902.3) if Y ≤ 8
11  * Y = ((L* + 16) / 116)^3 if Y > 8
12  * where L is lightness (0..100) and Y is luminance (0..1)
13  *
14  * The table below corresponds to :
15  * * lightness 0..100
16  * * luminance 0..255
17  *
18  * This table has 101 element, covering 0%..100%
19  */
20 static const uint8_t cie1931[101] =
21 {
22  0, 0, 1, 1, 1, 1, 2, 2, 2, 3,
23  3, 3, 4, 4, 4, 5, 5, 6, 6, 7,
24  8, 8, 9, 10, 10, 11, 12, 13, 14, 15,
25  16, 17, 18, 19, 20, 22, 23, 24, 26, 27,
26  29, 30, 32, 34, 35, 37, 39, 41, 43, 45,
27  47, 49, 51, 54, 56, 58, 61, 64, 66, 69,
28  72, 75, 78, 81, 84, 87, 90, 93, 97, 100,
29  104, 108, 111, 115, 119, 123, 127, 131, 136, 140,
30  145, 149, 154, 159, 163, 168, 173, 179, 184, 189,
31  195, 200, 206, 212, 217, 223, 230, 236, 242, 248,
32  255,
33 };
34 
35 #if LIGHTNESS_PWM_STEP != 255
36 #error this cie1931 array supports only 255 steps, feel free to implement your own
37 #endif
38 
39 uint8_t lightness_to_pwm(uint8_t percentage)
40 {
41  percentage = min(percentage, ARRAY_SIZE(cie1931) - 1);
42 
43  return cie1931[percentage];
44 }
Handle non-linearity in human eye brightness sensitivity.
uint8_t lightness_to_pwm(uint8_t percentage)
PWM value for driving a LED expressed as perceived percentage.
#define ARRAY_SIZE(x)
Number of elements in the array.
Definition: utils.h:19