2013-08-13 11:10:45 +02:00
|
|
|
#include <hyperion/ImageProcessor.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "ImageToLedsMap.h"
|
|
|
|
#include "ColorTransform.h"
|
|
|
|
|
|
|
|
using namespace hyperion;
|
|
|
|
|
|
|
|
ImageProcessor::ImageProcessor(const LedString& ledString) :
|
|
|
|
mLedString(ledString),
|
|
|
|
mImageToLeds(nullptr)
|
|
|
|
{
|
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageProcessor::~ImageProcessor()
|
|
|
|
{
|
|
|
|
delete mImageToLeds;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageProcessor::setSize(const unsigned width, const unsigned height)
|
|
|
|
{
|
|
|
|
// Check if the existing buffer-image is already the correct dimensions
|
2013-08-14 17:02:09 +02:00
|
|
|
if (mImageToLeds && mImageToLeds->width() == width && mImageToLeds->height() == height)
|
2013-08-13 11:10:45 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up the old buffer and mapping
|
|
|
|
delete mImageToLeds;
|
|
|
|
|
|
|
|
// Construct a new buffer and mapping
|
2013-08-21 17:24:42 +02:00
|
|
|
mImageToLeds = new ImageToLedsMap(width, height, 0, 0, mLedString.leds());
|
2013-08-13 11:10:45 +02:00
|
|
|
}
|
|
|
|
|
2013-08-14 17:02:09 +02:00
|
|
|
std::vector<RgbColor> ImageProcessor::process(const RgbImage& image)
|
2013-08-13 11:10:45 +02:00
|
|
|
{
|
2013-08-14 17:02:09 +02:00
|
|
|
// Ensure that the buffer-image is the proper size
|
|
|
|
setSize(image.width(), image.height());
|
|
|
|
|
|
|
|
// Create a result vector and call the 'in place' functionl
|
|
|
|
std::vector<RgbColor> colors = mImageToLeds->getMeanLedColor(image);
|
|
|
|
|
|
|
|
// return the computed colors
|
|
|
|
return colors;
|
2013-08-13 11:10:45 +02:00
|
|
|
}
|
|
|
|
|
2013-08-14 17:02:09 +02:00
|
|
|
void ImageProcessor::process(const RgbImage& image, std::vector<RgbColor>& ledColors)
|
2013-08-13 11:10:45 +02:00
|
|
|
{
|
|
|
|
// Determine the mean-colors of each led (using the existing mapping)
|
2013-08-14 17:02:09 +02:00
|
|
|
mImageToLeds->getMeanLedColor(image, ledColors);
|
2013-08-13 11:10:45 +02:00
|
|
|
}
|