FastLED 3.9.7
Loading...
Searching...
No Matches
rgbw.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <stdint.h>
7
8#include "fl/force_inline.h"
9#include "fl/namespace.h"
10#include "eorder.h"
11
13
14
15enum RGBW_MODE {
16 kRGBWInvalid,
17 kRGBWNullWhitePixel,
18 kRGBWExactColors,
19 kRGBWBoostedWhite,
20 kRGBWMaxBrightness,
21 kRGBWUserFunction
22};
23
24enum {
25 kRGBWDefaultColorTemp = 6000,
26};
27
28struct Rgbw {
29 explicit Rgbw(uint16_t white_color_temp = kRGBWDefaultColorTemp,
30 RGBW_MODE rgbw_mode = kRGBWExactColors,
31 EOrderW _w_placement = WDefault)
32 : white_color_temp(white_color_temp), w_placement(_w_placement),
33 rgbw_mode(rgbw_mode) {}
34 uint16_t white_color_temp = kRGBWDefaultColorTemp;
35 EOrderW w_placement = WDefault;
36 RGBW_MODE rgbw_mode = kRGBWExactColors;
37 FASTLED_FORCE_INLINE bool active() const {
38 return rgbw_mode != kRGBWInvalid;
39 }
40};
41
42struct RgbwInvalid : public Rgbw {
43 RgbwInvalid() {
44 white_color_temp = kRGBWDefaultColorTemp;
45 rgbw_mode = kRGBWInvalid;
46 }
47 static Rgbw value() {
48 RgbwInvalid invalid;
49 return invalid;
50 }
51};
52
53struct RgbwDefault : public Rgbw {
54 RgbwDefault() {
55 white_color_temp = kRGBWDefaultColorTemp;
56 rgbw_mode = kRGBWExactColors;
57 }
58 static Rgbw value() {
59 RgbwDefault _default;
60 return _default;
61 }
62};
63
64struct RgbwWhiteIsOff : public Rgbw {
66 white_color_temp = kRGBWDefaultColorTemp;
67 rgbw_mode = kRGBWNullWhitePixel;
68 }
69 static Rgbw value() {
70 RgbwWhiteIsOff _default;
71 return _default;
72 }
73};
74
75typedef void (*rgb_2_rgbw_function)(uint16_t w_color_temperature, uint8_t r,
76 uint8_t g, uint8_t b, uint8_t r_scale,
77 uint8_t g_scale, uint8_t b_scale,
78 uint8_t *out_r, uint8_t *out_g,
79 uint8_t *out_b, uint8_t *out_w);
80
94void rgb_2_rgbw_exact(uint16_t w_color_temperature, uint8_t r, uint8_t g,
95 uint8_t b, uint8_t r_scale, uint8_t g_scale,
96 uint8_t b_scale, uint8_t *out_r, uint8_t *out_g,
97 uint8_t *out_b, uint8_t *out_w);
98
107void rgb_2_rgbw_max_brightness(uint16_t w_color_temperature, uint8_t r,
108 uint8_t g, uint8_t b, uint8_t r_scale,
109 uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
110 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w);
111
117void rgb_2_rgbw_null_white_pixel(uint16_t w_color_temperature, uint8_t r,
118 uint8_t g, uint8_t b, uint8_t r_scale,
119 uint8_t g_scale, uint8_t b_scale,
120 uint8_t *out_r, uint8_t *out_g, uint8_t *out_b,
121 uint8_t *out_w);
122
124void rgb_2_rgbw_white_boosted(uint16_t w_color_temperature, uint8_t r,
125 uint8_t g, uint8_t b, uint8_t r_scale,
126 uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
127 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w);
128
129void rgb_2_rgbw_user_function(uint16_t w_color_temperature, uint8_t r,
130 uint8_t g, uint8_t b, uint8_t r_scale,
131 uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
132 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w);
133
134void set_rgb_2_rgbw_function(rgb_2_rgbw_function func);
135
139FASTLED_FORCE_INLINE void rgb_2_rgbw(
140 RGBW_MODE mode, uint16_t w_color_temperature, uint8_t r, uint8_t g,
141 uint8_t b, uint8_t r_scale, uint8_t g_scale, uint8_t b_scale,
142 uint8_t *out_r, uint8_t *out_g, uint8_t *out_b, uint8_t *out_w) {
143 switch (mode) {
144 case kRGBWInvalid:
145 case kRGBWNullWhitePixel:
146 rgb_2_rgbw_null_white_pixel(w_color_temperature, r, g, b, r_scale,
147 g_scale, b_scale, out_r, out_g, out_b,
148 out_w);
149 return;
150 case kRGBWExactColors:
151 rgb_2_rgbw_exact(w_color_temperature, r, g, b, r_scale, g_scale,
152 b_scale, out_r, out_g, out_b, out_w);
153 return;
154 case kRGBWBoostedWhite:
155 rgb_2_rgbw_white_boosted(w_color_temperature, r, g, b, r_scale, g_scale,
156 b_scale, out_r, out_g, out_b, out_w);
157 return;
158 case kRGBWMaxBrightness:
159 rgb_2_rgbw_max_brightness(w_color_temperature, r, g, b, r_scale,
160 g_scale, b_scale, out_r, out_g, out_b, out_w);
161 return;
162 case kRGBWUserFunction:
163 rgb_2_rgbw_user_function(w_color_temperature, r, g, b, r_scale, g_scale,
164 b_scale, out_r, out_g, out_b, out_w);
165 return;
166 }
167 rgb_2_rgbw_null_white_pixel(w_color_temperature, r, g, b, r_scale, g_scale,
168 b_scale, out_r, out_g, out_b, out_w);
169}
170
171// @brief Converts RGB to RGBW using one of the functions.
172template <RGBW_MODE MODE>
173FASTLED_FORCE_INLINE void
174rgb_2_rgbw(uint16_t w_color_temperature, uint8_t r, uint8_t g, uint8_t b,
175 uint8_t r_scale, uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
176 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w) {
177 // We trust that the compiler will inline all of this.
178 rgb_2_rgbw(MODE, w_color_temperature, r, g, b, r_scale, g_scale, b_scale,
179 out_r, out_g, out_b, out_w);
180}
181
182// Assuming all RGB pixels are already ordered in native led ordering, then this
183// function will reorder them so that white is also the correct position.
184// b0-b2 are actually rgb that are already in native LED order.
185// and out_b0-out_b3 are the output RGBW in native LED chipset order.
186// w is the white component that needs to be inserted into the RGB data at
187// the correct position.
188void rgbw_partial_reorder(EOrderW w_placement, uint8_t b0, uint8_t b1,
189 uint8_t b2, uint8_t w, uint8_t *out_b0,
190 uint8_t *out_b1, uint8_t *out_b2, uint8_t *out_b3);
191
192
Defines color channel ordering enumerations.
EOrderW
Definition eorder.h:24
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
void rgb_2_rgbw_null_white_pixel(uint16_t w_color_temperature, uint8_t r, uint8_t g, uint8_t b, uint8_t r_scale, uint8_t g_scale, uint8_t b_scale, uint8_t *out_r, uint8_t *out_g, uint8_t *out_b, uint8_t *out_w)
Converts RGB to RGBW with the W channel set to black, always.
Definition rgbw.cpp:66
void rgb_2_rgbw_max_brightness(uint16_t w_color_temperature, uint8_t r, uint8_t g, uint8_t b, uint8_t r_scale, uint8_t g_scale, uint8_t b_scale, uint8_t *out_r, uint8_t *out_g, uint8_t *out_b, uint8_t *out_w)
The minimum brigthness of the RGB channels is used to set the W channel.
Definition rgbw.cpp:55
void rgb_2_rgbw_white_boosted(uint16_t w_color_temperature, uint8_t r, uint8_t g, uint8_t b, uint8_t r_scale, uint8_t g_scale, uint8_t b_scale, uint8_t *out_r, uint8_t *out_g, uint8_t *out_b, uint8_t *out_w)
Converts RGB to RGBW with a boosted white channel.
Definition rgbw.cpp:78
void rgb_2_rgbw_exact(uint16_t w_color_temperature, uint8_t r, uint8_t g, uint8_t b, uint8_t r_scale, uint8_t g_scale, uint8_t b_scale, uint8_t *out_r, uint8_t *out_g, uint8_t *out_b, uint8_t *out_w)
Converts RGB to RGBW using a color transfer method from saturated color channels to white.
Definition rgbw.cpp:40
FASTLED_FORCE_INLINE void rgb_2_rgbw(RGBW_MODE mode, uint16_t w_color_temperature, uint8_t r, uint8_t g, uint8_t b, uint8_t r_scale, uint8_t g_scale, uint8_t b_scale, uint8_t *out_r, uint8_t *out_g, uint8_t *out_b, uint8_t *out_w)
Converts RGB to RGBW using one of the functions.
Definition rgbw.h:139
Definition rgbw.h:28