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

◆ nblend() [1/4]

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

Definition at line 74 of file colorutils.cpp.

75 {
76 if (amountOfOverlay == 0) {
77 return existing;
78 }
79
80 if (amountOfOverlay == 255) {
81 existing = overlay;
82 return existing;
83 }
84
85 fract8 amountOfKeep = 255 - amountOfOverlay;
86
87 uint8_t huedelta8 = overlay.hue - existing.hue;
88
89 if (directionCode == SHORTEST_HUES) {
90 directionCode = FORWARD_HUES;
91 if (huedelta8 > 127) {
92 directionCode = BACKWARD_HUES;
93 }
94 }
95
96 if (directionCode == LONGEST_HUES) {
97 directionCode = FORWARD_HUES;
98 if (huedelta8 < 128) {
99 directionCode = BACKWARD_HUES;
100 }
101 }
102
103 if (directionCode == FORWARD_HUES) {
104 existing.hue = existing.hue + scale8(huedelta8, amountOfOverlay);
105 } else /* directionCode == BACKWARD_HUES */
106 {
107 huedelta8 = -huedelta8;
108 existing.hue = existing.hue - scale8(huedelta8, amountOfOverlay);
109 }
110
111 existing.sat = scale8_LEAVING_R1_DIRTY(existing.sat, amountOfKeep) +
112 scale8_LEAVING_R1_DIRTY(overlay.sat, amountOfOverlay);
113 existing.val = scale8_LEAVING_R1_DIRTY(existing.val, amountOfKeep) +
114 scale8_LEAVING_R1_DIRTY(overlay.val, amountOfOverlay);
115
116 cleanup_R1();
117
118 return existing;
119}
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:339
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:176
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:40
@ 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.

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: