41 enum XyMapType { kSeperentine = 0, kLineByLine, kFunction, kLookUpTable };
43 static XYMap constructWithUserFunction(uint16_t width, uint16_t height,
44 XYFunction xyFunction, uint16_t offset = 0) {
45 XYMap out(width, height, kFunction);
46 out.xyFunction = xyFunction;
51 static XYMap constructRectangularGrid(uint16_t width, uint16_t height, uint16_t offset = 0) {
52 XYMap out(width, height, kLineByLine);
57 static XYMap constructWithLookUpTable(uint16_t width, uint16_t height,
58 const uint16_t *lookUpTable, uint16_t offset = 0) {
59 XYMap out(width, height, kLookUpTable);
60 out.mLookUpTable = LUT16Ref::New(width * height);
61 memcpy(out.mLookUpTable->getData(), lookUpTable,
62 width * height *
sizeof(uint16_t));
69 XYMap(uint16_t width, uint16_t height,
bool is_serpentine =
true, uint16_t offset = 0)
70 : type(is_serpentine ? kSeperentine : kLineByLine),
71 width(width), height(height), mOffset(offset) {}
77 void mapPixels(
const CRGB* input,
CRGB* output)
const {
79 for (uint16_t y = 0; y < height; y++) {
80 for (uint16_t x = 0; x < width; x++) {
82 output[i] = input[mapToIndex(x, y)];
87 void convertToLookUpTable() {
88 if (type == kLookUpTable) {
91 mLookUpTable = LUT16Ref::New(width * height);
92 uint16_t *data = mLookUpTable->getData();
93 for (uint16_t y = 0; y < height; y++) {
94 for (uint16_t x = 0; x < width; x++) {
95 data[y * width + x] = mapToIndex(x, y);
102 void setRectangularGrid() {
104 xyFunction =
nullptr;
105 mLookUpTable.reset();
108 uint16_t mapToIndex(uint16_t x, uint16_t y)
const {
114 index = xy_serpentine(x, y, width, height);
117 index = xy_line_by_line(x, y, width, height);
122 index = xyFunction(x, y, width, height);
125 index = mLookUpTable->getData()[y * width + x];
130 return index + mOffset;
133 uint16_t getWidth()
const {
return width; }
134 uint16_t getHeight()
const {
return height; }
135 uint16_t getTotal()
const {
return width * height; }
136 XyMapType getType()
const {
return type; }
139 XYMap(uint16_t width, uint16_t height, XyMapType type)
140 : type(type), width(width), height(height), mOffset(0) {}
145 XYFunction xyFunction =
nullptr;
146 LUT16Ref mLookUpTable;
147 uint16_t mOffset = 0;