diff options
author | Mark Kriegsman <1334634+kriegsman@users.noreply.github.com> | 2020-02-11 18:08:31 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-11 18:08:31 +0300 |
commit | 89e83a930587f5a6bb5a7246f88330958ebbadcc (patch) | |
tree | d4c3c3207c9e7064384b7c65259b4544e3d15461 | |
parent | fec0f0300e14c7dd1fa4fb7eb08ff1fd862f0dae (diff) | |
parent | 3fb73d4ddf4d20e16e013cd931189a30e9c55b4a (diff) |
Merge pull request #963 from jackw01/master
Overload array subscript operator for CHSV structs
-rw-r--r-- | pixeltypes.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/pixeltypes.h b/pixeltypes.h index ff327fd9..f4e57061 100644 --- a/pixeltypes.h +++ b/pixeltypes.h @@ -38,6 +38,18 @@ struct CHSV { uint8_t raw[3]; }; + /// Array access operator to index into the chsv object + inline uint8_t& operator[] (uint8_t x) __attribute__((always_inline)) + { + return raw[x]; + } + + /// Array access operator to index into the chsv object + inline const uint8_t& operator[] (uint8_t x) const __attribute__((always_inline)) + { + return raw[x]; + } + /// default values are UNITIALIZED inline CHSV() __attribute__((always_inline)) { @@ -106,7 +118,7 @@ struct CRGB { uint8_t raw[3]; }; - /// Array access operator to index into the crgb object + /// Array access operator to index into the crgb object inline uint8_t& operator[] (uint8_t x) __attribute__((always_inline)) { return raw[x]; @@ -478,7 +490,7 @@ struct CRGB { uint8_t max = red; if( green > max) max = green; if( blue > max) max = blue; - + // stop div/0 when color is black if(max > 0) { uint16_t factor = ((uint16_t)(limit) * 256) / max; |