FastLED 3.10.8
Loading...
Searching...
No Matches
pixel_iterator_adapters.h
Go to the documentation of this file.
1#pragma once
2
14
15#include "fl/stl/stdint.h"
16#include "fl/stl/array.h"
17#include "fl/stl/pair.h"
18#include "fl/stl/iterator.h"
19#include "fl/stl/noexcept.h"
20#include "crgb.h" // FASTLED_HD_COLOR_MIXING
21
22namespace fl {
23
24class PixelIterator; // Forward declaration
25
26namespace detail {
27
37public:
38 // Iterator traits
42 using pointer = const array<u8, 3>*;
43 using reference = const array<u8, 3>&;
44
48 : mPixels(pixels), mCurrent(), mHasValue(false) {
49 advance(); // Preload first pixel
50 }
51
55
59 return mCurrent;
60 }
61
65 return &mCurrent;
66 }
67
71 advance();
72 return *this;
73 }
74
78 ScaledPixelIteratorRGB tmp = *this;
79 advance();
80 return tmp;
81 }
82
87 // Two end iterators are equal
88 if (!mHasValue && !other.mHasValue) {
89 return true;
90 }
91 // End iterator vs valid iterator
92 if (mHasValue != other.mHasValue) {
93 return false;
94 }
95 // Two valid iterators - compare underlying pixel iterators
96 return mPixels == other.mPixels;
97 }
98
103 return !(*this == other);
104 }
105
106private:
108 void advance() FL_NO_EXCEPT;
109
113};
114
121public:
122 // Iterator traits
126 using pointer = const array<u8, 4>*;
127 using reference = const array<u8, 4>&;
128
132 : mPixels(pixels), mCurrent(), mHasValue(false) {
133 advance(); // Preload first pixel
134 }
135
139
143 return mCurrent;
144 }
145
149 return &mCurrent;
150 }
151
154 advance();
155 return *this;
156 }
157
160 ScaledPixelIteratorRGBW tmp = *this;
161 advance();
162 return tmp;
163 }
164
167 if (!mHasValue && !other.mHasValue) {
168 return true;
169 }
170 if (mHasValue != other.mHasValue) {
171 return false;
172 }
173 return mPixels == other.mPixels;
174 }
175
178 return !(*this == other);
179 }
180
181private:
183 void advance() FL_NO_EXCEPT;
184
188};
189
195public:
199 using pointer = const array<u8, 5>*;
200 using reference = const array<u8, 5>&;
201
203 : mPixels(pixels), mCurrent(), mHasValue(false) {
204 advance();
205 }
206
209
210 const array<u8, 5>& operator*() const FL_NO_EXCEPT { return mCurrent; }
211 const array<u8, 5>* operator->() const FL_NO_EXCEPT { return &mCurrent; }
212
215 ScaledPixelIteratorRGBWW tmp = *this;
216 advance();
217 return tmp;
218 }
219
221 if (!mHasValue && !other.mHasValue) return true;
222 if (mHasValue != other.mHasValue) return false;
223 return mPixels == other.mPixels;
224 }
225
227 return !(*this == other);
228 }
229
230private:
231 void advance() FL_NO_EXCEPT;
232
236};
237
238#if FASTLED_HD_COLOR_MIXING
251class ScaledPixelIteratorBrightness {
252public:
253 // Iterator traits
255 using value_type = u8;
257 using pointer = const u8*;
258 using reference = u8;
259
262 explicit ScaledPixelIteratorBrightness(PixelIterator* pixels) FL_NO_EXCEPT
263 : mPixels(pixels), mCurrent(0) {
264 load();
265 }
266
268 u8 operator*() const FL_NO_EXCEPT {
269 return mCurrent;
270 }
271
273 ScaledPixelIteratorBrightness& operator++() FL_NO_EXCEPT {
274 load();
275 return *this;
276 }
277
279 ScaledPixelIteratorBrightness operator++(int) FL_NO_EXCEPT {
280 ScaledPixelIteratorBrightness tmp = *this;
281 load();
282 return tmp;
283 }
284
285 // No sentinel constructor and no comparisons, on purpose. This iterator
286 // advances nothing, so it can never reach an end -- any loop written
287 // against a sentinel here would spin forever. The encoders stop on the
288 // RGB range they walk alongside, which is the only real termination.
289
290private:
292 void load() FL_NO_EXCEPT;
293
295 u8 mCurrent;
296};
297#endif // FASTLED_HD_COLOR_MIXING
298
307public:
308 // Iterator traits
312 using pointer = const array<u16, 3>*;
313 using reference = const array<u16, 3>&;
314
318 : mPixels(pixels), mCurrent(), mHasValue(false) {
319 advance(); // Preload first pixel
320 }
321
325
329 return mCurrent;
330 }
331
335 return &mCurrent;
336 }
337
341 advance();
342 return *this;
343 }
344
348 ScaledPixelIteratorRGB16 tmp = *this;
349 advance();
350 return tmp;
351 }
352
357 // Two end iterators are equal
358 if (!mHasValue && !other.mHasValue) {
359 return true;
360 }
361 // End iterator vs valid iterator
362 if (mHasValue != other.mHasValue) {
363 return false;
364 }
365 // Two valid iterators - compare underlying pixel iterators
366 return mPixels == other.mPixels;
367 }
368
373 return !(*this == other);
374 }
375
376private:
378 void advance() FL_NO_EXCEPT;
379
381 array<u16, 3> mCurrent;
383};
384
385} // namespace detail
386
397
401inline pair<detail::ScaledPixelIteratorRGBW, detail::ScaledPixelIteratorRGBW>
408
410inline pair<detail::ScaledPixelIteratorRGBWW, detail::ScaledPixelIteratorRGBWW>
417
418#if FASTLED_HD_COLOR_MIXING
435inline detail::ScaledPixelIteratorBrightness
436makeScaledBrightness(PixelIterator* pixels) FL_NO_EXCEPT {
437 return detail::ScaledPixelIteratorBrightness(pixels);
438}
439#endif // FASTLED_HD_COLOR_MIXING
440
444inline pair<detail::ScaledPixelIteratorRGB16, detail::ScaledPixelIteratorRGB16>
451
452// NOTE: For APA102 HD mode, the chipset-specific gamma correction (five_bit_hd_gamma_bitshift)
453// needs to be applied. Since this is chipset-specific and not a general iterator adapter concern,
454// the APA102 controller applies it inline in the showPixelsGammaBitShift() method.
455// The controller uses getRawPixelData() to get raw RGB, applies gamma with loadRGBScaleAndBrightness(),
456// then uses loadAndScaleRGB() to get wire-ordered output.
457
458} // namespace fl
459
460// ===========================================================================
461// Implementation of adapter advance() methods
462// ===========================================================================
463// NOTE: These implementations are defined in pixel_iterator.h after the
464// PixelIterator class is fully defined, as they require complete type.
A fixed-size array implementation similar to std::array.
Definition array.h:27
void advance() FL_NO_EXCEPT
Advance to next pixel (or mark as end)
PixelIterator * mPixels
Underlying PixelIterator.
ScaledPixelIteratorRGB16(PixelIterator *pixels) FL_NO_EXCEPT
Construct from PixelIterator.
ScaledPixelIteratorRGB16 operator++(int) FL_NO_EXCEPT
Post-increment operator.
array< u16, 3 > mCurrent
Current pixel value (cached, wire order, 16-bit)
const array< u16, 3 > & operator*() const FL_NO_EXCEPT
Dereference operator.
bool operator!=(const ScaledPixelIteratorRGB16 &other) const FL_NO_EXCEPT
Inequality comparison.
bool mHasValue
true if current pixel is valid
ScaledPixelIteratorRGB16 & operator++() FL_NO_EXCEPT
Pre-increment operator.
ScaledPixelIteratorRGB16() FL_NO_EXCEPT
Sentinel constructor (end iterator)
const array< u16, 3 > * operator->() const FL_NO_EXCEPT
Arrow operator.
bool operator==(const ScaledPixelIteratorRGB16 &other) const FL_NO_EXCEPT
Equality comparison.
Input iterator adapter for PixelIterator yielding 16-bit RGB pixel data.
PixelIterator * mPixels
Underlying PixelIterator.
ScaledPixelIteratorRGB(PixelIterator *pixels) FL_NO_EXCEPT
Construct from PixelIterator.
const array< u8, 3 > * operator->() const FL_NO_EXCEPT
Arrow operator.
bool operator!=(const ScaledPixelIteratorRGB &other) const FL_NO_EXCEPT
Inequality comparison.
ScaledPixelIteratorRGB & operator++() FL_NO_EXCEPT
Pre-increment operator.
bool operator==(const ScaledPixelIteratorRGB &other) const FL_NO_EXCEPT
Equality comparison.
array< u8, 3 > mCurrent
Current pixel value (cached, wire order)
void advance() FL_NO_EXCEPT
Advance to next pixel (or mark as end)
const array< u8, 3 > & operator*() const FL_NO_EXCEPT
Dereference operator.
ScaledPixelIteratorRGB operator++(int) FL_NO_EXCEPT
Post-increment operator.
ScaledPixelIteratorRGB() FL_NO_EXCEPT
Sentinel constructor (end iterator)
bool mHasValue
true if current pixel is valid
Input iterator adapter for PixelIterator yielding 3-byte pixel data.
array< u8, 4 > mCurrent
Current pixel value (cached, wire order)
ScaledPixelIteratorRGBW(PixelIterator *pixels) FL_NO_EXCEPT
Construct from PixelIterator.
bool operator!=(const ScaledPixelIteratorRGBW &other) const FL_NO_EXCEPT
Inequality comparison.
const array< u8, 4 > * operator->() const FL_NO_EXCEPT
Arrow operator.
bool operator==(const ScaledPixelIteratorRGBW &other) const FL_NO_EXCEPT
Equality comparison.
bool mHasValue
true if current pixel is valid
ScaledPixelIteratorRGBW() FL_NO_EXCEPT
Sentinel constructor (end iterator)
ScaledPixelIteratorRGBW operator++(int) FL_NO_EXCEPT
Post-increment operator.
const array< u8, 4 > & operator*() const FL_NO_EXCEPT
Dereference operator.
PixelIterator * mPixels
Underlying PixelIterator.
ScaledPixelIteratorRGBW & operator++() FL_NO_EXCEPT
Pre-increment operator.
Input iterator adapter for PixelIterator yielding 4-byte pixel data.
ScaledPixelIteratorRGBWW & operator++() FL_NO_EXCEPT
ScaledPixelIteratorRGBWW(PixelIterator *pixels) FL_NO_EXCEPT
const array< u8, 5 > * operator->() const FL_NO_EXCEPT
bool operator!=(const ScaledPixelIteratorRGBWW &other) const FL_NO_EXCEPT
const array< u8, 5 > & operator*() const FL_NO_EXCEPT
bool operator==(const ScaledPixelIteratorRGBWW &other) const FL_NO_EXCEPT
ScaledPixelIteratorRGBWW operator++(int) FL_NO_EXCEPT
Input iterator adapter yielding 5-byte RGBWW pixels (issue #2558).
pair< typename fl::decay< T1 >::type, typename fl::decay< T2 >::type > make_pair(T1 &&t, T2 &&u) FL_NO_EXCEPT
Definition pair.h:97
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_info.h:57
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
pair< detail::ScaledPixelIteratorRGB16, detail::ScaledPixelIteratorRGB16 > makeScaledPixelRangeRGB16(PixelIterator *pixels) FL_NO_EXCEPT
Create 16-bit RGB input iterator range from PixelIterator.
pair< detail::ScaledPixelIteratorRGBW, detail::ScaledPixelIteratorRGBW > makeScaledPixelRangeRGBW(PixelIterator *pixels) FL_NO_EXCEPT
Create RGBW input iterator range from PixelIterator.
fl::ptrdiff_t ptrdiff_t
Definition s16x16x4.h:63
pair< detail::ScaledPixelIteratorRGB, detail::ScaledPixelIteratorRGB > makeScaledPixelRangeRGB(PixelIterator *pixels) FL_NO_EXCEPT
Create RGB input iterator range from PixelIterator.
pair< detail::ScaledPixelIteratorRGBWW, detail::ScaledPixelIteratorRGBWW > makeScaledPixelRangeRGBWW(PixelIterator *pixels) FL_NO_EXCEPT
Create RGBWW input iterator range from PixelIterator (issue #2558)
Base definition for an LED controller.
Definition crgb.hpp:179
fl::PixelIterator PixelIterator
#define FL_NO_EXCEPT