-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHSBColor.h
56 lines (42 loc) · 897 Bytes
/
HSBColor.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
50
51
52
53
54
55
56
#pragma once
#include <stdint.h>
#include "RGBColor.h"
#define HSBColorHueRange (1536)
// HSB == HSV, HSB != HSL
// hue is ranged from 0 - 1535 for performance reasons (6 * 256)
class HSBColor {
public:
HSBColor();
HSBColor(int16_t h, uint8_t s, uint8_t b);
HSBColor(float h, float s, float b);
void normalizeSelf();
operator RGBColor() const;
friend HSBColor lerp(const HSBColor c0, const HSBColor c1, const int16_t time);
public:
union {
struct {
int16_t h;
uint8_t s;
uint8_t b;
};
uint32_t value;
};
};
inline HSBColor::HSBColor() {
}
inline HSBColor::HSBColor(int16_t h, uint8_t s, uint8_t b) :
h(h),
s(s),
b(b) {
}
inline HSBColor::HSBColor(float h, float s, float b) :
h(h * (HSBColorHueRange - 1.0f)),
s(s * 255.0f),
b(b * 255.0f) {
}
inline void HSBColor::normalizeSelf() {
h %= HSBColorHueRange;
if(h < 0) {
h += HSBColorHueRange;
}
}