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