FastLED 3.9.15
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
23
24enum {
26};
27
28struct Rgbw {
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 {
58 static Rgbw value() {
59 RgbwInvalid invalid;
60 return invalid;
61 }
62};
63
64struct RgbwDefault : public Rgbw {
69 static Rgbw value() {
70 RgbwDefault _default;
71 return _default;
72 }
73};
74
75struct RgbwWhiteIsOff : public Rgbw {
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
146
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:
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;
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;
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;
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>
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
EOrderW
Definition eorder.h:24
@ WDefault
Definition eorder.h:29
Defines color channel ordering enumerations.
#define FASTLED_FORCE_INLINE
Definition force_inline.h:7
#define FASTLED_NAMESPACE_END
Definition namespace.h:22
Implements the FastLED namespace macros.
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_user_function(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)
Definition rgbw.cpp:125
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 set_rgb_2_rgbw_function(rgb_2_rgbw_function func)
Definition rgbw.cpp:117
RGBW_MODE
Definition rgbw.h:15
@ kRGBWMaxBrightness
Definition rgbw.h:20
@ kRGBWNullWhitePixel
Definition rgbw.h:17
@ kRGBWInvalid
Definition rgbw.h:16
@ kRGBWUserFunction
Definition rgbw.h:21
@ kRGBWBoostedWhite
Definition rgbw.h:19
@ kRGBWExactColors
Definition rgbw.h:18
@ kRGBWDefaultColorTemp
Definition rgbw.h:25
void rgbw_partial_reorder(EOrderW w_placement, uint8_t b0, uint8_t b1, uint8_t b2, uint8_t w, uint8_t *out_b0, uint8_t *out_b1, uint8_t *out_b2, uint8_t *out_b3)
Definition rgbw.cpp:133
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
void(* rgb_2_rgbw_function)(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)
Definition rgbw.h:86
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
EOrderW w_placement
Definition rgbw.h:35
FASTLED_FORCE_INLINE bool active() const
Definition rgbw.h:37
Rgbw(uint16_t white_color_temp=kRGBWDefaultColorTemp, RGBW_MODE rgbw_mode=kRGBWExactColors, EOrderW _w_placement=WDefault)
Definition rgbw.h:29
RGBW_MODE rgbw_mode
Definition rgbw.h:36
uint16_t white_color_temp
Definition rgbw.h:34
static uint32_t size_as_rgb(uint32_t num_of_rgbw_pixels)
Definition rgbw.h:41
static Rgbw value()
Definition rgbw.h:69
RgbwDefault()
Definition rgbw.h:65
RgbwInvalid()
Definition rgbw.h:54
static Rgbw value()
Definition rgbw.h:58
static Rgbw value()
Definition rgbw.h:80
RgbwWhiteIsOff()
Definition rgbw.h:76