FastLED 3.7.8
Loading...
Searching...
No Matches
rgbw.h
1#pragma once
2
3#include <stdint.h>
4
5#include "force_inline.h"
6#include "namespace.h"
7#include "eorder.h"
8
9FASTLED_NAMESPACE_BEGIN
10
11
12enum RGBW_MODE {
13 kRGBWInvalid,
14 kRGBWNullWhitePixel,
15 kRGBWExactColors,
16 kRGBWBoostedWhite,
17 kRGBWMaxBrightness,
18 kRGBWUserFunction
19};
20
21enum {
22 kRGBWDefaultColorTemp = 6000,
23};
24
25struct Rgbw {
26 explicit Rgbw(uint16_t white_color_temp = kRGBWDefaultColorTemp,
27 RGBW_MODE rgbw_mode = kRGBWExactColors,
28 EOrderW _w_placement = WDefault)
29 : white_color_temp(white_color_temp), w_placement(_w_placement),
30 rgbw_mode(rgbw_mode) {}
31 uint16_t white_color_temp = kRGBWDefaultColorTemp;
32 EOrderW w_placement = WDefault;
33 RGBW_MODE rgbw_mode = kRGBWExactColors;
34 FASTLED_FORCE_INLINE bool active() const {
35 return rgbw_mode != kRGBWInvalid;
36 }
37};
38
39struct RgbwInvalid : public Rgbw {
40 RgbwInvalid() {
41 white_color_temp = kRGBWDefaultColorTemp;
42 rgbw_mode = kRGBWInvalid;
43 }
44 static Rgbw value() {
45 RgbwInvalid invalid;
46 return invalid;
47 }
48};
49
50struct RgbwDefault : public Rgbw {
51 RgbwDefault() {
52 white_color_temp = kRGBWDefaultColorTemp;
53 rgbw_mode = kRGBWExactColors;
54 }
55 static Rgbw value() {
56 RgbwDefault _default;
57 return _default;
58 }
59};
60
61typedef void (*rgb_2_rgbw_function)(uint16_t w_color_temperature, uint8_t r,
62 uint8_t g, uint8_t b, uint8_t r_scale,
63 uint8_t g_scale, uint8_t b_scale,
64 uint8_t *out_r, uint8_t *out_g,
65 uint8_t *out_b, uint8_t *out_w);
66
77void rgb_2_rgbw_exact(uint16_t w_color_temperature, uint8_t r, uint8_t g,
78 uint8_t b, uint8_t r_scale, uint8_t g_scale,
79 uint8_t b_scale, uint8_t *out_r, uint8_t *out_g,
80 uint8_t *out_b, uint8_t *out_w);
81
87void rgb_2_rgbw_max_brightness(uint16_t w_color_temperature, uint8_t r,
88 uint8_t g, uint8_t b, uint8_t r_scale,
89 uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
90 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w);
91
94void rgb_2_rgbw_null_white_pixel(uint16_t w_color_temperature, uint8_t r,
95 uint8_t g, uint8_t b, uint8_t r_scale,
96 uint8_t g_scale, uint8_t b_scale,
97 uint8_t *out_r, uint8_t *out_g, uint8_t *out_b,
98 uint8_t *out_w);
99
101void rgb_2_rgbw_white_boosted(uint16_t w_color_temperature, uint8_t r,
102 uint8_t g, uint8_t b, uint8_t r_scale,
103 uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
104 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w);
105
106void rgb_2_rgbw_user_function(uint16_t w_color_temperature, uint8_t r,
107 uint8_t g, uint8_t b, uint8_t r_scale,
108 uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
109 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w);
110
111void set_rgb_2_rgbw_function(rgb_2_rgbw_function func);
112
114FASTLED_FORCE_INLINE void rgb_2_rgbw(
118 RGBW_MODE mode, uint16_t w_color_temperature, uint8_t r, uint8_t g,
119 uint8_t b, uint8_t r_scale, uint8_t g_scale, uint8_t b_scale,
120 uint8_t *out_r, uint8_t *out_g, uint8_t *out_b, uint8_t *out_w) {
121 switch (mode) {
122 case kRGBWInvalid:
123 case kRGBWNullWhitePixel:
124 rgb_2_rgbw_null_white_pixel(w_color_temperature, r, g, b, r_scale,
125 g_scale, b_scale, out_r, out_g, out_b,
126 out_w);
127 return;
128 case kRGBWExactColors:
129 rgb_2_rgbw_exact(w_color_temperature, r, g, b, r_scale, g_scale,
130 b_scale, out_r, out_g, out_b, out_w);
131 return;
132 case kRGBWBoostedWhite:
133 rgb_2_rgbw_white_boosted(w_color_temperature, r, g, b, r_scale, g_scale,
134 b_scale, out_r, out_g, out_b, out_w);
135 return;
136 case kRGBWMaxBrightness:
137 rgb_2_rgbw_max_brightness(w_color_temperature, r, g, b, r_scale,
138 g_scale, b_scale, out_r, out_g, out_b, out_w);
139 return;
140 case kRGBWUserFunction:
141 rgb_2_rgbw_user_function(w_color_temperature, r, g, b, r_scale, g_scale,
142 b_scale, out_r, out_g, out_b, out_w);
143 return;
144 }
145 rgb_2_rgbw_null_white_pixel(w_color_temperature, r, g, b, r_scale, g_scale,
146 b_scale, out_r, out_g, out_b, out_w);
147}
148
149// @brief Converts RGB to RGBW using one of the functions.
150template <RGBW_MODE MODE>
151FASTLED_FORCE_INLINE void
152rgb_2_rgbw(uint16_t w_color_temperature, uint8_t r, uint8_t g, uint8_t b,
153 uint8_t r_scale, uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
154 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w) {
155 // We trust that the compiler will inline all of this.
156 rgb_2_rgbw(MODE, w_color_temperature, r, g, b, r_scale, g_scale, b_scale,
157 out_r, out_g, out_b, out_w);
158}
159
160// Assuming all RGB pixels are already ordered in native led ordering, then this
161// function will reorder them so that white is also the correct position.
162// b0-b2 are actually rgb that are already in native LED order.
163// and out_b0-out_b3 are the output RGBW in native LED chipset order.
164// w is the white component that needs to be inserted into the RGB data at
165// the correct position.
166void rgbw_partial_reorder(EOrderW w_placement, uint8_t b0, uint8_t b1,
167 uint8_t b2, uint8_t w, uint8_t *out_b0,
168 uint8_t *out_b1, uint8_t *out_b2, uint8_t *out_b3);
169
170
171FASTLED_NAMESPACE_END
Definition rgbw.h:25