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

◆ PixelIterator()

template<typename PixelControllerT>
fl::PixelIterator::PixelIterator ( PixelControllerT * pc,
Rgbw rgbw )
inline

Definition at line 101 of file pixel_iterator.h.

102 : mPixelController(pc), mRgbw(rgbw) {
103 // Manually build up a vtable.
104 // Wait... what? Stupid nerds trying to show off how smart they are...
105 // Why not just use a virtual function?!
106 //
107 // Before you think this then you should know that the alternative straight
108 // forward way is to have a virtual interface class that PixelController inherits from.
109 // ...and that was already tried. And if you try to do this yourself
110 // this then let me tell you what is going to happen...
111 //
112 // EVERY SINGLE PLATFORM THAT HAS A COMPILED BINARY SIZE CHECK WILL IMMEDIATELY
113 // FAIL AS THE BINARY BLOWS UP BY 10-30%!!! It doesn't matter if only one PixelController
114 // with a vtable is used, gcc seems not to de-virtualize the calls. And we really care
115 // about binary size since FastLED needs to run on those tiny little microcontrollers like
116 // the Attiny85 (and family) which are in the sub $1 range used for commercial products.
117 //
118 // So to satisfy these tight memory requirements we make the dynamic dispatch used in PixelIterator
119 // an optional zero-cost abstraction which doesn't affect the binary size for platforms that
120 // don't use it. So that's why we are using this manual construction of the vtable that is built
121 // up using template magic. If your platform has lots of memory then you'll gladly trade
122 // a sliver of memory for the convenience of having a concrete implementation of
123 // PixelController that you can use without having to make all your driver code a template.
124 //
125 // Btw, this pattern in C++ is called the "type-erasure pattern". It allows non virtual
126 // polymorphism by leveraging the C++ template system to ensure type safety.
127 typedef PixelControllerVtable<PixelControllerT> Vtable;
130 #if FASTLED_PIXEL_ITERATOR_HAS_APA102_HD
131 mLoadAndScale_APA102_HD = &Vtable::loadAndScale_APA102_HD;
132 #endif
137 mHas = &Vtable::has;
138 #if FASTLED_HD_COLOR_MIXING
139 mGetHdScale = &Vtable::getHdScale;
140 #endif
141 }
Rgbw rgbw
loadAndScale_WS2816_HDFunction mLoadAndScale_WS2816_HD
void loadAndScaleRGBW(uint8_t *b0_out, uint8_t *b1_out, uint8_t *b2_out, uint8_t *w_out)
stepDitheringFunction mStepDithering
advanceDataFunction mAdvanceData
loadAndScaleRGBFunction mLoadAndScaleRGB
void loadAndScale_WS2816_HD(uint16_t *s0_out, uint16_t *s1_out, uint16_t *s2_out)
void loadAndScaleRGB(uint8_t *r_out, uint8_t *g_out, uint8_t *b_out)
loadAndScaleRGBWFunction mLoadAndScaleRGBW

References mAdvanceData, mHas, mLoadAndScale_WS2816_HD, mLoadAndScaleRGB, mLoadAndScaleRGBW, mPixelController, mRgbw, mSize, mStepDithering, and rgbw.