Fill a range of LEDs with a smooth HSV gradient between two HSV colors.
79 {
80
81 if (endpos < startpos) {
82 uint16_t t = endpos;
84 endcolor = startcolor;
85 endpos = startpos;
86 startpos = t;
87 startcolor = tc;
88 }
89
90
91
92
93
94 if (endcolor.value == 0 || endcolor.saturation == 0) {
95 endcolor.hue = startcolor.hue;
96 }
97
98
99
100
101
102 if (startcolor.value == 0 || startcolor.saturation == 0) {
103 startcolor.hue = endcolor.hue;
104 }
105
109
110 satdistance87 = (endcolor.sat - startcolor.sat) << 7;
111 valdistance87 = (endcolor.val - startcolor.val) << 7;
112
113 uint8_t huedelta8 = endcolor.hue - startcolor.hue;
114
115 if (directionCode == SHORTEST_HUES) {
117 if (huedelta8 > 127) {
119 }
120 }
121
122 if (directionCode == LONGEST_HUES) {
124 if (huedelta8 < 128) {
126 }
127 }
128
129 if (directionCode == FORWARD_HUES) {
130 huedistance87 = huedelta8 << 7;
131 } else
132 {
133 huedistance87 = (uint8_t)(256 - huedelta8) << 7;
134 huedistance87 = -huedistance87;
135 }
136
137 uint16_t pixeldistance = endpos - startpos;
138 int16_t divisor = pixeldistance ? pixeldistance : 1;
139
140#if FASTLED_USE_32_BIT_GRADIENT_FILL
141
142 int32_t huedelta823 = (huedistance87 * 65536) / divisor;
143 int32_t satdelta823 = (satdistance87 * 65536) / divisor;
144 int32_t valdelta823 = (valdistance87 * 65536) / divisor;
145
146 huedelta823 *= 2;
147 satdelta823 *= 2;
148 valdelta823 *= 2;
149 uint32_t hue824 = static_cast<uint32_t>(startcolor.hue) << 24;
150 uint32_t sat824 = static_cast<uint32_t>(startcolor.sat) << 24;
151 uint32_t val824 = static_cast<uint32_t>(startcolor.val) << 24;
152 for (uint16_t i = startpos; i <= endpos; ++i) {
153 targetArray[i] =
CHSV(hue824 >> 24, sat824 >> 24, val824 >> 24);
154 hue824 += huedelta823;
155 sat824 += satdelta823;
156 val824 += valdelta823;
157 }
158#else
159
160 saccum87 huedelta87 = huedistance87 / divisor;
161 saccum87 satdelta87 = satdistance87 / divisor;
162 saccum87 valdelta87 = valdistance87 / divisor;
163
164 huedelta87 *= 2;
165 satdelta87 *= 2;
166 valdelta87 *= 2;
167
168 accum88 hue88 = startcolor.hue << 8;
169 accum88 sat88 = startcolor.sat << 8;
170 accum88 val88 = startcolor.val << 8;
171 for (uint16_t i = startpos; i <= endpos; ++i) {
172 targetArray[i] =
CHSV(hue88 >> 8, sat88 >> 8, val88 >> 8);
173 hue88 += huedelta87;
174 sat88 += satdelta87;
175 val88 += valdelta87;
176 }
177#endif
178}
#define saccum87
ANSI: signed short _Accum.
uint16_t accum88
ANSI: unsigned short _Accum. 8 bits int, 8 bits fraction.
@ FORWARD_HUES
Hue always goes clockwise around the color wheel.
@ BACKWARD_HUES
Hue always goes counter-clockwise around the color wheel.
Representation of an HSV pixel (hue, saturation, value (aka brightness)).