FastLED 3.6.0
Loading...
Searching...
No Matches
colorutils.h
Go to the documentation of this file.
1#ifndef __INC_COLORUTILS_H
2#define __INC_COLORUTILS_H
3
6
7#include "FastLED.h"
8#include "pixeltypes.h"
9#include "fastled_progmem.h"
10
11FASTLED_NAMESPACE_BEGIN
12
16
20
25void fill_solid( struct CRGB * targetArray, int numToFill,
26 const struct CRGB& color);
27
29void fill_solid( struct CHSV* targetArray, int numToFill,
30 const struct CHSV& color);
31
32
40void fill_rainbow( struct CRGB * targetArray, int numToFill,
41 uint8_t initialhue,
42 uint8_t deltahue = 5);
43
45void fill_rainbow( struct CHSV * targetArray, int numToFill,
46 uint8_t initialhue,
47 uint8_t deltahue = 5);
48
49
58void fill_rainbow_circular(struct CRGB* targetArray, int numToFill,
59 uint8_t initialhue, bool reversed=false);
60
62void fill_rainbow_circular(struct CHSV* targetArray, int numToFill,
63 uint8_t initialhue, bool reversed=false);
64
65
69typedef enum {
75
76
79#define saccum87 int16_t
80
81
97template <typename T>
98void fill_gradient( T* targetArray,
99 uint16_t startpos, CHSV startcolor,
100 uint16_t endpos, CHSV endcolor,
101 TGradientDirectionCode directionCode = SHORTEST_HUES )
102{
103 // if the points are in the wrong order, straighten them
104 if( endpos < startpos ) {
105 uint16_t t = endpos;
106 CHSV tc = endcolor;
107 endcolor = startcolor;
108 endpos = startpos;
109 startpos = t;
110 startcolor = tc;
111 }
112
113 // If we're fading toward black (val=0) or white (sat=0),
114 // then set the endhue to the starthue.
115 // This lets us ramp smoothly to black or white, regardless
116 // of what 'hue' was set in the endcolor (since it doesn't matter)
117 if( endcolor.value == 0 || endcolor.saturation == 0) {
118 endcolor.hue = startcolor.hue;
119 }
120
121 // Similarly, if we're fading in from black (val=0) or white (sat=0)
122 // then set the starthue to the endhue.
123 // This lets us ramp smoothly up from black or white, regardless
124 // of what 'hue' was set in the startcolor (since it doesn't matter)
125 if( startcolor.value == 0 || startcolor.saturation == 0) {
126 startcolor.hue = endcolor.hue;
127 }
128
129 saccum87 huedistance87;
130 saccum87 satdistance87;
131 saccum87 valdistance87;
132
133 satdistance87 = (endcolor.sat - startcolor.sat) << 7;
134 valdistance87 = (endcolor.val - startcolor.val) << 7;
135
136 uint8_t huedelta8 = endcolor.hue - startcolor.hue;
137
138 if( directionCode == SHORTEST_HUES ) {
139 directionCode = FORWARD_HUES;
140 if( huedelta8 > 127) {
141 directionCode = BACKWARD_HUES;
142 }
143 }
144
145 if( directionCode == LONGEST_HUES ) {
146 directionCode = FORWARD_HUES;
147 if( huedelta8 < 128) {
148 directionCode = BACKWARD_HUES;
149 }
150 }
151
152 if( directionCode == FORWARD_HUES) {
153 huedistance87 = huedelta8 << 7;
154 }
155 else /* directionCode == BACKWARD_HUES */
156 {
157 huedistance87 = (uint8_t)(256 - huedelta8) << 7;
158 huedistance87 = -huedistance87;
159 }
160
161 uint16_t pixeldistance = endpos - startpos;
162 int16_t divisor = pixeldistance ? pixeldistance : 1;
163
164 saccum87 huedelta87 = huedistance87 / divisor;
165 saccum87 satdelta87 = satdistance87 / divisor;
166 saccum87 valdelta87 = valdistance87 / divisor;
167
168 huedelta87 *= 2;
169 satdelta87 *= 2;
170 valdelta87 *= 2;
171
172 accum88 hue88 = startcolor.hue << 8;
173 accum88 sat88 = startcolor.sat << 8;
174 accum88 val88 = startcolor.val << 8;
175 for( uint16_t i = startpos; i <= endpos; ++i) {
176 targetArray[i] = CHSV( hue88 >> 8, sat88 >> 8, val88 >> 8);
177 hue88 += huedelta87;
178 sat88 += satdelta87;
179 val88 += valdelta87;
180 }
181}
182
183
191template <typename T>
192void fill_gradient( T* targetArray, uint16_t numLeds, const CHSV& c1, const CHSV& c2,
193 TGradientDirectionCode directionCode = SHORTEST_HUES )
194{
195 uint16_t last = numLeds - 1;
196 fill_gradient( targetArray, 0, c1, last, c2, directionCode);
197}
198
207template <typename T>
208void fill_gradient( T* targetArray, uint16_t numLeds,
209 const CHSV& c1, const CHSV& c2, const CHSV& c3,
210 TGradientDirectionCode directionCode = SHORTEST_HUES )
211{
212 uint16_t half = (numLeds / 2);
213 uint16_t last = numLeds - 1;
214 fill_gradient( targetArray, 0, c1, half, c2, directionCode);
215 fill_gradient( targetArray, half, c2, last, c3, directionCode);
216}
217
227template <typename T>
228void fill_gradient( T* targetArray, uint16_t numLeds,
229 const CHSV& c1, const CHSV& c2, const CHSV& c3, const CHSV& c4,
230 TGradientDirectionCode directionCode = SHORTEST_HUES )
231{
232 uint16_t onethird = (numLeds / 3);
233 uint16_t twothirds = ((numLeds * 2) / 3);
234 uint16_t last = numLeds - 1;
235 fill_gradient( targetArray, 0, c1, onethird, c2, directionCode);
236 fill_gradient( targetArray, onethird, c2, twothirds, c3, directionCode);
237 fill_gradient( targetArray, twothirds, c3, last, c4, directionCode);
238}
239
241#define fill_gradient_HSV fill_gradient
242
243
253void fill_gradient_RGB( CRGB* leds,
254 uint16_t startpos, CRGB startcolor,
255 uint16_t endpos, CRGB endcolor );
256
263void fill_gradient_RGB( CRGB* leds, uint16_t numLeds, const CRGB& c1, const CRGB& c2);
264
272void fill_gradient_RGB( CRGB* leds, uint16_t numLeds, const CRGB& c1, const CRGB& c2, const CRGB& c3);
273
282void fill_gradient_RGB( CRGB* leds, uint16_t numLeds, const CRGB& c1, const CRGB& c2, const CRGB& c3, const CRGB& c4);
283
285
286
290
296void fadeLightBy( CRGB* leds, uint16_t num_leds, uint8_t fadeBy);
297
299void fade_video( CRGB* leds, uint16_t num_leds, uint8_t fadeBy);
300
306void nscale8_video( CRGB* leds, uint16_t num_leds, uint8_t scale);
307
308
314void fadeToBlackBy( CRGB* leds, uint16_t num_leds, uint8_t fadeBy);
315
317void fade_raw( CRGB* leds, uint16_t num_leds, uint8_t fadeBy);
318
319
326void nscale8( CRGB* leds, uint16_t num_leds, uint8_t scale);
327
328
339void fadeUsingColor( CRGB* leds, uint16_t numLeds, const CRGB& colormask);
340
342
343
347
352CRGB blend( const CRGB& p1, const CRGB& p2, fract8 amountOfP2 );
353
356CHSV blend( const CHSV& p1, const CHSV& p2, fract8 amountOfP2,
357 TGradientDirectionCode directionCode = SHORTEST_HUES );
358
359
368CRGB* blend( const CRGB* src1, const CRGB* src2, CRGB* dest,
369 uint16_t count, fract8 amountOfsrc2 );
370
373CHSV* blend( const CHSV* src1, const CHSV* src2, CHSV* dest,
374 uint16_t count, fract8 amountOfsrc2,
375 TGradientDirectionCode directionCode = SHORTEST_HUES );
376
377
382CRGB& nblend( CRGB& existing, const CRGB& overlay, fract8 amountOfOverlay );
383
386CHSV& nblend( CHSV& existing, const CHSV& overlay, fract8 amountOfOverlay,
387 TGradientDirectionCode directionCode = SHORTEST_HUES );
388
389
395void nblend( CRGB* existing, CRGB* overlay, uint16_t count, fract8 amountOfOverlay);
396
399void nblend( CHSV* existing, CHSV* overlay, uint16_t count, fract8 amountOfOverlay,
400 TGradientDirectionCode directionCode = SHORTEST_HUES);
401
403
404
408
423void blur1d( CRGB* leds, uint16_t numLeds, fract8 blur_amount);
424
440void blur2d( CRGB* leds, uint8_t width, uint8_t height, fract8 blur_amount);
441
442
449void blurRows( CRGB* leds, uint8_t width, uint8_t height, fract8 blur_amount);
450
453void blurColumns(CRGB* leds, uint8_t width, uint8_t height, fract8 blur_amount);
454
456
457
460
466CRGB HeatColor( uint8_t temperature);
467
470
471
539
540
547
548class CRGBPalette16;
549class CRGBPalette32;
550class CRGBPalette256;
551class CHSVPalette16;
552class CHSVPalette32;
553class CHSVPalette256;
554
555typedef uint32_t TProgmemRGBPalette16[16];
556typedef uint32_t TProgmemHSVPalette16[16];
558#define TProgmemPalette16 TProgmemRGBPalette16
559typedef uint32_t TProgmemRGBPalette32[32];
560typedef uint32_t TProgmemHSVPalette32[32];
562#define TProgmemPalette32 TProgmemRGBPalette32
563
572
577typedef union {
578 struct {
579 uint8_t index;
580 uint8_t r;
581 uint8_t g;
582 uint8_t b;
583 };
584 uint32_t dword;
585 uint8_t bytes[4];
587
591
593
594
598
602void UpscalePalette(const struct CRGBPalette16& srcpal16, struct CRGBPalette256& destpal256);
604void UpscalePalette(const struct CHSVPalette16& srcpal16, struct CHSVPalette256& destpal256);
605
609void UpscalePalette(const struct CRGBPalette16& srcpal16, struct CRGBPalette32& destpal32);
611void UpscalePalette(const struct CHSVPalette16& srcpal16, struct CHSVPalette32& destpal32);
612
616void UpscalePalette(const struct CRGBPalette32& srcpal32, struct CRGBPalette256& destpal256);
618void UpscalePalette(const struct CHSVPalette32& srcpal32, struct CHSVPalette256& destpal256);
619
621
622
625
628public:
630
633
635 CHSVPalette16( const CHSV& c00,const CHSV& c01,const CHSV& c02,const CHSV& c03,
636 const CHSV& c04,const CHSV& c05,const CHSV& c06,const CHSV& c07,
637 const CHSV& c08,const CHSV& c09,const CHSV& c10,const CHSV& c11,
638 const CHSV& c12,const CHSV& c13,const CHSV& c14,const CHSV& c15 )
639 {
640 entries[0]=c00; entries[1]=c01; entries[2]=c02; entries[3]=c03;
641 entries[4]=c04; entries[5]=c05; entries[6]=c06; entries[7]=c07;
642 entries[8]=c08; entries[9]=c09; entries[10]=c10; entries[11]=c11;
643 entries[12]=c12; entries[13]=c13; entries[14]=c14; entries[15]=c15;
644 };
645
648 {
649 memmove8( (void *) &(entries[0]), &(rhs.entries[0]), sizeof( entries));
650 }
651
654 {
655 memmove8( (void *) &(entries[0]), &(rhs.entries[0]), sizeof( entries));
656 return *this;
657 }
658
661 {
662 for( uint8_t i = 0; i < 16; ++i) {
663 CRGB xyz = FL_PGM_READ_DWORD_NEAR( rhs + i);
664 entries[i].hue = xyz.red;
665 entries[i].sat = xyz.green;
666 entries[i].val = xyz.blue;
667 }
668 }
669
672 {
673 for( uint8_t i = 0; i < 16; ++i) {
674 CRGB xyz = FL_PGM_READ_DWORD_NEAR( rhs + i);
675 entries[i].hue = xyz.red;
676 entries[i].sat = xyz.green;
677 entries[i].val = xyz.blue;
678 }
679 return *this;
680 }
681
688 inline CHSV& operator[] (uint8_t x) __attribute__((always_inline))
689 {
690 return entries[x];
691 }
692
694 inline const CHSV& operator[] (uint8_t x) const __attribute__((always_inline))
695 {
696 return entries[x];
697 }
698
700 inline CHSV& operator[] (int x) __attribute__((always_inline))
701 {
702 return entries[(uint8_t)x];
703 }
704
706 inline const CHSV& operator[] (int x) const __attribute__((always_inline))
707 {
708 return entries[(uint8_t)x];
709 }
710
712 operator CHSV*()
713 {
714 return &(entries[0]);
715 }
716
718 bool operator==( const CHSVPalette16 &rhs) const
719 {
720 const uint8_t* p = (const uint8_t*)(&(this->entries[0]));
721 const uint8_t* q = (const uint8_t*)(&(rhs.entries[0]));
722 if( p == q) return true;
723 for( uint8_t i = 0; i < (sizeof( entries)); ++i) {
724 if( *p != *q) return false;
725 ++p;
726 ++q;
727 }
728 return true;
729 }
730
732 bool operator!=( const CHSVPalette16 &rhs) const
733 {
734 return !( *this == rhs);
735 }
736
739 CHSVPalette16( const CHSV& c1)
740 {
741 fill_solid( &(entries[0]), 16, c1);
742 }
743
747 CHSVPalette16( const CHSV& c1, const CHSV& c2)
748 {
749 fill_gradient( &(entries[0]), 16, c1, c2);
750 }
751
756 CHSVPalette16( const CHSV& c1, const CHSV& c2, const CHSV& c3)
757 {
758 fill_gradient( &(entries[0]), 16, c1, c2, c3);
759 }
760
766 CHSVPalette16( const CHSV& c1, const CHSV& c2, const CHSV& c3, const CHSV& c4)
767 {
768 fill_gradient( &(entries[0]), 16, c1, c2, c3, c4);
769 }
770
771};
772
775public:
777
780
785 CHSVPalette256( const CHSV& c00,const CHSV& c01,const CHSV& c02,const CHSV& c03,
786 const CHSV& c04,const CHSV& c05,const CHSV& c06,const CHSV& c07,
787 const CHSV& c08,const CHSV& c09,const CHSV& c10,const CHSV& c11,
788 const CHSV& c12,const CHSV& c13,const CHSV& c14,const CHSV& c15 )
789 {
790 CHSVPalette16 p16(c00,c01,c02,c03,c04,c05,c06,c07,
791 c08,c09,c10,c11,c12,c13,c14,c15);
792 *this = p16;
793 };
794
797 {
798 memmove8( (void *) &(entries[0]), &(rhs.entries[0]), sizeof( entries));
799 }
802 {
803 memmove8( (void *) &(entries[0]), &(rhs.entries[0]), sizeof( entries));
804 return *this;
805 }
806
809 {
810 UpscalePalette( rhs16, *this);
811 }
814 {
815 UpscalePalette( rhs16, *this);
816 return *this;
817 }
818
821 {
822 CHSVPalette16 p16(rhs);
823 *this = p16;
824 }
827 {
828 CHSVPalette16 p16(rhs);
829 *this = p16;
830 return *this;
831 }
832
834 inline CHSV& operator[] (uint8_t x) __attribute__((always_inline))
835 {
836 return entries[x];
837 }
839 inline const CHSV& operator[] (uint8_t x) const __attribute__((always_inline))
840 {
841 return entries[x];
842 }
843
845 inline CHSV& operator[] (int x) __attribute__((always_inline))
846 {
847 return entries[(uint8_t)x];
848 }
850 inline const CHSV& operator[] (int x) const __attribute__((always_inline))
851 {
852 return entries[(uint8_t)x];
853 }
854
856 operator CHSV*()
857 {
858 return &(entries[0]);
859 }
860
862 bool operator==( const CHSVPalette256 &rhs) const
863 {
864 const uint8_t* p = (const uint8_t*)(&(this->entries[0]));
865 const uint8_t* q = (const uint8_t*)(&(rhs.entries[0]));
866 if( p == q) return true;
867 for( uint16_t i = 0; i < (sizeof( entries)); ++i) {
868 if( *p != *q) return false;
869 ++p;
870 ++q;
871 }
872 return true;
873 }
874
876 bool operator!=( const CHSVPalette256 &rhs) const
877 {
878 return !( *this == rhs);
879 }
880
883 {
884 fill_solid( &(entries[0]), 256, c1);
885 }
887 CHSVPalette256( const CHSV& c1, const CHSV& c2)
888 {
889 fill_gradient( &(entries[0]), 256, c1, c2);
890 }
892 CHSVPalette256( const CHSV& c1, const CHSV& c2, const CHSV& c3)
893 {
894 fill_gradient( &(entries[0]), 256, c1, c2, c3);
895 }
897 CHSVPalette256( const CHSV& c1, const CHSV& c2, const CHSV& c3, const CHSV& c4)
898 {
899 fill_gradient( &(entries[0]), 256, c1, c2, c3, c4);
900 }
901};
902
905public:
907
910
912 CRGBPalette16( const CRGB& c00,const CRGB& c01,const CRGB& c02,const CRGB& c03,
913 const CRGB& c04,const CRGB& c05,const CRGB& c06,const CRGB& c07,
914 const CRGB& c08,const CRGB& c09,const CRGB& c10,const CRGB& c11,
915 const CRGB& c12,const CRGB& c13,const CRGB& c14,const CRGB& c15 )
916 {
917 entries[0]=c00; entries[1]=c01; entries[2]=c02; entries[3]=c03;
918 entries[4]=c04; entries[5]=c05; entries[6]=c06; entries[7]=c07;
919 entries[8]=c08; entries[9]=c09; entries[10]=c10; entries[11]=c11;
920 entries[12]=c12; entries[13]=c13; entries[14]=c14; entries[15]=c15;
921 };
922
925 {
926 memmove8( (void *) &(entries[0]), &(rhs.entries[0]), sizeof( entries));
927 }
929 CRGBPalette16( const CRGB rhs[16])
930 {
931 memmove8( (void *) &(entries[0]), &(rhs[0]), sizeof( entries));
932 }
935 {
936 memmove8( (void *) &(entries[0]), &(rhs.entries[0]), sizeof( entries));
937 return *this;
938 }
940 CRGBPalette16& operator=( const CRGB rhs[16])
941 {
942 memmove8( (void *) &(entries[0]), &(rhs[0]), sizeof( entries));
943 return *this;
944 }
945
948 {
949 for( uint8_t i = 0; i < 16; ++i) {
950 entries[i] = rhs.entries[i]; // implicit HSV-to-RGB conversion
951 }
952 }
954 CRGBPalette16( const CHSV rhs[16])
955 {
956 for( uint8_t i = 0; i < 16; ++i) {
957 entries[i] = rhs[i]; // implicit HSV-to-RGB conversion
958 }
959 }
962 {
963 for( uint8_t i = 0; i < 16; ++i) {
964 entries[i] = rhs.entries[i]; // implicit HSV-to-RGB conversion
965 }
966 return *this;
967 }
969 CRGBPalette16& operator=( const CHSV rhs[16])
970 {
971 for( uint8_t i = 0; i < 16; ++i) {
972 entries[i] = rhs[i]; // implicit HSV-to-RGB conversion
973 }
974 return *this;
975 }
976
979 {
980 for( uint8_t i = 0; i < 16; ++i) {
981 entries[i] = FL_PGM_READ_DWORD_NEAR( rhs + i);
982 }
983 }
986 {
987 for( uint8_t i = 0; i < 16; ++i) {
988 entries[i] = FL_PGM_READ_DWORD_NEAR( rhs + i);
989 }
990 return *this;
991 }
992
994 bool operator==( const CRGBPalette16 &rhs) const
995 {
996 const uint8_t* p = (const uint8_t*)(&(this->entries[0]));
997 const uint8_t* q = (const uint8_t*)(&(rhs.entries[0]));
998 if( p == q) return true;
999 for( uint8_t i = 0; i < (sizeof( entries)); ++i) {
1000 if( *p != *q) return false;
1001 ++p;
1002 ++q;
1003 }
1004 return true;
1005 }
1007 bool operator!=( const CRGBPalette16 &rhs) const
1008 {
1009 return !( *this == rhs);
1010 }
1012 inline CRGB& operator[] (uint8_t x) __attribute__((always_inline))
1013 {
1014 return entries[x];
1015 }
1017 inline const CRGB& operator[] (uint8_t x) const __attribute__((always_inline))
1018 {
1019 return entries[x];
1020 }
1021
1023 inline CRGB& operator[] (int x) __attribute__((always_inline))
1024 {
1025 return entries[(uint8_t)x];
1026 }
1028 inline const CRGB& operator[] (int x) const __attribute__((always_inline))
1029 {
1030 return entries[(uint8_t)x];
1031 }
1032
1034 operator CRGB*()
1035 {
1036 return &(entries[0]);
1037 }
1038
1041 {
1042 fill_solid( &(entries[0]), 16, c1);
1043 }
1045 CRGBPalette16( const CHSV& c1, const CHSV& c2)
1046 {
1047 fill_gradient( &(entries[0]), 16, c1, c2);
1048 }
1050 CRGBPalette16( const CHSV& c1, const CHSV& c2, const CHSV& c3)
1051 {
1052 fill_gradient( &(entries[0]), 16, c1, c2, c3);
1053 }
1055 CRGBPalette16( const CHSV& c1, const CHSV& c2, const CHSV& c3, const CHSV& c4)
1056 {
1057 fill_gradient( &(entries[0]), 16, c1, c2, c3, c4);
1058 }
1059
1062 {
1063 fill_solid( &(entries[0]), 16, c1);
1064 }
1066 CRGBPalette16( const CRGB& c1, const CRGB& c2)
1067 {
1068 fill_gradient_RGB( &(entries[0]), 16, c1, c2);
1069 }
1071 CRGBPalette16( const CRGB& c1, const CRGB& c2, const CRGB& c3)
1072 {
1073 fill_gradient_RGB( &(entries[0]), 16, c1, c2, c3);
1074 }
1076 CRGBPalette16( const CRGB& c1, const CRGB& c2, const CRGB& c3, const CRGB& c4)
1077 {
1078 fill_gradient_RGB( &(entries[0]), 16, c1, c2, c3, c4);
1079 }
1080
1111 {
1112 *this = progpal;
1113 }
1116 {
1119
1120 // Count entries
1121 uint16_t count = 0;
1122 do {
1123 u.dword = FL_PGM_READ_DWORD_NEAR(progent + count);
1124 ++count;
1125 } while ( u.index != 255);
1126
1127 int8_t lastSlotUsed = -1;
1128
1129 u.dword = FL_PGM_READ_DWORD_NEAR( progent);
1130 CRGB rgbstart( u.r, u.g, u.b);
1131
1132 int indexstart = 0;
1133 uint8_t istart8 = 0;
1134 uint8_t iend8 = 0;
1135 while( indexstart < 255) {
1136 ++progent;
1137 u.dword = FL_PGM_READ_DWORD_NEAR( progent);
1138 int indexend = u.index;
1139 CRGB rgbend( u.r, u.g, u.b);
1140 istart8 = indexstart / 16;
1141 iend8 = indexend / 16;
1142 if( count < 16) {
1143 if( (istart8 <= lastSlotUsed) && (lastSlotUsed < 15)) {
1144 istart8 = lastSlotUsed + 1;
1145 if( iend8 < istart8) {
1146 iend8 = istart8;
1147 }
1148 }
1149 lastSlotUsed = iend8;
1150 }
1151 fill_gradient_RGB( &(entries[0]), istart8, rgbstart, iend8, rgbend);
1152 indexstart = indexend;
1153 rgbstart = rgbend;
1154 }
1155 return *this;
1156 }
1160 {
1163
1164 // Count entries
1165 uint16_t count = 0;
1166 do {
1167 u = *(ent + count);
1168 ++count;
1169 } while ( u.index != 255);
1170
1171 int8_t lastSlotUsed = -1;
1172
1173
1174 u = *ent;
1175 CRGB rgbstart( u.r, u.g, u.b);
1176
1177 int indexstart = 0;
1178 uint8_t istart8 = 0;
1179 uint8_t iend8 = 0;
1180 while( indexstart < 255) {
1181 ++ent;
1182 u = *ent;
1183 int indexend = u.index;
1184 CRGB rgbend( u.r, u.g, u.b);
1185 istart8 = indexstart / 16;
1186 iend8 = indexend / 16;
1187 if( count < 16) {
1188 if( (istart8 <= lastSlotUsed) && (lastSlotUsed < 15)) {
1189 istart8 = lastSlotUsed + 1;
1190 if( iend8 < istart8) {
1191 iend8 = istart8;
1192 }
1193 }
1194 lastSlotUsed = iend8;
1195 }
1196 fill_gradient_RGB( &(entries[0]), istart8, rgbstart, iend8, rgbend);
1197 indexstart = indexend;
1198 rgbstart = rgbend;
1199 }
1200 return *this;
1201 }
1202
1203};
1204
1205
1208public:
1210
1213
1218 CHSVPalette32( const CHSV& c00,const CHSV& c01,const CHSV& c02,const CHSV& c03,
1219 const CHSV& c04,const CHSV& c05,const CHSV& c06,const CHSV& c07,
1220 const CHSV& c08,const CHSV& c09,const CHSV& c10,const CHSV& c11,
1221 const CHSV& c12,const CHSV& c13,const CHSV& c14,const CHSV& c15 )
1222 {
1223 for( uint8_t i = 0; i < 2; ++i) {
1224 entries[0+i]=c00; entries[2+i]=c01; entries[4+i]=c02; entries[6+i]=c03;
1225 entries[8+i]=c04; entries[10+i]=c05; entries[12+i]=c06; entries[14+i]=c07;
1226 entries[16+i]=c08; entries[18+i]=c09; entries[20+i]=c10; entries[22+i]=c11;
1227 entries[24+i]=c12; entries[26+i]=c13; entries[28+i]=c14; entries[30+i]=c15;
1228 }
1229 };
1230
1233 {
1234 memmove8( (void *) &(entries[0]), &(rhs.entries[0]), sizeof( entries));
1235 }
1238 {
1239 memmove8( (void *) &(entries[0]), &(rhs.entries[0]), sizeof( entries));
1240 return *this;
1241 }
1242
1245 {
1246 for( uint8_t i = 0; i < 32; ++i) {
1247 CRGB xyz = FL_PGM_READ_DWORD_NEAR( rhs + i);
1248 entries[i].hue = xyz.red;
1249 entries[i].sat = xyz.green;
1250 entries[i].val = xyz.blue;
1251 }
1252 }
1255 {
1256 for( uint8_t i = 0; i < 32; ++i) {
1257 CRGB xyz = FL_PGM_READ_DWORD_NEAR( rhs + i);
1258 entries[i].hue = xyz.red;
1259 entries[i].sat = xyz.green;
1260 entries[i].val = xyz.blue;
1261 }
1262 return *this;
1263 }
1264
1266 inline CHSV& operator[] (uint8_t x) __attribute__((always_inline))
1267 {
1268 return entries[x];
1269 }
1271 inline const CHSV& operator[] (uint8_t x) const __attribute__((always_inline))
1272 {
1273 return entries[x];
1274 }
1275
1277 inline CHSV& operator[] (int x) __attribute__((always_inline))
1278 {
1279 return entries[(uint8_t)x];
1280 }
1282 inline const CHSV& operator[] (int x) const __attribute__((always_inline))
1283 {
1284 return entries[(uint8_t)x];
1285 }
1286
1288 operator CHSV*()
1289 {
1290 return &(entries[0]);
1291 }
1292
1294 bool operator==( const CHSVPalette32 &rhs) const
1295 {
1296 const uint8_t* p = (const uint8_t*)(&(this->entries[0]));
1297 const uint8_t* q = (const uint8_t*)(&(rhs.entries[0]));
1298 if( p == q) return true;
1299 for( uint8_t i = 0; i < (sizeof( entries)); ++i) {
1300 if( *p != *q) return false;
1301 ++p;
1302 ++q;
1303 }
1304 return true;
1305 }
1307 bool operator!=( const CHSVPalette32 &rhs) const
1308 {
1309 return !( *this == rhs);
1310 }
1311
1314 {
1315 fill_solid( &(entries[0]), 32, c1);
1316 }
1318 CHSVPalette32( const CHSV& c1, const CHSV& c2)
1319 {
1320 fill_gradient( &(entries[0]), 32, c1, c2);
1321 }
1323 CHSVPalette32( const CHSV& c1, const CHSV& c2, const CHSV& c3)
1324 {
1325 fill_gradient( &(entries[0]), 32, c1, c2, c3);
1326 }
1328 CHSVPalette32( const CHSV& c1, const CHSV& c2, const CHSV& c3, const CHSV& c4)
1329 {
1330 fill_gradient( &(entries[0]), 32, c1, c2, c3, c4);
1331 }
1332
1333};
1334
1337public:
1339
1342
1348 CRGBPalette32( const CRGB& c00,const CRGB& c01,const CRGB& c02,const CRGB& c03,
1349 const CRGB& c04,const CRGB& c05,const CRGB& c06,const CRGB& c07,
1350 const CRGB& c08,const CRGB& c09,const CRGB& c10,const CRGB& c11,
1351 const CRGB& c12,const CRGB& c13,const CRGB& c14,const CRGB& c15 )
1352 {
1353 for( uint8_t i = 0; i < 2; ++i) {
1354 entries[0+i]=c00; entries[2+i]=c01; entries[4+i]=c02; entries[6+i]=c03;
1355 entries[8+i]=c04; entries[10+i]=c05; entries[12+i]=c06; entries[14+i]=c07;
1356 entries[16+i]=c08; entries[18+i]=c09; entries[20+i]=c10; entries[22+i]=c11;
1357 entries[24+i]=c12; entries[26+i]=c13; entries[28+i]=c14; entries[30+i]=c15;
1358 }
1359 };
1360
1363 {
1364 memmove8( (void *) &(entries[0]), &(rhs.entries[0]), sizeof( entries));
1365 }
1367 CRGBPalette32( const CRGB rhs[32])
1368 {
1369 memmove8( (void *) &(entries[0]), &(rhs[0]), sizeof( entries));
1370 }
1373 {
1374 memmove8( (void *) &(entries[0]), &(rhs.entries[0]), sizeof( entries));
1375 return *this;
1376 }
1379 {
1380 memmove8( (void *) &(entries[0]), &(rhs[0]), sizeof( entries));
1381 return *this;
1382 }
1383
1386 {
1387 for( uint8_t i = 0; i < 32; ++i) {
1388 entries[i] = rhs.entries[i]; // implicit HSV-to-RGB conversion
1389 }
1390 }
1392 CRGBPalette32( const CHSV rhs[32])
1393 {
1394 for( uint8_t i = 0; i < 32; ++i) {
1395 entries[i] = rhs[i]; // implicit HSV-to-RGB conversion
1396 }
1397 }
1400 {
1401 for( uint8_t i = 0; i < 32; ++i) {
1402 entries[i] = rhs.entries[i]; // implicit HSV-to-RGB conversion
1403 }
1404 return *this;
1405 }
1408 {
1409 for( uint8_t i = 0; i < 32; ++i) {
1410 entries[i] = rhs[i]; // implicit HSV-to-RGB conversion
1411 }
1412 return *this;
1413 }
1414
1417 {
1418 for( uint8_t i = 0; i < 32; ++i) {
1419 entries[i] = FL_PGM_READ_DWORD_NEAR( rhs + i);
1420 }
1421 }
1424 {
1425 for( uint8_t i = 0; i < 32; ++i) {
1426 entries[i] = FL_PGM_READ_DWORD_NEAR( rhs + i);
1427 }
1428 return *this;
1429 }
1430
1432 bool operator==( const CRGBPalette32 &rhs) const
1433 {
1434 const uint8_t* p = (const uint8_t*)(&(this->entries[0]));
1435 const uint8_t* q = (const uint8_t*)(&(rhs.entries[0]));
1436 if( p == q) return true;
1437 for( uint8_t i = 0; i < (sizeof( entries)); ++i) {
1438 if( *p != *q) return false;
1439 ++p;
1440 ++q;
1441 }
1442 return true;
1443 }
1445 bool operator!=( const CRGBPalette32 &rhs) const
1446 {
1447 return !( *this == rhs);
1448 }
1449
1451 inline CRGB& operator[] (uint8_t x) __attribute__((always_inline))
1452 {
1453 return entries[x];
1454 }
1456 inline const CRGB& operator[] (uint8_t x) const __attribute__((always_inline))
1457 {
1458 return entries[x];
1459 }
1460
1462 inline CRGB& operator[] (int x) __attribute__((always_inline))
1463 {
1464 return entries[(uint8_t)x];
1465 }
1467 inline const CRGB& operator[] (int x) const __attribute__((always_inline))
1468 {
1469 return entries[(uint8_t)x];
1470 }
1471
1473 operator CRGB*()
1474 {
1475 return &(entries[0]);
1476 }
1477
1480 {
1481 fill_solid( &(entries[0]), 32, c1);
1482 }
1484 CRGBPalette32( const CHSV& c1, const CHSV& c2)
1485 {
1486 fill_gradient( &(entries[0]), 32, c1, c2);
1487 }
1489 CRGBPalette32( const CHSV& c1, const CHSV& c2, const CHSV& c3)
1490 {
1491 fill_gradient( &(entries[0]), 32, c1, c2, c3);
1492 }
1494 CRGBPalette32( const CHSV& c1, const CHSV& c2, const CHSV& c3, const CHSV& c4)
1495 {
1496 fill_gradient( &(entries[0]), 32, c1, c2, c3, c4);
1497 }
1498
1501 {
1502 fill_solid( &(entries[0]), 32, c1);
1503 }
1505 CRGBPalette32( const CRGB& c1, const CRGB& c2)
1506 {
1507 fill_gradient_RGB( &(entries[0]), 32, c1, c2);
1508 }
1510 CRGBPalette32( const CRGB& c1, const CRGB& c2, const CRGB& c3)
1511 {
1512 fill_gradient_RGB( &(entries[0]), 32, c1, c2, c3);
1513 }
1515 CRGBPalette32( const CRGB& c1, const CRGB& c2, const CRGB& c3, const CRGB& c4)
1516 {
1517 fill_gradient_RGB( &(entries[0]), 32, c1, c2, c3, c4);
1518 }
1519
1520
1523 {
1524 UpscalePalette( rhs16, *this);
1525 }
1528 {
1529 UpscalePalette( rhs16, *this);
1530 return *this;
1531 }
1532
1535 {
1536 CRGBPalette16 p16(rhs);
1537 *this = p16;
1538 }
1541 {
1542 CRGBPalette16 p16(rhs);
1543 *this = p16;
1544 return *this;
1545 }
1546
1547
1550 {
1551 *this = progpal;
1552 }
1555 {
1558
1559 // Count entries
1560 uint16_t count = 0;
1561 do {
1562 u.dword = FL_PGM_READ_DWORD_NEAR(progent + count);
1563 ++count;
1564 } while ( u.index != 255);
1565
1566 int8_t lastSlotUsed = -1;
1567
1568 u.dword = FL_PGM_READ_DWORD_NEAR( progent);
1569 CRGB rgbstart( u.r, u.g, u.b);
1570
1571 int indexstart = 0;
1572 uint8_t istart8 = 0;
1573 uint8_t iend8 = 0;
1574 while( indexstart < 255) {
1575 ++progent;
1576 u.dword = FL_PGM_READ_DWORD_NEAR( progent);
1577 int indexend = u.index;
1578 CRGB rgbend( u.r, u.g, u.b);
1579 istart8 = indexstart / 8;
1580 iend8 = indexend / 8;
1581 if( count < 16) {
1582 if( (istart8 <= lastSlotUsed) && (lastSlotUsed < 31)) {
1583 istart8 = lastSlotUsed + 1;
1584 if( iend8 < istart8) {
1585 iend8 = istart8;
1586 }
1587 }
1588 lastSlotUsed = iend8;
1589 }
1590 fill_gradient_RGB( &(entries[0]), istart8, rgbstart, iend8, rgbend);
1591 indexstart = indexend;
1592 rgbstart = rgbend;
1593 }
1594 return *this;
1595 }
1598 {
1601
1602 // Count entries
1603 uint16_t count = 0;
1604 do {
1605 u = *(ent + count);
1606 ++count;
1607 } while ( u.index != 255);
1608
1609 int8_t lastSlotUsed = -1;
1610
1611
1612 u = *ent;
1613 CRGB rgbstart( u.r, u.g, u.b);
1614
1615 int indexstart = 0;
1616 uint8_t istart8 = 0;
1617 uint8_t iend8 = 0;
1618 while( indexstart < 255) {
1619 ++ent;
1620 u = *ent;
1621 int indexend = u.index;
1622 CRGB rgbend( u.r, u.g, u.b);
1623 istart8 = indexstart / 8;
1624 iend8 = indexend / 8;
1625 if( count < 16) {
1626 if( (istart8 <= lastSlotUsed) && (lastSlotUsed < 31)) {
1627 istart8 = lastSlotUsed + 1;
1628 if( iend8 < istart8) {
1629 iend8 = istart8;
1630 }
1631 }
1632 lastSlotUsed = iend8;
1633 }
1634 fill_gradient_RGB( &(entries[0]), istart8, rgbstart, iend8, rgbend);
1635 indexstart = indexend;
1636 rgbstart = rgbend;
1637 }
1638 return *this;
1639 }
1640
1641};
1642
1643
1646public:
1648
1651
1657 CRGBPalette256( const CRGB& c00,const CRGB& c01,const CRGB& c02,const CRGB& c03,
1658 const CRGB& c04,const CRGB& c05,const CRGB& c06,const CRGB& c07,
1659 const CRGB& c08,const CRGB& c09,const CRGB& c10,const CRGB& c11,
1660 const CRGB& c12,const CRGB& c13,const CRGB& c14,const CRGB& c15 )
1661 {
1662 CRGBPalette16 p16(c00,c01,c02,c03,c04,c05,c06,c07,
1663 c08,c09,c10,c11,c12,c13,c14,c15);
1664 *this = p16;
1665 };
1666
1669 {
1670 memmove8( (void *) &(entries[0]), &(rhs.entries[0]), sizeof( entries));
1671 }
1673 CRGBPalette256( const CRGB rhs[256])
1674 {
1675 memmove8( (void *) &(entries[0]), &(rhs[0]), sizeof( entries));
1676 }
1679 {
1680 memmove8( (void *) &(entries[0]), &(rhs.entries[0]), sizeof( entries));
1681 return *this;
1682 }
1685 {
1686 memmove8( (void *) &(entries[0]), &(rhs[0]), sizeof( entries));
1687 return *this;
1688 }
1689
1692 {
1693 for( int i = 0; i < 256; ++i) {
1694 entries[i] = rhs.entries[i]; // implicit HSV-to-RGB conversion
1695 }
1696 }
1698 CRGBPalette256( const CHSV rhs[256])
1699 {
1700 for( int i = 0; i < 256; ++i) {
1701 entries[i] = rhs[i]; // implicit HSV-to-RGB conversion
1702 }
1703 }
1706 {
1707 for( int i = 0; i < 256; ++i) {
1708 entries[i] = rhs.entries[i]; // implicit HSV-to-RGB conversion
1709 }
1710 return *this;
1711 }
1714 {
1715 for( int i = 0; i < 256; ++i) {
1716 entries[i] = rhs[i]; // implicit HSV-to-RGB conversion
1717 }
1718 return *this;
1719 }
1720
1723 {
1724 UpscalePalette( rhs16, *this);
1725 }
1728 {
1729 UpscalePalette( rhs16, *this);
1730 return *this;
1731 }
1732
1735 {
1736 CRGBPalette16 p16(rhs);
1737 *this = p16;
1738 }
1741 {
1742 CRGBPalette16 p16(rhs);
1743 *this = p16;
1744 return *this;
1745 }
1746
1748 bool operator==( const CRGBPalette256 &rhs) const
1749 {
1750 const uint8_t* p = (const uint8_t*)(&(this->entries[0]));
1751 const uint8_t* q = (const uint8_t*)(&(rhs.entries[0]));
1752 if( p == q) return true;
1753 for( uint16_t i = 0; i < (sizeof( entries)); ++i) {
1754 if( *p != *q) return false;
1755 ++p;
1756 ++q;
1757 }
1758 return true;
1759 }
1761 bool operator!=( const CRGBPalette256 &rhs) const
1762 {
1763 return !( *this == rhs);
1764 }
1765
1767 inline CRGB& operator[] (uint8_t x) __attribute__((always_inline))
1768 {
1769 return entries[x];
1770 }
1772 inline const CRGB& operator[] (uint8_t x) const __attribute__((always_inline))
1773 {
1774 return entries[x];
1775 }
1776
1778 inline CRGB& operator[] (int x) __attribute__((always_inline))
1779 {
1780 return entries[(uint8_t)x];
1781 }
1783 inline const CRGB& operator[] (int x) const __attribute__((always_inline))
1784 {
1785 return entries[(uint8_t)x];
1786 }
1787
1789 operator CRGB*()
1790 {
1791 return &(entries[0]);
1792 }
1793
1796 {
1797 fill_solid( &(entries[0]), 256, c1);
1798 }
1800 CRGBPalette256( const CHSV& c1, const CHSV& c2)
1801 {
1802 fill_gradient( &(entries[0]), 256, c1, c2);
1803 }
1805 CRGBPalette256( const CHSV& c1, const CHSV& c2, const CHSV& c3)
1806 {
1807 fill_gradient( &(entries[0]), 256, c1, c2, c3);
1808 }
1810 CRGBPalette256( const CHSV& c1, const CHSV& c2, const CHSV& c3, const CHSV& c4)
1811 {
1812 fill_gradient( &(entries[0]), 256, c1, c2, c3, c4);
1813 }
1814
1817 {
1818 fill_solid( &(entries[0]), 256, c1);
1819 }
1821 CRGBPalette256( const CRGB& c1, const CRGB& c2)
1822 {
1823 fill_gradient_RGB( &(entries[0]), 256, c1, c2);
1824 }
1826 CRGBPalette256( const CRGB& c1, const CRGB& c2, const CRGB& c3)
1827 {
1828 fill_gradient_RGB( &(entries[0]), 256, c1, c2, c3);
1829 }
1831 CRGBPalette256( const CRGB& c1, const CRGB& c2, const CRGB& c3, const CRGB& c4)
1832 {
1833 fill_gradient_RGB( &(entries[0]), 256, c1, c2, c3, c4);
1834 }
1835
1838 {
1839 *this = progpal;
1840 }
1843 {
1846 u.dword = FL_PGM_READ_DWORD_NEAR( progent);
1847 CRGB rgbstart( u.r, u.g, u.b);
1848
1849 int indexstart = 0;
1850 while( indexstart < 255) {
1851 ++progent;
1852 u.dword = FL_PGM_READ_DWORD_NEAR( progent);
1853 int indexend = u.index;
1854 CRGB rgbend( u.r, u.g, u.b);
1855 fill_gradient_RGB( &(entries[0]), indexstart, rgbstart, indexend, rgbend);
1856 indexstart = indexend;
1857 rgbstart = rgbend;
1858 }
1859 return *this;
1860 }
1863 {
1866 u = *ent;
1867 CRGB rgbstart( u.r, u.g, u.b);
1868
1869 int indexstart = 0;
1870 while( indexstart < 255) {
1871 ++ent;
1872 u = *ent;
1873 int indexend = u.index;
1874 CRGB rgbend( u.r, u.g, u.b);
1875 fill_gradient_RGB( &(entries[0]), indexstart, rgbstart, indexend, rgbend);
1876 indexstart = indexend;
1877 rgbstart = rgbend;
1878 }
1879 return *this;
1880 }
1881};
1882
1884
1885
1889
1891typedef enum {
1896
1907 uint8_t index,
1908 uint8_t brightness=255,
1909 TBlendType blendType=LINEARBLEND);
1910
1913 uint8_t index,
1914 uint8_t brightness=255,
1915 TBlendType blendType=LINEARBLEND);
1916
1919 uint8_t index,
1920 uint8_t brightness=255,
1921 TBlendType blendType=NOBLEND );
1922
1925 uint8_t index,
1926 uint8_t brightness=255,
1927 TBlendType blendType=LINEARBLEND);
1928
1931 uint8_t index,
1932 uint8_t brightness=255,
1933 TBlendType blendType=NOBLEND );
1934
1937 uint8_t index,
1938 uint8_t brightness=255,
1939 TBlendType blendType=LINEARBLEND);
1940
1943 uint8_t index,
1944 uint8_t brightness=255,
1945 TBlendType blendType=LINEARBLEND);
1946
1949 uint8_t index,
1950 uint8_t brightness=255,
1951 TBlendType blendType=LINEARBLEND);
1952
1953
1964template <typename PALETTE>
1965void fill_palette(CRGB* L, uint16_t N, uint8_t startIndex, uint8_t incIndex,
1966 const PALETTE& pal, uint8_t brightness=255, TBlendType blendType=LINEARBLEND)
1967{
1968 uint8_t colorIndex = startIndex;
1969 for( uint16_t i = 0; i < N; ++i) {
1970 L[i] = ColorFromPalette( pal, colorIndex, brightness, blendType);
1971 colorIndex += incIndex;
1972 }
1973}
1974
1975
1987template <typename PALETTE>
1988void fill_palette_circular(CRGB* L, uint16_t N, uint8_t startIndex,
1989 const PALETTE& pal, uint8_t brightness=255, TBlendType blendType=LINEARBLEND,
1990 bool reversed=false)
1991{
1992 if (N == 0) return; // avoiding div/0
1993
1994 const uint16_t colorChange = 65535 / N; // color change for each LED, * 256 for precision
1995 uint16_t colorIndex = ((uint16_t) startIndex) << 8; // offset for color index, with precision (*256)
1996
1997 for (uint16_t i = 0; i < N; ++i) {
1998 L[i] = ColorFromPalette(pal, (colorIndex >> 8), brightness, blendType);
1999 if (reversed) colorIndex -= colorChange;
2000 else colorIndex += colorChange;
2001 }
2002}
2003
2004
2022template <typename PALETTE>
2024 uint8_t *dataArray, uint16_t dataCount,
2025 CRGB* targetColorArray,
2026 const PALETTE& pal,
2027 uint8_t brightness=255,
2028 uint8_t opacity=255,
2029 TBlendType blendType=LINEARBLEND)
2030{
2031 for( uint16_t i = 0; i < dataCount; ++i) {
2032 uint8_t d = dataArray[i];
2033 CRGB rgb = ColorFromPalette( pal, d, brightness, blendType);
2034 if( opacity == 255 ) {
2035 targetColorArray[i] = rgb;
2036 } else {
2037 targetColorArray[i].nscale8( 256 - opacity);
2038 rgb.nscale8_video( opacity);
2039 targetColorArray[i] += rgb;
2040 }
2041 }
2042}
2043
2044
2083void nblendPaletteTowardPalette( CRGBPalette16& currentPalette,
2084 CRGBPalette16& targetPalette,
2085 uint8_t maxChanges=24);
2086
2088
2089
2134#define DEFINE_GRADIENT_PALETTE(X) \
2135 FL_ALIGN_PROGMEM \
2136 extern const TProgmemRGBGradientPalette_byte X[] FL_PROGMEM =
2137
2139#define DECLARE_GRADIENT_PALETTE(X) \
2140 FL_ALIGN_PROGMEM \
2141 extern const TProgmemRGBGradientPalette_byte X[] FL_PROGMEM
2142
2144
2145
2177
2182uint8_t applyGamma_video( uint8_t brightness, float gamma);
2183
2188CRGB applyGamma_video( const CRGB& orig, float gamma);
2189
2196CRGB applyGamma_video( const CRGB& orig, float gammaR, float gammaG, float gammaB);
2197
2198
2202CRGB& napplyGamma_video( CRGB& rgb, float gamma);
2203
2209CRGB& napplyGamma_video( CRGB& rgb, float gammaR, float gammaG, float gammaB);
2210
2215void napplyGamma_video( CRGB* rgbarray, uint16_t count, float gamma);
2216
2223void napplyGamma_video( CRGB* rgbarray, uint16_t count, float gammaR, float gammaG, float gammaB);
2224
2226
2227FASTLED_NAMESPACE_END
2228
2229#endif
central include file for FastLED, defines the CFastLED class/object
HSV color palette with 16 discrete values.
Definition colorutils.h:627
CHSVPalette16(const CHSV &c1)
Create palette filled with one color.
Definition colorutils.h:739
CHSVPalette16(const CHSVPalette16 &rhs)
Copy constructor.
Definition colorutils.h:647
CHSVPalette16(const CHSV &c00, const CHSV &c01, const CHSV &c02, const CHSV &c03, const CHSV &c04, const CHSV &c05, const CHSV &c06, const CHSV &c07, const CHSV &c08, const CHSV &c09, const CHSV &c10, const CHSV &c11, const CHSV &c12, const CHSV &c13, const CHSV &c14, const CHSV &c15)
Create palette from 16 CHSV values.
Definition colorutils.h:635
CHSVPalette16 & operator=(const TProgmemHSVPalette16 &rhs)
Create palette from palette stored in PROGMEM.
Definition colorutils.h:671
bool operator==(const CHSVPalette16 &rhs) const
Check if two palettes have the same color entries.
Definition colorutils.h:718
bool operator!=(const CHSVPalette16 &rhs) const
Check if two palettes do not have the same color entries.
Definition colorutils.h:732
CHSVPalette16(const CHSV &c1, const CHSV &c2, const CHSV &c3, const CHSV &c4)
Create palette with four-color gradient.
Definition colorutils.h:766
CHSVPalette16()
Default constructor.
Definition colorutils.h:632
CHSVPalette16(const CHSV &c1, const CHSV &c2)
Create palette with a gradient from one color to another.
Definition colorutils.h:747
CHSV entries[16]
the color entries that make up the palette
Definition colorutils.h:629
CHSVPalette16 & operator=(const CHSVPalette16 &rhs)
Copy constructor.
Definition colorutils.h:653
CHSVPalette16(const CHSV &c1, const CHSV &c2, const CHSV &c3)
Create palette with three-color gradient.
Definition colorutils.h:756
CHSVPalette16(const TProgmemHSVPalette16 &rhs)
Create palette from palette stored in PROGMEM.
Definition colorutils.h:660
CHSV & operator[](uint8_t x)
Array access operator to index into the gradient entries.
Definition colorutils.h:688
HSV color palette with 256 discrete values.
Definition colorutils.h:774
CHSV & operator[](uint8_t x)
Array access operator to index into the gradient entries.
Definition colorutils.h:834
CHSVPalette256()
Default constructor.
Definition colorutils.h:779
CHSVPalette256(const CHSV &c1, const CHSV &c2, const CHSV &c3, const CHSV &c4)
Create palette with four-color gradient.
Definition colorutils.h:897
CHSVPalette256 & operator=(const CHSVPalette256 &rhs)
Copy constructor.
Definition colorutils.h:801
CHSVPalette256(const CHSV &c1)
Create palette filled with one color.
Definition colorutils.h:882
CHSVPalette256(const CHSV &c00, const CHSV &c01, const CHSV &c02, const CHSV &c03, const CHSV &c04, const CHSV &c05, const CHSV &c06, const CHSV &c07, const CHSV &c08, const CHSV &c09, const CHSV &c10, const CHSV &c11, const CHSV &c12, const CHSV &c13, const CHSV &c14, const CHSV &c15)
Create palette from 16 CHSV values.
Definition colorutils.h:785
CHSV entries[256]
the color entries that make up the palette
Definition colorutils.h:776
CHSVPalette256(const CHSVPalette16 &rhs16)
Create upscaled palette from 16-entry palette.
Definition colorutils.h:808
CHSVPalette256(const CHSV &c1, const CHSV &c2, const CHSV &c3)
Create palette with three-color gradient.
Definition colorutils.h:892
CHSVPalette256(const CHSVPalette256 &rhs)
Copy constructor.
Definition colorutils.h:796
CHSVPalette256 & operator=(const TProgmemRGBPalette16 &rhs)
Create palette from palette stored in PROGMEM.
Definition colorutils.h:826
CHSVPalette256(const CHSV &c1, const CHSV &c2)
Create palette with a gradient from one color to another.
Definition colorutils.h:887
bool operator!=(const CHSVPalette256 &rhs) const
Check if two palettes do not have the same color entries.
Definition colorutils.h:876
bool operator==(const CHSVPalette256 &rhs) const
Check if two palettes have the same color entries.
Definition colorutils.h:862
CHSVPalette256 & operator=(const CHSVPalette16 &rhs16)
Create upscaled palette from 16-entry palette.
Definition colorutils.h:813
CHSVPalette256(const TProgmemRGBPalette16 &rhs)
Create palette from palette stored in PROGMEM.
Definition colorutils.h:820
HSV color palette with 32 discrete values.
CHSV entries[32]
the color entries that make up the palette
CHSVPalette32(const TProgmemHSVPalette32 &rhs)
Create palette from palette stored in PROGMEM.
bool operator!=(const CHSVPalette32 &rhs) const
Check if two palettes do not have the same color entries.
CHSVPalette32(const CHSVPalette32 &rhs)
Copy constructor.
CHSVPalette32(const CHSV &c00, const CHSV &c01, const CHSV &c02, const CHSV &c03, const CHSV &c04, const CHSV &c05, const CHSV &c06, const CHSV &c07, const CHSV &c08, const CHSV &c09, const CHSV &c10, const CHSV &c11, const CHSV &c12, const CHSV &c13, const CHSV &c14, const CHSV &c15)
Create palette from 16 CHSV values.
CHSVPalette32 & operator=(const CHSVPalette32 &rhs)
Copy constructor.
CHSVPalette32(const CHSV &c1, const CHSV &c2)
Create palette with a gradient from one color to another.
CHSVPalette32()
Default constructor.
bool operator==(const CHSVPalette32 &rhs) const
Check if two palettes have the same color entries.
CHSVPalette32(const CHSV &c1, const CHSV &c2, const CHSV &c3)
Create palette with three-color gradient.
CHSVPalette32(const CHSV &c1, const CHSV &c2, const CHSV &c3, const CHSV &c4)
Create palette with four-color gradient.
CHSVPalette32 & operator=(const TProgmemHSVPalette32 &rhs)
Create palette from palette stored in PROGMEM.
CHSV & operator[](uint8_t x)
Create palette from palette stored in PROGMEM.
CHSVPalette32(const CHSV &c1)
Create palette filled with one color.
RGB color palette with 16 discrete values.
Definition colorutils.h:904
CRGBPalette16(const CHSV &c1)
Create palette filled with one color.
CRGBPalette16(const CRGB &c1, const CRGB &c2)
Create palette with a gradient from one color to another.
CRGB entries[16]
the color entries that make up the palette
Definition colorutils.h:906
CRGBPalette16(const TProgmemRGBPalette16 &rhs)
Create palette from palette stored in PROGMEM.
Definition colorutils.h:978
bool operator!=(const CRGBPalette16 &rhs) const
Check if two palettes do not have the same color entries.
CRGBPalette16 & operator=(const CHSV rhs[16])
Create palette from array of CHSV colors.
Definition colorutils.h:969
CRGBPalette16(const CHSV &c1, const CHSV &c2, const CHSV &c3, const CHSV &c4)
Create palette with four-color gradient.
CRGBPalette16(const CHSV rhs[16])
Create palette from array of CHSV colors.
Definition colorutils.h:954
bool operator==(const CRGBPalette16 &rhs) const
Check if two palettes have the same color entries.
Definition colorutils.h:994
CRGBPalette16(const CRGB &c00, const CRGB &c01, const CRGB &c02, const CRGB &c03, const CRGB &c04, const CRGB &c05, const CRGB &c06, const CRGB &c07, const CRGB &c08, const CRGB &c09, const CRGB &c10, const CRGB &c11, const CRGB &c12, const CRGB &c13, const CRGB &c14, const CRGB &c15)
Create palette from 16 CRGB values.
Definition colorutils.h:912
CRGBPalette16(const CRGB &c1, const CRGB &c2, const CRGB &c3)
Create palette with three-color gradient.
CRGBPalette16 & operator=(const CRGBPalette16 &rhs)
Copy constructor.
Definition colorutils.h:934
CRGBPalette16(const CHSVPalette16 &rhs)
Create palette from CHSV palette.
Definition colorutils.h:947
CRGBPalette16(const CHSV &c1, const CHSV &c2, const CHSV &c3)
Create palette with three-color gradient.
CRGBPalette16(TProgmemRGBGradientPalette_bytes progpal)
Creates a palette from a gradient palette in PROGMEM.
CRGBPalette16 & operator=(const CHSVPalette16 &rhs)
Create palette from CHSV palette.
Definition colorutils.h:961
CRGBPalette16 & operator=(const TProgmemRGBPalette16 &rhs)
Create palette from palette stored in PROGMEM.
Definition colorutils.h:985
CRGBPalette16(const CRGB rhs[16])
Create palette from array of CRGB colors.
Definition colorutils.h:929
CRGBPalette16(const CHSV &c1, const CHSV &c2)
Create palette with a gradient from one color to another.
CRGBPalette16(const CRGBPalette16 &rhs)
Copy constructor.
Definition colorutils.h:924
CRGBPalette16 & operator=(const CRGB rhs[16])
Create palette from array of CRGB colors.
Definition colorutils.h:940
CRGB & operator[](uint8_t x)
Array access operator to index into the gradient entries.
CRGBPalette16 & loadDynamicGradientPalette(TDynamicRGBGradientPalette_bytes gpal)
Creates a palette from a gradient palette in dynamic (heap) memory.
CRGBPalette16(const CRGB &c1)
Create palette filled with one color.
CRGBPalette16(const CRGB &c1, const CRGB &c2, const CRGB &c3, const CRGB &c4)
Create palette with four-color gradient.
CRGBPalette16()
Default constructor.
Definition colorutils.h:909
CRGBPalette16 & operator=(TProgmemRGBGradientPalette_bytes progpal)
Creates a palette from a gradient palette in PROGMEM.
RGB color palette with 256 discrete values.
CRGBPalette256(const CRGBPalette16 &rhs16)
Create upscaled palette from 16-entry palette.
CRGBPalette256(const CHSV &c1, const CHSV &c2, const CHSV &c3, const CHSV &c4)
Create palette with four-color gradient.
CRGBPalette256(const TProgmemRGBPalette16 &rhs)
Create palette from palette stored in PROGMEM.
CRGBPalette256(const CRGB &c1, const CRGB &c2)
Create palette with a gradient from one color to another.
CRGBPalette256 & operator=(const CHSV rhs[256])
Create palette from array of CHSV colors.
CRGB entries[256]
the color entries that make up the palette
bool operator!=(const CRGBPalette256 &rhs) const
Check if two palettes do not have the same color entries.
CRGBPalette256(const CRGB &c00, const CRGB &c01, const CRGB &c02, const CRGB &c03, const CRGB &c04, const CRGB &c05, const CRGB &c06, const CRGB &c07, const CRGB &c08, const CRGB &c09, const CRGB &c10, const CRGB &c11, const CRGB &c12, const CRGB &c13, const CRGB &c14, const CRGB &c15)
Create palette from 16 CRGB values.
CRGBPalette256(const CRGB &c1, const CRGB &c2, const CRGB &c3, const CRGB &c4)
Create palette with four-color gradient.
CRGBPalette256(const CHSVPalette256 &rhs)
Create palette from CHSV palette.
CRGBPalette256 & loadDynamicGradientPalette(TDynamicRGBGradientPalette_bytes gpal)
Creates a palette from a gradient palette in dynamic (heap) memory.
CRGBPalette256 & operator=(TProgmemRGBGradientPalette_bytes progpal)
Creates a palette from a gradient palette in PROGMEM.
CRGBPalette256 & operator=(const CRGBPalette256 &rhs)
Copy constructor.
CRGBPalette256 & operator=(const CRGBPalette16 &rhs16)
Create upscaled palette from 16-entry palette.
CRGBPalette256(const CHSV &c1, const CHSV &c2)
Create palette with a gradient from one color to another.
CRGBPalette256(const CHSV rhs[256])
Create palette from array of CHSV colors.
CRGBPalette256(const CHSV &c1)
Create palette filled with one color.
CRGBPalette256(const CRGB rhs[256])
Create palette from array of CRGB colors.
CRGBPalette256(const CRGBPalette256 &rhs)
Copy constructor.
CRGBPalette256 & operator=(const CHSVPalette256 &rhs)
Copy constructor.
CRGBPalette256(const CRGB &c1, const CRGB &c2, const CRGB &c3)
Create palette with three-color gradient.
bool operator==(const CRGBPalette256 &rhs) const
Check if two palettes have the same color entries.
CRGBPalette256()
Default constructor.
CRGBPalette256 & operator=(const CRGB rhs[256])
Create palette from array of CRGB colors.
CRGBPalette256(TProgmemRGBGradientPalette_bytes progpal)
Creates a palette from a gradient palette in PROGMEM.
CRGB & operator[](uint8_t x)
Array access operator to index into the gradient entries.
CRGBPalette256(const CHSV &c1, const CHSV &c2, const CHSV &c3)
Create palette with three-color gradient.
CRGBPalette256(const CRGB &c1)
Create palette filled with one color.
CRGBPalette256 & operator=(const TProgmemRGBPalette16 &rhs)
Create palette from palette stored in PROGMEM.
RGB color palette with 32 discrete values.
CRGBPalette32(const CHSV &c1, const CHSV &c2, const CHSV &c3)
Create palette with three-color gradient.
CRGBPalette32(const TProgmemRGBPalette16 &rhs)
Create palette from palette stored in PROGMEM.
bool operator!=(const CRGBPalette32 &rhs) const
Check if two palettes do not have the same color entries.
CRGBPalette32(const CHSV &c1)
Create palette filled with one color.
CRGBPalette32()
Default constructor.
CRGBPalette32 & operator=(const CRGBPalette32 &rhs)
Copy constructor.
bool operator==(const CRGBPalette32 &rhs) const
Check if two palettes have the same color entries.
CRGBPalette32(const CRGB rhs[32])
Create palette from array of CRGB colors.
CRGBPalette32(const CHSV &c1, const CHSV &c2)
Create palette with a gradient from one color to another.
CRGBPalette32(const CRGB &c1, const CRGB &c2, const CRGB &c3)
Create palette with three-color gradient.
CRGBPalette32(const CRGB &c1)
Create palette filled with one color.
CRGBPalette32 & operator=(const CHSVPalette32 &rhs)
Create palette from CHSV palette.
CRGBPalette32 & loadDynamicGradientPalette(TDynamicRGBGradientPalette_bytes gpal)
Creates a palette from a gradient palette in dynamic (heap) memory.
CRGBPalette32(const CRGBPalette32 &rhs)
Copy constructor.
CRGBPalette32(const TProgmemRGBPalette32 &rhs)
Create palette from palette stored in PROGMEM.
CRGBPalette32 & operator=(const CHSV rhs[32])
Create palette from array of CHSV colors.
CRGBPalette32 & operator=(const CRGB rhs[32])
Create palette from array of CRGB colors.
CRGBPalette32 & operator=(const CRGBPalette16 &rhs16)
Create upscaled palette from 16-entry palette.
CRGBPalette32(const CHSV &c1, const CHSV &c2, const CHSV &c3, const CHSV &c4)
Create palette with four-color gradient.
CRGBPalette32(const CRGBPalette16 &rhs16)
Create upscaled palette from 16-entry palette.
CRGBPalette32 & operator=(const TProgmemRGBPalette32 &rhs)
Create palette from palette stored in PROGMEM.
CRGB & operator[](uint8_t x)
Array access operator to index into the gradient entries.
CRGBPalette32 & operator=(TProgmemRGBGradientPalette_bytes progpal)
Creates a palette from a gradient palette in PROGMEM.
CRGBPalette32(const CRGB &c1, const CRGB &c2, const CRGB &c3, const CRGB &c4)
Create palette with four-color gradient.
CRGBPalette32(const CHSV rhs[32])
Create palette from array of CHSV colors.
CRGBPalette32(const CRGB &c00, const CRGB &c01, const CRGB &c02, const CRGB &c03, const CRGB &c04, const CRGB &c05, const CRGB &c06, const CRGB &c07, const CRGB &c08, const CRGB &c09, const CRGB &c10, const CRGB &c11, const CRGB &c12, const CRGB &c13, const CRGB &c14, const CRGB &c15)
Create palette from 16 CRGB values.
CRGB entries[32]
the color entries that make up the palette
CRGBPalette32(const CHSVPalette32 &rhs)
Create palette from CHSV palette.
CRGBPalette32(TProgmemRGBGradientPalette_bytes progpal)
Creates a palette from a gradient palette in PROGMEM.
CRGBPalette32(const CRGB &c1, const CRGB &c2)
Create palette with a gradient from one color to another.
CRGBPalette32 & operator=(const TProgmemRGBPalette16 &rhs)
Create palette from palette stored in PROGMEM.
Template class for representing fractional ints.
Definition lib8tion.h:899
Wrapper definitions to allow seamless use of PROGMEM in environments that have it.
CRGB & nblend(CRGB &existing, const CRGB &overlay, fract8 amountOfOverlay)
Destructively modifies one color, blending in a given fraction of an overlay color.
CRGB blend(const CRGB &p1, const CRGB &p2, fract8 amountOfP2)
Computes a new color blended some fraction of the way between two other colors.
void blurRows(CRGB *leds, uint8_t width, uint8_t height, fract8 blur_amount)
Perform a blur1d() on every row of a rectangular matrix.
void blur1d(CRGB *leds, uint16_t numLeds, fract8 blur_amount)
One-dimensional blur filter.
void blurColumns(CRGB *leds, uint8_t width, uint8_t height, fract8 blur_amount)
Perform a blur1d() on every column of a rectangular matrix.
void blur2d(CRGB *leds, uint8_t width, uint8_t height, fract8 blur_amount)
Two-dimensional blur filter.
void fadeToBlackBy(CRGB *leds, uint16_t num_leds, uint8_t fadeBy)
Reduce the brightness of an array of pixels all at once.
void nscale8_video(CRGB *leds, uint16_t num_leds, uint8_t scale)
Scale the brightness of an array of pixels all at once.
void fade_raw(CRGB *leds, uint16_t num_leds, uint8_t fadeBy)
Reduce the brightness of an array of pixels all at once.
void fadeLightBy(CRGB *leds, uint16_t num_leds, uint8_t fadeBy)
Reduce the brightness of an array of pixels all at once.
void nscale8(CRGB *leds, uint16_t num_leds, uint8_t scale)
Scale the brightness of an array of pixels all at once.
void fadeUsingColor(CRGB *leds, uint16_t numLeds, const CRGB &colormask)
Reduce the brightness of an array of pixels as thought it were seen through a transparent filter with...
void fade_video(CRGB *leds, uint16_t num_leds, uint8_t fadeBy)
Reduce the brightness of an array of pixels all at once.
TGradientDirectionCode
Hue direction for calculating fill gradients.
Definition colorutils.h:69
void fill_rainbow(struct CRGB *targetArray, int numToFill, uint8_t initialhue, uint8_t deltahue=5)
Fill a range of LEDs with a rainbow of colors.
void fill_gradient(T *targetArray, uint16_t startpos, CHSV startcolor, uint16_t endpos, CHSV endcolor, TGradientDirectionCode directionCode=SHORTEST_HUES)
Fill a range of LEDs with a smooth HSV gradient between two HSV colors.
Definition colorutils.h:98
#define saccum87
ANSI: signed short _Accum.
Definition colorutils.h:79
void fill_gradient_RGB(CRGB *leds, uint16_t startpos, CRGB startcolor, uint16_t endpos, CRGB endcolor)
Fill a range of LEDs with a smooth RGB gradient between two RGB colors.
void fill_rainbow_circular(struct CRGB *targetArray, int numToFill, uint8_t initialhue, bool reversed=false)
Fill a range of LEDs with a rainbow of colors, so that the hues are continuous between the end of the...
void fill_solid(struct CRGB *targetArray, int numToFill, const struct CRGB &color)
Fill a range of LEDs with a solid color.
CRGB HeatColor(uint8_t temperature)
Approximates a "black body radiation" spectrum for a given "heat" level.
@ LONGEST_HUES
Hue goes whichever way is longest.
Definition colorutils.h:73
@ FORWARD_HUES
Hue always goes clockwise around the color wheel.
Definition colorutils.h:70
@ SHORTEST_HUES
Hue goes whichever way is shortest.
Definition colorutils.h:72
@ BACKWARD_HUES
Hue always goes counter-clockwise around the color wheel.
Definition colorutils.h:71
void * memmove8(void *dst, const void *src, uint16_t num)
Faster alternative to memmove() on AVR.
uint16_t accum88
ANSI: unsigned short _Accum. 8 bits int, 8 bits fraction.
Definition lib8tion.h:420
uint8_t fract8
ANSI: unsigned short _Fract.
Definition lib8tion.h:402
CRGB & napplyGamma_video(CRGB &rgb, float gamma)
Destructively applies a gamma adjustment to a color.
uint8_t applyGamma_video(uint8_t brightness, float gamma)
Applies a gamma adjustment to a color channel.
uint32_t TProgmemRGBPalette32[32]
CRGBPalette32 entries stored in PROGMEM memory.
Definition colorutils.h:559
uint32_t TProgmemRGBPalette16[16]
CRGBPalette16 entries stored in PROGMEM memory.
Definition colorutils.h:555
uint32_t TProgmemHSVPalette32[32]
CHSVPalette32 entries stored in PROGMEM memory.
Definition colorutils.h:560
const TProgmemRGBGradientPalette_byte * TProgmemRGBGradientPalette_bytes
Pointer to bytes of an RGB gradient, stored in PROGMEM memory.
Definition colorutils.h:569
const uint8_t TProgmemRGBGradientPalette_byte
Byte of an RGB gradient, stored in PROGMEM memory.
Definition colorutils.h:565
uint32_t TProgmemHSVPalette16[16]
CHSVPalette16 entries stored in PROGMEM memory.
Definition colorutils.h:556
TDynamicRGBGradientPalette_bytes TDynamicRGBGradientPalettePtr
Alias of TDynamicRGBGradientPalette_bytes.
Definition colorutils.h:590
uint8_t TDynamicRGBGradientPalette_byte
Byte of an RGB gradient entry, stored in dynamic (heap) memory.
Definition colorutils.h:588
TProgmemRGBGradientPalette_bytes TProgmemRGBGradientPalettePtr
Alias of TProgmemRGBGradientPalette_bytes.
Definition colorutils.h:571
const TDynamicRGBGradientPalette_byte * TDynamicRGBGradientPalette_bytes
Pointer to bytes of an RGB gradient, stored in dynamic (heap) memory.
Definition colorutils.h:589
void fill_palette_circular(CRGB *L, uint16_t N, uint8_t startIndex, const PALETTE &pal, uint8_t brightness=255, TBlendType blendType=LINEARBLEND, bool reversed=false)
Fill a range of LEDs with a sequence of entries from a palette, so that the entire palette smoothly c...
void nblendPaletteTowardPalette(CRGBPalette16 &currentPalette, CRGBPalette16 &targetPalette, uint8_t maxChanges=24)
Alter one palette by making it slightly more like a "target palette".
TBlendType
Color interpolation options for palette.
void fill_palette(CRGB *L, uint16_t N, uint8_t startIndex, uint8_t incIndex, const PALETTE &pal, uint8_t brightness=255, TBlendType blendType=LINEARBLEND)
Fill a range of LEDs with a sequence of entries from a palette.
CRGB ColorFromPalette(const CRGBPalette16 &pal, uint8_t index, uint8_t brightness=255, TBlendType blendType=LINEARBLEND)
Get a color from a palette.
void map_data_into_colors_through_palette(uint8_t *dataArray, uint16_t dataCount, CRGB *targetColorArray, const PALETTE &pal, uint8_t brightness=255, uint8_t opacity=255, TBlendType blendType=LINEARBLEND)
Maps an array of palette color indexes into an array of LED colors.
@ NOBLEND
No interpolation between palette entries.
@ LINEARBLEND
Linear interpolation between palette entries, with wrap-around from end to the beginning again.
@ LINEARBLEND_NOWRAP
Linear interpolation between palette entries, but no wrap-around.
void UpscalePalette(const struct CRGBPalette16 &srcpal16, struct CRGBPalette256 &destpal256)
Convert a 16-entry palette to a 256-entry palette.
Definitions for pixel color data structs.
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Definition pixeltypes.h:27
uint8_t hue
Color hue.
Definition pixeltypes.h:34
uint8_t sat
Color saturation.
Definition pixeltypes.h:41
uint8_t value
Color value (brightness).
Definition pixeltypes.h:47
uint8_t saturation
Color saturation.
Definition pixeltypes.h:40
uint8_t val
Color value (brightness).
Definition pixeltypes.h:48
Representation of an RGB pixel (Red, Green, Blue)
Definition pixeltypes.h:120
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 & 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 red
Red channel value.
Definition pixeltypes.h:125
uint8_t blue
Blue channel value.
Definition pixeltypes.h:133
uint8_t green
Green channel value.
Definition pixeltypes.h:129
Struct for digesting gradient pointer data into its components.
Definition colorutils.h:577
uint8_t g
CRGB::green channel value of the color entry.
Definition colorutils.h:581
uint32_t dword
values as a packed 32-bit double word
Definition colorutils.h:584
uint8_t b
CRGB::blue channel value of the color entry.
Definition colorutils.h:582
uint8_t index
index of the color entry in the gradient
Definition colorutils.h:579
uint8_t r
CRGB::red channel value of the color entry.
Definition colorutils.h:580