FastLED 3.10.6
Loading...
Searching...
No Matches

◆ encodeUCS7604()

template<typename OutputIterator>
void fl::encodeUCS7604 ( PixelIterator & pixel_iter,
size_t num_leds,
OutputIterator out,
UCS7604Mode mode,
const UCS7604CurrentControl & current,
bool is_rgbw,
const Gamma8 * gamma = nullptr,
bool wide_source = false )

Encode complete UCS7604 frame (preamble + padding + pixel data)

Template Parameters
OutputIteratorOutput iterator accepting uint8_t
Parameters
pixel_iterPixelIterator with pixel data and scaling/gamma/dithering
num_ledsNumber of LEDs to encode
outOutput iterator for complete frame
modeUCS7604 protocol mode (8-bit/16-bit)
currentCurrent control settings (wire order RGBW)
is_rgbwTrue for RGBW mode, false for RGB mode
gammaGamma8 LUT for 16-bit modes (nullable, ignored for 8-bit mode)
Note
Outputs: preamble (15 bytes) + padding (0-2 bytes) + LED data
Total output size is always divisible by 3 (required by UCS7604 protocol)

Definition at line 273 of file ucs7604.h.

276 {
277 constexpr size_t PREAMBLE_LEN = 15;
278
279#if FL_PLATFORM_HAS_TINY_MEMORY
280 // No wide encoder exists on TINY, so the flag selects nothing there.
281 FL_UNUSED(wide_source);
282#endif
283
284 // Padding comes from ucs7604FrameBytes() so the length callers predict and
285 // the length written here are the same number by construction.
286 const size_t led_data_size = num_leds * ucs7604BytesPerLed(mode, is_rgbw);
287 const size_t padding =
288 ucs7604FrameBytes(num_leds, mode, is_rgbw) - PREAMBLE_LEN - led_data_size;
289
290 // Build preamble (15 bytes) with current control
291 buildUCS7604Preamble(out, mode, current.r, current.g, current.b, current.w);
292
293 // Add padding (0-2 zero bytes)
294 for (size_t i = 0; i < padding; ++i) {
295 *out++ = 0;
296 }
297
298 // Encode LED data based on mode and RGB/RGBW
300 if (is_rgbw) {
301 auto range = makeScaledPixelRangeRGBW(&pixel_iter);
302 encodeUCS7604_8bit_RGBW(range.first, range.second, out);
303 } else {
304 auto range = makeScaledPixelRangeRGB(&pixel_iter);
305 encodeUCS7604_8bit_RGB(range.first, range.second, out);
306 }
307 } else {
308 // 16-bit modes -- fall back to gamma 2.8 if no gamma provided
309 static fl::shared_ptr<const Gamma8> default_gamma;
310 const Gamma8& g = gamma ? *gamma : *(default_gamma ? default_gamma : (default_gamma = Gamma8::getOrCreate(2.8f)));
311 if (is_rgbw) {
312 // RGBW stays on the gamma path: `ColorManagedPixelSource`
313 // delegates its RGBW entry point to the legacy controller, so
314 // there is no wide drive to consume here yet.
315 auto range = makeScaledPixelRangeRGBW(&pixel_iter);
316 encodeUCS7604_16bit_RGBW(range.first, range.second, out, g);
317#if !FL_PLATFORM_HAS_TINY_MEMORY
318 } else if (wide_source) {
319 encodeUCS7604_16bit_RGB_wide(pixel_iter, out);
320#endif
321 } else {
322 auto range = makeScaledPixelRangeRGB(&pixel_iter);
323 encodeUCS7604_16bit_RGB(range.first, range.second, out, g);
324 }
325 }
326}
static fl::shared_ptr< const Gamma8 > getOrCreate(float gamma) FL_NO_EXCEPT
Definition ease.cpp.hpp:459
#define FL_UNUSED(x)
constexpr u32 gamma(float g) FL_NO_EXCEPT
Definition gamma_lut.h:36
size_t ucs7604FrameBytes(size_t num_leds, UCS7604Mode mode, bool is_rgbw) FL_NO_EXCEPT
Total wire bytes of a complete UCS7604 frame.
Definition ucs7604.h:253
pair< detail::ScaledPixelIteratorRGBW, detail::ScaledPixelIteratorRGBW > makeScaledPixelRangeRGBW(PixelIterator *pixels) FL_NO_EXCEPT
Create RGBW input iterator range from PixelIterator.
void buildUCS7604Preamble(OutputIterator out, UCS7604Mode mode, u8 r_current, u8 g_current, u8 b_current, u8 w_current)
Build UCS7604 preamble (15 bytes)
Definition ucs7604.h:71
void encodeUCS7604_8bit_RGB(InputIterator first, InputIterator last, OutputIterator out)
Encode RGB pixels in UCS7604 8-bit format.
Definition ucs7604.h:108
void encodeUCS7604_16bit_RGBW(InputIterator first, InputIterator last, OutputIterator out, const Gamma8 &gamma)
Encode RGBW pixels in UCS7604 16-bit format with gamma correction.
Definition ucs7604.h:216
void encodeUCS7604_16bit_RGB_wide(PixelIterator &pixels, OutputIterator out) FL_NO_EXCEPT
Wide RGB straight off the iterator, with no adapter (P8, #4042 / #4326).
Definition ucs7604.h:191
@ UCS7604_MODE_8BIT_800KHZ
Definition ucs7604.h:31
void encodeUCS7604_16bit_RGB(InputIterator first, InputIterator last, OutputIterator out, const Gamma8 &gamma) FL_NO_EXCEPT
Encode RGB pixels in UCS7604 16-bit format with gamma correction.
Definition ucs7604.h:146
InputGamut g
Definition rgbw.h:124
void encodeUCS7604_8bit_RGBW(InputIterator first, InputIterator last, OutputIterator out)
Encode RGBW pixels in UCS7604 8-bit format.
Definition ucs7604.h:126
size_t ucs7604BytesPerLed(UCS7604Mode mode, bool is_rgbw) FL_NO_EXCEPT
Wire bytes each LED contributes to a UCS7604 frame.
Definition ucs7604.h:240
pair< detail::ScaledPixelIteratorRGB, detail::ScaledPixelIteratorRGB > makeScaledPixelRangeRGB(PixelIterator *pixels) FL_NO_EXCEPT
Create RGB input iterator range from PixelIterator.
u8 g
Green channel current (0x0-0xF)
Definition ucs7604.h:39
u8 b
Blue channel current (0x0-0xF)
Definition ucs7604.h:40
u8 w
White channel current (0x0-0xF)
Definition ucs7604.h:41
u8 r
Red channel current (0x0-0xF)
Definition ucs7604.h:38

References fl::UCS7604CurrentControl::b, buildUCS7604Preamble(), encodeUCS7604_16bit_RGB(), encodeUCS7604_16bit_RGB_wide(), encodeUCS7604_16bit_RGBW(), encodeUCS7604_8bit_RGB(), encodeUCS7604_8bit_RGBW(), FL_NO_EXCEPT, FL_UNUSED, g, fl::UCS7604CurrentControl::g, gamma(), fl::Gamma8::getOrCreate(), makeScaledPixelRangeRGB(), makeScaledPixelRangeRGBW(), fl::UCS7604CurrentControl::r, UCS7604_MODE_8BIT_800KHZ, ucs7604BytesPerLed(), ucs7604FrameBytes(), and fl::UCS7604CurrentControl::w.

Referenced by fl::UCS7604ControllerT< DATA_PIN, RGB_ORDER, fl::UCS7604Mode::UCS7604_MODE_8BIT_800KHZ, fl::TIMING_UCS7604_800KHZ, CLOCKLESS_CONTROLLER >::showPixels(), and fl::anonymous_namespace{channel.cpp.hpp}::writeUCS7604().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: