FastLED 3.10.8
Loading...
Searching...
No Matches

◆ nblend() [1/4]

CHSV & fl::nblend ( CHSV & existing,
const CHSV & overlay,
fract8 amountOfOverlay,
TGradientDirectionCode directionCode )

Definition at line 158 of file colorutils.cpp.hpp.

159 {
160 if (amountOfOverlay == 0) {
161 return existing;
162 }
163
164 if (amountOfOverlay == 255) {
165 existing = overlay;
166 return existing;
167 }
168
169 fract8 amountOfKeep = 255 - amountOfOverlay;
170
171 fl::u8 huedelta8 = overlay.hue - existing.hue;
172
173 if (directionCode == SHORTEST_HUES) {
174 directionCode = FORWARD_HUES;
175 if (huedelta8 > 127) {
176 directionCode = BACKWARD_HUES;
177 }
178 }
179
180 if (directionCode == LONGEST_HUES) {
181 directionCode = FORWARD_HUES;
182 if (huedelta8 < 128) {
183 directionCode = BACKWARD_HUES;
184 }
185 }
186
187 if (directionCode == FORWARD_HUES) {
188 existing.hue = existing.hue + scale8(huedelta8, amountOfOverlay);
189 } else /* directionCode == BACKWARD_HUES */
190 {
191 huedelta8 = -huedelta8;
192 existing.hue = existing.hue - scale8(huedelta8, amountOfOverlay);
193 }
194
195 existing.sat = scale8_LEAVING_R1_DIRTY(existing.sat, amountOfKeep) +
196 scale8_LEAVING_R1_DIRTY(overlay.sat, amountOfOverlay);
197 existing.val = scale8_LEAVING_R1_DIRTY(existing.val, amountOfKeep) +
198 scale8_LEAVING_R1_DIRTY(overlay.val, amountOfOverlay);
199
200 cleanup_R1();
201
202 return existing;
203}
unsigned char u8
Definition stdint.h:131
@ SHORTEST_HUES
Hue goes whichever way is shortest.
@ LONGEST_HUES
Hue goes whichever way is longest.
@ FORWARD_HUES
Hue always goes clockwise around the color wheel.
@ BACKWARD_HUES
Hue always goes counter-clockwise around the color wheel.
u8 fract8
Fixed-Point Fractional Types.
Definition stdint.h:160

References BACKWARD_HUES, FL_NO_EXCEPT, FORWARD_HUES, LONGEST_HUES, and SHORTEST_HUES.