FastLED 3.9.15
Loading...
Searching...
No Matches

◆ nblend() [1/4]

CHSV & nblend ( CHSV & existing,
const CHSV & overlay,
fract8 amountOfOverlay,
TGradientDirectionCode directionCode = SHORTEST_HUES )

Destructively modifies one color, blending in a given fraction of an overlay color.

Parameters
existingthe color to modify
overlaythe color to blend into existing
amountOfOverlaythe fraction of overlay to blend into existing
directionCodethe direction to travel around the color wheel

Definition at line 364 of file colorutils.cpp.

365{
366 if( amountOfOverlay == 0) {
367 return existing;
368 }
369
370 if( amountOfOverlay == 255) {
371 existing = overlay;
372 return existing;
373 }
374
375 fract8 amountOfKeep = 255 - amountOfOverlay;
376
377 uint8_t huedelta8 = overlay.hue - existing.hue;
378
379 if( directionCode == SHORTEST_HUES ) {
380 directionCode = FORWARD_HUES;
381 if( huedelta8 > 127) {
382 directionCode = BACKWARD_HUES;
383 }
384 }
385
386 if( directionCode == LONGEST_HUES ) {
387 directionCode = FORWARD_HUES;
388 if( huedelta8 < 128) {
389 directionCode = BACKWARD_HUES;
390 }
391 }
392
393 if( directionCode == FORWARD_HUES) {
394 existing.hue = existing.hue + scale8( huedelta8, amountOfOverlay);
395 }
396 else /* directionCode == BACKWARD_HUES */
397 {
398 huedelta8 = -huedelta8;
399 existing.hue = existing.hue - scale8( huedelta8, amountOfOverlay);
400 }
401
402 existing.sat = scale8_LEAVING_R1_DIRTY( existing.sat, amountOfKeep)
403 + scale8_LEAVING_R1_DIRTY( overlay.sat, amountOfOverlay);
404 existing.val = scale8_LEAVING_R1_DIRTY( existing.val, amountOfKeep)
405 + scale8_LEAVING_R1_DIRTY( overlay.val, amountOfOverlay);
406
407 cleanup_R1();
408
409 return existing;
410}
@ LONGEST_HUES
Hue goes whichever way is longest.
Definition colorutils.h:164
@ FORWARD_HUES
Hue always goes clockwise around the color wheel.
Definition colorutils.h:161
@ SHORTEST_HUES
Hue goes whichever way is shortest.
Definition colorutils.h:163
@ BACKWARD_HUES
Hue always goes counter-clockwise around the color wheel.
Definition colorutils.h:162
uint8_t fract8
ANSI: unsigned short _Fract.
Definition types.h:36
LIB8STATIC_ALWAYS_INLINE void cleanup_R1()
Clean up the r1 register after a series of *LEAVING_R1_DIRTY calls.
Definition scale8.h:333
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:170
LIB8STATIC_ALWAYS_INLINE uint8_t scale8(uint8_t i, fract8 scale)
Scale one byte by a second one, which is treated as the numerator of a fraction whose denominator is ...
Definition scale8.h:34

References BACKWARD_HUES, cleanup_R1(), FORWARD_HUES, LONGEST_HUES, scale8(), scale8_LEAVING_R1_DIRTY(), and SHORTEST_HUES.

+ Here is the call graph for this function: