15#include "platforms/is_platform.h"
46#define RO(X) RGB_BYTE(RGB_ORDER, X)
54#define RGB_BYTE(RO,X) ((static_cast<int>(RO)>>(3*(2-(X)))) & 0x3)
58#define RGB_BYTE0(RO) ((static_cast<int>(RO)>>6) & 0x3)
61#define RGB_BYTE1(RO) ((static_cast<int>(RO)>>3) & 0x3)
64#define RGB_BYTE2(RO) (static_cast<int>(RO) & 0x3)
76 #if FASTLED_HD_COLOR_MIXING
86 #if FASTLED_HD_COLOR_MIXING
87 adj.color =
CRGB(255, 255, 255);
101template<EOrder RGB_ORDER,
int LANES=1, fl::u32 MASK=0xFFFFFFFF>
122 #if FASTLED_HD_COLOR_MIXING
134 template<EOrder RGB_ORDER_OTHER>
139 template<
typename PixelControllerT>
140 void copy(
const PixelControllerT& other) {
141 FL_STATIC_ASSERT(
int(
kLanes) ==
int(PixelControllerT::kLanes),
"PixelController lanes must match or mOffsets will be wrong");
142 FL_STATIC_ASSERT(
int(
kMask) ==
int(PixelControllerT::kMask),
"PixelController mask must match or else one or the other controls different lanes");
153 for(
int i = 0; i < LANES; ++i) {
mOffsets[i] = other.mOffsets[i]; }
160 for(
int i = 0; i < LANES; ++i) {
162 if((1<<i) & MASK) { nOffset += (len *
mAdvance); }
210 #if FASTLED_HD_COLOR_MIXING
211 fl::u8 global_brightness()
const {
268#if !defined(NO_DITHERING) || (NO_DITHERING != 1)
271#define MAX_LIKELY_UPDATE_RATE_HZ 400
274#define MIN_ACCEPTABLE_DITHER_RATE_HZ 50
277#define UPDATES_PER_FULL_DITHER_CYCLE (MAX_LIKELY_UPDATE_RATE_HZ / MIN_ACCEPTABLE_DITHER_RATE_HZ)
292#define RECOMMENDED_VIRTUAL_BITS ((UPDATES_PER_FULL_DITHER_CYCLE>1) + \
293 (UPDATES_PER_FULL_DITHER_CYCLE>2) + \
294 (UPDATES_PER_FULL_DITHER_CYCLE>4) + \
295 (UPDATES_PER_FULL_DITHER_CYCLE>8) + \
296 (UPDATES_PER_FULL_DITHER_CYCLE>16) + \
297 (UPDATES_PER_FULL_DITHER_CYCLE>32) + \
298 (UPDATES_PER_FULL_DITHER_CYCLE>64) + \
299 (UPDATES_PER_FULL_DITHER_CYCLE>128) )
302#define VIRTUAL_BITS RECOMMENDED_VIRTUAL_BITS
310#if !defined(NO_DITHERING) || (NO_DITHERING != 1)
317 R &= (0x01 << ditherBits) - 1;
325 if(R & 0x01) { Q |= 0x80; }
326 if(R & 0x02) { Q |= 0x40; }
327 if(R & 0x04) { Q |= 0x20; }
328 if(R & 0x08) { Q |= 0x10; }
329 if(R & 0x10) { Q |= 0x08; }
330 if(R & 0x20) { Q |= 0x04; }
331 if(R & 0x40) { Q |= 0x02; }
332 if(R & 0x80) { Q |= 0x01; }
337 if( ditherBits < 8) {
338 Q += 0x01 << (7 - ditherBits);
345 for(
int i = 0; i < 3; ++i) {
350 e[i] = s ? (256/s) + 1 : 0;
353 d[i] = fl::scale8(Q,
e[i]);
355#if (FASTLED_SCALE8_FIXED == 1)
377 default:
d[0]=
d[1]=
d[2]=
e[0]=
e[1]=
e[2]=0;
break;
551 #if FASTLED_HD_COLOR_MIXING
559 *c0 = getScaleFullBrightness<0>(*
this);
560 *c1 = getScaleFullBrightness<1>(*
this);
561 *c2 = getScaleFullBrightness<2>(*
this);
568 loadRGBScaleAndBrightness(c0, c1, c2,
brightness);
605 w_placement, out[0], out[1], out[2],
607 b0_out, b1_out, b2_out, b3_out);
616 rgbw.white_color_temp,
619 &rgb.r, &rgb.g, &rgb.b, &w);
627 b0_out, b1_out, b2_out, b3_out);
645 FL_WARN_ONCE(
"RGBWW colorimetric is not supported on AVR — the warm "
646 "and cool white channels will be black. Use an ESP32 / "
647 "Teensy / RP2040 target for full RGBWW support.");
655 b0_out, b1_out, b2_out, b3_out, b4_out);
668 &rgb.r, &rgb.g, &rgb.b, &ww, &wc);
675 b0_out, b1_out, b2_out, b3_out, b4_out);
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
fl::UISlider scale("Scale", 4,.1, 4,.1)
#define BINARY_DITHER
Enable dithering using binary dithering (only option)
fl::u8 EDitherMode
The dither setting, either DISABLE_DITHER or BINARY_DITHER.
Declares dithering options and types.
Defines color channel ordering enumerations.
Declares functions for five-bit gamma correction.
Integer mapping functions between different integer sizes.
Legacy compatibility header for 8-bit math functions.
Legacy compatibility header for 8-bit scaling functions.
Centralized logging categories for FastLED hardware interfaces and subsystems.
void rgbw_partial_reorder(EOrderW w_placement, u8 b0, u8 b1, u8 b2, u8 w, u8 *out_b0, u8 *out_b1, u8 *out_b2, u8 *out_b3)
FASTLED_FORCE_INLINE void rgb_2_rgbw(RGBW_MODE mode, u16 w_color_temperature, u8 r, u8 g, u8 b, u8 r_scale, u8 g_scale, u8 b_scale, u8 *out_r, u8 *out_g, u8 *out_b, u8 *out_w) FL_NOEXCEPT
Converts RGB to RGBW using one of the functions.
FASTLED_FORCE_INLINE void rgb_2_rgbww(const Rgbww &cfg, fl::u8 r, fl::u8 g, fl::u8 b, fl::u8 r_scale, fl::u8 g_scale, fl::u8 b_scale, fl::u8 *out_r, fl::u8 *out_g, fl::u8 *out_b, fl::u8 *out_ww, fl::u8 *out_wc) FL_NOEXCEPT
void rgbww_partial_reorder(EOrderWW ww_placement, u8 b0, u8 b1, u8 b2, u8 ww, u8 wc, u8 *out_b0, u8 *out_b1, u8 *out_b2, u8 *out_b3, u8 *out_b4) FL_NOEXCEPT
Dispatch RGB->RGBWW for a given mode.
Base definition for an LED controller.
#define VIRTUAL_BITS
Alias for RECOMMENDED_VIRTUAL_BITS.
#define RGB_BYTE2(RO)
Gets the color channel for byte 2.
#define RGB_BYTE1(RO)
Gets the color channel for byte 1.
#define RGB_BYTE0(RO)
Gets the color channel for byte 0.
#define RO(X)
Gets the assigned color channel for a byte's position in the output, using the color order (EOrder) t...
Functions for red, green, blue, white (RGBW) output.
5-channel RGB + warm-W + cool-W (RGBWW / RGBCCT) configuration types (issue #2558,...
#define FL_DISABLE_WARNING_IMPLICIT_INT_CONVERSION
#define FL_STATIC_ASSERT(...)
#define FASTLED_FORCE_INLINE
#define FL_DISABLE_WARNING_PUSH
#define FL_DEPRECATED(msg)
#define FL_DISABLE_WARNING_SIGN_CONVERSION
#define FL_DISABLE_WARNING_POP
#define FL_DISABLE_WARNING_FLOAT_CONVERSION
Portable compile-time assertion wrapper.
static ColorAdjustment noAdjustment()
the per-channel scale values premixed with brightness.
Color adjustment structure for pixel output.
static FASTLED_FORCE_INLINE fl::u8 loadAndScale(PixelController &pc, int lane, fl::u8 d, fl::u8 scale)
Complete pipeline: load → dither → scale (explicit dither/scale values)
static FASTLED_FORCE_INLINE fl::u8 advanceAndLoadAndScale(PixelController &pc, int lane)
A version of loadAndScale() that advances the output data pointer.
FASTLED_FORCE_INLINE fl::u8 loadAndScale1()
FASTLED_FORCE_INLINE int size() const
Get the length of the LED strip.
PixelController(const fl::u8 *d, int len, ColorAdjustment color_adjustment, EDitherMode dither, bool advance, fl::u8 skip)
Constructor.
static FASTLED_FORCE_INLINE fl::u8 scale(PixelController &, fl::u8 b, fl::u8 scale)
Scale a value.
static FASTLED_FORCE_INLINE fl::u8 loadByte(PixelController &pc)
Read a byte of LED data.
void init_binary_dithering()
Set up the values for binary dithering.
static FASTLED_FORCE_INLINE fl::u8 advanceAndLoadAndScale(PixelController &pc, int lane, fl::u8 scale)
A version of loadAndScale() that advances the output data pointer without dithering.
int mLenRemaining
counter for the number of LEDs left to process
void initOffsets(int len)
Initialize the PixelController::mOffsets array based on the length of the strip.
FASTLED_FORCE_INLINE fl::u8 stepAdvanceAndLoadAndScale0(int lane, fl::u8 scale)
stepDithering() and advanceAndLoadAndScale0()
FASTLED_FORCE_INLINE fl::u8 getScale1()
non-template alias of getscale<1>()
FASTLED_FORCE_INLINE void preStepFirstByteDithering()
Some chipsets pre-cycle the first byte, which means we want to cycle byte 0's dithering separately.
fl::u8 e[3]
[DITHER] Max dither range per R,G,B channel (inversely proportional to brightness)
FASTLED_FORCE_INLINE void loadAndScaleRGBWW(fl::Rgbww rgbww, fl::u8 *b0_out, fl::u8 *b1_out, fl::u8 *b2_out, fl::u8 *b3_out, fl::u8 *b4_out)
Load + scale a single pixel to 5-channel RGBWW (issue #2558).
FASTLED_FORCE_INLINE fl::u8 loadAndScale0()
FASTLED_FORCE_INLINE int advanceBy()
Get the amount to advance the pointer by.
static FASTLED_FORCE_INLINE fl::u8 loadAndScale(PixelController &pc, int lane)
Complete pipeline: load → dither → scale (parallel output version)
static FASTLED_FORCE_INLINE fl::u8 loadByte(PixelController &pc, int lane)
Read a byte of LED data for parallel output.
static FASTLED_FORCE_INLINE fl::u8 scale(PixelController &pc, fl::u8 b)
Scale a value using the per-channel scale data.
FASTLED_FORCE_INLINE int lanes()
Get the number of lanes of the Controller.
fl::u8 d[3]
[DITHER] Current dither offset per R,G,B channel (toggles via stepDithering)
FASTLED_FORCE_INLINE fl::u8 stepAdvanceAndLoadAndScale0()
int mOffsets[LANES]
the number of bytes to offset each lane from the starting pointer
FASTLED_FORCE_INLINE fl::u8 loadAndScale2()
static FASTLED_FORCE_INLINE fl::u8 getscale(PixelController &pc)
Gets the scale data for the provided output slot.
PixelController(const PixelController< RGB_ORDER_OTHER, LANES, MASK > &other)
FASTLED_FORCE_INLINE void loadAndScaleRGBW(Rgbw rgbw, fl::u8 *b0_out, fl::u8 *b1_out, fl::u8 *b2_out, fl::u8 *b3_out)
PixelController(const CRGB &d, int len, ColorAdjustment color_adjustment, EDitherMode dither)
Constructor.
ColorAdjustment mColorAdjustment
const fl::u8 * mData
pointer to the underlying LED data
FASTLED_FORCE_INLINE void loadAndScaleRGB(fl::u8 *b0_out, fl::u8 *b1_out, fl::u8 *b2_out)
int mLen
number of LEDs in the data for one lane
FASTLED_FORCE_INLINE fl::u8 loadAndScale0(int lane, fl::u8 scale)
non-template alias of loadAndScale<0>()
FASTLED_FORCE_INLINE fl::u8 loadAndScale2(int lane)
void disableColorAdjustment()
const fl::u8 * getRawPixelData() const
Get read-only access to the current pixel data Used by encoders to access raw RGB values for HD proce...
static FASTLED_FORCE_INLINE fl::u8 advanceAndLoadAndScale(PixelController &pc)
A version of loadAndScale() that advances the output data pointer.
FASTLED_FORCE_INLINE fl::u8 advanceAndLoadAndScale0()
void enable_dithering(EDitherMode dither)
Toggle dithering enable/disable.
FASTLED_FORCE_INLINE fl::u8 getScale0()
non-template alias of getscale<0>()
FASTLED_FORCE_INLINE void advanceData()
Advance the data pointer forward, adjust position counter.
static FASTLED_FORCE_INLINE fl::u8 dither(PixelController &, fl::u8 b, fl::u8 d)
Add explicit dither offset to pixel value (BEFORE scaling).
FASTLED_FORCE_INLINE fl::u8 loadAndScale1(int lane, fl::u8 scale)
non-template alias of loadAndScale<1>()
FASTLED_FORCE_INLINE fl::u8 stepAdvanceAndLoadAndScale0(int lane)
FASTLED_FORCE_INLINE fl::u8 advanceAndLoadAndScale0(int lane, fl::u8 scale)
non-template alias of advanceAndLoadAndScale<0>()
FASTLED_FORCE_INLINE bool has(int n)
Do we have n pixels left to process?
static FASTLED_FORCE_INLINE fl::u8 getd(PixelController &pc)
Gets the dithering data for the provided output slot.
PixelController(const CRGB *d, int len, ColorAdjustment color_adjustment, EDitherMode dither)
Constructor.
FASTLED_FORCE_INLINE void stepDithering()
Step the dithering forward - creates triangular wave that toggles between pixels.
FASTLED_FORCE_INLINE fl::u8 loadAndScale2(int lane, fl::u8 scale)
non-template alias of loadAndScale<2>()
FASTLED_FORCE_INLINE fl::PixelIterator as_iterator(const Rgbw &rgbw)
static FASTLED_FORCE_INLINE fl::u8 loadAndScale(PixelController &pc)
Complete pipeline: load → dither → scale (THE MAGIC HAPPENS HERE!) Order is critical: pixel + dither ...
FASTLED_FORCE_INLINE fl::u8 loadAndScale1(int lane)
PixelController(const PixelController &other)
Copy constructor.
FASTLED_FORCE_INLINE fl::u8 getScale2()
non-template alias of getscale<2>()
static FASTLED_FORCE_INLINE fl::u8 loadAndScale(PixelController &pc, int lane, fl::u8 scale)
Loads and scales a single byte for a given output slot and lane.
static FASTLED_FORCE_INLINE fl::u8 dither(PixelController &pc, fl::u8 b)
Add dither offset to pixel value (BEFORE scaling).
void copy(const PixelControllerT &other)
FASTLED_FORCE_INLINE fl::u8 advanceAndLoadAndScale0(int lane)
fl::i8 mAdvance
how many bytes to advance the pointer by each time. For CRGB this is 3.
FASTLED_FORCE_INLINE fl::u8 loadAndScale0(int lane)
Per-strip RGBWW configuration.