mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Add color adjustment to all RBG channels
* Channel adjustment config * Create RgbChannelAdjustment.h * Delete RgbChannelAdjustment.h * Create RgbChannelAdjustment.cpp * Create RgbChannelAdjustment.h * Delete RgbChannelAdjustment.cpp * Create ColorAdjustment.cpp * Delete RgbChannelAdjustment.h * Create ColorAdjustment.h * Update ColorAdjustment.h * Update ColorAdjustment.h * Update ColorAdjustment.h * Update ColorAdjustment.cpp * Update Hyperion.cpp * Update Hyperion.cpp * Update Hyperion.cpp * Update Hyperion.h * Create RgbChannelAdjustment.cpp * Create RgbChannelAdjustment.h * Create ColorAdjustment.h * Create MultiColorAdjustment.h * Update MultiColorAdjustment.h * Create MultiColorAdjustment.cpp * Delete ColorAdjustment.cpp * Delete ColorAdjustment.h * Update RgbChannelAdjustment.cpp * Update Hyperion.cpp * Update Hyperion.h * Update Hyperion.cpp * Bug fixes * Update hyperion.config.json * Add color adjustment to json server and client and adapt hyperion-remote * Change the color modification order * Minor bug fix * Create calibration Images folder * Create calibration Gamma folder * Create calibration RGB folder * Added files via upload * Delete .gitkeep * Delete .gitkeep * Added files via upload * Delete .gitkeep * Update color effect order and don't correct twice * Uploaded gradient images Former-commit-id: 8ab465e59834f12a21709a6f4546bd6808a2a495
This commit is contained in:
@@ -19,6 +19,7 @@ SET(Hyperion_HEADERS
|
||||
|
||||
${CURRENT_SOURCE_DIR}/MultiColorTransform.h
|
||||
${CURRENT_SOURCE_DIR}/MultiColorCorrection.h
|
||||
${CURRENT_SOURCE_DIR}/MultiColorAdjustment.h
|
||||
${CURRENT_HEADER_DIR}/MessageForwarder.h
|
||||
)
|
||||
|
||||
@@ -32,6 +33,7 @@ SET(Hyperion_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/ImageToLedsMap.cpp
|
||||
${CURRENT_SOURCE_DIR}/MultiColorTransform.cpp
|
||||
${CURRENT_SOURCE_DIR}/MultiColorCorrection.cpp
|
||||
${CURRENT_SOURCE_DIR}/MultiColorAdjustment.cpp
|
||||
${CURRENT_SOURCE_DIR}/LinearColorSmoothing.cpp
|
||||
${CURRENT_SOURCE_DIR}/MessageForwarder.cpp
|
||||
)
|
||||
|
@@ -17,6 +17,7 @@
|
||||
#include <hyperion/ImageProcessorFactory.h>
|
||||
#include <hyperion/ColorTransform.h>
|
||||
#include <hyperion/ColorCorrection.h>
|
||||
#include <hyperion/ColorAdjustment.h>
|
||||
|
||||
// Leddevice includes
|
||||
#include <leddevice/LedDevice.h>
|
||||
@@ -24,6 +25,7 @@
|
||||
|
||||
#include "MultiColorTransform.h"
|
||||
#include "MultiColorCorrection.h"
|
||||
#include "MultiColorAdjustment.h"
|
||||
#include "LinearColorSmoothing.h"
|
||||
|
||||
// effect engine includes
|
||||
@@ -101,6 +103,7 @@ ColorTransform * Hyperion::createColorTransform(const Json::Value & transformCon
|
||||
return transform;
|
||||
}
|
||||
|
||||
|
||||
ColorCorrection * Hyperion::createColorCorrection(const Json::Value & correctionConfig)
|
||||
{
|
||||
const std::string id = correctionConfig.get("id", "default").asString();
|
||||
@@ -117,6 +120,30 @@ ColorCorrection * Hyperion::createColorCorrection(const Json::Value & correction
|
||||
return correction;
|
||||
}
|
||||
|
||||
|
||||
ColorAdjustment * Hyperion::createColorAdjustment(const Json::Value & adjustmentConfig)
|
||||
{
|
||||
const std::string id = adjustmentConfig.get("id", "default").asString();
|
||||
|
||||
RgbChannelAdjustment * redAdjustment = createRgbChannelAdjustment(adjustmentConfig["pureRed"],RED);
|
||||
RgbChannelAdjustment * greenAdjustment = createRgbChannelAdjustment(adjustmentConfig["pureGreen"],GREEN);
|
||||
RgbChannelAdjustment * blueAdjustment = createRgbChannelAdjustment(adjustmentConfig["pureBlue"],BLUE);
|
||||
|
||||
ColorAdjustment * adjustment = new ColorAdjustment();
|
||||
adjustment->_id = id;
|
||||
adjustment->_rgbRedAdjustment = *redAdjustment;
|
||||
adjustment->_rgbGreenAdjustment = *greenAdjustment;
|
||||
adjustment->_rgbBlueAdjustment = *blueAdjustment;
|
||||
|
||||
// Cleanup the allocated individual adjustments
|
||||
delete redAdjustment;
|
||||
delete greenAdjustment;
|
||||
delete blueAdjustment;
|
||||
|
||||
return adjustment;
|
||||
}
|
||||
|
||||
|
||||
MultiColorTransform * Hyperion::createLedColorsTransform(const unsigned ledCnt, const Json::Value & colorConfig)
|
||||
{
|
||||
// Create the result, the transforms are added to this
|
||||
@@ -206,7 +233,7 @@ MultiColorCorrection * Hyperion::createLedColorsCorrection(const unsigned ledCnt
|
||||
}
|
||||
else if (!correctionConfig.isArray())
|
||||
{
|
||||
ColorCorrection * colorCorrection = createColorCorrection(colorConfig);
|
||||
ColorCorrection * colorCorrection = createColorCorrection(correctionConfig);
|
||||
correction->addCorrection(colorCorrection);
|
||||
correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1);
|
||||
}
|
||||
@@ -280,7 +307,7 @@ MultiColorCorrection * Hyperion::createLedColorsTemperature(const unsigned ledCn
|
||||
}
|
||||
else if (!correctionConfig.isArray())
|
||||
{
|
||||
ColorCorrection * colorCorrection = createColorCorrection(colorConfig);
|
||||
ColorCorrection * colorCorrection = createColorCorrection(correctionConfig);
|
||||
correction->addCorrection(colorCorrection);
|
||||
correction->setCorrectionForLed(colorCorrection->_id, 0, ledCnt-1);
|
||||
}
|
||||
@@ -339,6 +366,80 @@ MultiColorCorrection * Hyperion::createLedColorsTemperature(const unsigned ledCn
|
||||
return correction;
|
||||
}
|
||||
|
||||
MultiColorAdjustment * Hyperion::createLedColorsAdjustment(const unsigned ledCnt, const Json::Value & colorConfig)
|
||||
{
|
||||
// Create the result, the transforms are added to this
|
||||
MultiColorAdjustment * adjustment = new MultiColorAdjustment(ledCnt);
|
||||
|
||||
const Json::Value adjustmentConfig = colorConfig.get("channelAdjustment", Json::nullValue);
|
||||
if (adjustmentConfig.isNull())
|
||||
{
|
||||
// Old style color transformation config (just one for all leds)
|
||||
ColorAdjustment * colorAdjustment = createColorAdjustment(colorConfig);
|
||||
adjustment->addAdjustment(colorAdjustment);
|
||||
adjustment->setAdjustmentForLed(colorAdjustment->_id, 0, ledCnt-1);
|
||||
}
|
||||
else if (!adjustmentConfig.isArray())
|
||||
{
|
||||
ColorAdjustment * colorAdjustment = createColorAdjustment(adjustmentConfig);
|
||||
adjustment->addAdjustment(colorAdjustment);
|
||||
adjustment->setAdjustmentForLed(colorAdjustment->_id, 0, ledCnt-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
const QRegExp overallExp("([0-9]+(\\-[0-9]+)?)(,[ ]*([0-9]+(\\-[0-9]+)?))*");
|
||||
|
||||
for (Json::UInt i = 0; i < adjustmentConfig.size(); ++i)
|
||||
{
|
||||
const Json::Value & config = adjustmentConfig[i];
|
||||
ColorAdjustment * colorAdjustment = createColorAdjustment(config);
|
||||
adjustment->addAdjustment(colorAdjustment);
|
||||
|
||||
const QString ledIndicesStr = QString(config.get("leds", "").asCString()).trimmed();
|
||||
if (ledIndicesStr.compare("*") == 0)
|
||||
{
|
||||
// Special case for indices '*' => all leds
|
||||
adjustment->setAdjustmentForLed(colorAdjustment->_id, 0, ledCnt-1);
|
||||
std::cout << "HYPERION INFO: ColorAdjustment '" << colorAdjustment->_id << "' => [0; "<< ledCnt-1 << "]" << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!overallExp.exactMatch(ledIndicesStr))
|
||||
{
|
||||
std::cerr << "HYPERION ERROR: Given led indices " << i << " not correct format: " << ledIndicesStr.toStdString() << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
std::cout << "HYPERION INFO: ColorAdjustment '" << colorAdjustment->_id << "' => [";
|
||||
|
||||
const QStringList ledIndexList = ledIndicesStr.split(",");
|
||||
for (int i=0; i<ledIndexList.size(); ++i) {
|
||||
if (i > 0)
|
||||
{
|
||||
std::cout << ", ";
|
||||
}
|
||||
if (ledIndexList[i].contains("-"))
|
||||
{
|
||||
QStringList ledIndices = ledIndexList[i].split("-");
|
||||
int startInd = ledIndices[0].toInt();
|
||||
int endInd = ledIndices[1].toInt();
|
||||
|
||||
adjustment->setAdjustmentForLed(colorAdjustment->_id, startInd, endInd);
|
||||
std::cout << startInd << "-" << endInd;
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = ledIndexList[i].toInt();
|
||||
adjustment->setAdjustmentForLed(colorAdjustment->_id, index, index);
|
||||
std::cout << index;
|
||||
}
|
||||
}
|
||||
std::cout << "]" << std::endl;
|
||||
}
|
||||
}
|
||||
return adjustment;
|
||||
}
|
||||
|
||||
HsvTransform * Hyperion::createHsvTransform(const Json::Value & hsvConfig)
|
||||
{
|
||||
const double saturationGain = hsvConfig.get("saturationGain", 1.0).asDouble();
|
||||
@@ -376,6 +477,32 @@ RgbChannelCorrection* Hyperion::createRgbChannelCorrection(const Json::Value& co
|
||||
return correction;
|
||||
}
|
||||
|
||||
RgbChannelAdjustment* Hyperion::createRgbChannelAdjustment(const Json::Value& colorConfig, const RgbChannel color)
|
||||
{
|
||||
int varR, varG, varB;
|
||||
if (color == RED)
|
||||
{
|
||||
varR = colorConfig.get("redChannel", 255).asInt();
|
||||
varG = colorConfig.get("greenChannel", 0).asInt();
|
||||
varB = colorConfig.get("blueChannel", 0).asInt();
|
||||
}
|
||||
else if (color == GREEN)
|
||||
{
|
||||
varR = colorConfig.get("redChannel", 0).asInt();
|
||||
varG = colorConfig.get("greenChannel", 255).asInt();
|
||||
varB = colorConfig.get("blueChannel", 0).asInt();
|
||||
}
|
||||
else if (color == BLUE)
|
||||
{
|
||||
varR = colorConfig.get("redChannel", 0).asInt();
|
||||
varG = colorConfig.get("greenChannel", 0).asInt();
|
||||
varB = colorConfig.get("blueChannel", 255).asInt();
|
||||
}
|
||||
|
||||
RgbChannelAdjustment* adjustment = new RgbChannelAdjustment(varR, varG, varB);
|
||||
return adjustment;
|
||||
}
|
||||
|
||||
LedString Hyperion::createLedString(const Json::Value& ledsConfig, const ColorOrder deviceOrder)
|
||||
{
|
||||
LedString ledString;
|
||||
@@ -490,6 +617,7 @@ MessageForwarder * Hyperion::getForwarder()
|
||||
Hyperion::Hyperion(const Json::Value &jsonConfig) :
|
||||
_ledString(createLedString(jsonConfig["leds"], createColorOrder(jsonConfig["device"]))),
|
||||
_muxer(_ledString.leds().size()),
|
||||
_raw2ledAdjustment(createLedColorsAdjustment(_ledString.leds().size(), jsonConfig["color"])),
|
||||
_raw2ledCorrection(createLedColorsCorrection(_ledString.leds().size(), jsonConfig["color"])),
|
||||
_raw2ledTemperature(createLedColorsTemperature(_ledString.leds().size(), jsonConfig["color"])),
|
||||
_raw2ledTransform(createLedColorsTransform(_ledString.leds().size(), jsonConfig["color"])),
|
||||
@@ -498,6 +626,10 @@ Hyperion::Hyperion(const Json::Value &jsonConfig) :
|
||||
_messageForwarder(createMessageForwarder(jsonConfig["forwarder"])),
|
||||
_timer()
|
||||
{
|
||||
if (!_raw2ledAdjustment->verifyAdjustments())
|
||||
{
|
||||
throw std::runtime_error("HYPERION ERROR: Color adjustment incorrectly set");
|
||||
}
|
||||
if (!_raw2ledCorrection->verifyCorrections())
|
||||
{
|
||||
throw std::runtime_error("HYPERION ERROR: Color correction incorrectly set");
|
||||
@@ -551,6 +683,9 @@ Hyperion::~Hyperion()
|
||||
|
||||
// delete the color temperature correction
|
||||
delete _raw2ledTemperature;
|
||||
|
||||
// delete the color adjustment
|
||||
delete _raw2ledAdjustment;
|
||||
|
||||
// delete the message forwarder
|
||||
delete _messageForwarder;
|
||||
@@ -609,6 +744,11 @@ const std::vector<std::string> & Hyperion::getTemperatureIds() const
|
||||
return _raw2ledTemperature->getCorrectionIds();
|
||||
}
|
||||
|
||||
const std::vector<std::string> & Hyperion::getAdjustmentIds() const
|
||||
{
|
||||
return _raw2ledAdjustment->getAdjustmentIds();
|
||||
}
|
||||
|
||||
ColorTransform * Hyperion::getTransform(const std::string& id)
|
||||
{
|
||||
return _raw2ledTransform->getTransform(id);
|
||||
@@ -624,6 +764,11 @@ ColorCorrection * Hyperion::getTemperature(const std::string& id)
|
||||
return _raw2ledTemperature->getCorrection(id);
|
||||
}
|
||||
|
||||
ColorAdjustment * Hyperion::getAdjustment(const std::string& id)
|
||||
{
|
||||
return _raw2ledAdjustment->getAdjustment(id);
|
||||
}
|
||||
|
||||
void Hyperion::transformsUpdated()
|
||||
{
|
||||
update();
|
||||
@@ -639,6 +784,11 @@ void Hyperion::temperaturesUpdated()
|
||||
update();
|
||||
}
|
||||
|
||||
void Hyperion::adjustmentsUpdated()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
void Hyperion::clear(int priority)
|
||||
{
|
||||
if (_muxer.hasPriority(priority))
|
||||
@@ -703,9 +853,11 @@ void Hyperion::update()
|
||||
const PriorityMuxer::InputInfo & priorityInfo = _muxer.getInputInfo(priority);
|
||||
|
||||
// Apply the correction and the transform to each led and color-channel
|
||||
std::vector<ColorRgb> correctedColors = _raw2ledCorrection->applyCorrection(priorityInfo.ledColors);
|
||||
std::vector<ColorRgb> temperatureColors = _raw2ledTemperature->applyCorrection(correctedColors);
|
||||
std::vector<ColorRgb> ledColors =_raw2ledTransform->applyTransform(temperatureColors);
|
||||
// Avoid applying correction, the same task is performed by adjustment
|
||||
// std::vector<ColorRgb> correctedColors = _raw2ledCorrection->applyCorrection(priorityInfo.ledColors);
|
||||
std::vector<ColorRgb> adjustedColors = _raw2ledAdjustment->applyAdjustment(priorityInfo.ledColors);
|
||||
std::vector<ColorRgb> transformColors =_raw2ledTransform->applyTransform(adjustedColors);
|
||||
std::vector<ColorRgb> ledColors = _raw2ledTemperature->applyCorrection(transformColors);
|
||||
const std::vector<Led>& leds = _ledString.leds();
|
||||
int i = 0;
|
||||
for (ColorRgb& color : ledColors)
|
||||
|
124
libsrc/hyperion/MultiColorAdjustment.cpp
Normal file
124
libsrc/hyperion/MultiColorAdjustment.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
|
||||
// STL includes
|
||||
#include <cassert>
|
||||
|
||||
// Hyperion includes
|
||||
#include "MultiColorAdjustment.h"
|
||||
|
||||
MultiColorAdjustment::MultiColorAdjustment(const unsigned ledCnt) :
|
||||
_ledAdjustments(ledCnt, nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
MultiColorAdjustment::~MultiColorAdjustment()
|
||||
{
|
||||
// Clean up all the transforms
|
||||
for (ColorAdjustment * adjustment : _adjustment)
|
||||
{
|
||||
delete adjustment;
|
||||
}
|
||||
}
|
||||
|
||||
void MultiColorAdjustment::addAdjustment(ColorAdjustment * adjustment)
|
||||
{
|
||||
_adjustmentIds.push_back(adjustment->_id);
|
||||
_adjustment.push_back(adjustment);
|
||||
}
|
||||
|
||||
void MultiColorAdjustment::setAdjustmentForLed(const std::string& id, const unsigned startLed, const unsigned endLed)
|
||||
{
|
||||
assert(startLed <= endLed);
|
||||
assert(endLed < _ledAdjustments.size());
|
||||
|
||||
// Get the identified adjustment (don't care if is nullptr)
|
||||
ColorAdjustment * adjustment = getAdjustment(id);
|
||||
for (unsigned iLed=startLed; iLed<=endLed; ++iLed)
|
||||
{
|
||||
_ledAdjustments[iLed] = adjustment;
|
||||
}
|
||||
}
|
||||
|
||||
bool MultiColorAdjustment::verifyAdjustments() const
|
||||
{
|
||||
bool allLedsSet = true;
|
||||
for (unsigned iLed=0; iLed<_ledAdjustments.size(); ++iLed)
|
||||
{
|
||||
if (_ledAdjustments[iLed] == nullptr)
|
||||
{
|
||||
std::cerr << "HYPERION (C.adjustment) ERROR: No adjustment set for " << iLed << std::endl;
|
||||
allLedsSet = false;
|
||||
}
|
||||
}
|
||||
return allLedsSet;
|
||||
}
|
||||
|
||||
const std::vector<std::string> & MultiColorAdjustment::getAdjustmentIds()
|
||||
{
|
||||
return _adjustmentIds;
|
||||
}
|
||||
|
||||
ColorAdjustment* MultiColorAdjustment::getAdjustment(const std::string& id)
|
||||
{
|
||||
// Iterate through the unique adjustments until we find the one with the given id
|
||||
for (ColorAdjustment* adjustment : _adjustment)
|
||||
{
|
||||
if (adjustment->_id == id)
|
||||
{
|
||||
return adjustment;
|
||||
}
|
||||
}
|
||||
|
||||
// The ColorAdjustment was not found
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<ColorRgb> MultiColorAdjustment::applyAdjustment(const std::vector<ColorRgb>& rawColors)
|
||||
{
|
||||
// Create a copy, as we will do the rest of the adjustment in place
|
||||
std::vector<ColorRgb> ledColors(rawColors);
|
||||
|
||||
const size_t itCnt = std::min(_ledAdjustments.size(), rawColors.size());
|
||||
for (size_t i=0; i<itCnt; ++i)
|
||||
{
|
||||
ColorAdjustment* adjustment = _ledAdjustments[i];
|
||||
if (adjustment == nullptr)
|
||||
{
|
||||
// No transform set for this led (do nothing)
|
||||
continue;
|
||||
}
|
||||
ColorRgb& color = ledColors[i];
|
||||
|
||||
int RR = adjustment->_rgbRedAdjustment.adjustmentR(color.red);
|
||||
int RG = adjustment->_rgbRedAdjustment.adjustmentG(color.red);
|
||||
int RB = adjustment->_rgbRedAdjustment.adjustmentB(color.red);
|
||||
int GR = adjustment->_rgbGreenAdjustment.adjustmentR(color.green);
|
||||
int GG = adjustment->_rgbGreenAdjustment.adjustmentG(color.green);
|
||||
int GB = adjustment->_rgbGreenAdjustment.adjustmentB(color.green);
|
||||
int BR = adjustment->_rgbBlueAdjustment.adjustmentR(color.blue);
|
||||
int BG = adjustment->_rgbBlueAdjustment.adjustmentG(color.blue);
|
||||
int BB = adjustment->_rgbBlueAdjustment.adjustmentB(color.blue);
|
||||
|
||||
int ledR = RR + GR + BR;
|
||||
int maxR = (int)adjustment->_rgbRedAdjustment.getadjustmentR();
|
||||
int ledG = RG + GG + BG;
|
||||
int maxG = (int)adjustment->_rgbGreenAdjustment.getadjustmentG();
|
||||
int ledB = RB + GB + BB;
|
||||
int maxB = (int)adjustment->_rgbBlueAdjustment.getadjustmentB();
|
||||
|
||||
if (ledR > maxR)
|
||||
color.red = (uint8_t)maxR;
|
||||
else
|
||||
color.red = (uint8_t)ledR;
|
||||
|
||||
if (ledG > maxG)
|
||||
color.green = (uint8_t)maxG;
|
||||
else
|
||||
color.green = (uint8_t)ledG;
|
||||
|
||||
if (ledB > maxB)
|
||||
color.blue = (uint8_t)maxB;
|
||||
else
|
||||
color.blue = (uint8_t)ledB;
|
||||
}
|
||||
return ledColors;
|
||||
}
|
66
libsrc/hyperion/MultiColorAdjustment.h
Normal file
66
libsrc/hyperion/MultiColorAdjustment.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <vector>
|
||||
|
||||
// Utils includes
|
||||
#include <utils/ColorRgb.h>
|
||||
|
||||
// Hyperion includes
|
||||
#include <hyperion/ColorAdjustment.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 MultiColorAdjustment
|
||||
{
|
||||
public:
|
||||
MultiColorAdjustment(const unsigned ledCnt);
|
||||
~MultiColorAdjustment();
|
||||
|
||||
/**
|
||||
* Adds a new ColorAdjustment to this MultiColorTransform
|
||||
*
|
||||
* @param adjustment The new ColorAdjustment (ownership is transfered)
|
||||
*/
|
||||
void addAdjustment(ColorAdjustment * adjustment);
|
||||
|
||||
void setAdjustmentForLed(const std::string& id, const unsigned startLed, const unsigned endLed);
|
||||
|
||||
bool verifyAdjustments() const;
|
||||
|
||||
///
|
||||
/// Returns the identifier of all the unique ColorAdjustment
|
||||
///
|
||||
/// @return The list with unique id's of the ColorAdjustment
|
||||
const std::vector<std::string> & getAdjustmentIds();
|
||||
|
||||
///
|
||||
/// Returns the pointer to the ColorAdjustment with the given id
|
||||
///
|
||||
/// @param id The identifier of the ColorAdjustment
|
||||
///
|
||||
/// @return The ColorAdjustment with the given id (or nullptr if it does not exist)
|
||||
///
|
||||
ColorAdjustment* getAdjustment(const std::string& id);
|
||||
|
||||
///
|
||||
/// Performs the color adjustment from raw-color to led-color
|
||||
///
|
||||
/// @param rawColors The list with raw colors
|
||||
///
|
||||
/// @return The list with led-colors
|
||||
///
|
||||
std::vector<ColorRgb> applyAdjustment(const std::vector<ColorRgb>& rawColors);
|
||||
|
||||
private:
|
||||
/// List with transform ids
|
||||
std::vector<std::string> _adjustmentIds;
|
||||
|
||||
/// List with unique ColorTransforms
|
||||
std::vector<ColorAdjustment*> _adjustment;
|
||||
|
||||
/// List with a pointer to the ColorAdjustment for each individual led
|
||||
std::vector<ColorAdjustment*> _ledAdjustments;
|
||||
};
|
@@ -19,6 +19,7 @@
|
||||
#include <hyperion/MessageForwarder.h>
|
||||
#include <hyperion/ColorTransform.h>
|
||||
#include <hyperion/ColorCorrection.h>
|
||||
#include <hyperion/ColorAdjustment.h>
|
||||
#include <utils/ColorRgb.h>
|
||||
|
||||
// project includes
|
||||
@@ -252,6 +253,8 @@ void JsonClientConnection::handleMessage(const std::string &messageString)
|
||||
handleCorrectionCommand(message);
|
||||
else if (command == "temperature")
|
||||
handleTemperatureCommand(message);
|
||||
else if (command == "adjustment")
|
||||
handleAdjustmentCommand(message);
|
||||
else
|
||||
handleNotImplemented();
|
||||
}
|
||||
@@ -470,6 +473,34 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &)
|
||||
whitelevel.append(colorTransform->_rgbGreenTransform.getWhitelevel());
|
||||
whitelevel.append(colorTransform->_rgbBlueTransform.getWhitelevel());
|
||||
}
|
||||
|
||||
// collect adjustment information
|
||||
Json::Value & adjustmentArray = info["adjustment"];
|
||||
for (const std::string& adjustmentId : _hyperion->getAdjustmentIds())
|
||||
{
|
||||
const ColorAdjustment * colorAdjustment = _hyperion->getAdjustment(adjustmentId);
|
||||
if (colorAdjustment == nullptr)
|
||||
{
|
||||
std::cerr << "JSONCLIENT ERROR: Incorrect color adjustment id: " << adjustmentId << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
Json::Value & adjustment = adjustmentArray.append(Json::Value());
|
||||
adjustment["id"] = adjustmentId;
|
||||
|
||||
Json::Value & redAdjust = adjustment["redAdjust"];
|
||||
redAdjust.append(colorAdjustment->_rgbRedAdjustment.getadjustmentR());
|
||||
redAdjust.append(colorAdjustment->_rgbRedAdjustment.getadjustmentG());
|
||||
redAdjust.append(colorAdjustment->_rgbRedAdjustment.getadjustmentB());
|
||||
Json::Value & greenAdjust = adjustment["greenAdjust"];
|
||||
greenAdjust.append(colorAdjustment->_rgbGreenAdjustment.getadjustmentR());
|
||||
greenAdjust.append(colorAdjustment->_rgbGreenAdjustment.getadjustmentG());
|
||||
greenAdjust.append(colorAdjustment->_rgbGreenAdjustment.getadjustmentB());
|
||||
Json::Value & blueAdjust = adjustment["blueAdjust"];
|
||||
blueAdjust.append(colorAdjustment->_rgbBlueAdjustment.getadjustmentR());
|
||||
blueAdjust.append(colorAdjustment->_rgbBlueAdjustment.getadjustmentG());
|
||||
blueAdjust.append(colorAdjustment->_rgbBlueAdjustment.getadjustmentB());
|
||||
}
|
||||
|
||||
// collect effect info
|
||||
Json::Value & effects = info["effects"] = Json::Value(Json::arrayValue);
|
||||
@@ -634,6 +665,47 @@ void JsonClientConnection::handleTemperatureCommand(const Json::Value &message)
|
||||
|
||||
sendSuccessReply();
|
||||
}
|
||||
|
||||
void JsonClientConnection::handleAdjustmentCommand(const Json::Value &message)
|
||||
{
|
||||
const Json::Value & adjustment = message["adjustment"];
|
||||
|
||||
const std::string adjustmentId = adjustment.get("id", _hyperion->getAdjustmentIds().front()).asString();
|
||||
ColorAdjustment * colorAdjustment = _hyperion->getAdjustment(adjustmentId);
|
||||
if (colorAdjustment == nullptr)
|
||||
{
|
||||
//sendErrorReply(std::string("Incorrect transform identifier: ") + transformId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (adjustment.isMember("redAdjust"))
|
||||
{
|
||||
const Json::Value & values = adjustment["redAdjust"];
|
||||
colorAdjustment->_rgbRedAdjustment.setadjustmentR(values[0u].asInt());
|
||||
colorAdjustment->_rgbRedAdjustment.setadjustmentG(values[1u].asInt());
|
||||
colorAdjustment->_rgbRedAdjustment.setadjustmentB(values[2u].asInt());
|
||||
}
|
||||
|
||||
if (adjustment.isMember("greenAdjust"))
|
||||
{
|
||||
const Json::Value & values = adjustment["greenAdjust"];
|
||||
colorAdjustment->_rgbGreenAdjustment.setadjustmentR(values[0u].asInt());
|
||||
colorAdjustment->_rgbGreenAdjustment.setadjustmentG(values[1u].asInt());
|
||||
colorAdjustment->_rgbGreenAdjustment.setadjustmentB(values[2u].asInt());
|
||||
}
|
||||
|
||||
if (adjustment.isMember("blueAdjust"))
|
||||
{
|
||||
const Json::Value & values = adjustment["blueAdjust"];
|
||||
colorAdjustment->_rgbBlueAdjustment.setadjustmentR(values[0u].asInt());
|
||||
colorAdjustment->_rgbBlueAdjustment.setadjustmentG(values[1u].asInt());
|
||||
colorAdjustment->_rgbBlueAdjustment.setadjustmentB(values[2u].asInt());
|
||||
}
|
||||
// commit the changes
|
||||
_hyperion->adjustmentsUpdated();
|
||||
|
||||
sendSuccessReply();
|
||||
}
|
||||
|
||||
void JsonClientConnection::handleNotImplemented()
|
||||
{
|
||||
@@ -712,7 +784,6 @@ void JsonClientConnection::sendMessage(const Json::Value & message, QTcpSocket *
|
||||
|
||||
}
|
||||
|
||||
|
||||
void JsonClientConnection::sendSuccessReply()
|
||||
{
|
||||
// create reply
|
||||
|
@@ -126,6 +126,13 @@ private:
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleTemperatureCommand(const Json::Value & message);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON Adjustment message
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleAdjustmentCommand(const Json::Value & message);
|
||||
|
||||
///
|
||||
/// Handle an incoming JSON message of unknown type
|
||||
|
@@ -9,6 +9,7 @@
|
||||
<file alias="schema-transform">schema/schema-transform.json</file>
|
||||
<file alias="schema-correction">schema/schema-correction.json</file>
|
||||
<file alias="schema-temperature">schema/schema-temperature.json</file>
|
||||
<file alias="schema-adjustment">schema/schema-adjustment.json</file>
|
||||
<file alias="schema-effect">schema/schema-effect.json</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
56
libsrc/jsonserver/schema/schema-adjustment.json
Normal file
56
libsrc/jsonserver/schema/schema-adjustment.json
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"properties":{
|
||||
"command": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["adjustment"]
|
||||
},
|
||||
"adjustment": {
|
||||
"type": "object",
|
||||
"required": true,
|
||||
"properties": {
|
||||
"id" : {
|
||||
"type" : "string",
|
||||
"required" : false
|
||||
},
|
||||
"redAdjust": {
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 255
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 3
|
||||
},
|
||||
"greenAdjust": {
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 255
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 3
|
||||
},
|
||||
"blueAdjust": {
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type": "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 255
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 3
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
@@ -5,7 +5,7 @@
|
||||
"command": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["color", "image", "effect", "serverinfo", "clear", "clearall", "transform", "correction", "temperature"]
|
||||
"enum" : ["color", "image", "effect", "serverinfo", "clear", "clearall", "transform", "correction", "temperature", "adjustment"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -29,6 +29,8 @@ add_library(hyperion-utils
|
||||
${CURRENT_SOURCE_DIR}/RgbChannelTransform.cpp
|
||||
${CURRENT_HEADER_DIR}/RgbChannelCorrection.h
|
||||
${CURRENT_SOURCE_DIR}/RgbChannelCorrection.cpp
|
||||
${CURRENT_HEADER_DIR}/RgbChannelAdjustment.h
|
||||
${CURRENT_SOURCE_DIR}/RgbChannelAdjustment.cpp
|
||||
|
||||
${CURRENT_HEADER_DIR}/jsonschema/JsonFactory.h
|
||||
${CURRENT_HEADER_DIR}/jsonschema/JsonSchemaChecker.h
|
||||
|
107
libsrc/utils/RgbChannelAdjustment.cpp
Normal file
107
libsrc/utils/RgbChannelAdjustment.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
// STL includes
|
||||
#include <cmath>
|
||||
|
||||
// Utils includes
|
||||
#include <utils/RgbChannelAdjustment.h>
|
||||
|
||||
RgbChannelAdjustment::RgbChannelAdjustment() :
|
||||
_adjustR(255),
|
||||
_adjustG(255),
|
||||
_adjustB(255)
|
||||
{
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
RgbChannelAdjustment::RgbChannelAdjustment(int adjustR, int adjustG, int adjustB) :
|
||||
_adjustR(adjustR),
|
||||
_adjustG(adjustG),
|
||||
_adjustB(adjustB)
|
||||
{
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
RgbChannelAdjustment::~RgbChannelAdjustment()
|
||||
{
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::getadjustmentR() const
|
||||
{
|
||||
return _adjustR;
|
||||
}
|
||||
|
||||
void RgbChannelAdjustment::setadjustmentR(uint8_t adjustR)
|
||||
{
|
||||
_adjustR = adjustR;
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::getadjustmentG() const
|
||||
{
|
||||
return _adjustG;
|
||||
}
|
||||
|
||||
void RgbChannelAdjustment::setadjustmentG(uint8_t adjustG)
|
||||
{
|
||||
_adjustG = adjustG;
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::getadjustmentB() const
|
||||
{
|
||||
return _adjustB;
|
||||
}
|
||||
|
||||
void RgbChannelAdjustment::setadjustmentB(uint8_t adjustB)
|
||||
{
|
||||
_adjustB = adjustB;
|
||||
initializeMapping();
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::adjustmentR(uint8_t inputR) const
|
||||
{
|
||||
return _mappingR[inputR];
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::adjustmentG(uint8_t inputG) const
|
||||
{
|
||||
return _mappingG[inputG];
|
||||
}
|
||||
|
||||
uint8_t RgbChannelAdjustment::adjustmentB(uint8_t inputB) const
|
||||
{
|
||||
return _mappingB[inputB];
|
||||
}
|
||||
|
||||
void RgbChannelAdjustment::initializeMapping()
|
||||
{
|
||||
// initialize the mapping
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
int outputR = (i * _adjustR) / 255;
|
||||
if (outputR > 255)
|
||||
{
|
||||
outputR = 255;
|
||||
}
|
||||
_mappingR[i] = outputR;
|
||||
}
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
int outputG = (i * _adjustG) / 255;
|
||||
if (outputG > 255)
|
||||
{
|
||||
outputG = 255;
|
||||
}
|
||||
_mappingG[i] = outputG;
|
||||
}
|
||||
for (int i = 0; i < 256; ++i)
|
||||
{
|
||||
int outputB = (i * _adjustB) / 255;
|
||||
if (outputB > 255)
|
||||
{
|
||||
outputB = 255;
|
||||
}
|
||||
_mappingB[i] = outputB;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user