HSV to RGB implementation in raw C, platform independent.
42{
43
44
45
46
47
49 uint8_t saturation = hsv.sat;
50
51
52
54 uint8_t brightness_floor = (value * invsat) / 256;
55
56
57
58
59 uint8_t color_amplitude = value - brightness_floor;
60
61
62
65
66 uint8_t rampup = offset;
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99 uint8_t rampup_amp_adj = (rampup * color_amplitude) / (256 / 4);
100 uint8_t rampdown_amp_adj = (rampdown * color_amplitude) / (256 / 4);
101
102
103 uint8_t rampup_adj_with_floor = rampup_amp_adj + brightness_floor;
104 uint8_t rampdown_adj_with_floor = rampdown_amp_adj + brightness_floor;
105
106
107 if( section ) {
108 if( section == 1) {
109
110 rgb.r = brightness_floor;
111 rgb.g = rampdown_adj_with_floor;
112 rgb.b = rampup_adj_with_floor;
113 } else {
114
115 rgb.r = rampup_adj_with_floor;
116 rgb.g = brightness_floor;
117 rgb.b = rampdown_adj_with_floor;
118 }
119 } else {
120
121 rgb.r = rampdown_adj_with_floor;
122 rgb.g = rampup_adj_with_floor;
123 rgb.b = brightness_floor;
124 }
125}
#define APPLY_DIMMING(X)
Apply dimming compensation to values.
#define HSV_SECTION_3
Divide the color wheel into four sections, 64 elements each.