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

◆ nblend()

CRGB & fl::nblend ( CRGB & existing,
const CRGB & overlay,
fract8 amountOfOverlay )
Examples
Pride2015.ino.

Definition at line 20 of file colorutils.cpp.

20 {
21 if (amountOfOverlay == 0) {
22 return existing;
23 }
24
25 if (amountOfOverlay == 255) {
26 existing = overlay;
27 return existing;
28 }
29
30#if 0
31 // Old blend method which unfortunately had some rounding errors
32 fract8 amountOfKeep = 255 - amountOfOverlay;
33
34 existing.red = scale8_LEAVING_R1_DIRTY( existing.red, amountOfKeep)
35 + scale8_LEAVING_R1_DIRTY( overlay.red, amountOfOverlay);
36 existing.green = scale8_LEAVING_R1_DIRTY( existing.green, amountOfKeep)
37 + scale8_LEAVING_R1_DIRTY( overlay.green, amountOfOverlay);
38 existing.blue = scale8_LEAVING_R1_DIRTY( existing.blue, amountOfKeep)
39 + scale8_LEAVING_R1_DIRTY( overlay.blue, amountOfOverlay);
40
41 cleanup_R1();
42#else
43 // Corrected blend method, with no loss-of-precision rounding errors
44 existing.red = blend8(existing.red, overlay.red, amountOfOverlay);
45 existing.green = blend8(existing.green, overlay.green, amountOfOverlay);
46 existing.blue = blend8(existing.blue, overlay.blue, amountOfOverlay);
47#endif
48
49 return existing;
50}
LIB8STATIC uint8_t blend8(uint8_t a, uint8_t b, uint8_t amountOfB)
Blend a variable proportion (0-255) of one byte to another.
Definition math8.h:683
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
u8 fract8
Fixed-Point Fractional Types.
Definition int.h:49