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 238 of file pixel_controller.h.

238 {
239#if !defined(NO_DITHERING) || (NO_DITHERING != 1)
240 // R is the digther signal 'counter'.
241 static uint8_t R = 0;
242 ++R;
243
244 // R is wrapped around at 2^ditherBits,
245 // so if ditherBits is 2, R will cycle through (0,1,2,3)
247 R &= (0x01 << ditherBits) - 1;
248
249 // Q is the "unscaled dither signal" itself.
250 // It's initialized to the reversed bits of R.
251 // If 'ditherBits' is 2, Q here will cycle through (0,128,64,192)
252 uint8_t Q = 0;
253
254 // Reverse bits in a byte
255 {
256 if(R & 0x01) { Q |= 0x80; }
257 if(R & 0x02) { Q |= 0x40; }
258 if(R & 0x04) { Q |= 0x20; }
259 if(R & 0x08) { Q |= 0x10; }
260 if(R & 0x10) { Q |= 0x08; }
261 if(R & 0x20) { Q |= 0x04; }
262 if(R & 0x40) { Q |= 0x02; }
263 if(R & 0x80) { Q |= 0x01; }
264 }
265
266 // Now we adjust Q to fall in the center of each range,
267 // instead of at the start of the range.
268 // If ditherBits is 2, Q will be (0, 128, 64, 192) at first,
269 // and this adjustment makes it (31, 159, 95, 223).
270 if( ditherBits < 8) {
271 Q += 0x01 << (7 - ditherBits);
272 }
273
274 // D and E form the "scaled dither signal"
275 // which is added to pixel values to affect the
276 // actual dithering.
277
278 // Setup the initial D and E values
279 for(int i = 0; i < 3; ++i) {
280 uint8_t s = mColorAdjustment.premixed.raw[i];
281 e[i] = s ? (256/s) + 1 : 0;
282 d[i] = scale8(Q, e[i]);
283#if (FASTLED_SCALE8_FIXED == 1)
284 if(d[i]) (--d[i]);
285#endif
286 if(e[i]) --e[i];
287 }
288#endif
289 }
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:44
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: