FastLED 3.9.15
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
21namespace fl {
22
23class PixelIterator; // Forward declaration
24
25namespace detail {
26
36public:
37 // Iterator traits
41 using pointer = const array<u8, 3>*;
42 using reference = const array<u8, 3>&;
43
47 : mPixels(pixels), mCurrent(), mHasValue(false) {
48 advance(); // Preload first pixel
49 }
50
54
58 return mCurrent;
59 }
60
64 return &mCurrent;
65 }
66
70 advance();
71 return *this;
72 }
73
77 ScaledPixelIteratorRGB tmp = *this;
78 advance();
79 return tmp;
80 }
81
86 // Two end iterators are equal
87 if (!mHasValue && !other.mHasValue) {
88 return true;
89 }
90 // End iterator vs valid iterator
91 if (mHasValue != other.mHasValue) {
92 return false;
93 }
94 // Two valid iterators - compare underlying pixel iterators
95 return mPixels == other.mPixels;
96 }
97
102 return !(*this == other);
103 }
104
105private:
107 void advance() FL_NOEXCEPT;
108
112};
113
120public:
121 // Iterator traits
125 using pointer = const array<u8, 4>*;
126 using reference = const array<u8, 4>&;
127
131 : mPixels(pixels), mCurrent(), mHasValue(false) {
132 advance(); // Preload first pixel
133 }
134
138
142 return mCurrent;
143 }
144
148 return &mCurrent;
149 }
150
153 advance();
154 return *this;
155 }
156
159 ScaledPixelIteratorRGBW tmp = *this;
160 advance();
161 return tmp;
162 }
163
166 if (!mHasValue && !other.mHasValue) {
167 return true;
168 }
169 if (mHasValue != other.mHasValue) {
170 return false;
171 }
172 return mPixels == other.mPixels;
173 }
174
177 return !(*this == other);
178 }
179
180private:
182 void advance() FL_NOEXCEPT;
183
187};
188
194public:
198 using pointer = const array<u8, 5>*;
199 using reference = const array<u8, 5>&;
200
202 : mPixels(pixels), mCurrent(), mHasValue(false) {
203 advance();
204 }
205
208
209 const array<u8, 5>& operator*() const FL_NOEXCEPT { return mCurrent; }
210 const array<u8, 5>* operator->() const FL_NOEXCEPT { return &mCurrent; }
211
214 ScaledPixelIteratorRGBWW tmp = *this;
215 advance();
216 return tmp;
217 }
218
220 if (!mHasValue && !other.mHasValue) return true;
221 if (mHasValue != other.mHasValue) return false;
222 return mPixels == other.mPixels;
223 }
224
226 return !(*this == other);
227 }
228
229private:
230 void advance() FL_NOEXCEPT;
231
235};
236
241public:
242 // Iterator traits
244 using value_type = u8;
246 using pointer = const u8*;
247 using reference = u8;
248
252 : mPixels(pixels), mCurrent(0), mHasValue(false) {
253 advance(); // Preload first brightness
254 }
255
259
262 return mCurrent;
263 }
264
267 advance();
268 return *this;
269 }
270
277
280 if (!mHasValue && !other.mHasValue) {
281 return true;
282 }
283 if (mHasValue != other.mHasValue) {
284 return false;
285 }
286 return mPixels == other.mPixels;
287 }
288
291 return !(*this == other);
292 }
293
294private:
296 void advance() FL_NOEXCEPT;
297
301};
302
311public:
312 // Iterator traits
316 using pointer = const array<u16, 3>*;
317 using reference = const array<u16, 3>&;
318
322 : mPixels(pixels), mCurrent(), mHasValue(false) {
323 advance(); // Preload first pixel
324 }
325
329
333 return mCurrent;
334 }
335
339 return &mCurrent;
340 }
341
345 advance();
346 return *this;
347 }
348
352 ScaledPixelIteratorRGB16 tmp = *this;
353 advance();
354 return tmp;
355 }
356
361 // Two end iterators are equal
362 if (!mHasValue && !other.mHasValue) {
363 return true;
364 }
365 // End iterator vs valid iterator
366 if (mHasValue != other.mHasValue) {
367 return false;
368 }
369 // Two valid iterators - compare underlying pixel iterators
370 return mPixels == other.mPixels;
371 }
372
377 return !(*this == other);
378 }
379
380private:
382 void advance() FL_NOEXCEPT;
383
385 array<u16, 3> mCurrent;
387};
388
389} // namespace detail
390
401
405inline pair<detail::ScaledPixelIteratorRGBW, detail::ScaledPixelIteratorRGBW>
412
414inline pair<detail::ScaledPixelIteratorRGBWW, detail::ScaledPixelIteratorRGBWW>
421
425inline pair<detail::ScaledPixelIteratorBrightness, detail::ScaledPixelIteratorBrightness>
432
436inline pair<detail::ScaledPixelIteratorRGB16, detail::ScaledPixelIteratorRGB16>
443
444// NOTE: For APA102 HD mode, the chipset-specific gamma correction (five_bit_hd_gamma_bitshift)
445// needs to be applied. Since this is chipset-specific and not a general iterator adapter concern,
446// the APA102 controller applies it inline in the showPixelsGammaBitShift() method.
447// The controller uses getRawPixelData() to get raw RGB, applies gamma with loadRGBScaleAndBrightness(),
448// then uses loadAndScaleRGB() to get wire-ordered output.
449
450} // namespace fl
451
452// ===========================================================================
453// Implementation of adapter advance() methods
454// ===========================================================================
455// NOTE: These implementations are defined in pixel_iterator.h after the
456// PixelIterator class is fully defined, as they require complete type.
A fixed-size array implementation similar to std::array.
Definition array.h:27
u8 operator*() const FL_NOEXCEPT
Dereference operator.
bool operator!=(const ScaledPixelIteratorBrightness &other) const FL_NOEXCEPT
Inequality comparison.
ScaledPixelIteratorBrightness & operator++() FL_NOEXCEPT
Pre-increment operator.
bool operator==(const ScaledPixelIteratorBrightness &other) const FL_NOEXCEPT
Equality comparison.
ScaledPixelIteratorBrightness() FL_NOEXCEPT
Sentinel constructor (end iterator)
ScaledPixelIteratorBrightness(PixelIterator *pixels) FL_NOEXCEPT
Construct from PixelIterator.
bool mHasValue
true if current value is valid
u8 mCurrent
Current brightness value (cached)
PixelIterator * mPixels
Underlying PixelIterator.
ScaledPixelIteratorBrightness operator++(int) FL_NOEXCEPT
Post-increment operator.
Input iterator adapter for PixelIterator yielding brightness values.
bool operator!=(const ScaledPixelIteratorRGB16 &other) const FL_NOEXCEPT
Inequality comparison.
ScaledPixelIteratorRGB16 & operator++() FL_NOEXCEPT
Pre-increment operator.
PixelIterator * mPixels
Underlying PixelIterator.
array< u16, 3 > mCurrent
Current pixel value (cached, wire order, 16-bit)
ScaledPixelIteratorRGB16() FL_NOEXCEPT
Sentinel constructor (end iterator)
ScaledPixelIteratorRGB16(PixelIterator *pixels) FL_NOEXCEPT
Construct from PixelIterator.
bool mHasValue
true if current pixel is valid
ScaledPixelIteratorRGB16 operator++(int) FL_NOEXCEPT
Post-increment operator.
bool operator==(const ScaledPixelIteratorRGB16 &other) const FL_NOEXCEPT
Equality comparison.
const array< u16, 3 > * operator->() const FL_NOEXCEPT
Arrow operator.
const array< u16, 3 > & operator*() const FL_NOEXCEPT
Dereference operator.
Input iterator adapter for PixelIterator yielding 16-bit RGB pixel data.
PixelIterator * mPixels
Underlying PixelIterator.
ScaledPixelIteratorRGB(PixelIterator *pixels) FL_NOEXCEPT
Construct from PixelIterator.
const array< u8, 3 > & operator*() const FL_NOEXCEPT
Dereference operator.
bool operator!=(const ScaledPixelIteratorRGB &other) const FL_NOEXCEPT
Inequality comparison.
const array< u8, 3 > * operator->() const FL_NOEXCEPT
Arrow operator.
ScaledPixelIteratorRGB() FL_NOEXCEPT
Sentinel constructor (end iterator)
ScaledPixelIteratorRGB & operator++() FL_NOEXCEPT
Pre-increment operator.
ScaledPixelIteratorRGB operator++(int) FL_NOEXCEPT
Post-increment operator.
void advance() FL_NOEXCEPT
Advance to next pixel (or mark as end)
array< u8, 3 > mCurrent
Current pixel value (cached, wire order)
bool operator==(const ScaledPixelIteratorRGB &other) const FL_NOEXCEPT
Equality comparison.
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() FL_NOEXCEPT
Sentinel constructor (end iterator)
ScaledPixelIteratorRGBW operator++(int) FL_NOEXCEPT
Post-increment operator.
bool operator!=(const ScaledPixelIteratorRGBW &other) const FL_NOEXCEPT
Inequality comparison.
const array< u8, 4 > & operator*() const FL_NOEXCEPT
Dereference operator.
const array< u8, 4 > * operator->() const FL_NOEXCEPT
Arrow operator.
bool mHasValue
true if current pixel is valid
ScaledPixelIteratorRGBW & operator++() FL_NOEXCEPT
Pre-increment operator.
ScaledPixelIteratorRGBW(PixelIterator *pixels) FL_NOEXCEPT
Construct from PixelIterator.
PixelIterator * mPixels
Underlying PixelIterator.
bool operator==(const ScaledPixelIteratorRGBW &other) const FL_NOEXCEPT
Equality comparison.
Input iterator adapter for PixelIterator yielding 4-byte pixel data.
bool operator==(const ScaledPixelIteratorRGBWW &other) const FL_NOEXCEPT
const array< u8, 5 > & operator*() const FL_NOEXCEPT
ScaledPixelIteratorRGBWW & operator++() FL_NOEXCEPT
bool operator!=(const ScaledPixelIteratorRGBWW &other) const FL_NOEXCEPT
const array< u8, 5 > * operator->() const FL_NOEXCEPT
ScaledPixelIteratorRGBWW operator++(int) FL_NOEXCEPT
ScaledPixelIteratorRGBWW(PixelIterator *pixels) FL_NOEXCEPT
Input iterator adapter yielding 5-byte RGBWW pixels (issue #2558).
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_traits.h:48
pair< detail::ScaledPixelIteratorRGB, detail::ScaledPixelIteratorRGB > makeScaledPixelRangeRGB(PixelIterator *pixels) FL_NOEXCEPT
Create RGB input iterator range from PixelIterator.
pair< detail::ScaledPixelIteratorRGB16, detail::ScaledPixelIteratorRGB16 > makeScaledPixelRangeRGB16(PixelIterator *pixels) FL_NOEXCEPT
Create 16-bit RGB input iterator range from PixelIterator.
unsigned char u8
Definition stdint.h:131
pair< detail::ScaledPixelIteratorRGBWW, detail::ScaledPixelIteratorRGBWW > makeScaledPixelRangeRGBWW(PixelIterator *pixels) FL_NOEXCEPT
Create RGBWW input iterator range from PixelIterator (issue #2558)
pair< detail::ScaledPixelIteratorBrightness, detail::ScaledPixelIteratorBrightness > makeScaledBrightnessRange(PixelIterator *pixels) FL_NOEXCEPT
Create brightness input iterator range from PixelIterator.
pair< detail::ScaledPixelIteratorRGBW, detail::ScaledPixelIteratorRGBW > makeScaledPixelRangeRGBW(PixelIterator *pixels) FL_NOEXCEPT
Create RGBW input iterator range from PixelIterator.
pair< typename fl::decay< T1 >::type, typename fl::decay< T2 >::type > make_pair(T1 &&t, T2 &&u) FL_NOEXCEPT
Definition pair.h:95
fl::ptrdiff ptrdiff_t
Definition s16x16x4.h:226
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT