FastLED 3.9.12
Loading...
Searching...
No Matches
crgb.cpp
Go to the documentation of this file.
1
3
4#define FASTLED_INTERNAL
5#include "FastLED.h"
6#include "crgb.h"
7#include "lib8tion/math8.h"
8
9#include "fl/namespace.h"
10
12
13fl::Str CRGB::toString() const {
14 fl::Str out;
15 out.append("CRGB(");
16 out.append(int16_t(r));
17 out.append(",");
18 out.append(int16_t(g));
19 out.append(",");
20 out.append(int16_t(b));
21 out.append(")");
22 return out;
23}
24
25CRGB CRGB::computeAdjustment(uint8_t scale, const CRGB & colorCorrection, const CRGB & colorTemperature) {
26 #if defined(NO_CORRECTION) && (NO_CORRECTION==1)
27 return CRGB(scale,scale,scale);
28 #else
29 CRGB adj(0,0,0);
30 if(scale > 0) {
31 for(uint8_t i = 0; i < 3; ++i) {
32 uint8_t cc = colorCorrection.raw[i];
33 uint8_t ct = colorTemperature.raw[i];
34 if(cc > 0 && ct > 0) {
35 // Optimized for AVR size. This function is only called very infrequently so size
36 // matters more than speed.
37 uint32_t work = (((uint16_t)cc)+1);
38 work *= (((uint16_t)ct)+1);
39 work *= scale;
40 work /= 0x10000L;
41 adj.raw[i] = work & 0xFF;
42 }
43 }
44 }
45 return adj;
46 #endif
47}
48
49
50CRGB CRGB::blend(const CRGB& p1, const CRGB& p2, fract8 amountOfP2) {
51 return CRGB(
52 blend8(p1.r, p2.r, amountOfP2),
53 blend8(p1.g, p2.g, amountOfP2),
54 blend8(p1.b, p2.b, amountOfP2)
55 );
56}
57
58CRGB& CRGB::nscale8 (uint8_t scaledown )
59{
60 nscale8x3( r, g, b, scaledown);
61 return *this;
62}
63
64
central include file for FastLED, defines the CFastLED class/object
Definition str.h:368
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
LIB8STATIC void nscale8x3(uint8_t &r, uint8_t &g, uint8_t &b, fract8 scale)
Scale three one-byte values by a fourth one, which is treated as the numerator of a fraction whose de...
Definition scale8.h:357
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
CRGB & nscale8(uint8_t scaledown)
Scale down a RGB to N/256ths of its current brightness, using "plain math" dimming rules.
Definition crgb.cpp: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:25
uint8_t g
Green channel value.
Definition crgb.h:62
uint8_t b
Blue channel value.
Definition crgb.h:66