Hex string custom palette option
This commit is contained in:
parent
e7449b4d56
commit
0a0ced3e8e
@ -1512,14 +1512,27 @@ void WS2812FX::loadCustomPalettes()
|
|||||||
if (readObjectFromFile(fileName, nullptr, &pDoc)) {
|
if (readObjectFromFile(fileName, nullptr, &pDoc)) {
|
||||||
JsonArray pal = pDoc[F("palette")];
|
JsonArray pal = pDoc[F("palette")];
|
||||||
if (!pal.isNull() && pal.size()>7) { // not an empty palette (at least 2 entries)
|
if (!pal.isNull() && pal.size()>7) { // not an empty palette (at least 2 entries)
|
||||||
size_t palSize = MIN(pal.size(), 72);
|
if (pal[0].is<int>() && pal[1].is<const char *>()) {
|
||||||
palSize -= palSize % 4; // make sure size is multiple of 4
|
// we have an array of index & hex strings
|
||||||
for (size_t i=0; i<palSize && pal[i].as<int>()<256; i+=4) {
|
size_t palSize = MIN(pal.size(), 36);
|
||||||
tcp[ i ] = (uint8_t) pal[ i ].as<int>(); // index
|
palSize -= palSize % 2; // make sure size is multiple of 2
|
||||||
tcp[i+1] = (uint8_t) pal[i+1].as<int>(); // R
|
for (size_t i=0, j=0; i<palSize && pal[i].as<int>()<256; i+=2, j+=4) {
|
||||||
tcp[i+2] = (uint8_t) pal[i+2].as<int>(); // G
|
uint8_t rgbw[] = {0,0,0,0};
|
||||||
tcp[i+3] = (uint8_t) pal[i+3].as<int>(); // B
|
tcp[ j ] = (uint8_t) pal[ i ].as<int>(); // index
|
||||||
DEBUG_PRINTF("%d(%d) : %d %d %d\n", i, int(tcp[i]), int(tcp[i+1]), int(tcp[i+2]), int(tcp[i+3]));
|
colorFromHexString(rgbw, pal[i+1].as<const char *>()); // will catch non-string entires
|
||||||
|
for (size_t c=0; c<3; c++) tcp[j+c] = rgbw[c]; // only use RGB component
|
||||||
|
DEBUG_PRINTF("%d(%d) : %d %d %d\n", i, int(tcp[i]), int(tcp[i+1]), int(tcp[i+2]), int(tcp[i+3]));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
size_t palSize = MIN(pal.size(), 72);
|
||||||
|
palSize -= palSize % 4; // make sure size is multiple of 4
|
||||||
|
for (size_t i=0; i<palSize && pal[i].as<int>()<256; i+=4) {
|
||||||
|
tcp[ i ] = (uint8_t) pal[ i ].as<int>(); // index
|
||||||
|
tcp[i+1] = (uint8_t) pal[i+1].as<int>(); // R
|
||||||
|
tcp[i+2] = (uint8_t) pal[i+2].as<int>(); // G
|
||||||
|
tcp[i+3] = (uint8_t) pal[i+3].as<int>(); // B
|
||||||
|
DEBUG_PRINTF("%d(%d) : %d %d %d\n", i, int(tcp[i]), int(tcp[i+1]), int(tcp[i+2]), int(tcp[i+3]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
customPalettes.push_back(targetPalette.loadDynamicGradientPalette(tcp));
|
customPalettes.push_back(targetPalette.loadDynamicGradientPalette(tcp));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user