87 inline Pixel(uint8_t r, uint8_t g, uint8_t b) __attribute__((always_inline))
88 : red(r), green(g), blue(b) {
92 inline Pixel() __attribute__((always_inline)) {}
95 inline Pixel &operator=(
const CRGB &rhs) __attribute__((always_inline)) {
101 inline Pixel &operator=(
CRGB &rhs) __attribute__((always_inline)) {
107 inline Pixel(
const CRGB &rhs) __attribute__((always_inline)) {
114 inline Pixel(
const Pixel &rhs) __attribute__((always_inline)) {
120 inline Pixel &operator=(
const uint32_t colorcode)
121 __attribute__((always_inline)) {
123 red = (colorcode >> 16) & 0xFF;
124 green = (colorcode >> 8) & 0xFF;
125 blue = (colorcode >> 0) & 0xFF;
128 inline __attribute__((always_inline))
bool operator==(
const Pixel &rhs) {
129 return (red == rhs.red) && (green == rhs.green) && (blue == rhs.blue);
131 inline __attribute__((always_inline))
bool operator!=(
const Pixel &rhs) {
132 return !((red == rhs.red) && (green == rhs.green) &&
143 inline Pixels() __attribute__((always_inline)) {}
144 inline Pixels(
const Pixels &rhs) __attribute__((always_inline)) {
146 _direction = rhs._direction;
147 _num_strips = rhs._num_strips;
148 for (
int i = 0; i < _num_strips; i++) {
149 _sizes[i] = rhs._sizes[i];
151 ledpointer = rhs.ledpointer;
152 mapFunction = rhs.mapFunction;
157 Pixels(size, ledpoi, leddirection::FORWARD);
160 Pixels(
int size,
Pixel *ledpoi, leddirection direction) {
161 __Pixels(size, ledpoi, direction,
this);
164 void __Pixels(
int size,
Pixel *ledpoi, leddirection direction,
167 pib->ledpointer = ledpoi;
168 pib->_num_strips = 0;
169 pib->_direction = direction;
173 Pixels(
int num_led_per_strip,
int num_strips) {
175 for (
int i = 0; i < num_strips; i++) {
176 sizes[i] = num_led_per_strip;
178 __Pixels(sizes, num_strips, leddirection::FORWARD,
this);
181 Pixels(
int *sizes,
int num_strips) {
182 __Pixels(sizes, num_strips, leddirection::FORWARD,
this);
185 Pixels(
int *sizes,
int num_strips, leddirection direction) {
186 __Pixels(sizes, num_strips, direction,
this);
188 void __Pixels(
int *sizes,
int num_strips, leddirection direction,
191 for (
int i = 0; i < num_strips; i++) {
193 pib->_sizes[i] = sizes[i];
196 pib->_num_strips = num_strips;
198 ledpointer = (
Pixel *)calloc(size,
sizeof(
Pixel));
199 if (ledpointer == NULL) {
204 pib->_direction = direction;
206 Pixel &operator[](
int i) {
207 switch (_direction) {
209 case (leddirection::FORWARD):
211 return *(ledpointer + i % _size);
214 case (leddirection::BACKWARD):
216 return *(ledpointer + (_size - i % (_size)-1));
219 case (leddirection::MAP):
221 int offset = mapFunction(i, arguments);
223 if (offset == _OUT_OF_BOUND) {
226 return *(ledpointer + (mapFunction(i, arguments) % _size));
230 return *(ledpointer);
233 return *(ledpointer);
238 void copy(
Pixels ori) { copy(ori, leddirection::FORWARD); }
240 void copy(
Pixels ori, leddirection dir) {
241 leddirection ledd = _direction;
242 if (_direction == leddirection::MAP)
243 ledd = leddirection::FORWARD;
244 for (
int i = 0; i < ori._size; i++) {
248 (*this)[i] = ori[ori._size - i % (ori._size) - 1];
253 Pixels getStrip(
int num_strip, leddirection direction) {
254 if (_num_strips == 0 or _num_strips < num_strip) {
257 return Pixels(d, 1, direction);
260 for (
int i = 0; i < num_strip % _num_strips; i++) {
264 return Pixels(_sizes[num_strip], ledpointer + off, direction);
268 Pixels getStrip(
int num_strip) {
269 return getStrip(num_strip, leddirection::FORWARD);
272 int *getLengths() {
return _sizes; }
274 int getNumStrip() {
return _num_strips; }
275 uint8_t *getPixels() {
return (uint8_t *)ledpointer; }
280 Pixels createSubset(
int start,
int length) {
281 return createSubset(start, length, leddirection::FORWARD);
284 Pixels createSubset(
int start, leddirection direction) {
287 return Pixels(_size, ledpointer + start, direction);
290 Pixels createSubset(
int start,
int length, leddirection direction) {
295 return Pixels(length, ledpointer + start, direction);
309 inline void setMapFunction(
int (*fptr)(
int i,
void *args),
void *args,
312 if (arguments == NULL)
313 arguments = (
void *)malloc(
sizeof(size));
314 memcpy(arguments, args, size);
322 leddirection _direction;
327 int (*mapFunction)(
int i,
void *args);