FastLED 3.10.6
Loading...
Searching...
No Matches

◆ nblend() [1/4]

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

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

158 {
159 if (amountOfOverlay == 0) {
160 return existing;
161 }
162
163 if (amountOfOverlay == 255) {
164 existing = overlay;
165 return existing;
166 }
167
168 fract8 amountOfKeep = 255 - amountOfOverlay;
169
170 fl::u8 huedelta8 = overlay.hue - existing.hue;
171
172 if (directionCode == SHORTEST_HUES) {
173 directionCode = FORWARD_HUES;
174 if (huedelta8 > 127) {
175 directionCode = BACKWARD_HUES;
176 }
177 }
178
179 if (directionCode == LONGEST_HUES) {
180 directionCode = FORWARD_HUES;
181 if (huedelta8 < 128) {
182 directionCode = BACKWARD_HUES;
183 }
184 }
185
186 if (directionCode == FORWARD_HUES) {
187 existing.hue = existing.hue + scale8(huedelta8, amountOfOverlay);
188 } else /* directionCode == BACKWARD_HUES */
189 {
190 huedelta8 = -huedelta8;
191 existing.hue = existing.hue - scale8(huedelta8, amountOfOverlay);
192 }
193
194 existing.sat = scale8_LEAVING_R1_DIRTY(existing.sat, amountOfKeep) +
195 scale8_LEAVING_R1_DIRTY(overlay.sat, amountOfOverlay);
196 existing.val = scale8_LEAVING_R1_DIRTY(existing.val, amountOfKeep) +
197 scale8_LEAVING_R1_DIRTY(overlay.val, amountOfOverlay);
198
199 cleanup_R1();
200
201 return existing;
202}
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, FORWARD_HUES, LONGEST_HUES, and SHORTEST_HUES.