FastLED 3.9.3
Loading...
Searching...
No Matches
crgb.cpp
1
2#include "FastLED.h"
3#include "crgb.h"
4#include "lib8tion/math8.h"
5
6#include "namespace.h"
7
8FASTLED_NAMESPACE_BEGIN
9
10CRGB CRGB::computeAdjustment(uint8_t scale, const CRGB & colorCorrection, const CRGB & colorTemperature) {
11 #if defined(NO_CORRECTION) && (NO_CORRECTION==1)
12 return CRGB(scale,scale,scale);
13 #else
14 CRGB adj(0,0,0);
15 if(scale > 0) {
16 for(uint8_t i = 0; i < 3; ++i) {
17 uint8_t cc = colorCorrection.raw[i];
18 uint8_t ct = colorTemperature.raw[i];
19 if(cc > 0 && ct > 0) {
20 // Optimized for AVR size. This function is only called very infrequently so size
21 // matters more than speed.
22 uint32_t work = (((uint16_t)cc)+1);
23 work *= (((uint16_t)ct)+1);
24 work *= scale;
25 work /= 0x10000L;
26 adj.raw[i] = work & 0xFF;
27 }
28 }
29 }
30 return adj;
31 #endif
32}
33
34
35CRGB CRGB::blend(const CRGB& p1, const CRGB& p2, fract8 amountOfP2) {
36 return CRGB(
37 blend8(p1.r, p2.r, amountOfP2),
38 blend8(p1.g, p2.g, amountOfP2),
39 blend8(p1.b, p2.b, amountOfP2)
40 );
41}
42
43FASTLED_NAMESPACE_END
central include file for FastLED, defines the CFastLED class/object
uint8_t fract8
ANSI: unsigned short _Fract.
Definition types.h:30
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:667
FASTLED_FORCE_INLINE CRGB()=default
Default constructor.
uint8_t raw[3]
Access the red, green, and blue data as an array.
Definition crgb.h:60
uint8_t r
Red channel value.
Definition crgb.h:43
static CRGB computeAdjustment(uint8_t scale, const CRGB &colorCorrection, const CRGB &colorTemperature)
Calculates the combined color adjustment to the LEDs at a given scale, color correction,...
Definition crgb.cpp:10
uint8_t g
Green channel value.
Definition crgb.h:47
uint8_t b
Blue channel value.
Definition crgb.h:51
Fast, efficient 8-bit math functions specifically designed for high-performance LED programming.
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:39