1 #ifndef __INC_PIXELSET_H
2 #define __INC_PIXELSET_H
9 template<
class PIXEL_TYPE>
14 PIXEL_TYPE *
const leds;
15 PIXEL_TYPE *
const end_pos;
20 inline CPixelView(
const CPixelView & other) : dir(other.dir), len(other.len), leds(other.leds), end_pos(other.end_pos) {}
26 inline CPixelView(PIXEL_TYPE *_leds,
int _len) : dir(_len < 0 ? -1 : 1), len(_len), leds(_leds), end_pos(_leds + _len) {}
33 inline CPixelView(PIXEL_TYPE *_leds,
int _start,
int _end) : dir(((_end-_start)<0) ? -1 : 1), len((_end - _start) + dir), leds(_leds + _start), end_pos(_leds + _start + len) {}
37 int size() {
return abs(len); }
44 bool operator==(
const CPixelView & rhs)
const {
return leds == rhs.leds && len == rhs.len && dir == rhs.dir; }
47 bool operator!=(
const CPixelView & rhs)
const {
return leds != rhs.leds || len != rhs.len || dir != rhs.dir; }
50 inline PIXEL_TYPE &
operator[](
int x)
const {
if(dir & 0x80) {
return leds[-x]; }
else {
return leds[x]; } }
66 inline operator PIXEL_TYPE* ()
const {
return leds; }
71 for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel) = color; }
88 for(iterator pixel = begin(), rhspixel = rhs.begin(), _end = end(), rhs_end = rhs.end(); (pixel != _end) && (rhspixel != rhs_end); ++pixel, ++rhspixel) {
89 (*pixel) = (*rhspixel);
96 inline CPixelView &
addToRGB(uint8_t inc) {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel) += inc; }
return *
this; }
99 inline CPixelView &
operator+=(
CPixelView & rhs) {
for(iterator pixel = begin(), rhspixel = rhs.begin(), _end = end(), rhs_end = rhs.end(); (pixel != _end) && (rhspixel != rhs_end); ++pixel, ++rhspixel) { (*pixel) += (*rhspixel); }
return *
this; }
102 inline CPixelView &
subFromRGB(uint8_t inc) {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel) -= inc; }
return *
this; }
104 inline CPixelView &
operator-=(
CPixelView & rhs) {
for(iterator pixel = begin(), rhspixel = rhs.begin(), _end = end(), rhs_end = rhs.end(); (pixel != _end) && (rhspixel != rhs_end); ++pixel, ++rhspixel) { (*pixel) -= (*rhspixel); }
return *
this; }
107 inline CPixelView &
operator++() {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel)++; }
return *
this; }
109 inline CPixelView &
operator++(
int DUMMY_ARG) {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel)++; }
return *
this; }
112 inline CPixelView &
operator--() {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel)--; }
return *
this; }
114 inline CPixelView &
operator--(
int DUMMY_ARG) {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel)--; }
return *
this; }
117 inline CPixelView &
operator/=(uint8_t d) {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel) /= d; }
return *
this; }
119 inline CPixelView &
operator>>=(uint8_t d) {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel) >>= d; }
return *
this; }
121 inline CPixelView &
operator*=(uint8_t d) {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel) *= d; }
return *
this; }
131 inline CPixelView &
nscale8(uint8_t scaledown) {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel).
nscale8(scaledown); }
return *
this; }
133 inline CPixelView &
nscale8(PIXEL_TYPE & scaledown) {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel).
nscale8(scaledown); }
return *
this; }
135 inline CPixelView &
nscale8(
CPixelView & rhs) {
for(iterator pixel = begin(), rhspixel = rhs.begin(), _end = end(), rhs_end = rhs.end(); (pixel != _end) && (rhspixel != rhs_end); ++pixel, ++rhspixel) { (*pixel).
nscale8((*rhspixel)); }
return *
this; }
141 inline CPixelView &
operator|=(
const PIXEL_TYPE & rhs) {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel) |= rhs; }
return *
this; }
143 inline CPixelView &
operator|=(
const CPixelView & rhs) {
for(iterator pixel = begin(), rhspixel = rhs.begin(), _end = end(), rhs_end = rhs.end(); (pixel != _end) && (rhspixel != rhs_end); ++pixel, ++rhspixel) { (*pixel) |= (*rhspixel); }
return *
this; }
145 inline CPixelView &
operator|=(uint8_t d) {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel) |= d; }
return *
this; }
148 inline CPixelView &
operator&=(
const PIXEL_TYPE & rhs) {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel) &= rhs; }
return *
this; }
150 inline CPixelView &
operator&=(
const CPixelView & rhs) {
for(iterator pixel = begin(), rhspixel = rhs.begin(), _end = end(), rhs_end = rhs.end(); (pixel != _end) && (rhspixel != rhs_end); ++pixel, ++rhspixel) { (*pixel) &= (*rhspixel); }
return *
this; }
152 inline CPixelView &
operator&=(uint8_t d) {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { (*pixel) &= d; }
return *
this; }
156 inline operator bool() {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) {
if((*pixel))
return true; }
return false; }
159 inline CPixelView & fill_solid(
const PIXEL_TYPE & color) { *
this = color;
return *
this; }
160 inline CPixelView & fill_solid(
const CHSV & color) {
if(dir>0) { *
this = color;
return *
this; } }
162 inline CPixelView & fill_rainbow(uint8_t initialhue, uint8_t deltahue=5) {
164 ::fill_rainbow(leds,len,initialhue,deltahue);
166 ::fill_rainbow(leds+len+1,-len,initialhue,deltahue);
171 inline CPixelView & fill_gradient(
const CHSV & startcolor,
const CHSV & endcolor, TGradientDirectionCode directionCode = SHORTEST_HUES) {
173 ::fill_gradient(leds,len,startcolor, endcolor, directionCode);
175 ::fill_gradient(leds + len + 1, (-len), endcolor, startcolor, directionCode);
180 inline CPixelView & fill_gradient(
const CHSV & c1,
const CHSV & c2,
const CHSV & c3, TGradientDirectionCode directionCode = SHORTEST_HUES) {
182 ::fill_gradient(leds, len, c1, c2, c3, directionCode);
184 ::fill_gradient(leds + len + 1, -len, c3, c2, c1, directionCode);
189 inline CPixelView & fill_gradient(
const CHSV & c1,
const CHSV & c2,
const CHSV & c3,
const CHSV & c4, TGradientDirectionCode directionCode = SHORTEST_HUES) {
191 ::fill_gradient(leds, len, c1, c2, c3, c4, directionCode);
193 ::fill_gradient(leds + len + 1, -len, c4, c3, c2, c1, directionCode);
198 inline CPixelView & fill_gradient_RGB(
const PIXEL_TYPE & startcolor,
const PIXEL_TYPE & endcolor, TGradientDirectionCode directionCode = SHORTEST_HUES) {
200 ::fill_gradient_RGB(leds,len,startcolor, endcolor);
202 ::fill_gradient_RGB(leds + len + 1, (-len), endcolor, startcolor);
207 inline CPixelView & fill_gradient_RGB(
const PIXEL_TYPE & c1,
const PIXEL_TYPE & c2,
const PIXEL_TYPE & c3) {
209 ::fill_gradient_RGB(leds, len, c1, c2, c3);
211 ::fill_gradient_RGB(leds + len + 1, -len, c3, c2, c1);
216 inline CPixelView & fill_gradient_RGB(
const PIXEL_TYPE & c1,
const PIXEL_TYPE & c2,
const PIXEL_TYPE & c3,
const PIXEL_TYPE & c4) {
218 ::fill_gradient_RGB(leds, len, c1, c2, c3, c4);
220 ::fill_gradient_RGB(leds + len + 1, -len, c4, c3, c2, c1);
225 inline CPixelView & nblend(
const PIXEL_TYPE & overlay,
fract8 amountOfOverlay) {
for(iterator pixel = begin(), _end = end(); pixel != _end; ++pixel) { ::nblend((*pixel), overlay, amountOfOverlay); }
return *
this; }
226 inline CPixelView & nblend(
const CPixelView & rhs,
fract8 amountOfOverlay) {
for(iterator pixel = begin(), rhspixel = rhs.begin(), _end = end(), rhs_end = rhs.end(); (pixel != _end) && (rhspixel != rhs_end); ++pixel, ++rhspixel) { ::nblend((*pixel), (*rhspixel), amountOfOverlay); }
return *
this; }
231 ::blur1d(leds, len, blur_amount);
233 ::blur1d(leds + len + 1, -len, blur_amount);
238 inline CPixelView & napplyGamma_video(
float gamma) {
240 ::napplyGamma_video(leds, len, gamma);
242 ::napplyGamma_video(leds + len + 1, -len, gamma);
247 inline CPixelView & napplyGamma_video(
float gammaR,
float gammaG,
float gammaB) {
249 ::napplyGamma_video(leds, len, gammaR, gammaG, gammaB);
251 ::napplyGamma_video(leds + len + 1, -len, gammaR, gammaG, gammaB);
263 __attribute__((always_inline))
inline pixelset_iterator_base(T * _leds,
const char _dir) : leds(_leds), dir(_dir) {}
271 __attribute__((always_inline))
inline PIXEL_TYPE& operator*()
const {
return *leds; }
277 iterator begin() {
return iterator(leds, dir); }
278 iterator end() {
return iterator(end_pos, dir); }
280 iterator begin()
const {
return iterator(leds, dir); }
281 iterator end()
const {
return iterator(end_pos, dir); }
283 const_iterator cbegin()
const {
return const_iterator(leds, dir); }
284 const_iterator cend()
const {
return const_iterator(end_pos, dir); }
290 inline
CRGB *operator+(const CRGBSet & pixels,
int offset) {
return (
CRGB*)pixels + offset; }
CPixelView & nscale8(PIXEL_TYPE &scaledown)
Scale every led by the given scale.
CPixelView operator-()
Access an inclusive subset of the leds in this set, starting from the first.
CPixelView & operator&=(const PIXEL_TYPE &rhs)
Apply the PIXEL_TYPE &= operator to every pixel in this set with the given PIXEL_TYPE value (bringing...
CPixelView & operator++(int DUMMY_ARG)
Increment every pixel value in this set.
CPixelView & fadeLightBy(uint8_t fadefactor)
Fade every led down by the given scale.
Representation of an RGB pixel (Red, Green, Blue)
CPixelView & operator*=(uint8_t d)
Multiply every led in this set by the given value.
CPixelView & operator&=(const CPixelView &rhs)
Apply the PIXEL_TYPE &= operator to every pixel in this set with every pixel in the passed in set...
CPixelView & operator++()
Increment every pixel value in this set.
CPixelView & addToRGB(uint8_t inc)
Add the passed in value to r,g, b for all the pixels in this set.
CPixelView & operator=(const PIXEL_TYPE &color)
Assign the passed in color to all elements in this set.
bool reversed()
Whether or not this set goes backwards.
CPixelView & operator--()
Decrement every pixel value in this set.
CPixelView & operator--(int DUMMY_ARG)
Decrement every pixel value in this set.
CPixelView operator()(int start, int end)
Access an inclusive subset of the leds in this set.
CPixelView(const CPixelView &other)
PixelSet copy constructor.
CPixelView & nscale8(CPixelView &rhs)
Scale every led in this set by every led in the other set.
CPixelView(PIXEL_TYPE *_leds, int _start, int _end)
PixelSet constructor for the given set of leds, with start and end boundaries.
uint8_t fract8
ANSI unsigned short _Fract.
CPixelView & nscale8_video(uint8_t scaledown)
Scale every led by the given scale.
CPixelView & operator%=(uint8_t scaledown)
Scale down every led by the given scale.
CPixelView & operator+=(CPixelView &rhs)
Add every pixel in the other set to this set.
bool operator!=(const CPixelView &rhs) const
do these sets point to the different things (note, this is different from the contents of the set bei...
Represents a set of CRGB led objects.
CPixelView & nscale8(uint8_t scaledown)
Scale every led by the given scale.
central include file for FastLED, defines the CFastLED class/object
CPixelView & fadeToBlackBy(uint8_t fade)
Fade every led down by the given scale.
CPixelView & operator|=(const CPixelView &rhs)
Apply the PIXEL_TYPE |= operator to every pixel in this set with every pixel in the passed in set...
CPixelView & operator/=(uint8_t d)
Divide every led by the given value.
int size()
Get the size of this set.
bool operator==(const CPixelView &rhs) const
do these sets point to the same thing (note, this is different from the contents of the set being the...
CPixelView & operator=(const CPixelView &rhs)
Copy the contents of the passed in set to our set.
CPixelView & operator-=(CPixelView &rhs)
Subtract every pixel in the other set from this set.
CPixelView & operator|=(const PIXEL_TYPE &rhs)
Apply the PIXEL_TYPE |= operator to every pixel in this set with the given PIXEL_TYPE value (bringing...
__attribute__((always_inline)) inline void swapbits8(bitswap_type in
Do an 8byte by 8bit rotation.
CPixelView & operator|=(uint8_t d)
Apply the PIXEL_TYPE |= operator to every pixel in this set.
PIXEL_TYPE & operator[](int x) const
access a single element in this set, just like an array operator
CPixelView(PIXEL_TYPE *_leds, int _len)
pixelset constructor for a pixel set starting at the given PIXEL_TYPE* and going for _len leds...
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
CPixelView & operator>>=(uint8_t d)
Shift every led in this set right by the given number of bits.
CPixelView & operator&=(uint8_t d)
APply the PIXEL_TYPE &= operator to every pixel in this set with the passed in value.
CPixelView & subFromRGB(uint8_t inc)
Subtract the passed in value from r,g,b for all pixels in this set.