FastLED 3.6.0
Loading...
Searching...
No Matches
pixeltypes.h
Go to the documentation of this file.
1#ifndef __INC_PIXELS_H
2#define __INC_PIXELS_H
3
4#include "FastLED.h"
5
6#include <stdint.h>
7#include "lib8tion.h"
8#include "color.h"
9
12
13FASTLED_NAMESPACE_BEGIN
14
15struct CRGB;
16struct CHSV;
17
21
24extern void hsv2rgb_rainbow( const CHSV& hsv, CRGB& rgb);
25
27struct CHSV {
28 union {
29 struct {
30 union {
34 uint8_t hue;
35 uint8_t h;
36 };
37 union {
40 uint8_t saturation;
41 uint8_t sat;
42 uint8_t s;
43 };
44 union {
47 uint8_t value;
48 uint8_t val;
49 uint8_t v;
50 };
51 };
57 uint8_t raw[3];
58 };
59
63 inline uint8_t& operator[] (uint8_t x) __attribute__((always_inline))
64 {
65 return raw[x];
66 }
67
69 inline const uint8_t& operator[] (uint8_t x) const __attribute__((always_inline))
70 {
71 return raw[x];
72 }
73
76 inline CHSV() __attribute__((always_inline)) = default;
77
82 inline CHSV( uint8_t ih, uint8_t is, uint8_t iv) __attribute__((always_inline))
83 : h(ih), s(is), v(iv)
84 {
85 }
86
88 inline CHSV(const CHSV& rhs) __attribute__((always_inline)) = default;
89
91 inline CHSV& operator= (const CHSV& rhs) __attribute__((always_inline)) = default;
92
98 inline CHSV& setHSV(uint8_t ih, uint8_t is, uint8_t iv) __attribute__((always_inline))
99 {
100 h = ih;
101 s = is;
102 v = iv;
103 return *this;
104 }
105};
106
108typedef enum {
113 HUE_AQUA = 128,
114 HUE_BLUE = 160,
116 HUE_PINK = 224
118
120struct CRGB {
121 union {
122 struct {
123 union {
124 uint8_t r;
125 uint8_t red;
126 };
127 union {
128 uint8_t g;
129 uint8_t green;
130 };
131 union {
132 uint8_t b;
133 uint8_t blue;
134 };
135 };
141 uint8_t raw[3];
142 };
143
147 inline uint8_t& operator[] (uint8_t x) __attribute__((always_inline))
148 {
149 return raw[x];
150 }
151
155 inline const uint8_t& operator[] (uint8_t x) const __attribute__((always_inline))
156 {
157 return raw[x];
158 }
159
162 inline CRGB() __attribute__((always_inline)) = default;
163
168 inline CRGB( uint8_t ir, uint8_t ig, uint8_t ib) __attribute__((always_inline))
169 : r(ir), g(ig), b(ib)
170 {
171 }
172
175 inline CRGB( uint32_t colorcode) __attribute__((always_inline))
176 : r((colorcode >> 16) & 0xFF), g((colorcode >> 8) & 0xFF), b((colorcode >> 0) & 0xFF)
177 {
178 }
179
182 inline CRGB( LEDColorCorrection colorcode) __attribute__((always_inline))
183 : r((colorcode >> 16) & 0xFF), g((colorcode >> 8) & 0xFF), b((colorcode >> 0) & 0xFF)
184 {
185
186 }
187
190 inline CRGB( ColorTemperature colorcode) __attribute__((always_inline))
191 : r((colorcode >> 16) & 0xFF), g((colorcode >> 8) & 0xFF), b((colorcode >> 0) & 0xFF)
192 {
193
194 }
195
197 inline CRGB(const CRGB& rhs) __attribute__((always_inline)) = default;
198
200 inline CRGB(const CHSV& rhs) __attribute__((always_inline))
201 {
202 hsv2rgb_rainbow( rhs, *this);
203 }
204
206 inline CRGB& operator= (const CRGB& rhs) __attribute__((always_inline)) = default;
207
210 inline CRGB& operator= (const uint32_t colorcode) __attribute__((always_inline))
211 {
212 r = (colorcode >> 16) & 0xFF;
213 g = (colorcode >> 8) & 0xFF;
214 b = (colorcode >> 0) & 0xFF;
215 return *this;
216 }
217
222 inline CRGB& setRGB (uint8_t nr, uint8_t ng, uint8_t nb) __attribute__((always_inline))
223 {
224 r = nr;
225 g = ng;
226 b = nb;
227 return *this;
228 }
229
234 inline CRGB& setHSV (uint8_t hue, uint8_t sat, uint8_t val) __attribute__((always_inline))
235 {
236 hsv2rgb_rainbow( CHSV(hue, sat, val), *this);
237 return *this;
238 }
239
243 inline CRGB& setHue (uint8_t hue) __attribute__((always_inline))
244 {
245 hsv2rgb_rainbow( CHSV(hue, 255, 255), *this);
246 return *this;
247 }
248
250 inline CRGB& operator= (const CHSV& rhs) __attribute__((always_inline))
251 {
252 hsv2rgb_rainbow( rhs, *this);
253 return *this;
254 }
255
258 inline CRGB& setColorCode (uint32_t colorcode) __attribute__((always_inline))
259 {
260 r = (colorcode >> 16) & 0xFF;
261 g = (colorcode >> 8) & 0xFF;
262 b = (colorcode >> 0) & 0xFF;
263 return *this;
264 }
265
266
268 inline CRGB& operator+= (const CRGB& rhs )
269 {
270 r = qadd8( r, rhs.r);
271 g = qadd8( g, rhs.g);
272 b = qadd8( b, rhs.b);
273 return *this;
274 }
275
280 inline CRGB& addToRGB (uint8_t d )
281 {
282 r = qadd8( r, d);
283 g = qadd8( g, d);
284 b = qadd8( b, d);
285 return *this;
286 }
287
289 inline CRGB& operator-= (const CRGB& rhs )
290 {
291 r = qsub8( r, rhs.r);
292 g = qsub8( g, rhs.g);
293 b = qsub8( b, rhs.b);
294 return *this;
295 }
296
301 inline CRGB& subtractFromRGB(uint8_t d )
302 {
303 r = qsub8( r, d);
304 g = qsub8( g, d);
305 b = qsub8( b, d);
306 return *this;
307 }
308
310 inline CRGB& operator-- () __attribute__((always_inline))
311 {
313 return *this;
314 }
315
317 inline CRGB operator-- (int ) __attribute__((always_inline))
318 {
319 CRGB retval(*this);
320 --(*this);
321 return retval;
322 }
323
325 inline CRGB& operator++ () __attribute__((always_inline))
326 {
327 addToRGB(1);
328 return *this;
329 }
330
332 inline CRGB operator++ (int ) __attribute__((always_inline))
333 {
334 CRGB retval(*this);
335 ++(*this);
336 return retval;
337 }
338
340 inline CRGB& operator/= (uint8_t d )
341 {
342 r /= d;
343 g /= d;
344 b /= d;
345 return *this;
346 }
347
349 inline CRGB& operator>>= (uint8_t d)
350 {
351 r >>= d;
352 g >>= d;
353 b >>= d;
354 return *this;
355 }
356
359 inline CRGB& operator*= (uint8_t d )
360 {
361 r = qmul8( r, d);
362 g = qmul8( g, d);
363 b = qmul8( b, d);
364 return *this;
365 }
366
373 inline CRGB& nscale8_video (uint8_t scaledown )
374 {
375 nscale8x3_video( r, g, b, scaledown);
376 return *this;
377 }
378
381 inline CRGB& operator%= (uint8_t scaledown )
382 {
383 nscale8x3_video( r, g, b, scaledown);
384 return *this;
385 }
386
389 inline CRGB& fadeLightBy (uint8_t fadefactor )
390 {
391 nscale8x3_video( r, g, b, 255 - fadefactor);
392 return *this;
393 }
394
399 inline CRGB& nscale8 (uint8_t scaledown )
400 {
401 nscale8x3( r, g, b, scaledown);
402 return *this;
403 }
404
409 inline CRGB& nscale8 (const CRGB & scaledown )
410 {
411 r = ::scale8(r, scaledown.r);
412 g = ::scale8(g, scaledown.g);
413 b = ::scale8(b, scaledown.b);
414 return *this;
415 }
416
418 inline CRGB scale8 (uint8_t scaledown ) const
419 {
420 CRGB out = *this;
421 nscale8x3( out.r, out.g, out.b, scaledown);
422 return out;
423 }
424
426 inline CRGB scale8 (const CRGB & scaledown ) const
427 {
428 CRGB out;
429 out.r = ::scale8(r, scaledown.r);
430 out.g = ::scale8(g, scaledown.g);
431 out.b = ::scale8(b, scaledown.b);
432 return out;
433 }
434
437 inline CRGB& fadeToBlackBy (uint8_t fadefactor )
438 {
439 nscale8x3( r, g, b, 255 - fadefactor);
440 return *this;
441 }
442
444 inline CRGB& operator|= (const CRGB& rhs )
445 {
446 if( rhs.r > r) r = rhs.r;
447 if( rhs.g > g) g = rhs.g;
448 if( rhs.b > b) b = rhs.b;
449 return *this;
450 }
451
453 inline CRGB& operator|= (uint8_t d )
454 {
455 if( d > r) r = d;
456 if( d > g) g = d;
457 if( d > b) b = d;
458 return *this;
459 }
460
462 inline CRGB& operator&= (const CRGB& rhs )
463 {
464 if( rhs.r < r) r = rhs.r;
465 if( rhs.g < g) g = rhs.g;
466 if( rhs.b < b) b = rhs.b;
467 return *this;
468 }
469
471 inline CRGB& operator&= (uint8_t d )
472 {
473 if( d < r) r = d;
474 if( d < g) g = d;
475 if( d < b) b = d;
476 return *this;
477 }
478
480 inline explicit operator bool() const __attribute__((always_inline))
481 {
482 return r || g || b;
483 }
484
486 inline explicit operator uint32_t() const
487 {
488 return uint32_t{0xff000000} |
489 (uint32_t{r} << 16) |
490 (uint32_t{g} << 8) |
491 uint32_t{b};
492 }
493
495 inline CRGB operator- () const
496 {
497 CRGB retval;
498 retval.r = 255 - r;
499 retval.g = 255 - g;
500 retval.b = 255 - b;
501 return retval;
502 }
503
504#if (defined SmartMatrix_h || defined SmartMatrix3_h)
507 operator rgb24() const {
508 rgb24 ret;
509 ret.red = r;
510 ret.green = g;
511 ret.blue = b;
512 return ret;
513 }
514#endif
515
518 inline uint8_t getLuma ( ) const {
519 //Y' = 0.2126 R' + 0.7152 G' + 0.0722 B'
520 // 54 183 18 (!)
521
522 uint8_t luma = scale8_LEAVING_R1_DIRTY( r, 54) + \
523 scale8_LEAVING_R1_DIRTY( g, 183) + \
524 scale8_LEAVING_R1_DIRTY( b, 18);
525 cleanup_R1();
526 return luma;
527 }
528
530 inline uint8_t getAverageLight( ) const {
531#if FASTLED_SCALE8_FIXED == 1
532 const uint8_t eightyfive = 85;
533#else
534 const uint8_t eightyfive = 86;
535#endif
536 uint8_t avg = scale8_LEAVING_R1_DIRTY( r, eightyfive) + \
537 scale8_LEAVING_R1_DIRTY( g, eightyfive) + \
538 scale8_LEAVING_R1_DIRTY( b, eightyfive);
539 cleanup_R1();
540 return avg;
541 }
542
548 inline void maximizeBrightness( uint8_t limit = 255 ) {
549 uint8_t max = red;
550 if( green > max) max = green;
551 if( blue > max) max = blue;
552
553 // stop div/0 when color is black
554 if(max > 0) {
555 uint16_t factor = ((uint16_t)(limit) * 256) / max;
556 red = (red * factor) / 256;
557 green = (green * factor) / 256;
558 blue = (blue * factor) / 256;
559 }
560 }
561
563 inline CRGB lerp8( const CRGB& other, fract8 frac) const
564 {
565 CRGB ret;
566
567 ret.r = lerp8by8(r,other.r,frac);
568 ret.g = lerp8by8(g,other.g,frac);
569 ret.b = lerp8by8(b,other.b,frac);
570
571 return ret;
572 }
573
575 inline CRGB lerp16( const CRGB& other, fract16 frac) const
576 {
577 CRGB ret;
578
579 ret.r = lerp16by16(r<<8,other.r<<8,frac)>>8;
580 ret.g = lerp16by16(g<<8,other.g<<8,frac)>>8;
581 ret.b = lerp16by16(b<<8,other.b<<8,frac)>>8;
582
583 return ret;
584 }
585
587 inline uint8_t getParity()
588 {
589 uint8_t sum = r + g + b;
590 return (sum & 0x01);
591 }
592
615 inline void setParity( uint8_t parity)
616 {
617 uint8_t curparity = getParity();
618
619 if( parity == curparity) return;
620
621 if( parity ) {
622 // going 'up'
623 if( (b > 0) && (b < 255)) {
624 if( r == g && g == b) {
625 ++r;
626 ++g;
627 }
628 ++b;
629 } else if( (r > 0) && (r < 255)) {
630 ++r;
631 } else if( (g > 0) && (g < 255)) {
632 ++g;
633 } else {
634 if( r == g && g == b) {
635 r ^= 0x01;
636 g ^= 0x01;
637 }
638 b ^= 0x01;
639 }
640 } else {
641 // going 'down'
642 if( b > 1) {
643 if( r == g && g == b) {
644 --r;
645 --g;
646 }
647 --b;
648 } else if( g > 1) {
649 --g;
650 } else if( r > 1) {
651 --r;
652 } else {
653 if( r == g && g == b) {
654 r ^= 0x01;
655 g ^= 0x01;
656 }
657 b ^= 0x01;
658 }
659 }
660 }
661
663 typedef enum {
664 AliceBlue=0xF0F8FF,
665 Amethyst=0x9966CC,
666 AntiqueWhite=0xFAEBD7,
667 Aqua=0x00FFFF,
668 Aquamarine=0x7FFFD4,
669 Azure=0xF0FFFF,
670 Beige=0xF5F5DC,
671 Bisque=0xFFE4C4,
672 Black=0x000000,
673 BlanchedAlmond=0xFFEBCD,
674 Blue=0x0000FF,
675 BlueViolet=0x8A2BE2,
676 Brown=0xA52A2A,
677 BurlyWood=0xDEB887,
678 CadetBlue=0x5F9EA0,
679 Chartreuse=0x7FFF00,
680 Chocolate=0xD2691E,
681 Coral=0xFF7F50,
682 CornflowerBlue=0x6495ED,
683 Cornsilk=0xFFF8DC,
684 Crimson=0xDC143C,
685 Cyan=0x00FFFF,
686 DarkBlue=0x00008B,
687 DarkCyan=0x008B8B,
688 DarkGoldenrod=0xB8860B,
689 DarkGray=0xA9A9A9,
690 DarkGrey=0xA9A9A9,
691 DarkGreen=0x006400,
692 DarkKhaki=0xBDB76B,
693 DarkMagenta=0x8B008B,
694 DarkOliveGreen=0x556B2F,
695 DarkOrange=0xFF8C00,
696 DarkOrchid=0x9932CC,
697 DarkRed=0x8B0000,
698 DarkSalmon=0xE9967A,
699 DarkSeaGreen=0x8FBC8F,
700 DarkSlateBlue=0x483D8B,
701 DarkSlateGray=0x2F4F4F,
702 DarkSlateGrey=0x2F4F4F,
703 DarkTurquoise=0x00CED1,
704 DarkViolet=0x9400D3,
705 DeepPink=0xFF1493,
706 DeepSkyBlue=0x00BFFF,
707 DimGray=0x696969,
708 DimGrey=0x696969,
709 DodgerBlue=0x1E90FF,
710 FireBrick=0xB22222,
711 FloralWhite=0xFFFAF0,
712 ForestGreen=0x228B22,
713 Fuchsia=0xFF00FF,
714 Gainsboro=0xDCDCDC,
715 GhostWhite=0xF8F8FF,
716 Gold=0xFFD700,
717 Goldenrod=0xDAA520,
718 Gray=0x808080,
719 Grey=0x808080,
720 Green=0x008000,
721 GreenYellow=0xADFF2F,
722 Honeydew=0xF0FFF0,
723 HotPink=0xFF69B4,
724 IndianRed=0xCD5C5C,
725 Indigo=0x4B0082,
726 Ivory=0xFFFFF0,
727 Khaki=0xF0E68C,
728 Lavender=0xE6E6FA,
729 LavenderBlush=0xFFF0F5,
730 LawnGreen=0x7CFC00,
731 LemonChiffon=0xFFFACD,
732 LightBlue=0xADD8E6,
733 LightCoral=0xF08080,
734 LightCyan=0xE0FFFF,
736 LightGreen=0x90EE90,
737 LightGrey=0xD3D3D3,
738 LightPink=0xFFB6C1,
739 LightSalmon=0xFFA07A,
740 LightSeaGreen=0x20B2AA,
741 LightSkyBlue=0x87CEFA,
742 LightSlateGray=0x778899,
743 LightSlateGrey=0x778899,
744 LightSteelBlue=0xB0C4DE,
745 LightYellow=0xFFFFE0,
746 Lime=0x00FF00,
747 LimeGreen=0x32CD32,
748 Linen=0xFAF0E6,
749 Magenta=0xFF00FF,
750 Maroon=0x800000,
752 MediumBlue=0x0000CD,
753 MediumOrchid=0xBA55D3,
754 MediumPurple=0x9370DB,
755 MediumSeaGreen=0x3CB371,
760 MidnightBlue=0x191970,
761 MintCream=0xF5FFFA,
762 MistyRose=0xFFE4E1,
763 Moccasin=0xFFE4B5,
764 NavajoWhite=0xFFDEAD,
765 Navy=0x000080,
766 OldLace=0xFDF5E6,
767 Olive=0x808000,
768 OliveDrab=0x6B8E23,
769 Orange=0xFFA500,
770 OrangeRed=0xFF4500,
771 Orchid=0xDA70D6,
772 PaleGoldenrod=0xEEE8AA,
773 PaleGreen=0x98FB98,
774 PaleTurquoise=0xAFEEEE,
775 PaleVioletRed=0xDB7093,
776 PapayaWhip=0xFFEFD5,
777 PeachPuff=0xFFDAB9,
778 Peru=0xCD853F,
779 Pink=0xFFC0CB,
780 Plaid=0xCC5533,
781 Plum=0xDDA0DD,
782 PowderBlue=0xB0E0E6,
783 Purple=0x800080,
784 Red=0xFF0000,
785 RosyBrown=0xBC8F8F,
786 RoyalBlue=0x4169E1,
787 SaddleBrown=0x8B4513,
788 Salmon=0xFA8072,
789 SandyBrown=0xF4A460,
790 SeaGreen=0x2E8B57,
791 Seashell=0xFFF5EE,
792 Sienna=0xA0522D,
793 Silver=0xC0C0C0,
794 SkyBlue=0x87CEEB,
795 SlateBlue=0x6A5ACD,
796 SlateGray=0x708090,
797 SlateGrey=0x708090,
798 Snow=0xFFFAFA,
799 SpringGreen=0x00FF7F,
800 SteelBlue=0x4682B4,
801 Tan=0xD2B48C,
802 Teal=0x008080,
803 Thistle=0xD8BFD8,
804 Tomato=0xFF6347,
805 Turquoise=0x40E0D0,
806 Violet=0xEE82EE,
807 Wheat=0xF5DEB3,
808 White=0xFFFFFF,
809 WhiteSmoke=0xF5F5F5,
810 Yellow=0xFFFF00,
811 YellowGreen=0x9ACD32,
812
813 // LED RGB color that roughly approximates
814 // the color of incandescent fairy lights,
815 // assuming that you're using FastLED
816 // color correction on your LEDs (recommended).
817 FairyLight=0xFFE42D,
818
819 // If you are using no color correction, use this
820 FairyLightNCC=0xFF9D2A
821
823};
824
825
827inline __attribute__((always_inline)) bool operator== (const CRGB& lhs, const CRGB& rhs)
828{
829 return (lhs.r == rhs.r) && (lhs.g == rhs.g) && (lhs.b == rhs.b);
830}
831
833inline __attribute__((always_inline)) bool operator!= (const CRGB& lhs, const CRGB& rhs)
834{
835 return !(lhs == rhs);
836}
837
839inline __attribute__((always_inline)) bool operator== (const CHSV& lhs, const CHSV& rhs)
840{
841 return (lhs.h == rhs.h) && (lhs.s == rhs.s) && (lhs.v == rhs.v);
842}
843
845inline __attribute__((always_inline)) bool operator!= (const CHSV& lhs, const CHSV& rhs)
846{
847 return !(lhs == rhs);
848}
849
851inline __attribute__((always_inline)) bool operator< (const CRGB& lhs, const CRGB& rhs)
852{
853 uint16_t sl, sr;
854 sl = lhs.r + lhs.g + lhs.b;
855 sr = rhs.r + rhs.g + rhs.b;
856 return sl < sr;
857}
858
860inline __attribute__((always_inline)) bool operator> (const CRGB& lhs, const CRGB& rhs)
861{
862 uint16_t sl, sr;
863 sl = lhs.r + lhs.g + lhs.b;
864 sr = rhs.r + rhs.g + rhs.b;
865 return sl > sr;
866}
867
869inline __attribute__((always_inline)) bool operator>= (const CRGB& lhs, const CRGB& rhs)
870{
871 uint16_t sl, sr;
872 sl = lhs.r + lhs.g + lhs.b;
873 sr = rhs.r + rhs.g + rhs.b;
874 return sl >= sr;
875}
876
878inline __attribute__((always_inline)) bool operator<= (const CRGB& lhs, const CRGB& rhs)
879{
880 uint16_t sl, sr;
881 sl = lhs.r + lhs.g + lhs.b;
882 sr = rhs.r + rhs.g + rhs.b;
883 return sl <= sr;
884}
885
886
888__attribute__((always_inline))
889inline CRGB operator+( const CRGB& p1, const CRGB& p2)
890{
891 return CRGB( qadd8( p1.r, p2.r),
892 qadd8( p1.g, p2.g),
893 qadd8( p1.b, p2.b));
894}
895
897__attribute__((always_inline))
898inline CRGB operator-( const CRGB& p1, const CRGB& p2)
899{
900 return CRGB( qsub8( p1.r, p2.r),
901 qsub8( p1.g, p2.g),
902 qsub8( p1.b, p2.b));
903}
904
906__attribute__((always_inline))
907inline CRGB operator*( const CRGB& p1, uint8_t d)
908{
909 return CRGB( qmul8( p1.r, d),
910 qmul8( p1.g, d),
911 qmul8( p1.b, d));
912}
913
915__attribute__((always_inline))
916inline CRGB operator/( const CRGB& p1, uint8_t d)
917{
918 return CRGB( p1.r/d, p1.g/d, p1.b/d);
919}
920
921
923__attribute__((always_inline))
924inline CRGB operator&( const CRGB& p1, const CRGB& p2)
925{
926 return CRGB( p1.r < p2.r ? p1.r : p2.r,
927 p1.g < p2.g ? p1.g : p2.g,
928 p1.b < p2.b ? p1.b : p2.b);
929}
930
932__attribute__((always_inline))
933inline CRGB operator|( const CRGB& p1, const CRGB& p2)
934{
935 return CRGB( p1.r > p2.r ? p1.r : p2.r,
936 p1.g > p2.g ? p1.g : p2.g,
937 p1.b > p2.b ? p1.b : p2.b);
938}
939
941__attribute__((always_inline))
942inline CRGB operator%( const CRGB& p1, uint8_t d)
943{
944 CRGB retval( p1);
945 retval.nscale8_video( d);
946 return retval;
947}
948
949
950
956enum EOrder {
957 RGB=0012,
958 RBG=0021,
959 GRB=0102,
960 GBR=0120,
961 BRG=0201,
962 BGR=0210
964
965FASTLED_NAMESPACE_END
967
968#endif
central include file for FastLED, defines the CFastLED class/object
Contains definitions for color correction and temperature.
ColorTemperature
Color temperature values.
Definition color.h:47
LEDColorCorrection
Color correction starting points.
Definition color.h:16
uint8_t fract8
ANSI: unsigned short _Fract.
Definition lib8tion.h:402
uint16_t fract16
ANSI: unsigned _Fract.
Definition lib8tion.h:412
LIB8STATIC uint8_t lerp8by8(uint8_t a, uint8_t b, fract8 frac)
Linear interpolation between two unsigned 8-bit values, with 8-bit fraction.
Definition lib8tion.h:532
LIB8STATIC uint16_t lerp16by16(uint16_t a, uint16_t b, fract16 frac)
Linear interpolation between two unsigned 16-bit values, with 16-bit fraction.
Definition lib8tion.h:549
LIB8STATIC_ALWAYS_INLINE uint8_t qadd8(uint8_t i, uint8_t j)
Add one byte to another, saturating at 0xFF.
Definition math8.h:28
LIB8STATIC_ALWAYS_INLINE uint8_t qmul8(uint8_t i, uint8_t j)
8x8 bit multiplication with 8-bit result, saturating at 0xFF.
Definition math8.h:492
LIB8STATIC_ALWAYS_INLINE uint8_t qsub8(uint8_t i, uint8_t j)
Subtract one byte from another, saturating at 0x00.
Definition math8.h:101
void hsv2rgb_rainbow(const CHSV &hsv, CRGB &rgb)
Forward declaration of hsv2rgb_rainbow here, to avoid circular dependencies.
Definition hsv2rgb.cpp:251
EOrder
RGB color channel orderings, used when instantiating controllers to determine what order the controll...
Definition pixeltypes.h:956
bool operator>(const CRGB &lhs, const CRGB &rhs)
Check if the sum of the color channels in one CRGB object is greater than another.
Definition pixeltypes.h:860
bool operator<(const CRGB &lhs, const CRGB &rhs)
Check if the sum of the color channels in one CRGB object is less than another.
Definition pixeltypes.h:851
bool operator==(const CRGB &lhs, const CRGB &rhs)
Check if two CRGB objects have the same color data.
Definition pixeltypes.h:827
HSVHue
Pre-defined hue values for CHSV objects.
Definition pixeltypes.h:108
bool operator>=(const CRGB &lhs, const CRGB &rhs)
Check if the sum of the color channels in one CRGB object is greater than or equal to another.
Definition pixeltypes.h:869
bool operator<=(const CRGB &lhs, const CRGB &rhs)
Check if the sum of the color channels in one CRGB object is less than or equal to another.
Definition pixeltypes.h:878
bool operator!=(const CRGB &lhs, const CRGB &rhs)
Check if two CRGB objects do not have the same color data.
Definition pixeltypes.h:833
@ RGB
Red, Green, Blue (0012)
Definition pixeltypes.h:957
@ BGR
Blue, Green, Red (0210)
Definition pixeltypes.h:962
@ BRG
Blue, Red, Green (0201)
Definition pixeltypes.h:961
@ GRB
Green, Red, Blue (0102)
Definition pixeltypes.h:959
@ RBG
Red, Blue, Green (0021)
Definition pixeltypes.h:958
@ GBR
Green, Blue, Red (0120)
Definition pixeltypes.h:960
@ HUE_ORANGE
Orange (45°)
Definition pixeltypes.h:110
@ HUE_BLUE
Blue (225°)
Definition pixeltypes.h:114
@ HUE_PINK
Pink (315°)
Definition pixeltypes.h:116
@ HUE_YELLOW
Yellow (90°)
Definition pixeltypes.h:111
@ HUE_PURPLE
Purple (270°)
Definition pixeltypes.h:115
@ HUE_AQUA
Aqua (180°)
Definition pixeltypes.h:113
@ HUE_GREEN
Green (135°)
Definition pixeltypes.h:112
@ HUE_RED
Red (0°)
Definition pixeltypes.h:109
LIB8STATIC_ALWAYS_INLINE void cleanup_R1()
Clean up the r1 register after a series of *LEAVING_R1_DIRTY calls.
Definition scale8.h:336
LIB8STATIC_ALWAYS_INLINE uint8_t scale8_LEAVING_R1_DIRTY(uint8_t i, fract8 scale)
This version of scale8() does not clean up the R1 register on AVR.
Definition scale8.h:169
LIB8STATIC void nscale8x3(uint8_t &r, uint8_t &g, uint8_t &b, fract8 scale)
Scale three one-byte values by a fourth one, which is treated as the numerator of a fraction whose de...
Definition scale8.h:357
LIB8STATIC void nscale8x3_video(uint8_t &r, uint8_t &g, uint8_t &b, fract8 scale)
Scale three one-byte values by a fourth one, which is treated as the numerator of a fraction whose de...
Definition scale8.h:392
Fast, efficient 8-bit math functions specifically designed for high-performance LED programming.
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Definition pixeltypes.h:27
CHSV & operator=(const CHSV &rhs)=default
Allow copy construction.
uint8_t v
Color value (brightness).
Definition pixeltypes.h:49
uint8_t raw[3]
Access the hue, saturation, and value data as an array.
Definition pixeltypes.h:57
uint8_t hue
Color hue.
Definition pixeltypes.h:34
uint8_t sat
Color saturation.
Definition pixeltypes.h:41
CHSV()=default
Default constructor.
uint8_t h
Color hue.
Definition pixeltypes.h:35
uint8_t value
Color value (brightness).
Definition pixeltypes.h:47
uint8_t saturation
Color saturation.
Definition pixeltypes.h:40
CHSV(const CHSV &rhs)=default
Allow copy construction.
uint8_t s
Color saturation.
Definition pixeltypes.h:42
uint8_t val
Color value (brightness).
Definition pixeltypes.h:48
uint8_t & operator[](uint8_t x)
Array access operator to index into the CHSV object.
Definition pixeltypes.h:63
CHSV & setHSV(uint8_t ih, uint8_t is, uint8_t iv)
Assign new HSV values.
Definition pixeltypes.h:98
Representation of an RGB pixel (Red, Green, Blue)
Definition pixeltypes.h:120
CRGB & nscale8(const CRGB &scaledown)
Scale down a RGB to N/256ths of its current brightness, using "plain math" dimming rules.
Definition pixeltypes.h:409
CRGB & operator++()
Add a constant of '1' from each channel, saturating at 0xFF.
Definition pixeltypes.h:325
CRGB(ColorTemperature colorcode)
Allow construction from a ColorTemperature enum.
Definition pixeltypes.h:190
CRGB & nscale8_video(uint8_t scaledown)
Scale down a RGB to N/256ths of it's current brightness using "video" dimming rules.
Definition pixeltypes.h:373
CRGB(LEDColorCorrection colorcode)
Allow construction from a LEDColorCorrection enum.
Definition pixeltypes.h:182
CRGB(const CHSV &rhs)
Allow construction from a CHSV color.
Definition pixeltypes.h:200
CRGB & operator-=(const CRGB &rhs)
Subtract one CRGB from another, saturating at 0x00 for each channel.
Definition pixeltypes.h:289
uint8_t raw[3]
Access the red, green, and blue data as an array.
Definition pixeltypes.h:141
CRGB & setColorCode(uint32_t colorcode)
Allow assignment from 32-bit (really 24-bit) 0xRRGGBB color code.
Definition pixeltypes.h:258
uint8_t r
Red channel value.
Definition pixeltypes.h:124
CRGB & setHSV(uint8_t hue, uint8_t sat, uint8_t val)
Allow assignment from hue, saturation, and value.
Definition pixeltypes.h:234
CRGB operator-() const
Invert each channel.
Definition pixeltypes.h:495
CRGB & subtractFromRGB(uint8_t d)
Subtract a constant from each channel, saturating at 0x00.
Definition pixeltypes.h:301
CRGB(const CRGB &rhs)=default
Allow copy construction.
CRGB scale8(const CRGB &scaledown) const
Return a CRGB object that is a scaled down version of this object.
Definition pixeltypes.h:426
CRGB & operator/=(uint8_t d)
Divide each of the channels by a constant.
Definition pixeltypes.h:340
CRGB & operator%=(uint8_t scaledown)
%= is a synonym for nscale8_video().
Definition pixeltypes.h:381
CRGB scale8(uint8_t scaledown) const
Return a CRGB object that is a scaled down version of this object.
Definition pixeltypes.h:418
CRGB()=default
Default constructor.
CRGB & fadeLightBy(uint8_t fadefactor)
fadeLightBy is a synonym for nscale8_video(), as a fade instead of a scale
Definition pixeltypes.h:389
CRGB & operator+=(const CRGB &rhs)
Add one CRGB to another, saturating at 0xFF for each channel.
Definition pixeltypes.h:268
CRGB & nscale8(uint8_t scaledown)
Scale down a RGB to N/256ths of its current brightness, using "plain math" dimming rules.
Definition pixeltypes.h:399
uint8_t & operator[](uint8_t x)
Array access operator to index into the CRGB object.
Definition pixeltypes.h:147
void maximizeBrightness(uint8_t limit=255)
Maximize the brightness of this CRGB object.
Definition pixeltypes.h:548
CRGB & operator|=(const CRGB &rhs)
"or" operator brings each channel up to the higher of the two values
Definition pixeltypes.h:444
CRGB & addToRGB(uint8_t d)
Add a constant to each channel, saturating at 0xFF.
Definition pixeltypes.h:280
CRGB lerp8(const CRGB &other, fract8 frac) const
Return a new CRGB object after performing a linear interpolation between this object and the passed i...
Definition pixeltypes.h:563
CRGB lerp16(const CRGB &other, fract16 frac) const
Return a new CRGB object after performing a linear interpolation between this object and the passed i...
Definition pixeltypes.h:575
uint8_t g
Green channel value.
Definition pixeltypes.h:128
uint8_t red
Red channel value.
Definition pixeltypes.h:125
CRGB & setHue(uint8_t hue)
Allow assignment from just a hue.
Definition pixeltypes.h:243
uint8_t blue
Blue channel value.
Definition pixeltypes.h:133
CRGB & setRGB(uint8_t nr, uint8_t ng, uint8_t nb)
Allow assignment from red, green, and blue.
Definition pixeltypes.h:222
uint8_t getAverageLight() const
Get the average of the R, G, and B values.
Definition pixeltypes.h:530
uint8_t b
Blue channel value.
Definition pixeltypes.h:132
CRGB & operator=(const CRGB &rhs)=default
Allow assignment from one RGB struct to another.
uint8_t green
Green channel value.
Definition pixeltypes.h:129
uint8_t getLuma() const
Get the "luma" of a CRGB object.
Definition pixeltypes.h:518
void setParity(uint8_t parity)
Adjusts the color in the smallest way possible so that the parity of the coloris now the desired valu...
Definition pixeltypes.h:615
CRGB & operator*=(uint8_t d)
Multiply each of the channels by a constant, saturating each channel at 0xFF.
Definition pixeltypes.h:359
CRGB & operator--()
Subtract a constant of '1' from each channel, saturating at 0x00.
Definition pixeltypes.h:310
HTMLColorCode
Predefined RGB colors.
Definition pixeltypes.h:663
@ DarkGray
Definition pixeltypes.h:689
@ Sienna
Definition pixeltypes.h:792
@ GhostWhite
Definition pixeltypes.h:715
@ DarkRed
Definition pixeltypes.h:697
@ DarkSlateGray
Definition pixeltypes.h:701
@ OldLace
Definition pixeltypes.h:766
@ Aquamarine
Definition pixeltypes.h:668
@ Violet
Definition pixeltypes.h:806
@ Salmon
Definition pixeltypes.h:788
@ Thistle
Definition pixeltypes.h:803
@ Cornsilk
Definition pixeltypes.h:683
@ MediumVioletRed
Definition pixeltypes.h:759
@ Coral
Definition pixeltypes.h:681
@ LightPink
Definition pixeltypes.h:738
@ DarkGrey
Definition pixeltypes.h:690
@ SlateGrey
Definition pixeltypes.h:797
@ NavajoWhite
Definition pixeltypes.h:764
@ PaleVioletRed
Definition pixeltypes.h:775
@ HotPink
Definition pixeltypes.h:723
@ BlanchedAlmond
Definition pixeltypes.h:673
@ RosyBrown
Definition pixeltypes.h:785
@ White
Definition pixeltypes.h:808
@ Moccasin
Definition pixeltypes.h:763
@ LightYellow
Definition pixeltypes.h:745
@ Bisque
Definition pixeltypes.h:671
@ DeepPink
Definition pixeltypes.h:705
@ Wheat
Definition pixeltypes.h:807
@ MediumOrchid
Definition pixeltypes.h:753
@ Goldenrod
Definition pixeltypes.h:717
@ Orange
Definition pixeltypes.h:769
@ MediumSpringGreen
Definition pixeltypes.h:757
@ Seashell
Definition pixeltypes.h:791
@ DarkViolet
Definition pixeltypes.h:704
@ Ivory
Definition pixeltypes.h:726
@ MistyRose
Definition pixeltypes.h:762
@ SlateBlue
Definition pixeltypes.h:795
@ Silver
Definition pixeltypes.h:793
@ Purple
Definition pixeltypes.h:783
@ DarkKhaki
Definition pixeltypes.h:692
@ SaddleBrown
Definition pixeltypes.h:787
@ LemonChiffon
Definition pixeltypes.h:731
@ Magenta
Definition pixeltypes.h:749
@ Beige
Definition pixeltypes.h:670
@ Crimson
Definition pixeltypes.h:684
@ MediumAquamarine
Definition pixeltypes.h:751
@ LawnGreen
Definition pixeltypes.h:730
@ DodgerBlue
Definition pixeltypes.h:709
@ Tomato
Definition pixeltypes.h:804
@ Fuchsia
Definition pixeltypes.h:713
@ Brown
Definition pixeltypes.h:676
@ Lavender
Definition pixeltypes.h:728
@ YellowGreen
Definition pixeltypes.h:811
@ DeepSkyBlue
Definition pixeltypes.h:706
@ Turquoise
Definition pixeltypes.h:805
@ SandyBrown
Definition pixeltypes.h:789
@ MediumSlateBlue
Definition pixeltypes.h:756
@ PeachPuff
Definition pixeltypes.h:777
@ Orchid
Definition pixeltypes.h:771
@ Green
Definition pixeltypes.h:720
@ SteelBlue
Definition pixeltypes.h:800
@ CornflowerBlue
Definition pixeltypes.h:682
@ DarkSalmon
Definition pixeltypes.h:698
@ SkyBlue
Definition pixeltypes.h:794
@ LightSalmon
Definition pixeltypes.h:739
@ RoyalBlue
Definition pixeltypes.h:786
@ DarkSlateGrey
Definition pixeltypes.h:702
@ LightCoral
Definition pixeltypes.h:733
@ PaleTurquoise
Definition pixeltypes.h:774
@ BurlyWood
Definition pixeltypes.h:677
@ DarkTurquoise
Definition pixeltypes.h:703
@ DarkMagenta
Definition pixeltypes.h:693
@ LightSeaGreen
Definition pixeltypes.h:740
@ MidnightBlue
Definition pixeltypes.h:760
@ LightSlateGray
Definition pixeltypes.h:742
@ Chocolate
Definition pixeltypes.h:680
@ Linen
Definition pixeltypes.h:748
@ SeaGreen
Definition pixeltypes.h:790
@ AntiqueWhite
Definition pixeltypes.h:666
@ LimeGreen
Definition pixeltypes.h:747
@ MediumTurquoise
Definition pixeltypes.h:758
@ LightGreen
Definition pixeltypes.h:736
@ MediumSeaGreen
Definition pixeltypes.h:755
@ PaleGreen
Definition pixeltypes.h:773
@ FireBrick
Definition pixeltypes.h:710
@ Amethyst
Definition pixeltypes.h:665
@ LightSteelBlue
Definition pixeltypes.h:744
@ LightGrey
Definition pixeltypes.h:737
@ BlueViolet
Definition pixeltypes.h:675
@ Indigo
Definition pixeltypes.h:725
@ LightCyan
Definition pixeltypes.h:734
@ Olive
Definition pixeltypes.h:767
@ PapayaWhip
Definition pixeltypes.h:776
@ Azure
Definition pixeltypes.h:669
@ DarkOrchid
Definition pixeltypes.h:696
@ PowderBlue
Definition pixeltypes.h:782
@ IndianRed
Definition pixeltypes.h:724
@ FairyLight
Definition pixeltypes.h:817
@ DarkGoldenrod
Definition pixeltypes.h:688
@ LightSkyBlue
Definition pixeltypes.h:741
@ DarkSlateBlue
Definition pixeltypes.h:700
@ MediumBlue
Definition pixeltypes.h:752
@ Black
Definition pixeltypes.h:672
@ LavenderBlush
Definition pixeltypes.h:729
@ DarkOrange
Definition pixeltypes.h:695
@ CadetBlue
Definition pixeltypes.h:678
@ SlateGray
Definition pixeltypes.h:796
@ OliveDrab
Definition pixeltypes.h:768
@ Plaid
Definition pixeltypes.h:780
@ SpringGreen
Definition pixeltypes.h:799
@ Honeydew
Definition pixeltypes.h:722
@ Gainsboro
Definition pixeltypes.h:714
@ MediumPurple
Definition pixeltypes.h:754
@ Yellow
Definition pixeltypes.h:810
@ DimGrey
Definition pixeltypes.h:708
@ FairyLightNCC
Definition pixeltypes.h:820
@ DarkOliveGreen
Definition pixeltypes.h:694
@ LightGoldenrodYellow
Definition pixeltypes.h:735
@ LightSlateGrey
Definition pixeltypes.h:743
@ AliceBlue
Definition pixeltypes.h:664
@ PaleGoldenrod
Definition pixeltypes.h:772
@ DarkSeaGreen
Definition pixeltypes.h:699
@ LightBlue
Definition pixeltypes.h:732
@ FloralWhite
Definition pixeltypes.h:711
@ Chartreuse
Definition pixeltypes.h:679
@ DimGray
Definition pixeltypes.h:707
@ OrangeRed
Definition pixeltypes.h:770
@ ForestGreen
Definition pixeltypes.h:712
@ Khaki
Definition pixeltypes.h:727
@ MintCream
Definition pixeltypes.h:761
@ DarkCyan
Definition pixeltypes.h:687
@ DarkGreen
Definition pixeltypes.h:691
@ GreenYellow
Definition pixeltypes.h:721
@ WhiteSmoke
Definition pixeltypes.h:809
@ DarkBlue
Definition pixeltypes.h:686
@ Maroon
Definition pixeltypes.h:750
CRGB(uint32_t colorcode)
Allow construction from 32-bit (really 24-bit) bit 0xRRGGBB color code.
Definition pixeltypes.h:175
CRGB & fadeToBlackBy(uint8_t fadefactor)
fadeToBlackBy is a synonym for nscale8(), as a fade instead of a scale
Definition pixeltypes.h:437
uint8_t getParity()
Returns 0 or 1, depending on the lowest bit of the sum of the color components.
Definition pixeltypes.h:587
CRGB & operator>>=(uint8_t d)
Right shift each of the channels by a constant.
Definition pixeltypes.h:349
CRGB & operator&=(const CRGB &rhs)
"and" operator brings each channel down to the lower of the two values
Definition pixeltypes.h:462