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:
@@ -16,7 +16,7 @@
|
||||
// hyperion util includes
|
||||
#include "hyperion/ImageProcessorFactory.h"
|
||||
#include "hyperion/ImageProcessor.h"
|
||||
#include "utils/RgbColor.h"
|
||||
#include "utils/ColorRgb.h"
|
||||
|
||||
// project includes
|
||||
#include "BoblightClientConnection.h"
|
||||
@@ -29,7 +29,7 @@ BoblightClientConnection::BoblightClientConnection(QTcpSocket *socket, Hyperion
|
||||
_hyperion(hyperion),
|
||||
_receiveBuffer(),
|
||||
_priority(255),
|
||||
_ledColors(hyperion->getLedCount(), RgbColor::BLACK)
|
||||
_ledColors(hyperion->getLedCount(), ColorRgb::BLACK)
|
||||
{
|
||||
// initalize the locale. Start with the default C-locale
|
||||
_locale.setNumberOptions(QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator);
|
||||
@@ -149,7 +149,7 @@ void BoblightClientConnection::handleMessage(const QString & message)
|
||||
|
||||
if (rc1 && rc2 && rc3)
|
||||
{
|
||||
RgbColor & rgb = _ledColors[ledIndex];
|
||||
ColorRgb & rgb = _ledColors[ledIndex];
|
||||
rgb.red = red;
|
||||
rgb.green = green;
|
||||
rgb.blue = blue;
|
||||
|
@@ -99,5 +99,5 @@ private:
|
||||
int _priority;
|
||||
|
||||
/// The latest led color data
|
||||
std::vector<RgbColor> _ledColors;
|
||||
std::vector<ColorRgb> _ledColors;
|
||||
};
|
||||
|
@@ -26,7 +26,7 @@ void AbstractBootSequence::update()
|
||||
}
|
||||
|
||||
// Obtain the next led-colors from the child-class
|
||||
const std::vector<RgbColor>& colors = nextColors();
|
||||
const std::vector<ColorRgb>& colors = nextColors();
|
||||
// Write the colors to hyperion
|
||||
_hyperion->setColors(_priority, colors, -1);
|
||||
|
||||
|
@@ -45,7 +45,7 @@ protected:
|
||||
///
|
||||
/// @return The next led colors in the boot sequence
|
||||
///
|
||||
virtual const std::vector<RgbColor>& nextColors() = 0;
|
||||
virtual const std::vector<ColorRgb>& nextColors() = 0;
|
||||
|
||||
private:
|
||||
/// The timer used to generate an 'update' signal every interval
|
||||
|
@@ -8,8 +8,8 @@
|
||||
KittBootSequence::KittBootSequence(Hyperion * hyperion, const unsigned duration_ms) :
|
||||
AbstractBootSequence(hyperion, 100, duration_ms/100),
|
||||
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
|
||||
_image(9, 1),
|
||||
_ledColors(hyperion->getLedCount(), RgbColor::BLACK),
|
||||
_image(9, 1, ColorRgb{0,0,0}),
|
||||
_ledColors(hyperion->getLedCount(), ColorRgb{0,0,0}),
|
||||
_forwardMove(false),
|
||||
_currentLight(0)
|
||||
{
|
||||
@@ -21,17 +21,17 @@ KittBootSequence::~KittBootSequence()
|
||||
delete _processor;
|
||||
}
|
||||
|
||||
const std::vector<RgbColor>& KittBootSequence::nextColors()
|
||||
const std::vector<ColorRgb>& KittBootSequence::nextColors()
|
||||
{
|
||||
|
||||
// Switch the previous light 'off'
|
||||
_image(_currentLight, 0) = RgbColor::BLACK;
|
||||
_image(_currentLight, 0) = ColorRgb{0,0,0};
|
||||
|
||||
// Move the current to the next light
|
||||
moveNextLight();
|
||||
|
||||
// Switch the current light 'on'
|
||||
_image(_currentLight, 0) = RgbColor::RED;
|
||||
_image(_currentLight, 0) = ColorRgb{255,0,0};
|
||||
|
||||
|
||||
// Translate the 'image' to led colors
|
||||
|
@@ -33,17 +33,17 @@ public:
|
||||
///
|
||||
/// @return The next colors for the leds
|
||||
///
|
||||
virtual const std::vector<RgbColor>& nextColors();
|
||||
virtual const std::vector<ColorRgb>& nextColors();
|
||||
|
||||
private:
|
||||
/// Image processor to compute led-colors from the image
|
||||
ImageProcessor * _processor;
|
||||
|
||||
/// 1D-Image of the KITT-grill contains a single red pixel and the rest black
|
||||
RgbImage _image;
|
||||
Image<ColorRgb> _image;
|
||||
|
||||
/// The vector with led-colors
|
||||
std::vector<RgbColor> _ledColors;
|
||||
std::vector<ColorRgb> _ledColors;
|
||||
|
||||
/// Direction the red-light is currently moving
|
||||
bool _forwardMove = true;
|
||||
|
@@ -11,15 +11,15 @@ RainbowBootSequence::RainbowBootSequence(Hyperion * hyperion, const unsigned dur
|
||||
{
|
||||
for (unsigned iLed=0; iLed<hyperion->getLedCount(); ++iLed)
|
||||
{
|
||||
RgbColor& color = _ledColors[iLed];
|
||||
ColorRgb& color = _ledColors[iLed];
|
||||
HsvTransform::hsv2rgb(iLed*360/hyperion->getLedCount(), 255, 255, color.red, color.green, color.blue);
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<RgbColor>& RainbowBootSequence::nextColors()
|
||||
const std::vector<ColorRgb>& RainbowBootSequence::nextColors()
|
||||
{
|
||||
// Rotate the colors left
|
||||
const RgbColor headColor = _ledColors.front();
|
||||
const ColorRgb headColor = _ledColors.front();
|
||||
for (unsigned i=1; i<_ledColors.size(); ++i)
|
||||
{
|
||||
_ledColors[i-1] = _ledColors[i];
|
||||
|
@@ -27,11 +27,11 @@ protected:
|
||||
///
|
||||
/// Moves the rainbow one led further
|
||||
///
|
||||
const std::vector<RgbColor>& nextColors();
|
||||
const std::vector<ColorRgb>& nextColors();
|
||||
|
||||
private:
|
||||
/// The current color of the boot sequence (the rainbow)
|
||||
std::vector<RgbColor> _ledColors;
|
||||
std::vector<ColorRgb> _ledColors;
|
||||
/// The counter of the number of iterations left
|
||||
int _iterationCounter;
|
||||
};
|
||||
|
@@ -1,4 +1,9 @@
|
||||
|
||||
// STL includes
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
// Local includes
|
||||
#include "DispmanxFrameGrabber.h"
|
||||
|
||||
DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned height) :
|
||||
@@ -32,7 +37,7 @@ DispmanxFrameGrabber::DispmanxFrameGrabber(const unsigned width, const unsigned
|
||||
// Create the resources for capturing image
|
||||
uint32_t vc_nativeImageHandle;
|
||||
_vc_resource = vc_dispmanx_resource_create(
|
||||
VC_IMAGE_RGB888,
|
||||
VC_IMAGE_RGBA32,
|
||||
width,
|
||||
height,
|
||||
&vc_nativeImageHandle);
|
||||
@@ -56,7 +61,7 @@ void DispmanxFrameGrabber::setFlags(const int vc_flags)
|
||||
_vc_flags = vc_flags;
|
||||
}
|
||||
|
||||
void DispmanxFrameGrabber::grabFrame(RgbImage& image)
|
||||
void DispmanxFrameGrabber::grabFrame(Image<ColorRgba> & image)
|
||||
{
|
||||
// Sanity check of the given image size
|
||||
assert(image.width() == _width && image.height() == _height);
|
||||
@@ -69,7 +74,7 @@ void DispmanxFrameGrabber::grabFrame(RgbImage& image)
|
||||
|
||||
// Read the snapshot into the memory
|
||||
void* image_ptr = image.memptr();
|
||||
const unsigned destPitch = _width * 3;
|
||||
const unsigned destPitch = _width * sizeof(ColorRgba);
|
||||
vc_dispmanx_resource_read_data(_vc_resource, &_rectangle, image_ptr, destPitch);
|
||||
|
||||
// Close the displaye
|
||||
|
@@ -8,7 +8,8 @@
|
||||
#include <cstdint>
|
||||
|
||||
// Utils includes
|
||||
#include <utils/RgbImage.h>
|
||||
#include <utils/Image.h>
|
||||
#include <utils/ColorRgba.h>
|
||||
|
||||
///
|
||||
/// The DispmanxFrameGrabber is used for creating snapshots of the display (screenshots) with a
|
||||
@@ -41,7 +42,7 @@ public:
|
||||
/// @param[out] image The snapped screenshot (should be initialized with correct width and
|
||||
/// height)
|
||||
///
|
||||
void grabFrame(RgbImage& image);
|
||||
void grabFrame(Image<ColorRgba> & image);
|
||||
|
||||
private:
|
||||
/// Handle to the display that is being captured
|
||||
|
@@ -20,7 +20,7 @@ DispmanxWrapper::DispmanxWrapper(const unsigned grabWidth, const unsigned grabHe
|
||||
_image(grabWidth, grabHeight),
|
||||
_frameGrabber(new DispmanxFrameGrabber(grabWidth, grabHeight)),
|
||||
_processor(ImageProcessorFactory::getInstance().newImageProcessor()),
|
||||
_ledColors(hyperion->getLedCount(), RgbColor::BLACK),
|
||||
_ledColors(hyperion->getLedCount(), ColorRgb{0,0,0}),
|
||||
_hyperion(hyperion)
|
||||
{
|
||||
// Configure the timer to generate events every n milliseconds
|
||||
|
@@ -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();
|
||||
|
@@ -14,7 +14,7 @@
|
||||
// hyperion util includes
|
||||
#include "hyperion/ImageProcessorFactory.h"
|
||||
#include "hyperion/ImageProcessor.h"
|
||||
#include "utils/RgbColor.h"
|
||||
#include "utils/ColorRgb.h"
|
||||
|
||||
// project includes
|
||||
#include "JsonClientConnection.h"
|
||||
@@ -111,7 +111,7 @@ void JsonClientConnection::handleColorCommand(const Json::Value &message)
|
||||
// extract parameters
|
||||
int priority = message["priority"].asInt();
|
||||
int duration = message.get("duration", -1).asInt();
|
||||
RgbColor color = {uint8_t(message["color"][0u].asInt()), uint8_t(message["color"][1u].asInt()), uint8_t(message["color"][2u].asInt())};
|
||||
ColorRgb color = {uint8_t(message["color"][0u].asInt()), uint8_t(message["color"][1u].asInt()), uint8_t(message["color"][2u].asInt())};
|
||||
|
||||
// set output
|
||||
_hyperion->setColor(priority, color, duration);
|
||||
@@ -139,12 +139,12 @@ void JsonClientConnection::handleImageCommand(const Json::Value &message)
|
||||
// set width and height of the image processor
|
||||
_imageProcessor->setSize(width, height);
|
||||
|
||||
// create RgbImage
|
||||
RgbImage image(width, height);
|
||||
// create ImageRgb
|
||||
Image<ColorRgb> image(width, height);
|
||||
memcpy(image.memptr(), data.data(), data.size());
|
||||
|
||||
// process the image
|
||||
std::vector<RgbColor> ledColors = _imageProcessor->process(image);
|
||||
std::vector<ColorRgb> ledColors = _imageProcessor->process(image);
|
||||
_hyperion->setColors(priority, ledColors, duration);
|
||||
|
||||
// send reply
|
||||
|
@@ -15,7 +15,7 @@
|
||||
// hyperion util includes
|
||||
#include "hyperion/ImageProcessorFactory.h"
|
||||
#include "hyperion/ImageProcessor.h"
|
||||
#include "utils/RgbColor.h"
|
||||
#include "utils/ColorRgb.h"
|
||||
|
||||
// project includes
|
||||
#include "ProtoClientConnection.h"
|
||||
@@ -120,7 +120,7 @@ void ProtoClientConnection::handleColorCommand(const proto::ColorRequest &messag
|
||||
// extract parameters
|
||||
int priority = message.priority();
|
||||
int duration = message.has_duration() ? message.duration() : -1;
|
||||
RgbColor color;
|
||||
ColorRgb color;
|
||||
color.red = qRed(message.rgbcolor());
|
||||
color.green = qGreen(message.rgbcolor());
|
||||
color.blue = qBlue(message.rgbcolor());
|
||||
@@ -151,12 +151,12 @@ void ProtoClientConnection::handleImageCommand(const proto::ImageRequest &messag
|
||||
// set width and height of the image processor
|
||||
_imageProcessor->setSize(width, height);
|
||||
|
||||
// create RgbImage
|
||||
RgbImage image(width, height);
|
||||
// create ImageRgb
|
||||
Image<ColorRgb> image(width, height);
|
||||
memcpy(image.memptr(), imageData.c_str(), imageData.size());
|
||||
|
||||
// process the image
|
||||
std::vector<RgbColor> ledColors = _imageProcessor->process(image);
|
||||
std::vector<ColorRgb> ledColors = _imageProcessor->process(image);
|
||||
_hyperion->setColors(priority, ledColors, duration);
|
||||
|
||||
// send reply
|
||||
|
@@ -24,7 +24,7 @@ message ColorRequest {
|
||||
required int32 priority = 1;
|
||||
|
||||
// integer value containing the rgb color (0x00RRGGBB)
|
||||
required int32 rgbColor = 2;
|
||||
required int32 RgbColor = 2;
|
||||
|
||||
// duration of the request (negative results in infinite)
|
||||
optional int32 duration = 3;
|
||||
|
@@ -4,13 +4,16 @@ SET(CURRENT_HEADER_DIR ${CMAKE_SOURCE_DIR}/include/utils)
|
||||
SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/utils)
|
||||
|
||||
add_library(hyperion-utils
|
||||
${CURRENT_HEADER_DIR}/RgbColor.h
|
||||
${CURRENT_HEADER_DIR}/RgbImage.h
|
||||
${CURRENT_HEADER_DIR}/ColorArgb.h
|
||||
${CURRENT_SOURCE_DIR}/ColorArgb.cpp
|
||||
${CURRENT_HEADER_DIR}/ColorRgb.h
|
||||
${CURRENT_SOURCE_DIR}/ColorRgb.cpp
|
||||
${CURRENT_HEADER_DIR}/ColorRgba.h
|
||||
${CURRENT_SOURCE_DIR}/ColorRgba.cpp
|
||||
${CURRENT_HEADER_DIR}/Image.h
|
||||
${CURRENT_HEADER_DIR}/ColorTransform.h
|
||||
${CURRENT_HEADER_DIR}/HsvTransform.h
|
||||
|
||||
${CURRENT_SOURCE_DIR}/RgbColor.cpp
|
||||
${CURRENT_SOURCE_DIR}/RgbImage.cpp
|
||||
${CURRENT_SOURCE_DIR}/ColorTransform.cpp
|
||||
${CURRENT_SOURCE_DIR}/HsvTransform.cpp
|
||||
|
||||
|
10
libsrc/utils/ColorArgb.cpp
Normal file
10
libsrc/utils/ColorArgb.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
// Utils includes
|
||||
#include <utils/ColorArgb.h>
|
||||
|
||||
ColorArgb ColorArgb::BLACK = { 255, 0, 0, 0 };
|
||||
ColorArgb ColorArgb::RED = { 255, 255, 0, 0 };
|
||||
ColorArgb ColorArgb::GREEN = { 255, 0, 255, 0 };
|
||||
ColorArgb ColorArgb::BLUE = { 255, 0, 0, 255 };
|
||||
ColorArgb ColorArgb::YELLOW= { 255, 255, 255, 0 };
|
||||
ColorArgb ColorArgb::WHITE = { 255, 255, 255, 255 };
|
10
libsrc/utils/ColorRgb.cpp
Normal file
10
libsrc/utils/ColorRgb.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
// Local includes
|
||||
#include <utils/ColorRgb.h>
|
||||
|
||||
ColorRgb ColorRgb::BLACK = { 0, 0, 0 };
|
||||
ColorRgb ColorRgb::RED = { 255, 0, 0 };
|
||||
ColorRgb ColorRgb::GREEN = { 0, 255, 0 };
|
||||
ColorRgb ColorRgb::BLUE = { 0, 0, 255 };
|
||||
ColorRgb ColorRgb::YELLOW= { 255, 255, 0 };
|
||||
ColorRgb ColorRgb::WHITE = { 255, 255, 255 };
|
10
libsrc/utils/ColorRgba.cpp
Normal file
10
libsrc/utils/ColorRgba.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
// Utils includes
|
||||
#include <utils/ColorRgba.h>
|
||||
|
||||
ColorRgba ColorRgba::BLACK = { 0, 0, 0, 255 };
|
||||
ColorRgba ColorRgba::RED = { 255, 0, 0, 255 };
|
||||
ColorRgba ColorRgba::GREEN = { 0, 255, 0, 255 };
|
||||
ColorRgba ColorRgba::BLUE = { 0, 0, 255, 255 };
|
||||
ColorRgba ColorRgba::YELLOW= { 255, 255, 0, 255 };
|
||||
ColorRgba ColorRgba::WHITE = { 255, 255, 255, 255 };
|
@@ -1,10 +0,0 @@
|
||||
|
||||
// Local includes
|
||||
#include <utils/RgbColor.h>
|
||||
|
||||
RgbColor RgbColor::BLACK = { 0, 0, 0 };
|
||||
RgbColor RgbColor::RED = { 255, 0, 0 };
|
||||
RgbColor RgbColor::GREEN = { 0, 255, 0 };
|
||||
RgbColor RgbColor::BLUE = { 0, 0, 255 };
|
||||
RgbColor RgbColor::YELLOW= { 255, 255, 0 };
|
||||
RgbColor RgbColor::WHITE = { 255, 255, 255 };
|
@@ -1,50 +0,0 @@
|
||||
|
||||
// STL includes
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
// hyperion Utils includes
|
||||
#include <utils/RgbImage.h>
|
||||
|
||||
|
||||
RgbImage::RgbImage(const unsigned width, const unsigned height, const RgbColor background) :
|
||||
_width(width),
|
||||
_height(height),
|
||||
mColors(new RgbColor[width*height])
|
||||
{
|
||||
for (unsigned i=0; i<width*height; ++i)
|
||||
{
|
||||
mColors[i] = background;
|
||||
}
|
||||
}
|
||||
|
||||
RgbImage::~RgbImage()
|
||||
{
|
||||
delete[] mColors;
|
||||
}
|
||||
|
||||
void RgbImage::setPixel(const unsigned x, const unsigned y, const RgbColor color)
|
||||
{
|
||||
// Debug-mode sanity check on given index
|
||||
(*this)(x,y) = color;
|
||||
}
|
||||
|
||||
const RgbColor& RgbImage::operator()(const unsigned x, const unsigned y) const
|
||||
{
|
||||
// Debug-mode sanity check on given index
|
||||
assert(x < _width);
|
||||
assert(y < _height);
|
||||
|
||||
const unsigned index = toIndex(x, y);
|
||||
return mColors[index];
|
||||
}
|
||||
|
||||
RgbColor& RgbImage::operator()(const unsigned x, const unsigned y)
|
||||
{
|
||||
// Debug-mode sanity check on given index
|
||||
assert(x < _width);
|
||||
assert(y < _height);
|
||||
|
||||
const unsigned index = toIndex(x, y);
|
||||
return mColors[index];
|
||||
}
|
Reference in New Issue
Block a user