| 141 | } |
| 142 | |
| 143 | void |
| 144 | Palette::deserialize(const Suscan::Object &obj) |
| 145 | { |
| 146 | Suscan::Object stops, entry; |
| 147 | unsigned int i, count; |
| 148 | int position; |
| 149 | qreal red, green, blue; |
| 150 | |
| 151 | this->name = obj.getField("name").value(); |
| 152 | stops = obj.getField("stops"); |
| 153 | |
| 154 | SU_ATTEMPT(stops.getType() == SUSCAN_OBJECT_TYPE_SET); |
| 155 | |
| 156 | memset(this->bitmap, 0, sizeof(this->bitmap)); |
| 157 | |
| 158 | /* Traverse stop list */ |
| 159 | count = stops.length(); |
| 160 | |
| 161 | for (i = 0; i < count; ++i) { |
| 162 | try { |
| 163 | QColor color; |
| 164 | entry = stops[i]; |
| 165 | |
| 166 | position = entry.get("position", -1); |
| 167 | if (position < 0 || position > 255) |
| 168 | continue; |
| 169 | |
| 170 | red = static_cast<qreal>(entry.get("red", -1.f)); |
| 171 | green = static_cast<qreal>(entry.get("green", -1.f)); |
| 172 | blue = static_cast<qreal>(entry.get("blue", -1.f)); |
| 173 | |
| 174 | if (red < 0 || green < 0 || blue < 0) |
| 175 | continue; |
| 176 | |
| 177 | if (red > 1 || green > 1 || blue > 1) |
| 178 | continue; |
| 179 | |
| 180 | color.setRgbF(red, green, blue); |
| 181 | |
| 182 | this->addStop(static_cast<unsigned int>(position), color); |
| 183 | } catch (Suscan::Exception &) { |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | this->compose(); |
| 188 | } |