FastLED 3.9.15
Loading...
Searching...
No Matches
pixel_iterator_any.h
Go to the documentation of this file.
1
3
4#pragma once
5
7#include "pixel_controller.h"
8#include "fl/stl/variant.h"
9#include "fl/stl/optional.h"
10#include "fl/stl/vector.h"
11#include "rgbw.h"
12#include "fl/gfx/rgbww.h"
13
14namespace fl {
15
16// Forward declarations
17class XYMap;
18
19
20
26 public:
36
37 template<typename PIXEL_CONTROLLER>
38 PixelIteratorAny(PIXEL_CONTROLLER &controller, EOrder newOrder, Rgbw rgbw,
39 Rgbww rgbww = RgbwwInvalid::value())
40 : mRgbw(rgbw), mRgbww(rgbww) {
41 // (#2558) Bugfix surfaced by CodeRabbit on PR #2560: the previous
42 // implementation constructed rgbController for normalization but then
43 // called init(controller, ...) — passing the un-normalized original
44 // controller. init() takes a PixelController<RGB>&, so a non-RGB
45 // PIXEL_CONTROLLER would have failed to compile if this branch was
46 // ever instantiated; the bug stayed latent until now.
47 PixelController<RGB> rgbController(controller); // Normalize to RGB order.
48 init(rgbController, newOrder);
49 }
50
53 const PixelIterator& get() const { return *mPixelIterator; }
54
56 operator PixelIterator&() { return *mPixelIterator; }
57
63
66 // Step 1: Create the appropriate PixelController variant based on color order
67 switch (newOrder) {
68 case RGB:
70 break;
71 case RBG:
73 break;
74 case GRB:
76 break;
77 case GBR:
79 break;
80 case BRG:
82 break;
83 case BGR:
85 break;
86 }
87
88 // Step 2: Use visitor pattern to construct PixelIterator with correct pointer type
89 // Note: fl::Optional::emplace takes a constructed object, not constructor args
90 struct PixelIteratorInitVisitor {
91 PixelIteratorInitVisitor(Rgbw rgbw, Rgbww rgbww)
92 : rgbw(rgbw), rgbww(rgbww) {}
93 fl::Optional<PixelIterator>* pixelIteratorPtr;
94 Rgbw rgbw;
95 Rgbww rgbww;
96
97 // Need concrete overloads for each type in the variant
98 void accept(PixelController<RGB>& controller) {
99 pixelIteratorPtr->emplace(PixelIterator(&controller, rgbw, rgbww));
100 }
101 void accept(PixelController<RBG>& controller) {
102 pixelIteratorPtr->emplace(PixelIterator(&controller, rgbw, rgbww));
103 }
104 void accept(PixelController<GRB>& controller) {
105 pixelIteratorPtr->emplace(PixelIterator(&controller, rgbw, rgbww));
106 }
107 void accept(PixelController<GBR>& controller) {
108 pixelIteratorPtr->emplace(PixelIterator(&controller, rgbw, rgbww));
109 }
110 void accept(PixelController<BRG>& controller) {
111 pixelIteratorPtr->emplace(PixelIterator(&controller, rgbw, rgbww));
112 }
113 void accept(PixelController<BGR>& controller) {
114 pixelIteratorPtr->emplace(PixelIterator(&controller, rgbw, rgbww));
115 }
116 };
117
118 PixelIteratorInitVisitor visitor(mRgbw, mRgbww);
119 visitor.pixelIteratorPtr = &mPixelIterator;
120 mAnyController.visit(visitor);
121 }
122
123 private:
124 fl::variant<PixelController<RGB>, PixelController<RBG>,
128
129 // fl::optional used just as a way to defer construction.
131
134
135 // XYMap for pixel addressing (optional) - contains embedded width/height
137};
138
139} // namespace fl
XYMap xymap
CLEDController * controller
Rgbw rgbw
void emplace(T &&value) FL_NOEXCEPT
Emplace with rvalue reference.
Definition optional.h:33
fl::variant< PixelController< RGB >, PixelController< RBG >, PixelController< GRB >, PixelController< GBR >, PixelController< BRG >, PixelController< BGR > > mAnyController
fl::Optional< PixelIterator > mPixelIterator
PixelIteratorAny(PIXEL_CONTROLLER &controller, EOrder newOrder, Rgbw rgbw, Rgbww rgbww=RgbwwInvalid::value())
PixelIteratorAny(PixelController< RGB > &controller, EOrder newOrder, Rgbw rgbw, Rgbww rgbww=RgbwwInvalid::value())
Construct adapter with color order conversion.
PixelIterator & get()
Get the type-erased PixelIterator.
fl::shared_ptr< const XYMap > mXyMap
const PixelIterator & get() const
void init(PixelController< RGB > &controller, EOrder newOrder)
Initialize the adapter with color order conversion.
void setXYMap(const fl::shared_ptr< const XYMap > &xymap)
Set XYMap for pixel addressing.
Non-templated low level pixel data writing class.
Functions for red, green, blue, white (RGBW) output.
EOrder
RGB color channel orderings, used when instantiating controllers to determine what order the controll...
Definition eorder.h:13
@ RBG
Red, Blue, Green (0021)
Definition eorder.h:15
@ BGR
Blue, Green, Red (0210)
Definition eorder.h:19
@ BRG
Blue, Red, Green (0201)
Definition eorder.h:18
@ GRB
Green, Red, Blue (0102)
Definition eorder.h:16
@ RGB
Red, Green, Blue (0012)
Definition eorder.h:14
@ GBR
Green, Blue, Red (0120)
Definition eorder.h:17
Base definition for an LED controller.
Definition crgb.hpp:179
Low level pixel data writing class.
fl::PixelIterator PixelIterator
5-channel RGB + warm-W + cool-W (RGBWW / RGBCCT) configuration types (issue #2558,...
Pixel controller class.
Per-strip RGBWW configuration.
Definition rgbww.h:60
static Rgbww value() FL_NOEXCEPT
Definition rgbww.h:90