FastLED 3.9.3
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
61struct RgbwWhiteIsOff : public Rgbw {
63 white_color_temp = kRGBWDefaultColorTemp;
64 rgbw_mode = kRGBWNullWhitePixel;
65 }
66 static Rgbw value() {
67 RgbwWhiteIsOff _default;
68 return _default;
69 }
70};
71
72typedef void (*rgb_2_rgbw_function)(uint16_t w_color_temperature, uint8_t r,
73 uint8_t g, uint8_t b, uint8_t r_scale,
74 uint8_t g_scale, uint8_t b_scale,
75 uint8_t *out_r, uint8_t *out_g,
76 uint8_t *out_b, uint8_t *out_w);
77
88void rgb_2_rgbw_exact(uint16_t w_color_temperature, uint8_t r, uint8_t g,
89 uint8_t b, uint8_t r_scale, uint8_t g_scale,
90 uint8_t b_scale, uint8_t *out_r, uint8_t *out_g,
91 uint8_t *out_b, uint8_t *out_w);
92
98void rgb_2_rgbw_max_brightness(uint16_t w_color_temperature, uint8_t r,
99 uint8_t g, uint8_t b, uint8_t r_scale,
100 uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
101 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w);
102
105void rgb_2_rgbw_null_white_pixel(uint16_t w_color_temperature, uint8_t r,
106 uint8_t g, uint8_t b, uint8_t r_scale,
107 uint8_t g_scale, uint8_t b_scale,
108 uint8_t *out_r, uint8_t *out_g, uint8_t *out_b,
109 uint8_t *out_w);
110
112void rgb_2_rgbw_white_boosted(uint16_t w_color_temperature, uint8_t r,
113 uint8_t g, uint8_t b, uint8_t r_scale,
114 uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
115 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w);
116
117void rgb_2_rgbw_user_function(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, uint8_t *out_r,
120 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w);
121
122void set_rgb_2_rgbw_function(rgb_2_rgbw_function func);
123
125FASTLED_FORCE_INLINE void rgb_2_rgbw(
129 RGBW_MODE mode, uint16_t w_color_temperature, uint8_t r, uint8_t g,
130 uint8_t b, uint8_t r_scale, uint8_t g_scale, uint8_t b_scale,
131 uint8_t *out_r, uint8_t *out_g, uint8_t *out_b, uint8_t *out_w) {
132 switch (mode) {
133 case kRGBWInvalid:
134 case kRGBWNullWhitePixel:
135 rgb_2_rgbw_null_white_pixel(w_color_temperature, r, g, b, r_scale,
136 g_scale, b_scale, out_r, out_g, out_b,
137 out_w);
138 return;
139 case kRGBWExactColors:
140 rgb_2_rgbw_exact(w_color_temperature, r, g, b, r_scale, g_scale,
141 b_scale, out_r, out_g, out_b, out_w);
142 return;
143 case kRGBWBoostedWhite:
144 rgb_2_rgbw_white_boosted(w_color_temperature, r, g, b, r_scale, g_scale,
145 b_scale, out_r, out_g, out_b, out_w);
146 return;
147 case kRGBWMaxBrightness:
148 rgb_2_rgbw_max_brightness(w_color_temperature, r, g, b, r_scale,
149 g_scale, b_scale, out_r, out_g, out_b, out_w);
150 return;
151 case kRGBWUserFunction:
152 rgb_2_rgbw_user_function(w_color_temperature, r, g, b, r_scale, g_scale,
153 b_scale, out_r, out_g, out_b, out_w);
154 return;
155 }
156 rgb_2_rgbw_null_white_pixel(w_color_temperature, r, g, b, r_scale, g_scale,
157 b_scale, out_r, out_g, out_b, out_w);
158}
159
160// @brief Converts RGB to RGBW using one of the functions.
161template <RGBW_MODE MODE>
162FASTLED_FORCE_INLINE void
163rgb_2_rgbw(uint16_t w_color_temperature, uint8_t r, uint8_t g, uint8_t b,
164 uint8_t r_scale, uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
165 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w) {
166 // We trust that the compiler will inline all of this.
167 rgb_2_rgbw(MODE, w_color_temperature, r, g, b, r_scale, g_scale, b_scale,
168 out_r, out_g, out_b, out_w);
169}
170
171// Assuming all RGB pixels are already ordered in native led ordering, then this
172// function will reorder them so that white is also the correct position.
173// b0-b2 are actually rgb that are already in native LED order.
174// and out_b0-out_b3 are the output RGBW in native LED chipset order.
175// w is the white component that needs to be inserted into the RGB data at
176// the correct position.
177void rgbw_partial_reorder(EOrderW w_placement, uint8_t b0, uint8_t b1,
178 uint8_t b2, uint8_t w, uint8_t *out_b0,
179 uint8_t *out_b1, uint8_t *out_b2, uint8_t *out_b3);
180
181
182FASTLED_NAMESPACE_END
Definition rgbw.h:25