FastLED 3.9.7
Loading...
Searching...
No Matches
color.h
1
2
3#ifndef COLOR_H_
4#define COLOR_H_
5
6#include <stdint.h>
7
8struct Color3i {
9 static Color3i Black() { return Color3i(0x0, 0x0, 0x0); }
10 static Color3i White() { return Color3i(0xff, 0xff, 0xff); }
11 static Color3i Red() { return Color3i(0xff, 0x00, 0x00); }
12 static Color3i Orange() { return Color3i(0xff, 0xff / 2,00); }
13 static Color3i Yellow() { return Color3i(0xff, 0xff,00); }
14 static Color3i Green() { return Color3i(0x00, 0xff, 0x00); }
15 static Color3i Cyan() { return Color3i(0x00, 0xff, 0xff); }
16 static Color3i Blue() { return Color3i(0x00, 0x00, 0xff); }
17 Color3i(uint8_t r, uint8_t g, uint8_t b) { Set(r,g,b); }
18 Color3i() { Set(0xff, 0xff, 0xff); }
19 Color3i(const Color3i& other) { Set(other); }
20
21 void Set(uint8_t r, uint8_t g, uint8_t b) { r_ = r; g_ = g; b_ = b; }
22 void Set(const Color3i& c) { Set(c.r_, c.g_, c.b_); }
23 void Mul(const Color3i& other_color);
24 void Mulf(float scale); // Input range is 0.0 -> 1.0
25 void Mul(uint8_t val) {
26 Mul(Color3i(val, val, val));
27 }
28 void Sub(const Color3i& color);
29 void Add(const Color3i& color);
30 uint8_t Get(int rgb_index) const;
31 void Set(int rgb_index, uint8_t val);
32 void Fill(uint8_t val) { Set(val, val, val); }
33 uint8_t MaxRGB() const {
34 uint8_t max_r_g = r_ > g_ ? r_ : g_;
35 return max_r_g > b_ ? max_r_g : b_;
36 }
37
38 template <typename PrintStream>
39 inline void Print(PrintStream* stream) const {
40 stream->print("RGB:\t");
41 stream->print(r_); stream->print(",\t");
42 stream->print(g_); stream->print(",\t");
43 stream->print(b_);
44 stream->print("\n");
45 }
46
47 void Interpolate(const Color3i& other_color, float t);
48
49 uint8_t* At(int rgb_index);
50 const uint8_t* At(int rgb_index) const;
51
52 uint8_t r_, g_, b_;
53};
54
55
56struct ColorHSV {
57 ColorHSV() : h_(0), s_(0), v_(0) {}
58 ColorHSV(float h, float s, float v) {
59 Set(h,s,v);
60 }
61 explicit ColorHSV(const Color3i& color) {
62 FromRGB(color);
63 }
64 ColorHSV& operator=(const Color3i& color) {
65 FromRGB(color);
66 return *this;
67 }
68 ColorHSV(const ColorHSV& other) {
69 Set(other);
70 }
71 void Set(const ColorHSV& other) {
72 Set(other.h_, other.s_, other.v_);
73 }
74 void Set(float h, float s, float v) {
75 h_ = h;
76 s_ = s;
77 v_ = v;
78 }
79
80 template <typename PrintStream>
81 inline void Print(PrintStream* stream) {
82 stream->print("HSV:\t");
83 stream->print(h_); stream->print(",\t");
84 stream->print(s_); stream->print(",\t");
85 stream->print(v_); stream->print("\n");
86 }
87
88 bool operator==(const ColorHSV& other) const {
89 return h_ == other.h_ && s_ == other.s_ && v_ == other.v_;
90 }
91 bool operator!=(const ColorHSV& other) const {
92 return !(*this == other);
93 }
94 void FromRGB(const Color3i& rgb);
95
96 Color3i ToRGB() const;
97
98 float h_, s_, v_;
99};
100
101
102#endif // COLOR_H_
Definition color.h:8