mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Changed RgbImage to template based Image (with template for pixel type)
Former-commit-id: ef02f164eaf3c2f9dd552c1c17b525cf6eed499c
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
|
||||
// Local-Hyperion includes
|
||||
#include "BlackBorderDetector.h"
|
||||
#include <hyperion/BlackBorderDetector.h>
|
||||
|
||||
using namespace hyperion;
|
||||
|
||||
@@ -8,56 +8,3 @@ BlackBorderDetector::BlackBorderDetector()
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
BlackBorder BlackBorderDetector::process(const RgbImage& image)
|
||||
{
|
||||
// only test the topleft third of the image
|
||||
int width = image.width() /3;
|
||||
int height = image.height() / 3;
|
||||
int maxSize = std::max(width, height);
|
||||
|
||||
int firstNonBlackXPixelIndex = -1;
|
||||
int firstNonBlackYPixelIndex = -1;
|
||||
|
||||
// find some pixel of the image
|
||||
for (int i = 0; i < maxSize; ++i)
|
||||
{
|
||||
int x = std::min(i, width);
|
||||
int y = std::min(i, height);
|
||||
|
||||
const RgbColor& color = image(x, y);
|
||||
if (!isBlack(color))
|
||||
{
|
||||
firstNonBlackXPixelIndex = x;
|
||||
firstNonBlackYPixelIndex = y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// expand image to the left
|
||||
for(; firstNonBlackXPixelIndex > 0; --firstNonBlackXPixelIndex)
|
||||
{
|
||||
const RgbColor& color = image(firstNonBlackXPixelIndex-1, firstNonBlackYPixelIndex);
|
||||
if (isBlack(color))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// expand image to the top
|
||||
for(; firstNonBlackYPixelIndex > 0; --firstNonBlackYPixelIndex)
|
||||
{
|
||||
const RgbColor& color = image(firstNonBlackXPixelIndex, firstNonBlackYPixelIndex-1);
|
||||
if (isBlack(color))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Construct result
|
||||
BlackBorder detectedBorder;
|
||||
detectedBorder.unknown = firstNonBlackXPixelIndex == -1 || firstNonBlackYPixelIndex == -1;
|
||||
detectedBorder.horizontalSize = firstNonBlackYPixelIndex;
|
||||
detectedBorder.verticalSize = firstNonBlackXPixelIndex;
|
||||
return detectedBorder;
|
||||
}
|
||||
|
@@ -1,79 +0,0 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// Utils includes
|
||||
#include <utils/RgbImage.h>
|
||||
|
||||
namespace hyperion
|
||||
{
|
||||
///
|
||||
/// Result structure of the detected blackborder.
|
||||
///
|
||||
struct BlackBorder
|
||||
{
|
||||
/// Falg indicating if the border is unknown
|
||||
bool unknown;
|
||||
|
||||
/// The size of the detected horizontal border
|
||||
int horizontalSize;
|
||||
|
||||
/// The size of the detected vertical border
|
||||
int verticalSize;
|
||||
|
||||
///
|
||||
/// Compares this BlackBorder to the given other BlackBorder
|
||||
///
|
||||
/// @param[in] other The other BlackBorder
|
||||
///
|
||||
/// @return True if this is the same border as other
|
||||
///
|
||||
inline bool operator== (const BlackBorder& other) const
|
||||
{
|
||||
if (unknown)
|
||||
{
|
||||
return other.unknown;
|
||||
}
|
||||
|
||||
return other.unknown==false && horizontalSize==other.horizontalSize && verticalSize==other.verticalSize;
|
||||
}
|
||||
};
|
||||
|
||||
///
|
||||
/// The BlackBorderDetector performs detection of black-borders on a single image.
|
||||
/// The detector will search for the upper left corner of the picture in the frame.
|
||||
/// Based on detected black pixels it will give an estimate of the black-border.
|
||||
///
|
||||
class BlackBorderDetector
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs a black-border detector
|
||||
///
|
||||
BlackBorderDetector();
|
||||
|
||||
///
|
||||
/// Performs the actual black-border detection on the given image
|
||||
///
|
||||
/// @param[in] image The image on which detection is performed
|
||||
///
|
||||
/// @return The detected (or not detected) black border info
|
||||
///
|
||||
BlackBorder process(const RgbImage& image);
|
||||
|
||||
private:
|
||||
|
||||
///
|
||||
/// Checks if a given color is considered black and therefor could be part of the border.
|
||||
///
|
||||
/// @param[in] color The color to check
|
||||
///
|
||||
/// @return True if the color is considered black else false
|
||||
///
|
||||
inline bool isBlack(const RgbColor& color)
|
||||
{
|
||||
// Return the simple compare of the color against black
|
||||
return RgbColor::BLACK == color;
|
||||
// TODO[TvdZ]: We could add a threshold to check that the color is close to black
|
||||
}
|
||||
};
|
||||
} // end namespace hyperion
|
@@ -1,6 +1,6 @@
|
||||
|
||||
// Local-Hyperion includes
|
||||
#include "BlackBorderProcessor.h"
|
||||
#include <hyperion/BlackBorderProcessor.h>
|
||||
|
||||
using namespace hyperion;
|
||||
|
||||
@@ -16,6 +16,7 @@ BlackBorderProcessor::BlackBorderProcessor(
|
||||
_previousDetectedBorder({true, -1, -1}),
|
||||
_consistentCnt(0)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
BlackBorder BlackBorderProcessor::getCurrentBorder() const
|
||||
@@ -23,46 +24,33 @@ BlackBorder BlackBorderProcessor::getCurrentBorder() const
|
||||
return _currentBorder;
|
||||
}
|
||||
|
||||
bool BlackBorderProcessor::process(const RgbImage& image)
|
||||
bool BlackBorderProcessor::updateBorder(const BlackBorder & newDetectedBorder)
|
||||
{
|
||||
// get the border for the single image
|
||||
BlackBorder imageBorder = _detector.process(image);
|
||||
|
||||
// add blur to the border
|
||||
if (imageBorder.horizontalSize > 0)
|
||||
{
|
||||
imageBorder.horizontalSize += _blurRemoveCnt;
|
||||
}
|
||||
if (imageBorder.verticalSize > 0)
|
||||
{
|
||||
imageBorder.verticalSize += _blurRemoveCnt;
|
||||
}
|
||||
|
||||
// set the consistency counter
|
||||
if (imageBorder == _previousDetectedBorder)
|
||||
if (newDetectedBorder == _previousDetectedBorder)
|
||||
{
|
||||
++_consistentCnt;
|
||||
}
|
||||
else
|
||||
{
|
||||
_previousDetectedBorder = imageBorder;
|
||||
_previousDetectedBorder = newDetectedBorder;
|
||||
_consistentCnt = 0;
|
||||
}
|
||||
|
||||
// check if there is a change
|
||||
if (_currentBorder == imageBorder)
|
||||
if (_currentBorder == newDetectedBorder)
|
||||
{
|
||||
// No change required
|
||||
return false;
|
||||
}
|
||||
|
||||
bool borderChanged = false;
|
||||
if (imageBorder.unknown)
|
||||
if (newDetectedBorder.unknown)
|
||||
{
|
||||
// apply the unknown border if we consistently can't determine a border
|
||||
if (_consistentCnt == _unknownSwitchCnt)
|
||||
{
|
||||
_currentBorder = imageBorder;
|
||||
_currentBorder = newDetectedBorder;
|
||||
borderChanged = true;
|
||||
}
|
||||
}
|
||||
@@ -71,21 +59,21 @@ bool BlackBorderProcessor::process(const RgbImage& image)
|
||||
// apply the detected border if it has been detected consistently
|
||||
if (_currentBorder.unknown || _consistentCnt == _borderSwitchCnt)
|
||||
{
|
||||
_currentBorder = imageBorder;
|
||||
_currentBorder = newDetectedBorder;
|
||||
borderChanged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// apply smaller borders immediately
|
||||
if (imageBorder.verticalSize < _currentBorder.verticalSize)
|
||||
if (newDetectedBorder.verticalSize < _currentBorder.verticalSize)
|
||||
{
|
||||
_currentBorder.verticalSize = imageBorder.verticalSize;
|
||||
_currentBorder.verticalSize = newDetectedBorder.verticalSize;
|
||||
borderChanged = true;
|
||||
}
|
||||
|
||||
if (imageBorder.horizontalSize < _currentBorder.horizontalSize)
|
||||
if (newDetectedBorder.horizontalSize < _currentBorder.horizontalSize)
|
||||
{
|
||||
_currentBorder.horizontalSize = imageBorder.horizontalSize;
|
||||
_currentBorder.horizontalSize = newDetectedBorder.horizontalSize;
|
||||
borderChanged = true;
|
||||
}
|
||||
}
|
||||
|
@@ -1,70 +0,0 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// Local Hyperion includes
|
||||
#include "BlackBorderDetector.h"
|
||||
|
||||
namespace hyperion
|
||||
{
|
||||
///
|
||||
/// The BlackBorder processor is a wrapper around the black-border detector for keeping track of
|
||||
/// detected borders and count of the type and size of detected borders.
|
||||
///
|
||||
class BlackBorderProcessor
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructor for the BlackBorderProcessor
|
||||
/// @param unknownFrameCnt The number of frames(images) that need to contain an unknown
|
||||
/// border before the current border is set to unknown
|
||||
/// @param borderFrameCnt The number of frames(images) that need to contain a vertical or
|
||||
/// horizontal border becomes the current border
|
||||
/// @param blurRemoveCnt The size to add to a horizontal or vertical border (because the
|
||||
/// outer pixels is blurred (black and color combined due to image scaling))
|
||||
///
|
||||
BlackBorderProcessor(
|
||||
const unsigned unknownFrameCnt,
|
||||
const unsigned borderFrameCnt,
|
||||
const unsigned blurRemoveCnt);
|
||||
|
||||
///
|
||||
/// Return the current (detected) border
|
||||
/// @return The current border
|
||||
///
|
||||
BlackBorder getCurrentBorder() const;
|
||||
|
||||
///
|
||||
/// Processes the image. This performs detecion of black-border on the given image and
|
||||
/// updates the current border accordingly. If the current border is updated the method call
|
||||
/// will return true else false
|
||||
///
|
||||
/// @param image The image to process
|
||||
///
|
||||
/// @return True if a different border was detected than the current else false
|
||||
///
|
||||
bool process(const RgbImage& image);
|
||||
|
||||
private:
|
||||
|
||||
/// The number of unknown-borders detected before it becomes the current border
|
||||
const unsigned _unknownSwitchCnt;
|
||||
|
||||
/// The number of horizontal/vertical borders detected before it becomes the current border
|
||||
const unsigned _borderSwitchCnt;
|
||||
|
||||
/// The number of pixels to increase a detected border for removing blury pixels
|
||||
unsigned _blurRemoveCnt;
|
||||
|
||||
/// The blackborder detector
|
||||
BlackBorderDetector _detector;
|
||||
|
||||
/// The current detected border
|
||||
BlackBorder _currentBorder;
|
||||
|
||||
/// The border detected in the previous frame
|
||||
BlackBorder _previousDetectedBorder;
|
||||
|
||||
/// The number of frame the previous detected border matched the incomming border
|
||||
unsigned _consistentCnt;
|
||||
};
|
||||
} // end namespace hyperion
|
@@ -13,13 +13,13 @@ SET(Hyperion_QT_HEADERS
|
||||
SET(Hyperion_HEADERS
|
||||
${CURRENT_HEADER_DIR}/ImageProcessor.h
|
||||
${CURRENT_HEADER_DIR}/ImageProcessorFactory.h
|
||||
${CURRENT_HEADER_DIR}/ImageToLedsMap.h
|
||||
${CURRENT_HEADER_DIR}/LedDevice.h
|
||||
${CURRENT_HEADER_DIR}/LedString.h
|
||||
${CURRENT_HEADER_DIR}/PriorityMuxer.h
|
||||
|
||||
${CURRENT_SOURCE_DIR}/BlackBorderDetector.h
|
||||
${CURRENT_SOURCE_DIR}/BlackBorderProcessor.h
|
||||
${CURRENT_SOURCE_DIR}/ImageToLedsMap.h
|
||||
${CURRENT_HEADER_DIR}/BlackBorderDetector.h
|
||||
${CURRENT_HEADER_DIR}/BlackBorderProcessor.h
|
||||
|
||||
${CURRENT_SOURCE_DIR}/device/LedSpiDevice.h
|
||||
${CURRENT_SOURCE_DIR}/device/LedRs232Device.h
|
||||
|
@@ -1,4 +1,7 @@
|
||||
|
||||
// STL includes
|
||||
#include <cassert>
|
||||
|
||||
// QT includes
|
||||
#include <QDateTime>
|
||||
|
||||
@@ -249,16 +252,16 @@ unsigned Hyperion::getLedCount() const
|
||||
return _ledString.leds().size();
|
||||
}
|
||||
|
||||
void Hyperion::setColor(int priority, const RgbColor &color, const int timeout_ms)
|
||||
void Hyperion::setColor(int priority, const ColorRgb &color, const int timeout_ms)
|
||||
{
|
||||
// create led output
|
||||
std::vector<RgbColor> ledColors(_ledString.leds().size(), color);
|
||||
std::vector<ColorRgb> ledColors(_ledString.leds().size(), color);
|
||||
|
||||
// set colors
|
||||
setColors(priority, ledColors, timeout_ms);
|
||||
}
|
||||
|
||||
void Hyperion::setColors(int priority, const std::vector<RgbColor>& ledColors, const int timeout_ms)
|
||||
void Hyperion::setColors(int priority, const std::vector<ColorRgb>& ledColors, const int timeout_ms)
|
||||
{
|
||||
if (timeout_ms > 0)
|
||||
{
|
||||
@@ -415,8 +418,8 @@ void Hyperion::update()
|
||||
const PriorityMuxer::InputInfo & priorityInfo = _muxer.getInputInfo(priority);
|
||||
|
||||
// Apply the transform to each led and color-channel
|
||||
std::vector<RgbColor> ledColors(priorityInfo.ledColors);
|
||||
for (RgbColor& color : ledColors)
|
||||
std::vector<ColorRgb> ledColors(priorityInfo.ledColors);
|
||||
for (ColorRgb& color : ledColors)
|
||||
{
|
||||
_hsvTransform->transform(color.red, color.green, color.blue);
|
||||
color.red = _redTransform->transform(color.red);
|
||||
|
@@ -1,13 +1,11 @@
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/ImageProcessor.h>
|
||||
#include <hyperion/ImageToLedsMap.h>
|
||||
#include <hyperion/BlackBorderProcessor.h>
|
||||
|
||||
#include <utils/ColorTransform.h>
|
||||
|
||||
// Local-Hyperion includes
|
||||
#include "BlackBorderProcessor.h"
|
||||
#include "ImageToLedsMap.h"
|
||||
|
||||
using namespace hyperion;
|
||||
|
||||
ImageProcessor::ImageProcessor(const LedString& ledString, bool enableBlackBorderDetector) :
|
||||
@@ -40,33 +38,6 @@ void ImageProcessor::setSize(const unsigned width, const unsigned height)
|
||||
mImageToLeds = new ImageToLedsMap(width, height, 0, 0, mLedString.leds());
|
||||
}
|
||||
|
||||
std::vector<RgbColor> ImageProcessor::process(const RgbImage& image)
|
||||
{
|
||||
// Ensure that the buffer-image is the proper size
|
||||
setSize(image.width(), image.height());
|
||||
|
||||
// Check black border detection
|
||||
verifyBorder(image);
|
||||
|
||||
// Create a result vector and call the 'in place' functionl
|
||||
std::vector<RgbColor> colors = mImageToLeds->getMeanLedColor(image);
|
||||
|
||||
// return the computed colors
|
||||
return colors;
|
||||
}
|
||||
|
||||
void ImageProcessor::process(const RgbImage& image, std::vector<RgbColor>& ledColors)
|
||||
{
|
||||
// Ensure that the buffer-image is the proper size
|
||||
setSize(image.width(), image.height());
|
||||
|
||||
// Check black border detection
|
||||
verifyBorder(image);
|
||||
|
||||
// Determine the mean-colors of each led (using the existing mapping)
|
||||
mImageToLeds->getMeanLedColor(image, ledColors);
|
||||
}
|
||||
|
||||
bool ImageProcessor::getScanParameters(size_t led, double &hscanBegin, double &hscanEnd, double &vscanBegin, double &vscanEnd) const
|
||||
{
|
||||
if (led < mLedString.leds().size())
|
||||
@@ -81,29 +52,3 @@ bool ImageProcessor::getScanParameters(size_t led, double &hscanBegin, double &h
|
||||
return false;
|
||||
}
|
||||
|
||||
void ImageProcessor::verifyBorder(const RgbImage& image)
|
||||
{
|
||||
if(_enableBlackBorderRemoval && _borderProcessor->process(image))
|
||||
{
|
||||
std::cout << "BORDER SWITCH REQUIRED!!" << std::endl;
|
||||
|
||||
const BlackBorder border = _borderProcessor->getCurrentBorder();
|
||||
|
||||
// Clean up the old mapping
|
||||
delete mImageToLeds;
|
||||
|
||||
if (border.unknown)
|
||||
{
|
||||
// Construct a new buffer and mapping
|
||||
mImageToLeds = new ImageToLedsMap(image.width(), image.height(), 0, 0, mLedString.leds());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Construct a new buffer and mapping
|
||||
mImageToLeds = new ImageToLedsMap(image.width(), image.height(), border.horizontalSize, border.verticalSize, mLedString.leds());
|
||||
}
|
||||
|
||||
std::cout << "CURRENT BORDER TYPE: unknown=" << border.unknown << " hor.size=" << border.horizontalSize << " vert.size=" << border.verticalSize << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,9 +1,10 @@
|
||||
|
||||
// STL includes
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
// hyperion includes
|
||||
#include "ImageToLedsMap.h"
|
||||
#include <hyperion/ImageToLedsMap.h>
|
||||
|
||||
using namespace hyperion;
|
||||
|
||||
@@ -61,52 +62,3 @@ unsigned ImageToLedsMap::height() const
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
|
||||
std::vector<RgbColor> ImageToLedsMap::getMeanLedColor(const RgbImage & image) const
|
||||
{
|
||||
std::vector<RgbColor> colors(mColorsMap.size(), RgbColor::BLACK);
|
||||
getMeanLedColor(image, colors);
|
||||
return colors;
|
||||
}
|
||||
|
||||
void ImageToLedsMap::getMeanLedColor(const RgbImage & image, std::vector<RgbColor> & ledColors) const
|
||||
{
|
||||
// Sanity check for the number of leds
|
||||
assert(mColorsMap.size() == ledColors.size());
|
||||
|
||||
// Iterate each led and compute the mean
|
||||
auto led = ledColors.begin();
|
||||
for (auto ledColors = mColorsMap.begin(); ledColors != mColorsMap.end(); ++ledColors, ++led)
|
||||
{
|
||||
const RgbColor color = calcMeanColor(image, *ledColors);
|
||||
*led = color;
|
||||
}
|
||||
}
|
||||
|
||||
RgbColor ImageToLedsMap::calcMeanColor(const RgbImage & image, const std::vector<unsigned> & colors) const
|
||||
{
|
||||
if (colors.size() == 0)
|
||||
{
|
||||
return RgbColor::BLACK;
|
||||
}
|
||||
|
||||
// Accumulate the sum of each seperate color channel
|
||||
uint_fast16_t cummRed = 0;
|
||||
uint_fast16_t cummGreen = 0;
|
||||
uint_fast16_t cummBlue = 0;
|
||||
for (const unsigned colorOffset : colors)
|
||||
{
|
||||
const RgbColor& color = image.memptr()[colorOffset];
|
||||
cummRed += color.red;
|
||||
cummGreen += color.green;
|
||||
cummBlue += color.blue;
|
||||
}
|
||||
|
||||
// Compute the average of each color channel
|
||||
const uint8_t avgRed = uint8_t(cummRed/colors.size());
|
||||
const uint8_t avgGreen = uint8_t(cummGreen/colors.size());
|
||||
const uint8_t avgBlue = uint8_t(cummBlue/colors.size());
|
||||
|
||||
// Return the computed color
|
||||
return {avgRed, avgGreen, avgBlue};
|
||||
}
|
||||
|
@@ -1,97 +0,0 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <sstream>
|
||||
|
||||
// hyperion-utils includes
|
||||
#include <utils/RgbImage.h>
|
||||
|
||||
// hyperion includes
|
||||
#include <hyperion/LedString.h>
|
||||
|
||||
namespace hyperion
|
||||
{
|
||||
|
||||
///
|
||||
/// The ImageToLedsMap holds a mapping of indices into an image to leds. It can be used to
|
||||
/// calculate the average (or mean) color per led for a specific region.
|
||||
///
|
||||
class ImageToLedsMap
|
||||
{
|
||||
public:
|
||||
|
||||
///
|
||||
/// Constructs an mapping from the absolute indices in an image to each led based on the border
|
||||
/// definition given in the list of leds. The map holds absolute indices to any given image,
|
||||
/// provided that it is row-oriented.
|
||||
/// The mapping is created purely on size (width and height). The given borders are excluded
|
||||
/// from indexing.
|
||||
///
|
||||
/// @param[in] width The width of the indexed image
|
||||
/// @param[in] height The width of the indexed image
|
||||
/// @param[in] horizontalBorder The size of the horizontal border (0=no border)
|
||||
/// @param[in] verticalBorder The size of the vertical border (0=no border)
|
||||
/// @param[in] leds The list with led specifications
|
||||
///
|
||||
ImageToLedsMap(
|
||||
const unsigned width,
|
||||
const unsigned height,
|
||||
const unsigned horizontalBorder,
|
||||
const unsigned verticalBorder,
|
||||
const std::vector<Led> & leds);
|
||||
|
||||
///
|
||||
/// Returns the width of the indexed image
|
||||
///
|
||||
/// @return The width of the indexed image [pixels]
|
||||
///
|
||||
unsigned width() const;
|
||||
|
||||
///
|
||||
/// Returns the height of the indexed image
|
||||
///
|
||||
/// @return The height of the indexed image [pixels]
|
||||
///
|
||||
unsigned height() const;
|
||||
|
||||
///
|
||||
/// Determines the mean-color for each led using the mapping the image given
|
||||
/// at construction.
|
||||
///
|
||||
/// @param[in] image The image from which to extract the led colors
|
||||
///
|
||||
/// @return ledColors The vector containing the output
|
||||
///
|
||||
std::vector<RgbColor> getMeanLedColor(const RgbImage & image) const;
|
||||
|
||||
///
|
||||
/// Determines the mean color for each led using the mapping the image given
|
||||
/// at construction.
|
||||
///
|
||||
/// @param[in] image The image from which to extract the led colors
|
||||
/// @param[out] ledColors The vector containing the output
|
||||
///
|
||||
void getMeanLedColor(const RgbImage & image, std::vector<RgbColor> & ledColors) const;
|
||||
|
||||
private:
|
||||
/// The width of the indexed image
|
||||
const unsigned _width;
|
||||
/// The height of the indexed image
|
||||
const unsigned _height;
|
||||
/// The absolute indices into the image for each led
|
||||
std::vector<std::vector<unsigned>> mColorsMap;
|
||||
|
||||
///
|
||||
/// Calculates the 'mean color' of the given list. This is the mean over each color-channel
|
||||
/// (red, green, blue)
|
||||
///
|
||||
/// @param[in] image The image a section from which an average color must be computed
|
||||
/// @param[in] colors The list with colors
|
||||
///
|
||||
/// @return The mean of the given list of colors (or black when empty)
|
||||
///
|
||||
RgbColor calcMeanColor(const RgbImage & image, const std::vector<unsigned> & colors) const;
|
||||
};
|
||||
|
||||
} // end namespace hyperion
|
@@ -22,7 +22,7 @@ LinearColorSmoothing::~LinearColorSmoothing()
|
||||
delete _ledDevice;
|
||||
}
|
||||
|
||||
int LinearColorSmoothing::write(const std::vector<RgbColor> &ledValues)
|
||||
int LinearColorSmoothing::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
// received a new target color
|
||||
if (_previousValues.size() == 0)
|
||||
@@ -38,7 +38,7 @@ int LinearColorSmoothing::write(const std::vector<RgbColor> &ledValues)
|
||||
else
|
||||
{
|
||||
_targetTime = QDateTime::currentMSecsSinceEpoch() + _settlingTime;
|
||||
memcpy(_targetValues.data(), ledValues.data(), ledValues.size() * sizeof(RgbColor));
|
||||
memcpy(_targetValues.data(), ledValues.data(), ledValues.size() * sizeof(ColorRgb));
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -66,7 +66,7 @@ void LinearColorSmoothing::updateLeds()
|
||||
|
||||
if (deltaTime < 0)
|
||||
{
|
||||
memcpy(_previousValues.data(), _targetValues.data(), _targetValues.size() * sizeof(RgbColor));
|
||||
memcpy(_previousValues.data(), _targetValues.data(), _targetValues.size() * sizeof(ColorRgb));
|
||||
_previousTime = now;
|
||||
|
||||
_ledDevice->write(_previousValues);
|
||||
@@ -77,8 +77,8 @@ void LinearColorSmoothing::updateLeds()
|
||||
|
||||
for (size_t i = 0; i < _previousValues.size(); ++i)
|
||||
{
|
||||
RgbColor & prev = _previousValues[i];
|
||||
RgbColor & target = _targetValues[i];
|
||||
ColorRgb & prev = _previousValues[i];
|
||||
ColorRgb & target = _targetValues[i];
|
||||
|
||||
prev.red += k * (target.red - prev.red);
|
||||
prev.green += k * (target.green - prev.green);
|
||||
|
@@ -36,7 +36,7 @@ public:
|
||||
/// @param ledValues The color-value per led
|
||||
/// @return Zero on succes else negative
|
||||
///
|
||||
virtual int write(const std::vector<RgbColor> &ledValues);
|
||||
virtual int write(const std::vector<ColorRgb> &ledValues);
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
@@ -62,11 +62,11 @@ private:
|
||||
int64_t _targetTime;
|
||||
|
||||
/// The target led data
|
||||
std::vector<RgbColor> _targetValues;
|
||||
std::vector<ColorRgb> _targetValues;
|
||||
|
||||
/// The timestamp of the previously written led data
|
||||
int64_t _previousTime;
|
||||
|
||||
/// The previously written led data
|
||||
std::vector<RgbColor> _previousValues;
|
||||
std::vector<ColorRgb> _previousValues;
|
||||
};
|
||||
|
@@ -13,7 +13,7 @@ PriorityMuxer::PriorityMuxer(int ledCount) :
|
||||
{
|
||||
_lowestPriorityInfo.priority = LOWEST_PRIORITY;
|
||||
_lowestPriorityInfo.timeoutTime_ms = -1;
|
||||
_lowestPriorityInfo.ledColors = std::vector<RgbColor>(ledCount, {0, 0, 0});
|
||||
_lowestPriorityInfo.ledColors = std::vector<ColorRgb>(ledCount, {0, 0, 0});
|
||||
}
|
||||
|
||||
PriorityMuxer::~PriorityMuxer()
|
||||
@@ -51,7 +51,7 @@ const PriorityMuxer::InputInfo& PriorityMuxer::getInputInfo(const int priority)
|
||||
return elemIt.value();
|
||||
}
|
||||
|
||||
void PriorityMuxer::setInput(const int priority, const std::vector<RgbColor>& ledColors, const int64_t timeoutTime_ms)
|
||||
void PriorityMuxer::setInput(const int priority, const std::vector<ColorRgb>& ledColors, const int64_t timeoutTime_ms)
|
||||
{
|
||||
InputInfo& input = _activeInputs[priority];
|
||||
input.priority = priority;
|
||||
|
@@ -17,7 +17,7 @@ LedDeviceLdp6803::LedDeviceLdp6803(const std::string& outputDevice, const unsign
|
||||
// empty
|
||||
}
|
||||
|
||||
int LedDeviceLdp6803::write(const std::vector<RgbColor> &ledValues)
|
||||
int LedDeviceLdp6803::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
// Reconfigure if the current connfiguration does not match the required configuration
|
||||
if (4 + 2*ledValues.size() != _ledBuffer.size())
|
||||
@@ -26,10 +26,10 @@ int LedDeviceLdp6803::write(const std::vector<RgbColor> &ledValues)
|
||||
_ledBuffer.resize(4 + 2*ledValues.size(), 0x00);
|
||||
}
|
||||
|
||||
// Copy the colors from the RgbColor vector to the Ldp6803 data vector
|
||||
// Copy the colors from the ColorRgb vector to the Ldp6803 data vector
|
||||
for (unsigned iLed=0; iLed<ledValues.size(); ++iLed)
|
||||
{
|
||||
const RgbColor& rgb = ledValues[iLed];
|
||||
const ColorRgb& rgb = ledValues[iLed];
|
||||
|
||||
_ledBuffer[4 + 2 * iLed] = 0x80 | ((rgb.red & 0xf8) >> 1) | (rgb.green >> 6);
|
||||
_ledBuffer[5 + 2 * iLed] = ((rgb.green & 0x38) << 2) | (rgb.blue >> 3);
|
||||
@@ -45,5 +45,5 @@ int LedDeviceLdp6803::write(const std::vector<RgbColor> &ledValues)
|
||||
|
||||
int LedDeviceLdp6803::switchOff()
|
||||
{
|
||||
return write(std::vector<RgbColor>(_ledBuffer.size(), RgbColor::BLACK));
|
||||
return write(std::vector<ColorRgb>(_ledBuffer.size(), ColorRgb{0,0,0}));
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ public:
|
||||
/// @param ledValues The color-value per led
|
||||
/// @return Zero on succes else negative
|
||||
///
|
||||
virtual int write(const std::vector<RgbColor> &ledValues);
|
||||
virtual int write(const std::vector<ColorRgb> &ledValues);
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
|
@@ -24,13 +24,13 @@ LedDeviceSedu::LedDeviceSedu(const std::string& outputDevice, const unsigned bau
|
||||
// empty
|
||||
}
|
||||
|
||||
int LedDeviceSedu::write(const std::vector<RgbColor> &ledValues)
|
||||
int LedDeviceSedu::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
if (_ledBuffer.size() == 0)
|
||||
{
|
||||
std::vector<FrameSpec> frameSpecs{{0xA0, 96}, {0xA1, 256}, {0xA2, 512}, {0xB0, 768}, {0xB1, 1536}, {0xB2, 3072} };
|
||||
|
||||
const unsigned reqColorChannels = ledValues.size() * sizeof(RgbColor);
|
||||
const unsigned reqColorChannels = ledValues.size() * sizeof(ColorRgb);
|
||||
|
||||
for (const FrameSpec& frameSpec : frameSpecs)
|
||||
{
|
||||
@@ -52,7 +52,7 @@ int LedDeviceSedu::write(const std::vector<RgbColor> &ledValues)
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(_ledBuffer.data()+2, ledValues.data(), ledValues.size() * sizeof(RgbColor));
|
||||
memcpy(_ledBuffer.data()+2, ledValues.data(), ledValues.size() * sizeof(ColorRgb));
|
||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||
}
|
||||
|
||||
|
@@ -26,7 +26,7 @@ public:
|
||||
/// @param ledValues The color-value per led
|
||||
/// @return Zero on succes else negative
|
||||
///
|
||||
virtual int write(const std::vector<RgbColor> &ledValues);
|
||||
virtual int write(const std::vector<ColorRgb> &ledValues);
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
|
@@ -13,10 +13,10 @@ LedDeviceTest::~LedDeviceTest()
|
||||
// empty
|
||||
}
|
||||
|
||||
int LedDeviceTest::write(const std::vector<RgbColor> & ledValues)
|
||||
int LedDeviceTest::write(const std::vector<ColorRgb> & ledValues)
|
||||
{
|
||||
_ofs << "[";
|
||||
for (const RgbColor& color : ledValues)
|
||||
for (const ColorRgb& color : ledValues)
|
||||
{
|
||||
_ofs << color;
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ public:
|
||||
///
|
||||
/// @return Zero on success else negative
|
||||
///
|
||||
virtual int write(const std::vector<RgbColor> & ledValues);
|
||||
virtual int write(const std::vector<ColorRgb> & ledValues);
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
|
@@ -18,11 +18,11 @@ LedDeviceWs2801::LedDeviceWs2801(const std::string& outputDevice, const unsigned
|
||||
// empty
|
||||
}
|
||||
|
||||
int LedDeviceWs2801::write(const std::vector<RgbColor> &ledValues)
|
||||
int LedDeviceWs2801::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
mLedCount = ledValues.size();
|
||||
|
||||
const unsigned dataLen = ledValues.size() * sizeof(RgbColor);
|
||||
const unsigned dataLen = ledValues.size() * sizeof(ColorRgb);
|
||||
const uint8_t * dataPtr = reinterpret_cast<const uint8_t *>(ledValues.data());
|
||||
|
||||
return writeBytes(dataLen, dataPtr);
|
||||
@@ -30,5 +30,5 @@ int LedDeviceWs2801::write(const std::vector<RgbColor> &ledValues)
|
||||
|
||||
int LedDeviceWs2801::switchOff()
|
||||
{
|
||||
return write(std::vector<RgbColor>(mLedCount, RgbColor::BLACK));
|
||||
return write(std::vector<ColorRgb>(mLedCount, ColorRgb{0,0,0}));
|
||||
}
|
||||
|
@@ -27,7 +27,7 @@ public:
|
||||
/// @param ledValues The color-value per led
|
||||
/// @return Zero on succes else negative
|
||||
///
|
||||
virtual int write(const std::vector<RgbColor> &ledValues);
|
||||
virtual int write(const std::vector<ColorRgb> &ledValues);
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
|
Reference in New Issue
Block a user