| 227 | } |
| 228 | |
| 229 | void ImageColorAveraging::Process(std::vector<ColorRgb>& colors, const Image<ColorRgb>& image, uint16_t* advanced) |
| 230 | { |
| 231 | switch (_mappingType) |
| 232 | { |
| 233 | case 3: |
| 234 | case 2: getMeanAdvLedColor(colors, image, advanced); break; |
| 235 | case 1: getUniLedColor(colors, image); break; |
| 236 | default: getMeanLedColor(colors, image); |
| 237 | } |
| 238 | |
| 239 | if (_groupMax > 0 && _mappingType != 1) |
| 240 | { |
| 241 | for (int i = std::max(_groupMin, 1); i <= _groupMax; i++) |
| 242 | { |
| 243 | int32_t r = 0, g = 0, b = 0, c = 0; |
| 244 | |
| 245 | auto groupIn = _colorsGroups.begin(); |
| 246 | for (auto _rgb = colors.begin(); _rgb != colors.end(); ++_rgb, ++groupIn) |
| 247 | if (*groupIn == i) |
| 248 | { |
| 249 | r += (*_rgb).red; |
| 250 | g += (*_rgb).green; |
| 251 | b += (*_rgb).blue; |
| 252 | c++; |
| 253 | } |
| 254 | |
| 255 | if (c > 0) |
| 256 | { |
| 257 | r /= c; |
| 258 | g /= c; |
| 259 | b /= c; |
| 260 | } |
| 261 | |
| 262 | auto groupOut = _colorsGroups.begin(); |
| 263 | for (auto _rgb = colors.begin(); _rgb != colors.end(); ++_rgb, ++groupOut) |
| 264 | if (*groupOut == i) |
| 265 | { |
| 266 | (*_rgb).red = r; |
| 267 | (*_rgb).green = g; |
| 268 | (*_rgb).blue = b; |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | void ImageColorAveraging::getMeanLedColor(std::vector<ColorRgb>& ledColors, const Image<ColorRgb>& image) const |
| 275 | { |