#pragma once // STL includes #include // hyperion-utils includes #include // hyperion includes #include namespace hyperion { class ImageToLedsMap { public: /** * Constructs an mapping from the colors in the image to each led based on the border * definition given in the list of leds. The map holds pointers to the given image and its * lifetime should never exceed that of the given image * * @param[in] image The RGB image * @param[in] leds The list with led specifications */ ImageToLedsMap(const unsigned width, const unsigned height, const std::vector & leds); unsigned width() const; unsigned height() const; /** * Determines the mean-color for each led using the mapping the image given * at construction. * * @return ledColors The vector containing the output */ std::vector getMeanLedColor(const RgbImage & image) const; /** * Determines the mean-color for each led using the mapping the image given * at construction. * * @param[out] ledColors The vector containing the output */ void getMeanLedColor(const RgbImage & image, std::vector & ledColors) const; std::string toString() const { std::stringstream sstream; sstream << "ImageToLedsMap(" << _width << "x" << _height << ") ["; for (const std::vector imageIndices : mColorsMap) { sstream << "{"; for (unsigned imageIndex : imageIndices) { sstream << imageIndex << ";"; } sstream << "}"; } sstream << "]" << std::endl; return sstream.str(); } private: const unsigned _width; const unsigned _height; std::vector > mColorsMap; /** * Finds the 'mean color' of the given list. This is the mean over each color-channel (red, * green, blue) * * @param colors The list with colors * * @return The mean of the given list of colors (or black when empty) */ RgbColor calcMeanColor(const RgbImage & image, const std::vector & colors) const; }; } // end namespace hyperion