5#include "fl/force_inline.h"
8#include "fl/screenmap.h"
16 const uint16_t length = width * height;
18 for (uint16_t w = 0; w < width; w++) {
19 for (uint16_t h = 0; h < height; h++) {
20 uint16_t index = mapToIndex(w, h);
22 static_cast<float>(w),
33XYMap XYMap::constructWithUserFunction(uint16_t width, uint16_t height,
34 XYFunction xyFunction, uint16_t offset) {
35 XYMap out(width, height, kFunction);
36 out.xyFunction = xyFunction;
43XYMap XYMap::constructRectangularGrid(uint16_t width, uint16_t height, uint16_t offset) {
44 XYMap out(width, height, kLineByLine);
51XYMap XYMap::constructWithLookUpTable(uint16_t width, uint16_t height,
52 const uint16_t *lookUpTable, uint16_t offset) {
53 XYMap out(width, height, kLookUpTable);
54 out.mLookUpTable = LUT16Ptr::New(width * height);
55 memcpy(out.mLookUpTable->getData(), lookUpTable,
56 width * height *
sizeof(uint16_t));
63XYMap::XYMap(uint16_t width, uint16_t height,
bool is_serpentine, uint16_t offset)
64 : type(is_serpentine ? kSerpentine : kLineByLine),
65 width(width), height(height), mOffset(offset) {}
69void XYMap::mapPixels(
const CRGB* input,
CRGB* output)
const {
71 for (uint16_t y = 0; y < height; y++) {
72 for (uint16_t x = 0; x < width; x++) {
74 output[i] = input[mapToIndex(x, y)];
81void XYMap::convertToLookUpTable() {
82 if (type == kLookUpTable) {
85 mLookUpTable = LUT16Ptr::New(width * height);
86 uint16_t *data = mLookUpTable->getData();
87 for (uint16_t y = 0; y < height; y++) {
88 for (uint16_t x = 0; x < width; x++) {
89 data[y * width + x] = mapToIndex(x, y);
98void XYMap::setRectangularGrid() {
100 xyFunction =
nullptr;
101 mLookUpTable.reset();
106uint16_t XYMap::mapToIndex(uint16_t x, uint16_t y)
const {
112 index = xy_serpentine(x, y, width, height);
115 index = xy_line_by_line(x, y, width, height);
120 index = xyFunction(x, y, width, height);
123 index = mLookUpTable->getData()[y * width + x];
128 return index + mOffset;
133uint16_t XYMap::getWidth()
const {
return width; }
137uint16_t XYMap::getHeight()
const {
return height; }
141uint16_t XYMap::getTotal()
const {
return width * height; }
145XYMap::XyMapType XYMap::getType()
const {
return type; }
149XYMap::XYMap(uint16_t width, uint16_t height, XyMapType type)
150 : type(type), width(width), height(height), mOffset(0) {}
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Representation of an RGB pixel (Red, Green, Blue)