FastLED 3.9.15
Loading...
Searching...
No Matches

◆ init_binary_dithering()

template<EOrder RGB_ORDER, int LANES = 1, uint32_t MASK = 0xFFFFFFFF>
void PixelController< RGB_ORDER, LANES, MASK >::init_binary_dithering ( )
inline

Set up the values for binary dithering.

Definition at line 226 of file pixel_controller.h.

226 {
227#if !defined(NO_DITHERING) || (NO_DITHERING != 1)
228 // R is the digther signal 'counter'.
229 static uint8_t R = 0;
230 ++R;
231
232 // R is wrapped around at 2^ditherBits,
233 // so if ditherBits is 2, R will cycle through (0,1,2,3)
235 R &= (0x01 << ditherBits) - 1;
236
237 // Q is the "unscaled dither signal" itself.
238 // It's initialized to the reversed bits of R.
239 // If 'ditherBits' is 2, Q here will cycle through (0,128,64,192)
240 uint8_t Q = 0;
241
242 // Reverse bits in a byte
243 {
244 if(R & 0x01) { Q |= 0x80; }
245 if(R & 0x02) { Q |= 0x40; }
246 if(R & 0x04) { Q |= 0x20; }
247 if(R & 0x08) { Q |= 0x10; }
248 if(R & 0x10) { Q |= 0x08; }
249 if(R & 0x20) { Q |= 0x04; }
250 if(R & 0x40) { Q |= 0x02; }
251 if(R & 0x80) { Q |= 0x01; }
252 }
253
254 // Now we adjust Q to fall in the center of each range,
255 // instead of at the start of the range.
256 // If ditherBits is 2, Q will be (0, 128, 64, 192) at first,
257 // and this adjustment makes it (31, 159, 95, 223).
258 if( ditherBits < 8) {
259 Q += 0x01 << (7 - ditherBits);
260 }
261
262 // D and E form the "scaled dither signal"
263 // which is added to pixel values to affect the
264 // actual dithering.
265
266 // Setup the initial D and E values
267 for(int i = 0; i < 3; ++i) {
268 uint8_t s = mColorAdjustment.premixed.raw[i];
269 e[i] = s ? (256/s) + 1 : 0;
270 d[i] = scale8(Q, e[i]);
271#if (FASTLED_SCALE8_FIXED == 1)
272 if(d[i]) (--d[i]);
273#endif
274 if(e[i]) --e[i];
275 }
276#endif
277 }
LIB8STATIC_ALWAYS_INLINE uint8_t scale8(uint8_t i, fract8 scale)
Scale one byte by a second one, which is treated as the numerator of a fraction whose denominator is ...
Definition scale8.h:34
uint8_t d[3]
values for the scaled dither signal
ColorAdjustment mColorAdjustment
uint8_t e[3]
values for the unscaled dither signal
Pixel controller class.

References d, e, mColorAdjustment, scale8(), and VIRTUAL_BITS.

Referenced by enable_dithering().

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