FastLED 3.9.15
Loading...
Searching...
No Matches
hsv.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include "fl/stdint.h"
7#include "fl/int.h"
8
9namespace fl {
10
13
15struct CHSV {
16 union {
17 struct {
18 union {
22 fl::u8 hue;
23 fl::u8 h;
24 };
25 union {
29 fl::u8 sat;
30 fl::u8 s;
31 };
32 union {
36 fl::u8 val;
37 fl::u8 v;
38 };
39 };
40
45 fl::u8 raw[3];
46 };
47
51 inline fl::u8& operator[] (fl::u8 x) __attribute__((always_inline))
52 {
53 return raw[x];
54 }
55
57 inline const fl::u8& operator[] (fl::u8 x) const __attribute__((always_inline))
58 {
59 return raw[x];
60 }
61
64 constexpr inline CHSV() __attribute__((always_inline)): h(0), s(0), v(0) { }
65
70 constexpr inline CHSV( fl::u8 ih, fl::u8 is, fl::u8 iv) __attribute__((always_inline))
71 : h(ih), s(is), v(iv)
72 {
73 }
74
76 constexpr inline CHSV(const CHSV& rhs) noexcept : h(rhs.h), s(rhs.s), v(rhs.v) { }
77
79 inline CHSV& operator= (const CHSV& rhs) __attribute__((always_inline)) = default;
80
86 inline CHSV& setHSV(fl::u8 ih, fl::u8 is, fl::u8 iv) __attribute__((always_inline))
87 {
88 h = ih;
89 s = is;
90 v = iv;
91 return *this;
92 }
93};
94
96typedef enum {
97 HUE_RED = 0,
101 HUE_AQUA = 128,
102 HUE_BLUE = 160,
104 HUE_PINK = 224
105} HSVHue;
106
108
109} // namespace fl
int x
Definition simple.h:92
HSVHue
Pre-defined hue values for CHSV objects.
Definition hsv.h:96
@ HUE_BLUE
Blue (225°)
Definition hsv.h:102
@ HUE_RED
Red (0°)
Definition hsv.h:97
@ HUE_AQUA
Aqua (180°)
Definition hsv.h:101
@ HUE_PINK
Pink (315°)
Definition hsv.h:104
@ HUE_GREEN
Green (135°)
Definition hsv.h:100
@ HUE_YELLOW
Yellow (90°)
Definition hsv.h:99
@ HUE_ORANGE
Orange (45°)
Definition hsv.h:98
@ HUE_PURPLE
Purple (270°)
Definition hsv.h:103
fl::u8 value
Color value (brightness).
unsigned char u8
Definition int.h:17
IMPORTANT!
Definition crgb.h:20
constexpr CHSV()
Default constructor.
Definition hsv.h:64
constexpr CHSV(const CHSV &rhs) noexcept
Allow copy construction.
Definition hsv.h:76
CHSV & operator=(const CHSV &rhs)=default
Allow copy construction.
constexpr CHSV(fl::u8 ih, fl::u8 is, fl::u8 iv)
Allow construction from hue, saturation, and value.
Definition hsv.h:70
constexpr CHSV()
Default constructor.
Definition hsv.h:64
CHSV & setHSV(fl::u8 ih, fl::u8 is, fl::u8 iv)
Assign new HSV values.
Definition hsv.h:86
fl::u8 & operator[](fl::u8 x)
Array access operator to index into the CHSV object.
Definition hsv.h:51