mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
6279dcb2a9
* add dynamic smoothing first step * extend prio muxer to hold smoothing preset id * add icons for systray * fix missing changes in prio muxer * implement specific smoothing params for effects * refactoring: std::min/max to qMin/Max * some code optimization * fix schema and translation * revoke change of python include order * fix eol in effect shemas * optimize random,candle and fadecandy json schemas
80 lines
2.2 KiB
C++
80 lines
2.2 KiB
C++
#include <hyperion/ImageToLedsMap.h>
|
|
|
|
using namespace hyperion;
|
|
|
|
ImageToLedsMap::ImageToLedsMap(
|
|
const unsigned width,
|
|
const unsigned height,
|
|
const unsigned horizontalBorder,
|
|
const unsigned verticalBorder,
|
|
const std::vector<Led>& leds)
|
|
: _width(width)
|
|
, _height(height)
|
|
, _horizontalBorder(horizontalBorder)
|
|
, _verticalBorder(verticalBorder)
|
|
, _colorsMap()
|
|
{
|
|
// Sanity check of the size of the borders (and width and height)
|
|
Q_ASSERT(_width > 2*_verticalBorder);
|
|
Q_ASSERT(_height > 2*_horizontalBorder);
|
|
|
|
// Reserve enough space in the map for the leds
|
|
_colorsMap.reserve(leds.size());
|
|
|
|
const unsigned xOffset = _verticalBorder;
|
|
const unsigned actualWidth = _width - 2 * _verticalBorder;
|
|
const unsigned yOffset = _horizontalBorder;
|
|
const unsigned actualHeight = _height - 2 * _horizontalBorder;
|
|
|
|
for (const Led& led : leds)
|
|
{
|
|
// skip leds without area
|
|
if ((led.maxX_frac-led.minX_frac) < 1e-6 || (led.maxY_frac-led.minY_frac) < 1e-6)
|
|
{
|
|
_colorsMap.emplace_back();
|
|
continue;
|
|
}
|
|
|
|
// Compute the index boundaries for this led
|
|
unsigned minX_idx = xOffset + unsigned(qRound(actualWidth * led.minX_frac));
|
|
unsigned maxX_idx = xOffset + unsigned(qRound(actualWidth * led.maxX_frac));
|
|
unsigned minY_idx = yOffset + unsigned(qRound(actualHeight * led.minY_frac));
|
|
unsigned maxY_idx = yOffset + unsigned(qRound(actualHeight * led.maxY_frac));
|
|
|
|
// make sure that the area is at least a single led large
|
|
minX_idx = qMin(minX_idx, xOffset + actualWidth - 1);
|
|
if (minX_idx == maxX_idx)
|
|
{
|
|
maxX_idx = minX_idx + 1;
|
|
}
|
|
minY_idx = qMin(minY_idx, yOffset + actualHeight - 1);
|
|
if (minY_idx == maxY_idx)
|
|
{
|
|
maxY_idx = minY_idx + 1;
|
|
}
|
|
|
|
// Add all the indices in the above defined rectangle to the indices for this led
|
|
std::vector<unsigned> ledColors;
|
|
for (unsigned y = minY_idx; y<maxY_idx && y<(yOffset+actualHeight); ++y)
|
|
{
|
|
for (unsigned x = minX_idx; x<maxX_idx && x<(xOffset+actualWidth); ++x)
|
|
{
|
|
ledColors.push_back(y*width + x);
|
|
}
|
|
}
|
|
|
|
// Add the constructed vector to the map
|
|
_colorsMap.push_back(ledColors);
|
|
}
|
|
}
|
|
|
|
unsigned ImageToLedsMap::width() const
|
|
{
|
|
return _width;
|
|
}
|
|
|
|
unsigned ImageToLedsMap::height() const
|
|
{
|
|
return _height;
|
|
}
|