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

78 {
79 if (amountOfOverlay == 0) {
80 return existing;
81 }
82
83 if (amountOfOverlay == 255) {
84 existing = overlay;
85 return existing;
86 }
87
88 fract8 amountOfKeep = 255 - amountOfOverlay;
89
90 fl::u8 huedelta8 = overlay.hue - existing.hue;
91
92 if (directionCode == SHORTEST_HUES) {
93 directionCode = FORWARD_HUES;
94 if (huedelta8 > 127) {
95 directionCode = BACKWARD_HUES;
96 }
97 }
98
99 if (directionCode == LONGEST_HUES) {
100 directionCode = FORWARD_HUES;
101 if (huedelta8 < 128) {
102 directionCode = BACKWARD_HUES;
103 }
104 }
105
106 if (directionCode == FORWARD_HUES) {
107 existing.hue = existing.hue + scale8(huedelta8, amountOfOverlay);
108 } else /* directionCode == BACKWARD_HUES */
109 {
110 huedelta8 = -huedelta8;
111 existing.hue = existing.hue - scale8(huedelta8, amountOfOverlay);
112 }
113
114 existing.sat = scale8_LEAVING_R1_DIRTY(existing.sat, amountOfKeep) +
115 scale8_LEAVING_R1_DIRTY(overlay.sat, amountOfOverlay);
116 existing.val = scale8_LEAVING_R1_DIRTY(existing.val, amountOfKeep) +
117 scale8_LEAVING_R1_DIRTY(overlay.val, amountOfOverlay);
118
119 cleanup_R1();
120
121 return existing;
122}
unsigned char u8
Definition s16x16x4.h:132
u8 fract8
Fixed-Point Fractional Types.
Definition s16x16x4.h:161
@ 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, FORWARD_HUES, LONGEST_HUES, and SHORTEST_HUES.