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

◆ encodeHD108()

template<typename InputIterator, typename OutputIterator>
void fl::encodeHD108 ( InputIterator first,
InputIterator last,
OutputIterator out,
u8 global_brightness = 255 )

Encode pixel data in HD108 format with global brightness.

Template Parameters
InputIteratorIterator yielding fl::array<u8, 3> (3 bytes in wire order)
OutputIteratorOutput iterator accepting uint8_t
Parameters
firstIterator to first pixel
lastIterator past last pixel
outOutput iterator for encoded bytes
global_brightnessAccepted and ignored. HD108's per-channel 5-bit gains are pinned at maximum (31) for precision and brightness is expected to be applied to the 16-bit values before encoding, so this argument reaches neither the header nor the payload. Kept for source compatibility; the sole in-tree caller passes 255 and pre-scales. Passing anything else does not dim (FastLED#4042).
Note
Uses gamma 2.8 correction for 16-bit RGB
HD108 uses RGB wire order: pixel[0]=Red, pixel[1]=Green, pixel[2]=Blue

Definition at line 43 of file hd108.h.

44 {
45 // Start frame: 64 bits (8 bytes) of 0x00
46 for (int i = 0; i < 8; i++) {
47 *out++ = 0x00;
48 }
49
50 // Compute brightness header bytes (cached for all LEDs)
51 u8 f0, f1;
52 hd108BrightnessHeader(global_brightness, &f0, &f1);
53
54 // LED data: 2-byte header + 6-byte RGB16 (count as we go)
55 size_t num_leds = 0;
56 while (first != last) {
57 const fl::array<u8, BYTES_PER_PIXEL_RGB>& pixel = *first;
58
59 // Apply gamma correction (2.8) to 16-bit (RGB order: 0=R, 1=G, 2=B)
60 u16 r16 = hd108GammaCorrect(pixel[0]); // Red
61 u16 g16 = hd108GammaCorrect(pixel[1]); // Green
62 u16 b16 = hd108GammaCorrect(pixel[2]); // Blue
63
64 // Transmit: 2 header + 6 color bytes (16-bit RGB, big-endian)
65 *out++ = f0;
66 *out++ = f1;
67 *out++ = static_cast<u8>(r16 >> 8);
68 *out++ = static_cast<u8>(r16 & 0xFF);
69 *out++ = static_cast<u8>(g16 >> 8);
70 *out++ = static_cast<u8>(g16 & 0xFF);
71 *out++ = static_cast<u8>(b16 >> 8);
72 *out++ = static_cast<u8>(b16 & 0xFF);
73
74 ++first;
75 ++num_leds;
76 }
77
78 // End frame: (num_leds / 2) + 4 bytes of 0xFF
79 const size_t latch = num_leds / 2 + 4;
80 for (size_t i = 0; i < latch; i++) {
81 *out++ = 0xFF;
82 }
83}
A fixed-size array implementation similar to std::array.
Definition array.h:27
unsigned char u8
Definition stdint.h:131
void hd108BrightnessHeader(u8 brightness_8bit, u8 *f0_out, u8 *f1_out) FL_NO_EXCEPT
Generate HD108 per-channel gain header bytes.
u16 hd108GammaCorrect(u8 value) FL_NO_EXCEPT
Convert 8-bit color to HD108 16-bit gamma-corrected value (gamma 2.8)

References FL_NO_EXCEPT, hd108BrightnessHeader(), and hd108GammaCorrect().

+ Here is the call graph for this function: