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 "fl/stdint.h"
7
8#include "eorder.h"
9#include "fl/force_inline.h"
10
11namespace fl {
12
21
22enum {
24};
25
26struct Rgbw {
36 return rgbw_mode != kRGBWInvalid;
37 }
38
39 static uint32_t size_as_rgb(uint32_t num_of_rgbw_pixels) {
40 // The ObjectFLED controller expects the raw pixel byte data in
41 // multiples of 3. In the case of src data not a multiple of 3, then we
42 // need to add pad bytes so that the delegate controller doesn't walk
43 // off the end of the array and invoke a buffer overflow panic.
44 num_of_rgbw_pixels = (num_of_rgbw_pixels * 4 + 2) / 3;
45 uint32_t extra = num_of_rgbw_pixels % 3 ? 1 : 0;
46 num_of_rgbw_pixels += extra;
47 return num_of_rgbw_pixels;
48 }
49};
50
51struct RgbwInvalid : public Rgbw {
56 static Rgbw value() {
57 RgbwInvalid invalid;
58 return invalid;
59 }
60};
61
62struct RgbwDefault : public Rgbw {
67 static Rgbw value() {
68 RgbwDefault _default;
69 return _default;
70 }
71};
72
73struct RgbwWhiteIsOff : public Rgbw {
78 static Rgbw value() {
79 RgbwWhiteIsOff _default;
80 return _default;
81 }
82};
83
84typedef void (*rgb_2_rgbw_function)(uint16_t w_color_temperature, uint8_t r,
85 uint8_t g, uint8_t b, uint8_t r_scale,
86 uint8_t g_scale, uint8_t b_scale,
87 uint8_t *out_r, uint8_t *out_g,
88 uint8_t *out_b, uint8_t *out_w);
89
103void rgb_2_rgbw_exact(uint16_t w_color_temperature, uint8_t r, uint8_t g,
104 uint8_t b, uint8_t r_scale, uint8_t g_scale,
105 uint8_t b_scale, uint8_t *out_r, uint8_t *out_g,
106 uint8_t *out_b, uint8_t *out_w);
107
116void rgb_2_rgbw_max_brightness(uint16_t w_color_temperature, uint8_t r,
117 uint8_t g, uint8_t b, uint8_t r_scale,
118 uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
119 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w);
120
126void rgb_2_rgbw_null_white_pixel(uint16_t w_color_temperature, uint8_t r,
127 uint8_t g, uint8_t b, uint8_t r_scale,
128 uint8_t g_scale, uint8_t b_scale,
129 uint8_t *out_r, uint8_t *out_g, uint8_t *out_b,
130 uint8_t *out_w);
131
133void rgb_2_rgbw_white_boosted(uint16_t w_color_temperature, uint8_t r,
134 uint8_t g, uint8_t b, uint8_t r_scale,
135 uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
136 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w);
137
138void rgb_2_rgbw_user_function(uint16_t w_color_temperature, uint8_t r,
139 uint8_t g, uint8_t b, uint8_t r_scale,
140 uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
141 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w);
142
144
149rgb_2_rgbw(RGBW_MODE mode, uint16_t w_color_temperature, uint8_t r, uint8_t g,
150 uint8_t b, uint8_t r_scale, uint8_t g_scale, uint8_t b_scale,
151 uint8_t *out_r, uint8_t *out_g, uint8_t *out_b, uint8_t *out_w) {
152 switch (mode) {
153 case kRGBWInvalid:
155 rgb_2_rgbw_null_white_pixel(w_color_temperature, r, g, b, r_scale,
156 g_scale, b_scale, out_r, out_g, out_b,
157 out_w);
158 return;
159 case kRGBWExactColors:
160 rgb_2_rgbw_exact(w_color_temperature, r, g, b, r_scale, g_scale,
161 b_scale, out_r, out_g, out_b, out_w);
162 return;
164 rgb_2_rgbw_white_boosted(w_color_temperature, r, g, b, r_scale, g_scale,
165 b_scale, out_r, out_g, out_b, out_w);
166 return;
168 rgb_2_rgbw_max_brightness(w_color_temperature, r, g, b, r_scale,
169 g_scale, b_scale, out_r, out_g, out_b, out_w);
170 return;
172 rgb_2_rgbw_user_function(w_color_temperature, r, g, b, r_scale, g_scale,
173 b_scale, out_r, out_g, out_b, out_w);
174 return;
175 }
176 rgb_2_rgbw_null_white_pixel(w_color_temperature, r, g, b, r_scale, g_scale,
177 b_scale, out_r, out_g, out_b, out_w);
178}
179
180// @brief Converts RGB to RGBW using one of the functions.
181template <RGBW_MODE MODE>
183rgb_2_rgbw(uint16_t w_color_temperature, uint8_t r, uint8_t g, uint8_t b,
184 uint8_t r_scale, uint8_t g_scale, uint8_t b_scale, uint8_t *out_r,
185 uint8_t *out_g, uint8_t *out_b, uint8_t *out_w) {
186 // We trust that the compiler will inline all of this.
187 rgb_2_rgbw(MODE, w_color_temperature, r, g, b, r_scale, g_scale, b_scale,
188 out_r, out_g, out_b, out_w);
189}
190
191// Assuming all RGB pixels are already ordered in native led ordering, then this
192// function will reorder them so that white is also the correct position.
193// b0-b2 are actually rgb that are already in native LED order.
194// and out_b0-out_b3 are the output RGBW in native LED chipset order.
195// w is the white component that needs to be inserted into the RGB data at
196// the correct position.
197void rgbw_partial_reorder(fl::EOrderW w_placement, uint8_t b0, uint8_t b1,
198 uint8_t b2, uint8_t w, uint8_t *out_b0,
199 uint8_t *out_b1, uint8_t *out_b2, uint8_t *out_b3);
200
201} // namespace fl
Defines color channel ordering enumerations in the fl namespace.
#define FASTLED_FORCE_INLINE
Definition force_inline.h:6
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:84
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:149
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:126
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:41
RGBW_MODE
Definition rgbw.h:13
@ kRGBWMaxBrightness
Definition rgbw.h:18
@ kRGBWBoostedWhite
Definition rgbw.h:17
@ kRGBWInvalid
Definition rgbw.h:14
@ kRGBWUserFunction
Definition rgbw.h:19
@ kRGBWNullWhitePixel
Definition rgbw.h:15
@ kRGBWExactColors
Definition rgbw.h:16
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:67
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:56
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:79
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:134
@ kRGBWDefaultColorTemp
Definition rgbw.h:23
EOrderW
Definition eorder.h:23
@ WDefault
Definition eorder.h:28
void set_rgb_2_rgbw_function(rgb_2_rgbw_function func)
Definition rgbw.cpp:118
IMPORTANT!
Definition crgb.h:20
uint16_t white_color_temp
Definition rgbw.h:32
RGBW_MODE rgbw_mode
Definition rgbw.h:34
static uint32_t size_as_rgb(uint32_t num_of_rgbw_pixels)
Definition rgbw.h:39
Rgbw(uint16_t white_color_temp=fl::kRGBWDefaultColorTemp, fl::RGBW_MODE rgbw_mode=fl::kRGBWExactColors, fl::EOrderW _w_placement=WDefault)
Definition rgbw.h:27
FASTLED_FORCE_INLINE bool active() const
Definition rgbw.h:35
fl::EOrderW w_placement
Definition rgbw.h:33
static Rgbw value()
Definition rgbw.h:67
static Rgbw value()
Definition rgbw.h:56
static Rgbw value()
Definition rgbw.h:78