diff options
author | danielgarcia@gmail.com <danielgarcia@gmail.com@4ad4ec5c-605d-bd5c-5796-512c9b60011b> | 2013-04-26 08:48:42 +0400 |
---|---|---|
committer | danielgarcia@gmail.com <danielgarcia@gmail.com@4ad4ec5c-605d-bd5c-5796-512c9b60011b> | 2013-04-26 08:48:42 +0400 |
commit | d8ce90645ee709e58bb46bdb957c4854cc08c3c4 (patch) | |
tree | 90984d65a7038100953746a55d699a9fc92d2d05 /pixeltypes.h | |
parent | c7689050e6db78098569c1903b443cef094fdcfc (diff) |
Add basic copy/assignment constructors to CHSV, add const operator[] to CRGB
Diffstat (limited to 'pixeltypes.h')
-rw-r--r-- | pixeltypes.h | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/pixeltypes.h b/pixeltypes.h index 99d26841..35acd628 100644 --- a/pixeltypes.h +++ b/pixeltypes.h @@ -22,6 +22,41 @@ struct CHSV { }; uint8_t raw[3]; }; + + // default values are UNITIALIZED + inline CHSV() __attribute__((always_inline)) + { + } + + // allow construction from H, S, V + inline CHSV( uint8_t ih, uint8_t is, uint8_t iv) __attribute__((always_inline)) + : h(ih), s(is), v(iv) + { + } + + // allow copy construction + inline CHSV(const CHSV& rhs) __attribute__((always_inline)) + { + h = rhs.h; + s = rhs.s; + v = rhs.v; + } + + inline CHSV& operator= (const CHSV& rhs) __attribute__((always_inline)) + { + h = rhs.h; + s = rhs.s; + v = rhs.v; + return *this; + } + + inline CHSV& setHSV(uint8_t ih, uint8_t is, uint8_t iv) __attribute__((always_inline)) + { + h = ih; + s = is; + v = iv; + return *this; + } }; @@ -49,6 +84,11 @@ struct CRGB { return raw[x]; } + inline const uint8_t& operator[] (uint8_t x) const __attribute__((always_inline)) + { + return raw[x]; + } + // default values are UNINITIALIZED inline CRGB() __attribute__((always_inline)) { @@ -90,22 +130,14 @@ struct CRGB { // allow assignment from H, S, and V inline CRGB& setHSV (uint8_t nh, uint8_t ns, uint8_t nv) __attribute__((always_inline)) { - CHSV hsv; - hsv.hue = nh; - hsv.sat = ns; - hsv.val = nv; - hsv2rgb( hsv, *this); + hsv2rgb(CHSV(nh, ns, nv), *this); return *this; } // allow assignment from H, S, and V inline CRGB& setRainbowHSV (uint8_t nh, uint8_t ns, uint8_t nv) __attribute__((always_inline)) { - CHSV hsv; - hsv.hue = nh; - hsv.sat = ns; - hsv.val = nv; - rainbow2rgb( hsv, *this); + hsv2rgb(CHSV(nh, ns, nv), *this); return *this; } #endif |