mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Added simple QT-based grabber.
Moved ImageToLedsMap from include to libsrc. Moved instantiation of objects to Hyperion (no JSON required outside this class).
This commit is contained in:
65
libsrc/hyperion/ImageProcessor.cpp
Normal file
65
libsrc/hyperion/ImageProcessor.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#include <hyperion/ImageProcessor.h>
|
||||
|
||||
|
||||
#include "ImageToLedsMap.h"
|
||||
#include "ColorTransform.h"
|
||||
|
||||
using namespace hyperion;
|
||||
|
||||
ImageProcessor::ImageProcessor(const LedString& ledString) :
|
||||
mLedString(ledString),
|
||||
mBuffer(nullptr),
|
||||
mImageToLeds(nullptr)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
ImageProcessor::~ImageProcessor()
|
||||
{
|
||||
delete mImageToLeds;
|
||||
delete mBuffer;
|
||||
}
|
||||
|
||||
std::vector<RgbColor> ImageProcessor::process(const RgbImage& image)
|
||||
{
|
||||
// Ensure that the buffer-image is the proper size
|
||||
setSize(image.width(), image.height());
|
||||
|
||||
// Copy the data of the given image into the mapped-image
|
||||
mBuffer->copy(image);
|
||||
|
||||
// Create a result vector and call the 'in place' functionl
|
||||
std::vector<RgbColor> colors(mLedString.leds().size(), RgbColor::BLACK);
|
||||
inplace_process(colors);
|
||||
|
||||
// return the computed colors
|
||||
return colors;
|
||||
}
|
||||
|
||||
void ImageProcessor::setSize(const unsigned width, const unsigned height)
|
||||
{
|
||||
// Check if the existing buffer-image is already the correct dimensions
|
||||
if (mBuffer && mBuffer->width() == width && mBuffer->height() == height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Clean up the old buffer and mapping
|
||||
delete mImageToLeds;
|
||||
delete mBuffer;
|
||||
|
||||
// Construct a new buffer and mapping
|
||||
mBuffer = new RgbImage(width, height);
|
||||
mImageToLeds = new ImageToLedsMap(*mBuffer, mLedString.leds());
|
||||
}
|
||||
|
||||
RgbImage& ImageProcessor::image()
|
||||
{
|
||||
return *mBuffer;
|
||||
}
|
||||
|
||||
void ImageProcessor::inplace_process(std::vector<RgbColor>& ledColors)
|
||||
{
|
||||
// Determine the mean-colors of each led (using the existing mapping)
|
||||
mImageToLeds->getMeanLedColor(ledColors);
|
||||
}
|
Reference in New Issue
Block a user