2013-08-13 11:10:45 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-08-15 21:11:02 +02:00
|
|
|
// STL includes
|
|
|
|
#include <sstream>
|
|
|
|
|
2013-08-13 11:10:45 +02:00
|
|
|
// hyperion-utils includes
|
|
|
|
#include <utils/RgbImage.h>
|
|
|
|
|
|
|
|
// hyperion includes
|
|
|
|
#include <hyperion/LedString.h>
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
2013-08-14 17:02:09 +02:00
|
|
|
ImageToLedsMap(const unsigned width, const unsigned height, const std::vector<Led> & leds);
|
|
|
|
|
|
|
|
unsigned width() const;
|
|
|
|
|
|
|
|
unsigned height() const;
|
2013-08-13 11:10:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines the mean-color for each led using the mapping the image given
|
|
|
|
* at construction.
|
|
|
|
*
|
|
|
|
* @return ledColors The vector containing the output
|
|
|
|
*/
|
2013-08-14 17:02:09 +02:00
|
|
|
std::vector<RgbColor> getMeanLedColor(const RgbImage & image) const;
|
2013-08-13 11:10:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines the mean-color for each led using the mapping the image given
|
|
|
|
* at construction.
|
|
|
|
*
|
|
|
|
* @param[out] ledColors The vector containing the output
|
|
|
|
*/
|
2013-08-14 17:02:09 +02:00
|
|
|
void getMeanLedColor(const RgbImage & image, std::vector<RgbColor> & ledColors) const;
|
2013-08-13 11:10:45 +02:00
|
|
|
|
2013-08-15 21:11:02 +02:00
|
|
|
std::string toString() const
|
|
|
|
{
|
|
|
|
std::stringstream sstream;
|
|
|
|
sstream << "ImageToLedsMap(" << _width << "x" << _height << ") [";
|
|
|
|
for (const std::vector<unsigned> imageIndices : mColorsMap)
|
|
|
|
{
|
|
|
|
sstream << "{";
|
|
|
|
for (unsigned imageIndex : imageIndices)
|
|
|
|
{
|
|
|
|
sstream << imageIndex << ";";
|
|
|
|
}
|
|
|
|
sstream << "}";
|
|
|
|
}
|
|
|
|
sstream << "]" << std::endl;
|
|
|
|
|
|
|
|
return sstream.str();
|
|
|
|
}
|
2013-08-13 11:10:45 +02:00
|
|
|
private:
|
2013-08-14 17:02:09 +02:00
|
|
|
const unsigned _width;
|
|
|
|
const unsigned _height;
|
|
|
|
std::vector<std::vector<unsigned> > mColorsMap;
|
2013-08-13 11:10:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2013-08-14 17:02:09 +02:00
|
|
|
RgbColor calcMeanColor(const RgbImage & image, const std::vector<unsigned> & colors) const;
|
2013-08-13 11:10:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace hyperion
|