FastLED 3.9.12
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 static uint32_t size_as_rgb(uint32_t num_of_rgbw_pixels) {
42 // The ObjectFLED controller expects the raw pixel byte data in multiples of 3.
43 // In the case of src data not a multiple of 3, then we need to
44 // add pad bytes so that the delegate controller doesn't walk off the end
45 // of the array and invoke a buffer overflow panic.
46 num_of_rgbw_pixels = (num_of_rgbw_pixels * 4 + 2) / 3;
47 uint32_t extra = num_of_rgbw_pixels % 3 ? 1 : 0;
48 num_of_rgbw_pixels += extra;
49 return num_of_rgbw_pixels;
50 }
51};
52
53struct RgbwInvalid : public Rgbw {
54 RgbwInvalid() {
55 white_color_temp = kRGBWDefaultColorTemp;
56 rgbw_mode = kRGBWInvalid;
57 }
58 static Rgbw value() {
59 RgbwInvalid invalid;
60 return invalid;
61 }
62};
63
64struct RgbwDefault : public Rgbw {
65 RgbwDefault() {
66 white_color_temp = kRGBWDefaultColorTemp;
67 rgbw_mode = kRGBWExactColors;
68 }
69 static Rgbw value() {
70 RgbwDefault _default;
71 return _default;
72 }
73};
74
75struct RgbwWhiteIsOff : public Rgbw {
77 white_color_temp = kRGBWDefaultColorTemp;
78 rgbw_mode = kRGBWNullWhitePixel;
79 }
80 static Rgbw value() {
81 RgbwWhiteIsOff _default;
82 return _default;
83 }
84};
85
86typedef void (*rgb_2_rgbw_function)(uint16_t w_color_temperature, uint8_t r,
87 uint8_t g, uint8_t b, uint8_t r_scale,
88 uint8_t g_scale, uint8_t b_scale,
89 uint8_t *out_r, uint8_t *out_g,
90 uint8_t *out_b, uint8_t *out_w);
91
105void rgb_2_rgbw_exact(uint16_t w_color_temperature, uint8_t r, uint8_t g,
106 uint8_t b, uint8_t r_scale, uint8_t g_scale,
107 uint8_t b_scale, uint8_t *out_r, uint8_t *out_g,
108 uint8_t *out_b, uint8_t *out_w);
109
118void rgb_2_rgbw_max_brightness(uint16_t w_color_temperature, uint8_t r,
119 uint8_t g, uint8_t b, uint8_t r_scale,
120 uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
121 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w);
122
128void rgb_2_rgbw_null_white_pixel(uint16_t w_color_temperature, uint8_t r,
129 uint8_t g, uint8_t b, uint8_t r_scale,
130 uint8_t g_scale, uint8_t b_scale,
131 uint8_t *out_r, uint8_t *out_g, uint8_t *out_b,
132 uint8_t *out_w);
133
135void rgb_2_rgbw_white_boosted(uint16_t w_color_temperature, uint8_t r,
136 uint8_t g, uint8_t b, uint8_t r_scale,
137 uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
138 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w);
139
140void rgb_2_rgbw_user_function(uint16_t w_color_temperature, uint8_t r,
141 uint8_t g, uint8_t b, uint8_t r_scale,
142 uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
143 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w);
144
145void set_rgb_2_rgbw_function(rgb_2_rgbw_function func);
146
150FASTLED_FORCE_INLINE void rgb_2_rgbw(
151 RGBW_MODE mode, uint16_t w_color_temperature, uint8_t r, uint8_t g,
152 uint8_t b, uint8_t r_scale, uint8_t g_scale, uint8_t b_scale,
153 uint8_t *out_r, uint8_t *out_g, uint8_t *out_b, uint8_t *out_w) {
154 switch (mode) {
155 case kRGBWInvalid:
156 case kRGBWNullWhitePixel:
157 rgb_2_rgbw_null_white_pixel(w_color_temperature, r, g, b, r_scale,
158 g_scale, b_scale, out_r, out_g, out_b,
159 out_w);
160 return;
161 case kRGBWExactColors:
162 rgb_2_rgbw_exact(w_color_temperature, r, g, b, r_scale, g_scale,
163 b_scale, out_r, out_g, out_b, out_w);
164 return;
165 case kRGBWBoostedWhite:
166 rgb_2_rgbw_white_boosted(w_color_temperature, r, g, b, r_scale, g_scale,
167 b_scale, out_r, out_g, out_b, out_w);
168 return;
169 case kRGBWMaxBrightness:
170 rgb_2_rgbw_max_brightness(w_color_temperature, r, g, b, r_scale,
171 g_scale, b_scale, out_r, out_g, out_b, out_w);
172 return;
173 case kRGBWUserFunction:
174 rgb_2_rgbw_user_function(w_color_temperature, r, g, b, r_scale, g_scale,
175 b_scale, out_r, out_g, out_b, out_w);
176 return;
177 }
178 rgb_2_rgbw_null_white_pixel(w_color_temperature, r, g, b, r_scale, g_scale,
179 b_scale, out_r, out_g, out_b, out_w);
180}
181
182// @brief Converts RGB to RGBW using one of the functions.
183template <RGBW_MODE MODE>
184FASTLED_FORCE_INLINE void
185rgb_2_rgbw(uint16_t w_color_temperature, uint8_t r, uint8_t g, uint8_t b,
186 uint8_t r_scale, uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
187 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w) {
188 // We trust that the compiler will inline all of this.
189 rgb_2_rgbw(MODE, w_color_temperature, r, g, b, r_scale, g_scale, b_scale,
190 out_r, out_g, out_b, out_w);
191}
192
193// Assuming all RGB pixels are already ordered in native led ordering, then this
194// function will reorder them so that white is also the correct position.
195// b0-b2 are actually rgb that are already in native LED order.
196// and out_b0-out_b3 are the output RGBW in native LED chipset order.
197// w is the white component that needs to be inserted into the RGB data at
198// the correct position.
199void rgbw_partial_reorder(EOrderW w_placement, uint8_t b0, uint8_t b1,
200 uint8_t b2, uint8_t w, uint8_t *out_b0,
201 uint8_t *out_b1, uint8_t *out_b2, uint8_t *out_b3);
202
203
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:150
Definition rgbw.h:28