12 if (!channel || *channel < 0 || *channel > 255) {
26 if (!red || !green || !blue) {
30 return CRGB(
static_cast<u8>(*red),
static_cast<u8>(*green),
31 static_cast<u8>(*blue));
36 if (!document.is_object() || document.size() != 2) {
40 const json versionJson = document[
"version"];
42 if (!versionJson.
is_int() || versionJson.
is_bool() || !version ||
47 const json encodedPixels = document[
"pixels"];
48 if (!encodedPixels.
is_array() || encodedPixels.
size() != pixels.size()) {
52 for (size i = 0; i < encodedPixels.
size(); ++i) {
54 if (!decoded || *decoded != pixels[i]) {
69 for (
const CRGB& pixel : pixels) {
78 if (encodedPixel.
size() != 3 || !crgbJsonPixel(encodedPixel)) {
82 const size oldSize = encodedPixels.
size();
84 if (encodedPixels.
size() != oldSize + 1) {
93 document.
set(
"version", 1);
94 document.
set(
"pixels", encodedPixels);
95 if (!crgbJsonMatches(document, pixels)) {
102 if (!document.is_object()) {
106 const json versionJson = document[
"version"];
108 if (!versionJson.
is_int() || versionJson.
is_bool() || !version ||
113 const json encodedPixels = document[
"pixels"];
114 if (!encodedPixels.
is_array() || encodedPixels.
size() != pixels.size()) {
118 for (size i = 0; i < encodedPixels.
size(); ++i) {
119 if (!crgbJsonPixel(encodedPixels[i])) {
124 for (size i = 0; i < encodedPixels.
size(); ++i) {
125 pixels[i] = *crgbJsonPixel(encodedPixels[i]);
bool is_object() const FL_NO_EXCEPT
size_t size() const FL_NO_EXCEPT
void set(const fl::string &key, const json &value) FL_NO_EXCEPT
bool is_int() const FL_NO_EXCEPT
bool is_array() const FL_NO_EXCEPT
void push_back(const json &value) FL_NO_EXCEPT
bool is_bool() const FL_NO_EXCEPT
fl::optional< T > as() const FL_NO_EXCEPT
static json object() FL_NO_EXCEPT
static json array() FL_NO_EXCEPT
JSON serialization helpers for CRGB pixel buffers.
optional< i64 > crgbJsonChannel(const json &value) FL_NO_EXCEPT
optional< CRGB > crgbJsonPixel(const json &value) FL_NO_EXCEPT
bool crgbJsonMatches(const json &document, span< const CRGB > pixels) FL_NO_EXCEPT
constexpr int type_rank< T >::value
optional< json > crgbToJson(span< const CRGB > pixels) FL_NO_EXCEPT
Encode a CRGB pixel buffer as a versioned JSON object.
InputGamut g FL_NO_EXCEPT
constexpr nullopt_t nullopt
bool crgbFromJson(const json &document, span< CRGB > pixels) FL_NO_EXCEPT
Decode a versioned JSON object into an existing CRGB pixel buffer.
Base definition for an LED controller.
Representation of an 8-bit RGB pixel (Red, Green, Blue)