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 75 of file colorutils.cpp.

76 {
77 if (amountOfOverlay == 0) {
78 return existing;
79 }
80
81 if (amountOfOverlay == 255) {
82 existing = overlay;
83 return existing;
84 }
85
86 fract8 amountOfKeep = 255 - amountOfOverlay;
87
88 fl::u8 huedelta8 = overlay.hue - existing.hue;
89
90 if (directionCode == SHORTEST_HUES) {
91 directionCode = FORWARD_HUES;
92 if (huedelta8 > 127) {
93 directionCode = BACKWARD_HUES;
94 }
95 }
96
97 if (directionCode == LONGEST_HUES) {
98 directionCode = FORWARD_HUES;
99 if (huedelta8 < 128) {
100 directionCode = BACKWARD_HUES;
101 }
102 }
103
104 if (directionCode == FORWARD_HUES) {
105 existing.hue = existing.hue + scale8(huedelta8, amountOfOverlay);
106 } else /* directionCode == BACKWARD_HUES */
107 {
108 huedelta8 = -huedelta8;
109 existing.hue = existing.hue - scale8(huedelta8, amountOfOverlay);
110 }
111
112 existing.sat = scale8_LEAVING_R1_DIRTY(existing.sat, amountOfKeep) +
113 scale8_LEAVING_R1_DIRTY(overlay.sat, amountOfOverlay);
114 existing.val = scale8_LEAVING_R1_DIRTY(existing.val, amountOfKeep) +
115 scale8_LEAVING_R1_DIRTY(overlay.val, amountOfOverlay);
116
117 cleanup_R1();
118
119 return existing;
120}
LIB8STATIC_ALWAYS_INLINE void cleanup_R1()
Clean up the r1 register after a series of *LEAVING_R1_DIRTY calls.
Definition scale8.h:343
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:180
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:44
unsigned char u8
Definition int.h:17
@ 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 int.h:49

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: