9 #include <utils/Image.h> 10 #include <utils/Logger.h> 13 #include <hyperion/LedString.h> 42 const unsigned horizontalBorder,
43 const unsigned verticalBorder,
44 const std::vector<Led> & leds);
51 unsigned width()
const;
60 unsigned horizontalBorder() {
return _horizontalBorder; };
61 unsigned verticalBorder() {
return _verticalBorder; };
71 template <
typename Pixel_T>
74 std::vector<ColorRgb> colors(_colorsMap.size(),
ColorRgb{0,0,0});
86 template <
typename Pixel_T>
91 if(_colorsMap.size() != ledColors.size())
93 Debug(Logger::getInstance(
"HYPERION"),
"ImageToLedsMap: colorsMap.size != ledColors.size -> %d != %d", _colorsMap.size(), ledColors.size());
98 auto led = ledColors.begin();
99 for (
auto colors = _colorsMap.begin(); colors != _colorsMap.end(); ++colors, ++led)
101 const ColorRgb color = calcMeanColor(image, *colors);
114 template <
typename Pixel_T>
117 std::vector<ColorRgb> colors(_colorsMap.size(),
ColorRgb{0,0,0});
129 template <
typename Pixel_T>
134 if(_colorsMap.size() != ledColors.size())
136 Debug(Logger::getInstance(
"HYPERION"),
"ImageToLedsMap: colorsMap.size != ledColors.size -> %d != %d", _colorsMap.size(), ledColors.size());
142 const ColorRgb color = calcMeanColor(image);
143 std::fill(ledColors.begin(),ledColors.end(), color);
148 const unsigned _width;
150 const unsigned _height;
152 const unsigned _horizontalBorder;
154 const unsigned _verticalBorder;
157 std::vector<std::vector<unsigned>> _colorsMap;
168 template <
typename Pixel_T>
171 const auto colorVecSize = colors.size();
173 if (colorVecSize == 0)
179 uint_fast16_t cummRed = 0;
180 uint_fast16_t cummGreen = 0;
181 uint_fast16_t cummBlue = 0;
182 const auto& imgData = image.
memptr();
184 for (
const unsigned colorOffset : colors)
186 const auto& pixel = imgData[colorOffset];
187 cummRed += pixel.red;
188 cummGreen += pixel.green;
189 cummBlue += pixel.blue;
193 const uint8_t avgRed = uint8_t(cummRed/colorVecSize);
194 const uint8_t avgGreen = uint8_t(cummGreen/colorVecSize);
195 const uint8_t avgBlue = uint8_t(cummBlue/colorVecSize);
198 return {avgRed, avgGreen, avgBlue};
209 template <
typename Pixel_T>
213 uint_fast16_t cummRed = 0;
214 uint_fast16_t cummGreen = 0;
215 uint_fast16_t cummBlue = 0;
216 const unsigned imageSize = image.
width() * image.
height();
218 const auto& imgData = image.
memptr();
220 for (
unsigned idx=0; idx<imageSize; idx++)
222 const auto& pixel = imgData[idx];
223 cummRed += pixel.red;
224 cummGreen += pixel.green;
225 cummBlue += pixel.blue;
229 const uint8_t avgRed = uint8_t(cummRed/imageSize);
230 const uint8_t avgGreen = uint8_t(cummGreen/imageSize);
231 const uint8_t avgBlue = uint8_t(cummBlue/imageSize);
234 return {avgRed, avgGreen, avgBlue};
ImageToLedsMap(const unsigned width, const unsigned height, const unsigned horizontalBorder, const unsigned verticalBorder, const std::vector< Led > &leds)
Constructs an mapping from the absolute indices in an image to each led based on the border definitio...
Definition: ImageToLedsMap.cpp:5
Provide utility methods for Hyperion class.
Definition: BlackBorderDetector.h:7
unsigned height() const
Returns the height of the indexed image.
Definition: ImageToLedsMap.cpp:83
std::vector< ColorRgb > getMeanLedColor(const Image< Pixel_T > &image) const
Determines the mean color for each led using the mapping the image given at construction.
Definition: ImageToLedsMap.h:72
unsigned height() const
Returns the height of the image.
Definition: Image.h:129
void getMeanLedColor(const Image< Pixel_T > &image, std::vector< ColorRgb > &ledColors) const
Determines the mean color for each led using the mapping the image given at construction.
Definition: ImageToLedsMap.h:87
unsigned width() const
Returns the width of the image.
Definition: Image.h:119
void getUniLedColor(const Image< Pixel_T > &image, std::vector< ColorRgb > &ledColors) const
Determines the uni color for each led using the mapping the image given at construction.
Definition: ImageToLedsMap.h:130
Pixel_T * memptr()
Returns a memory pointer to the first pixel in the image.
Definition: Image.h:208
unsigned width() const
Returns the width of the indexed image.
Definition: ImageToLedsMap.cpp:78
std::vector< ColorRgb > getUniLedColor(const Image< Pixel_T > &image) const
Determines the uni color for each led using the mapping the image given at construction.
Definition: ImageToLedsMap.h:115
static ColorRgb BLACK
'Black' RgbColor (0, 0, 0)
Definition: ColorRgb.h:23
The ImageToLedsMap holds a mapping of indices into an image to leds.
Definition: ImageToLedsMap.h:22
Plain-Old-Data structure containing the red-green-blue color specification.
Definition: ColorRgb.h:13