GCC Code Coverage Report


Directory: ./
File: overlays/wled/chsv.h
Date: 2026-10-29 08:11:58
Exec Total Coverage
Lines: 3 3 100.0%
Functions: 1 1 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /// @file chsv.h
2 /// Defines the hue, saturation, and value (HSV) pixel struct
3
4 #pragma once
5
6 #include <stdint.h>
7
8 #include "fl/namespace.h"
9
10 FASTLED_NAMESPACE_BEGIN
11
12 /// @addtogroup PixelTypes Pixel Data Types (CRGB/CHSV)
13 /// @{
14
15 /// Representation of an HSV pixel (hue, saturation, value (aka brightness)).
16 struct CHSV {
17 union {
18 struct {
19 union {
20 /// Color hue.
21 /// This is an 8-bit value representing an angle around
22 /// the color wheel. Where 0 is 0°, and 255 is 358°.
23 uint8_t hue;
24 uint8_t h; ///< @copydoc hue
25 };
26 union {
27 /// Color saturation.
28 /// This is an 8-bit value representing a percentage.
29 uint8_t saturation;
30 uint8_t sat; ///< @copydoc saturation
31 uint8_t s; ///< @copydoc saturation
32 };
33 union {
34 /// Color value (brightness).
35 /// This is an 8-bit value representing a percentage.
36 uint8_t value;
37 uint8_t val; ///< @copydoc value
38 uint8_t v; ///< @copydoc value
39 };
40 };
41 /// Access the hue, saturation, and value data as an array.
42 /// Where:
43 /// * `raw[0]` is the hue
44 /// * `raw[1]` is the saturation
45 /// * `raw[2]` is the value
46 uint8_t raw[3];
47 };
48
49 /// Array access operator to index into the CHSV object
50 /// @param x the index to retrieve (0-2)
51 /// @returns the CHSV::raw value for the given index
52 inline uint8_t& operator[] (uint8_t x) __attribute__((always_inline))
53 {
54 return raw[x];
55 }
56
57 /// @copydoc operator[]
58 inline const uint8_t& operator[] (uint8_t x) const __attribute__((always_inline))
59 {
60 return raw[x];
61 }
62
63 /// Default constructor
64 /// @warning Default values are UNITIALIZED!
65 constexpr inline CHSV() __attribute__((always_inline)): h(0), s(0), v(0) { }
66
67 /// Allow construction from hue, saturation, and value
68 /// @param ih input hue
69 /// @param is input saturation
70 /// @param iv input value
71 constexpr inline CHSV( uint8_t ih, uint8_t is, uint8_t iv) __attribute__((always_inline))
72 132786 : h(ih), s(is), v(iv)
73 {
74 132786 }
75
76 /// Allow copy construction
77 28182 constexpr inline CHSV(const CHSV& rhs) noexcept : h(rhs.h), s(rhs.s), v(rhs.v) { }
78
79 /// Allow copy construction
80 inline CHSV& operator= (const CHSV& rhs) __attribute__((always_inline)) = default;
81
82 /// Assign new HSV values
83 /// @param ih input hue
84 /// @param is input saturation
85 /// @param iv input value
86 /// @returns reference to the CHSV object
87 inline CHSV& setHSV(uint8_t ih, uint8_t is, uint8_t iv) __attribute__((always_inline))
88 {
89 h = ih;
90 s = is;
91 v = iv;
92 return *this;
93 }
94 };
95
96 /// Pre-defined hue values for CHSV objects
97 typedef enum {
98 HUE_RED = 0, ///< Red (0°)
99 HUE_ORANGE = 32, ///< Orange (45°)
100 HUE_YELLOW = 64, ///< Yellow (90°)
101 HUE_GREEN = 96, ///< Green (135°)
102 HUE_AQUA = 128, ///< Aqua (180°)
103 HUE_BLUE = 160, ///< Blue (225°)
104 HUE_PURPLE = 192, ///< Purple (270°)
105 HUE_PINK = 224 ///< Pink (315°)
106 } HSVHue;
107
108 /// @} PixelTypes
109
110 FASTLED_NAMESPACE_END
111