-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.def.h
49 lines (49 loc) · 1.75 KB
/
config.def.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* public domain */
/* This resembles the original way of looking up values from a table.
* Cribbed from redshift, but truncated with 500K steps and reduced accuracy to
* one percent */
struct whitepoint { float r, g, b; };
static const struct whitepoint whitepoints[] = {
#if 0 // we don't want cooler colors
{ 0.77, 0.85, 1.00, },
{ 0.77, 0.85, 1.00, },
{ 0.78, 0.86, 1.00, }, /* 10000K */
{ 0.80, 0.87, 1.00, },
{ 0.82, 0.89, 1.00, },
{ 0.85, 0.90, 1.00, },
{ 0.87, 0.92, 1.00, },
{ 0.91, 0.94, 1.00, },
{ 0.95, 0.96, 1.00, },
#endif
{ 1.00, 1.00, 1.00, }, /* 6500K */
{ 1.00, 0.97, 0.94, },
{ 1.00, 0.93, 0.88, },
{ 1.00, 0.90, 0.81, },
{ 1.00, 0.86, 0.73, },
{ 1.00, 0.82, 0.64, },
{ 1.00, 0.77, 0.54, },
{ 1.00, 0.71, 0.42, },
{ 1.00, 0.64, 0.28, },
{ 1.00, 0.54, 0.08, },
{ 1.00, 0.42, 0.00, },
{ 1.00, 0.18, 0.00, }, /* 1000K */
};
enum { red, green, blue};
static float avg(int permille, int color)
{
const unsigned int transitions = -1 + sizeof(whitepoints)/sizeof(whitepoints[0]);
const float transition_width = 1000.0 / transitions;
const int transition = 1.*permille / transition_width;
const float transition_progress_ratio = (1.*permille - transition_width * transition) / transition_width;
const struct whitepoint * wp = &whitepoints[transition];
float c, cn;
switch(color) {
case red: c = wp[0].r, cn = wp[1].r; break;
case green: c = wp[0].g, cn = wp[1].g; break;
default: c = wp[0].b, cn = wp[1].b; break;
}
return c - c * transition_progress_ratio + cn * transition_progress_ratio;
}
static float gammar(int permille) { return avg(permille, red); }
static float gammag(int permille) { return avg(permille, green); }
static float gammab(int permille) { return avg(permille, blue); }