| 210 | } |
| 211 | |
| 212 | Color jsonToColor(Json const& v) { |
| 213 | if (v.type() == Json::Type::Array) { |
| 214 | if (v.type() != Json::Type::Array || (v.size() != 3 && v.size() != 4)) |
| 215 | throw JsonException("Json not an array of size 3 or 4 in jsonToColor"); |
| 216 | Color c = Color::rgba(0, 0, 0, 255); |
| 217 | c.setRed(v.getInt(0)); |
| 218 | c.setGreen(v.getInt(1)); |
| 219 | c.setBlue(v.getInt(2)); |
| 220 | |
| 221 | if (v.size() == 4) |
| 222 | c.setAlpha(v.getInt(3)); |
| 223 | |
| 224 | return c; |
| 225 | } else if (v.type() == Json::Type::String) { |
| 226 | return Color(v.toString()); |
| 227 | } else { |
| 228 | throw JsonException(strf("Json of type {} cannot be converted to color", v.typeName())); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | Json jsonFromColor(Color const& color) { |
| 233 | JsonArray result; |