mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Merge branch 'master' into add_effect_engine
Conflicts: include/hyperion/Hyperion.h libsrc/hyperion/Hyperion.cpp libsrc/jsonserver/JsonClientConnection.cpp Former-commit-id: 1df163d1880691ded2fc8b5902c6ad3501912c48
This commit is contained in:
@@ -30,6 +30,8 @@ SET(Hyperion_HEADERS
|
||||
${CURRENT_HEADER_DIR}/BlackBorderDetector.h
|
||||
${CURRENT_HEADER_DIR}/BlackBorderProcessor.h
|
||||
|
||||
${CURRENT_SOURCE_DIR}/MultiColorTransform.h
|
||||
|
||||
${CURRENT_SOURCE_DIR}/device/LedSpiDevice.h
|
||||
${CURRENT_SOURCE_DIR}/device/LedRs232Device.h
|
||||
${CURRENT_SOURCE_DIR}/device/LedDeviceTest.h
|
||||
@@ -51,6 +53,7 @@ SET(Hyperion_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/BlackBorderDetector.cpp
|
||||
${CURRENT_SOURCE_DIR}/BlackBorderProcessor.cpp
|
||||
${CURRENT_SOURCE_DIR}/ImageToLedsMap.cpp
|
||||
${CURRENT_SOURCE_DIR}/MultiColorTransform.cpp
|
||||
${CURRENT_SOURCE_DIR}/LinearColorSmoothing.cpp
|
||||
|
||||
${CURRENT_SOURCE_DIR}/device/LedSpiDevice.cpp
|
||||
|
@@ -4,8 +4,6 @@
|
||||
#include <hyperion/ImageToLedsMap.h>
|
||||
#include <hyperion/BlackBorderProcessor.h>
|
||||
|
||||
#include <utils/ColorTransform.h>
|
||||
|
||||
using namespace hyperion;
|
||||
|
||||
ImageProcessor::ImageProcessor(const LedString& ledString, bool enableBlackBorderDetector) :
|
||||
|
97
libsrc/hyperion/MultiColorTransform.cpp
Normal file
97
libsrc/hyperion/MultiColorTransform.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
|
||||
// STL includes
|
||||
#include <cassert>
|
||||
|
||||
// Hyperion includes
|
||||
#include "MultiColorTransform.h"
|
||||
|
||||
MultiColorTransform::MultiColorTransform(const unsigned ledCnt) :
|
||||
_ledTransforms(ledCnt, nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
MultiColorTransform::~MultiColorTransform()
|
||||
{
|
||||
// Clean up all the transforms
|
||||
for (ColorTransform * transform : _transform)
|
||||
{
|
||||
delete transform;
|
||||
}
|
||||
}
|
||||
|
||||
void MultiColorTransform::addTransform(ColorTransform * transform)
|
||||
{
|
||||
_transformIds.push_back(transform->_id);
|
||||
_transform.push_back(transform);
|
||||
}
|
||||
|
||||
void MultiColorTransform::setTransformForLed(const std::string& id, const unsigned startLed, const unsigned endLed)
|
||||
{
|
||||
assert(startLed <= endLed);
|
||||
assert(endLed < _ledTransforms.size());
|
||||
|
||||
// Get the identified transform (don't care if is nullptr)
|
||||
ColorTransform * transform = getTransform(id);
|
||||
for (unsigned iLed=startLed; iLed<=endLed; ++iLed)
|
||||
{
|
||||
_ledTransforms[iLed] = transform;
|
||||
}
|
||||
}
|
||||
|
||||
bool MultiColorTransform::verifyTransforms() const
|
||||
{
|
||||
bool allLedsSet = true;
|
||||
for (unsigned iLed=0; iLed<_ledTransforms.size(); ++iLed)
|
||||
{
|
||||
if (_ledTransforms[iLed] == nullptr)
|
||||
{
|
||||
std::cerr << "No transform set for " << iLed << std::endl;
|
||||
allLedsSet = false;
|
||||
}
|
||||
}
|
||||
return allLedsSet;
|
||||
}
|
||||
|
||||
const std::vector<std::string> & MultiColorTransform::getTransformIds()
|
||||
{
|
||||
return _transformIds;
|
||||
}
|
||||
|
||||
ColorTransform* MultiColorTransform::getTransform(const std::string& id)
|
||||
{
|
||||
// Iterate through the unique transforms until we find the one with the given id
|
||||
for (ColorTransform* transform : _transform)
|
||||
{
|
||||
if (transform->_id == id)
|
||||
{
|
||||
return transform;
|
||||
}
|
||||
}
|
||||
|
||||
// The ColorTransform was not found
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<ColorRgb> MultiColorTransform::applyTransform(const std::vector<ColorRgb>& rawColors)
|
||||
{
|
||||
// Create a copy, as we will do the rest of the transformation in place
|
||||
std::vector<ColorRgb> ledColors(rawColors);
|
||||
|
||||
const size_t itCnt = std::min(_ledTransforms.size(), rawColors.size());
|
||||
for (size_t i=0; i<itCnt; ++i)
|
||||
{
|
||||
ColorTransform* transform = _ledTransforms[i];
|
||||
if (transform == nullptr)
|
||||
{
|
||||
// No transform set for this led (do nothing)
|
||||
continue;
|
||||
}
|
||||
ColorRgb& color = ledColors[i];
|
||||
|
||||
transform->_hsvTransform.transform(color.red, color.green, color.blue);
|
||||
color.red = transform->_rgbRedTransform.transform(color.red);
|
||||
color.green = transform->_rgbGreenTransform.transform(color.green);
|
||||
color.blue = transform->_rgbBlueTransform.transform(color.blue);
|
||||
}
|
||||
return ledColors;
|
||||
}
|
66
libsrc/hyperion/MultiColorTransform.h
Normal file
66
libsrc/hyperion/MultiColorTransform.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <vector>
|
||||
|
||||
// Utils includes
|
||||
#include <utils/ColorRgb.h>
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/ColorTransform.h>
|
||||
|
||||
///
|
||||
/// The LedColorTransform is responsible for performing color transformation from 'raw' colors
|
||||
/// received as input to colors mapped to match the color-properties of the leds.
|
||||
///
|
||||
class MultiColorTransform
|
||||
{
|
||||
public:
|
||||
MultiColorTransform(const unsigned ledCnt);
|
||||
~MultiColorTransform();
|
||||
|
||||
/**
|
||||
* Adds a new ColorTransform to this MultiColorTransform
|
||||
*
|
||||
* @param transform The new ColorTransform (ownership is transfered)
|
||||
*/
|
||||
void addTransform(ColorTransform * transform);
|
||||
|
||||
void setTransformForLed(const std::string& id, const unsigned startLed, const unsigned endLed);
|
||||
|
||||
bool verifyTransforms() const;
|
||||
|
||||
///
|
||||
/// Returns the identifier of all the unique ColorTransform
|
||||
///
|
||||
/// @return The list with unique id's of the ColorTransforms
|
||||
const std::vector<std::string> & getTransformIds();
|
||||
|
||||
///
|
||||
/// Returns the pointer to the ColorTransform with the given id
|
||||
///
|
||||
/// @param id The identifier of the ColorTransform
|
||||
///
|
||||
/// @return The ColorTransform with the given id (or nullptr if it does not exist)
|
||||
///
|
||||
ColorTransform* getTransform(const std::string& id);
|
||||
|
||||
///
|
||||
/// Performs the color transoformation from raw-color to led-color
|
||||
///
|
||||
/// @param rawColors The list with raw colors
|
||||
///
|
||||
/// @return The list with led-colors
|
||||
///
|
||||
std::vector<ColorRgb> applyTransform(const std::vector<ColorRgb>& rawColors);
|
||||
|
||||
private:
|
||||
/// List with transform ids
|
||||
std::vector<std::string> _transformIds;
|
||||
|
||||
/// List with unique ColorTransforms
|
||||
std::vector<ColorTransform*> _transform;
|
||||
|
||||
/// List with a pointer to the ColorTransform for each individual led
|
||||
std::vector<ColorTransform*> _ledTransforms;
|
||||
};
|
@@ -1,68 +1,72 @@
|
||||
{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"properties":{
|
||||
"command": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["transform"]
|
||||
},
|
||||
"transform": {
|
||||
"type": "object",
|
||||
"required": true,
|
||||
"properties": {
|
||||
"saturationGain" : {
|
||||
"type" : "double",
|
||||
"required" : false,
|
||||
"minimum" : 0.0
|
||||
},
|
||||
"valueGain" : {
|
||||
"type" : "double",
|
||||
"required" : false,
|
||||
"minimum" : 0.0
|
||||
},
|
||||
"threshold": {
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type": "double",
|
||||
"minimum": 0.0,
|
||||
"maximum": 1.0
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 3
|
||||
},
|
||||
"gamma": {
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type": "double",
|
||||
"minimum": 0.0
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 3
|
||||
},
|
||||
"blacklevel": {
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type": "double"
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 3
|
||||
},
|
||||
"whitelevel": {
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type": "double"
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 3
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"properties":{
|
||||
"command": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["transform"]
|
||||
},
|
||||
"transform": {
|
||||
"type": "object",
|
||||
"required": true,
|
||||
"properties": {
|
||||
"id" : {
|
||||
"type" : "string",
|
||||
"required" : false
|
||||
},
|
||||
"saturationGain" : {
|
||||
"type" : "double",
|
||||
"required" : false,
|
||||
"minimum" : 0.0
|
||||
},
|
||||
"valueGain" : {
|
||||
"type" : "double",
|
||||
"required" : false,
|
||||
"minimum" : 0.0
|
||||
},
|
||||
"threshold": {
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type": "double",
|
||||
"minimum": 0.0,
|
||||
"maximum": 1.0
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 3
|
||||
},
|
||||
"gamma": {
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type": "double",
|
||||
"minimum": 0.0
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 3
|
||||
},
|
||||
"blacklevel": {
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type": "double"
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 3
|
||||
},
|
||||
"whitelevel": {
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type": "double"
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 3
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
|
@@ -11,11 +11,11 @@ add_library(hyperion-utils
|
||||
${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}/ColorTransform.cpp
|
||||
${CURRENT_HEADER_DIR}/HsvTransform.h
|
||||
${CURRENT_SOURCE_DIR}/HsvTransform.cpp
|
||||
${CURRENT_HEADER_DIR}/RgbChannelTransform.h
|
||||
${CURRENT_SOURCE_DIR}/RgbChannelTransform.cpp
|
||||
|
||||
${CURRENT_HEADER_DIR}/jsonschema/JsonFactory.h
|
||||
${CURRENT_HEADER_DIR}/jsonschema/JsonSchemaChecker.h
|
||||
|
@@ -1,9 +1,10 @@
|
||||
// STL includes
|
||||
#include <cmath>
|
||||
|
||||
#include <utils/ColorTransform.h>
|
||||
// Utils includes
|
||||
#include <utils/RgbChannelTransform.h>
|
||||
|
||||
ColorTransform::ColorTransform() :
|
||||
RgbChannelTransform::RgbChannelTransform() :
|
||||
_threshold(0),
|
||||
_gamma(1.0),
|
||||
_blacklevel(0.0),
|
||||
@@ -12,7 +13,7 @@ ColorTransform::ColorTransform() :
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
ColorTransform::ColorTransform(double threshold, double gamma, double blacklevel, double whitelevel) :
|
||||
RgbChannelTransform::RgbChannelTransform(double threshold, double gamma, double blacklevel, double whitelevel) :
|
||||
_threshold(threshold),
|
||||
_gamma(gamma),
|
||||
_blacklevel(blacklevel),
|
||||
@@ -21,55 +22,55 @@ ColorTransform::ColorTransform(double threshold, double gamma, double blacklevel
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
ColorTransform::~ColorTransform()
|
||||
RgbChannelTransform::~RgbChannelTransform()
|
||||
{
|
||||
}
|
||||
|
||||
double ColorTransform::getThreshold() const
|
||||
double RgbChannelTransform::getThreshold() const
|
||||
{
|
||||
return _threshold;
|
||||
}
|
||||
|
||||
void ColorTransform::setThreshold(double threshold)
|
||||
void RgbChannelTransform::setThreshold(double threshold)
|
||||
{
|
||||
_threshold = threshold;
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
double ColorTransform::getGamma() const
|
||||
double RgbChannelTransform::getGamma() const
|
||||
{
|
||||
return _gamma;
|
||||
}
|
||||
|
||||
void ColorTransform::setGamma(double gamma)
|
||||
void RgbChannelTransform::setGamma(double gamma)
|
||||
{
|
||||
_gamma = gamma;
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
double ColorTransform::getBlacklevel() const
|
||||
double RgbChannelTransform::getBlacklevel() const
|
||||
{
|
||||
return _blacklevel;
|
||||
}
|
||||
|
||||
void ColorTransform::setBlacklevel(double blacklevel)
|
||||
void RgbChannelTransform::setBlacklevel(double blacklevel)
|
||||
{
|
||||
_blacklevel = blacklevel;
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
double ColorTransform::getWhitelevel() const
|
||||
double RgbChannelTransform::getWhitelevel() const
|
||||
{
|
||||
return _whitelevel;
|
||||
}
|
||||
|
||||
void ColorTransform::setWhitelevel(double whitelevel)
|
||||
void RgbChannelTransform::setWhitelevel(double whitelevel)
|
||||
{
|
||||
_whitelevel = whitelevel;
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
void ColorTransform::initializeMapping()
|
||||
void RgbChannelTransform::initializeMapping()
|
||||
{
|
||||
// initialize the mapping as a linear array
|
||||
for (int i = 0; i < 256; ++i)
|
@@ -154,6 +154,8 @@ void JsonSchemaChecker::checkType(const Json::Value & value, const Json::Value &
|
||||
wrongType = !value.isNumeric();
|
||||
else if (type == "integer")
|
||||
wrongType = !value.isIntegral();
|
||||
else if (type == "double")
|
||||
wrongType = !value.isDouble();
|
||||
else if (type == "boolean")
|
||||
wrongType = !value.isBool();
|
||||
else if (type == "object")
|
||||
@@ -162,6 +164,8 @@ void JsonSchemaChecker::checkType(const Json::Value & value, const Json::Value &
|
||||
wrongType = !value.isArray();
|
||||
else if (type == "null")
|
||||
wrongType = !value.isNull();
|
||||
else if (type == "enum")
|
||||
wrongType = !value.isString();
|
||||
else if (type == "any")
|
||||
wrongType = false;
|
||||
// else
|
||||
|
Reference in New Issue
Block a user