FastLED 3.9.7
Loading...
Searching...
No Matches
crgb.cpp
Go to the documentation of this file.
1
3
4#include "FastLED.h"
5#include "crgb.h"
6#include "lib8tion/math8.h"
7
8#include "fl/namespace.h"
9
11
12fl::Str CRGB::toString() const {
13 fl::Str out;
14 out.append("CRGB(");
15 out.append(int(r));
16 out.append(", ");
17 out.append(int(g));
18 out.append(", ");
19 out.append(int(b));
20 out.append(")");
21 return out;
22}
23
24CRGB CRGB::computeAdjustment(uint8_t scale, const CRGB & colorCorrection, const CRGB & colorTemperature) {
25 #if defined(NO_CORRECTION) && (NO_CORRECTION==1)
26 return CRGB(scale,scale,scale);
27 #else
28 CRGB adj(0,0,0);
29 if(scale > 0) {
30 for(uint8_t i = 0; i < 3; ++i) {
31 uint8_t cc = colorCorrection.raw[i];
32 uint8_t ct = colorTemperature.raw[i];
33 if(cc > 0 && ct > 0) {
34 // Optimized for AVR size. This function is only called very infrequently so size
35 // matters more than speed.
36 uint32_t work = (((uint16_t)cc)+1);
37 work *= (((uint16_t)ct)+1);
38 work *= scale;
39 work /= 0x10000L;
40 adj.raw[i] = work & 0xFF;
41 }
42 }
43 }
44 return adj;
45 #endif
46}
47
48
49CRGB CRGB::blend(const CRGB& p1, const CRGB& p2, fract8 amountOfP2) {
50 return CRGB(
51 blend8(p1.r, p2.r, amountOfP2),
52 blend8(p1.g, p2.g, amountOfP2),
53 blend8(p1.b, p2.b, amountOfP2)
54 );
55}
56
central include file for FastLED, defines the CFastLED class/object
Definition str.h:336
Defines the red, green, and blue (RGB) pixel struct.
uint8_t fract8
ANSI: unsigned short _Fract.
Definition types.h:36
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
Fast, efficient 8-bit math functions specifically designed for high-performance LED programming.
Implements the FastLED namespace macros.
#define FASTLED_NAMESPACE_END
End of the FastLED namespace.
Definition namespace.h:16
#define FASTLED_NAMESPACE_BEGIN
Start of the FastLED namespace.
Definition namespace.h:14
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54
FASTLED_FORCE_INLINE CRGB()=default
Default constructor.
uint8_t raw[3]
Access the red, green, and blue data as an array.
Definition crgb.h:75
uint8_t r
Red channel value.
Definition crgb.h:58
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:24
uint8_t g
Green channel value.
Definition crgb.h:62
uint8_t b
Blue channel value.
Definition crgb.h:66