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

◆ encodeHD108_HD()

template<typename InputIterator, typename BrightnessIterator, typename OutputIterator>
void fl::encodeHD108_HD ( InputIterator first,
InputIterator last,
BrightnessIterator brightness_first,
OutputIterator out )

Encode pixel data in HD108 format with per-LED brightness.

Template Parameters
InputIteratorIterator yielding fl::array<u8, 3> (3 bytes in wire order)
BrightnessIteratorIterator yielding uint8_t brightness values
OutputIteratorOutput iterator accepting uint8_t
Parameters
firstIterator to first pixel
lastIterator past last pixel
brightness_firstAccepted and never read. hd108BrightnessHeader() pins all gains at 31 regardless, so per-LED brightness has no effect on the output (FastLED#4042) – it used to be dereferenced once per LED and thrown away, which cost a call each time (FastLED#4402). Kept for source compatibility.
outOutput iterator for encoded bytes
Note
HD108 uses RGB wire order: pixel[0]=Red, pixel[1]=Green, pixel[2]=Blue

Definition at line 99 of file hd108.h.

100 {
101 FL_UNUSED(brightness_first);
102 // Start frame: 64 bits (8 bytes) of 0x00
103 for (int i = 0; i < 8; i++) {
104 *out++ = 0x00;
105 }
106
107 // One header for the whole strip. `hd108BrightnessHeader` discards its
108 // argument -- `(void)brightness_8bit`, then three `constexpr` gains of 31
109 // -- so it returns 0xFF 0xFF for every input. There was a per-LED cache
110 // here guarding against recomputing a value that cannot change, and a
111 // `*brightness_first` read feeding it; both computed the same two bytes
112 // every time. Reading the brightness per LED was the more expensive half:
113 // `ScaledPixelIteratorBrightness::load()` is out of line, so it was a call
114 // per LED to fetch a number that reached nothing. See FastLED#4402.
115 u8 f0, f1;
116 hd108BrightnessHeader(0, &f0, &f1);
117
118 // LED data: 2-byte header + 6-byte RGB16 (count as we go)
119 size_t num_leds = 0;
120 while (first != last) {
121 const fl::array<u8, BYTES_PER_PIXEL_RGB>& pixel = *first;
122
123 // Apply gamma correction (2.8) to 16-bit (RGB order: 0=R, 1=G, 2=B)
124 u16 r16 = hd108GammaCorrect(pixel[0]); // Red
125 u16 g16 = hd108GammaCorrect(pixel[1]); // Green
126 u16 b16 = hd108GammaCorrect(pixel[2]); // Blue
127
128 // Transmit: 2 header + 6 color bytes (16-bit RGB, big-endian)
129 *out++ = f0;
130 *out++ = f1;
131 *out++ = static_cast<u8>(r16 >> 8);
132 *out++ = static_cast<u8>(r16 & 0xFF);
133 *out++ = static_cast<u8>(g16 >> 8);
134 *out++ = static_cast<u8>(g16 & 0xFF);
135 *out++ = static_cast<u8>(b16 >> 8);
136 *out++ = static_cast<u8>(b16 & 0xFF);
137
138 ++first;
139 ++num_leds;
140 }
141
142 // End frame: (num_leds / 2) + 4 bytes of 0xFF
143 const size_t latch = num_leds / 2 + 4;
144 for (size_t i = 0; i < latch; i++) {
145 *out++ = 0xFF;
146 }
147}
A fixed-size array implementation similar to std::array.
Definition array.h:27
#define FL_UNUSED(x)
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, FL_UNUSED, hd108BrightnessHeader(), and hd108GammaCorrect().

+ Here is the call graph for this function: