-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrgbw.cpp
52 lines (39 loc) · 943 Bytes
/
rgbw.cpp
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
50
51
52
#include <stdint.h>
#include "rgbw.h"
static uint8_t RGBW::b(uint32_t c) {
return (uint8_t)c;
}
static uint32_t RGBW::color(uint8_t r, uint8_t g, uint8_t b) {
return ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
}
static uint32_t RGBW::color(uint8_t r, uint8_t g, uint8_t b, uint8_t w) {
return ((uint32_t)w << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
}
static uint8_t RGBW::g(uint32_t c) {
return (uint8_t)(c >> 8);
}
static uint8_t RGBW::r(uint32_t c) {
return (uint8_t)(c >> 16);
}
static uint32_t RGBW::rotate(uint8_t deg, uint32_t c=0) {
uint8_t pos, r, g, b;
deg = 255 - deg;
if( deg < 85 ) {
r = 256 - 3* deg;
g = 0;
b = 3 * deg;
} else if( deg < 170 ) {
r = 0;
g = 3 * deg;
b = 255 - 3 * deg;
} else {
deg -= 170;
r = 3 * deg;
g = 255 - 3 * deg;
b = 0;
}
return color(r,g,b);
}
static uint8_t RGBW::w(uint32_t c) {
return (uint8_t)(c >> 24);
}