mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Added smoothing to the Hyperion configuration
Former-commit-id: 85e27d54841de5030199dd7f70bb0f29250abb6a
This commit is contained in:
parent
0b08341ef1
commit
3e4c38b57a
@ -21,13 +21,17 @@
|
|||||||
|
|
||||||
/// Color manipulation configuration used to tune the output colors to specific surroundings. Contains the following fields:
|
/// Color manipulation configuration used to tune the output colors to specific surroundings. Contains the following fields:
|
||||||
/// * 'hsv' : The manipulation in the Hue-Saturation-Value color domain with the following tuning parameters:
|
/// * 'hsv' : The manipulation in the Hue-Saturation-Value color domain with the following tuning parameters:
|
||||||
/// - 'saturationGain' The gain adjustement of the saturation
|
/// - 'saturationGain' The gain adjustement of the saturation
|
||||||
/// - 'valueGain' The gain adjustement of the value
|
/// - 'valueGain' The gain adjustement of the value
|
||||||
/// * 'red'/'green'/'blue' : The manipulation in the Red-Green-Blue color domain with the following tuning parameters for each channel:
|
/// * 'red'/'green'/'blue' : The manipulation in the Red-Green-Blue color domain with the following tuning parameters for each channel:
|
||||||
/// - 'threshold' The minimum required input value for the channel to be on (else zero)
|
/// - 'threshold' The minimum required input value for the channel to be on (else zero)
|
||||||
/// - 'gamma' The gamma-curve correction factor
|
/// - 'gamma' The gamma-curve correction factor
|
||||||
/// - 'blacklevel' The lowest possible value (when the channel is black)
|
/// - 'blacklevel' The lowest possible value (when the channel is black)
|
||||||
/// - 'whitelevel' The highest possible value (when the channel is white)
|
/// - 'whitelevel' The highest possible value (when the channel is white)
|
||||||
|
/// * 'smoothing' : Smoothing of the colors in the time-domain with the following tuning parameters:
|
||||||
|
/// - 'type' The type of smoothing algorithm ('linear' or 'none')
|
||||||
|
/// - 'time_ms' The time constant for smoothing algorithm in milliseconds
|
||||||
|
/// - 'updateFrequency' The update frequency of the leds in Hz
|
||||||
"color" :
|
"color" :
|
||||||
{
|
{
|
||||||
"hsv" :
|
"hsv" :
|
||||||
@ -55,6 +59,12 @@
|
|||||||
"gamma" : 2.0000,
|
"gamma" : 2.0000,
|
||||||
"blacklevel" : 0.0000,
|
"blacklevel" : 0.0000,
|
||||||
"whitelevel" : 1.0000
|
"whitelevel" : 1.0000
|
||||||
|
},
|
||||||
|
"smoothing" :
|
||||||
|
{
|
||||||
|
"type" : "none",
|
||||||
|
"time_ms" : 200,
|
||||||
|
"updateFrequency" : 20.0000
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
948743846fb38a0f1f9a91ebb721884f3890f965
|
35cdefd478667e83a1e20cda67cef4763b59ec25
|
Binary file not shown.
@ -1 +1 @@
|
|||||||
c2bbbf969d7dbe0e096670758e37284b827b3d03
|
460c18a960c7f021eb18eddc5b43f322cb40fced
|
@ -21,8 +21,12 @@
|
|||||||
LedDevice* Hyperion::createDevice(const Json::Value& deviceConfig)
|
LedDevice* Hyperion::createDevice(const Json::Value& deviceConfig)
|
||||||
{
|
{
|
||||||
std::cout << "Device configuration: " << deviceConfig << std::endl;
|
std::cout << "Device configuration: " << deviceConfig << std::endl;
|
||||||
|
|
||||||
|
std::string type = deviceConfig.get("type", "UNSPECIFIED").asString();
|
||||||
|
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
|
||||||
|
|
||||||
LedDevice* device = nullptr;
|
LedDevice* device = nullptr;
|
||||||
if (deviceConfig["type"].asString() == "ws2801")
|
if (type == "ws2801")
|
||||||
{
|
{
|
||||||
const std::string output = deviceConfig["output"].asString();
|
const std::string output = deviceConfig["output"].asString();
|
||||||
const unsigned rate = deviceConfig["rate"].asInt();
|
const unsigned rate = deviceConfig["rate"].asInt();
|
||||||
@ -32,13 +36,13 @@ LedDevice* Hyperion::createDevice(const Json::Value& deviceConfig)
|
|||||||
|
|
||||||
device = deviceWs2801;
|
device = deviceWs2801;
|
||||||
}
|
}
|
||||||
else if (deviceConfig["type"].asString() == "test")
|
else if (type == "test")
|
||||||
{
|
{
|
||||||
device = new LedDeviceTest();
|
device = new LedDeviceTest();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Unable to create device" << std::endl;
|
std::cout << "Unable to create device " << type << std::endl;
|
||||||
// Unknown / Unimplemented device
|
// Unknown / Unimplemented device
|
||||||
}
|
}
|
||||||
return device;
|
return device;
|
||||||
@ -95,7 +99,35 @@ LedString Hyperion::createLedString(const Json::Value& ledsConfig)
|
|||||||
|
|
||||||
LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig, LedDevice * ledDevice)
|
LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig, LedDevice * ledDevice)
|
||||||
{
|
{
|
||||||
//return new LinearColorSmoothing(ledDevice, 20.0, .3);
|
std::string type = smoothingConfig.get("type", "none").asString();
|
||||||
|
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
|
||||||
|
|
||||||
|
if (type == "none")
|
||||||
|
{
|
||||||
|
std::cout << "Not creating any smoothing" << std::endl;
|
||||||
|
return ledDevice;
|
||||||
|
}
|
||||||
|
else if (type == "linear")
|
||||||
|
{
|
||||||
|
if (!smoothingConfig.isMember("time_ms"))
|
||||||
|
{
|
||||||
|
std::cout << "Unable to create smoothing of type linear because of missing parameter 'time_ms'" << std::endl;
|
||||||
|
}
|
||||||
|
else if (!smoothingConfig.isMember("updateFrequency"))
|
||||||
|
{
|
||||||
|
std::cout << "Unable to create smoothing of type linear because of missing parameter 'updateFrequency'" << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Creating linear smoothing" << std::endl;
|
||||||
|
return new LinearColorSmoothing(ledDevice, smoothingConfig["updateFrequency"].asDouble(), smoothingConfig["time_ms"].asInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Unable to create smoothing of type " << type << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
return ledDevice;
|
return ledDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +146,7 @@ Hyperion::Hyperion(const Json::Value &jsonConfig) :
|
|||||||
ImageProcessorFactory::getInstance().init(_ledString, jsonConfig["blackborderdetector"].get("enable", true).asBool());
|
ImageProcessorFactory::getInstance().init(_ledString, jsonConfig["blackborderdetector"].get("enable", true).asBool());
|
||||||
|
|
||||||
// initialize the color smoothing filter
|
// initialize the color smoothing filter
|
||||||
_device = createColorSmoothing(jsonConfig["smoothing"], _device);
|
_device = createColorSmoothing(jsonConfig["color"]["smoothing"], _device);
|
||||||
|
|
||||||
// setup the timer
|
// setup the timer
|
||||||
_timer.setSingleShot(true);
|
_timer.setSingleShot(true);
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
|
|
||||||
#include "LinearColorSmoothing.h"
|
#include "LinearColorSmoothing.h"
|
||||||
|
|
||||||
LinearColorSmoothing::LinearColorSmoothing(LedDevice *ledDevice, double ledUpdateFrequency, double settlingTime) :
|
LinearColorSmoothing::LinearColorSmoothing(LedDevice *ledDevice, double ledUpdateFrequency_hz, int settlingTime_ms) :
|
||||||
QObject(),
|
QObject(),
|
||||||
LedDevice(),
|
LedDevice(),
|
||||||
_ledDevice(ledDevice),
|
_ledDevice(ledDevice),
|
||||||
_updateInterval(1000.0 / ledUpdateFrequency),
|
_updateInterval(1000 / ledUpdateFrequency_hz),
|
||||||
_settlingTime(1000 * settlingTime),
|
_settlingTime(settlingTime_ms),
|
||||||
_timer()
|
_timer()
|
||||||
{
|
{
|
||||||
_timer.setSingleShot(false);
|
_timer.setSingleShot(false);
|
||||||
|
@ -26,7 +26,7 @@ public:
|
|||||||
/// @param LedDevice the led device
|
/// @param LedDevice the led device
|
||||||
/// @param LedUpdatFrequency The frequency at which the leds will be updated (Hz)
|
/// @param LedUpdatFrequency The frequency at which the leds will be updated (Hz)
|
||||||
/// @param settingTime The time after which the updated led values have been fully applied (sec)
|
/// @param settingTime The time after which the updated led values have been fully applied (sec)
|
||||||
LinearColorSmoothing(LedDevice *ledDevice, double ledUpdateFrequency, double settlingTime);
|
LinearColorSmoothing(LedDevice *ledDevice, double ledUpdateFrequency, int settlingTime);
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
virtual ~LinearColorSmoothing();
|
virtual ~LinearColorSmoothing();
|
||||||
|
@ -125,7 +125,30 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties" : false
|
"additionalProperties" : false
|
||||||
|
},
|
||||||
|
"smoothing" : {
|
||||||
|
"type" : "object",
|
||||||
|
"required" : false,
|
||||||
|
"properties" : {
|
||||||
|
"type" : {
|
||||||
|
"type" : "enum",
|
||||||
|
"required" : true,
|
||||||
|
"values" : ["none", "linear"]
|
||||||
|
},
|
||||||
|
"time_ms" : {
|
||||||
|
"type" : "integer",
|
||||||
|
"required" : false,
|
||||||
|
"minimum" : 10
|
||||||
|
},
|
||||||
|
"updateFrequency" : {
|
||||||
|
"type" : "number",
|
||||||
|
"required" : false,
|
||||||
|
"minimum" : 0.001
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"additionalProperties" : false
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
"additionalProperties" : false
|
"additionalProperties" : false
|
||||||
},
|
},
|
||||||
|
@ -6,7 +6,6 @@ import java.util.Locale;
|
|||||||
* The color tuning parameters of the different color channels (both in RGB space as in HSV space)
|
* The color tuning parameters of the different color channels (both in RGB space as in HSV space)
|
||||||
*/
|
*/
|
||||||
public class ColorConfig {
|
public class ColorConfig {
|
||||||
|
|
||||||
/** The saturation gain (in HSV space) */
|
/** The saturation gain (in HSV space) */
|
||||||
double mSaturationGain = 1.0;
|
double mSaturationGain = 1.0;
|
||||||
/** The value gain (in HSV space) */
|
/** The value gain (in HSV space) */
|
||||||
@ -39,6 +38,13 @@ public class ColorConfig {
|
|||||||
/** The white-level of the BLUE-value (in RGB space) */
|
/** The white-level of the BLUE-value (in RGB space) */
|
||||||
double mBlueWhitelevel = 1.0;
|
double mBlueWhitelevel = 1.0;
|
||||||
|
|
||||||
|
/** The type of smoothing algorithm */
|
||||||
|
ColorSmoothingType mSmoothingType = ColorSmoothingType.none;
|
||||||
|
/** The time constant for smoothing algorithm in milliseconds */
|
||||||
|
int mSmoothingTime = 200;
|
||||||
|
/** The update frequency of the leds in Hz */
|
||||||
|
double mSmoothingUpdateFrequency = 20.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the JSON string of the configuration as used in the Hyperion daemon configfile
|
* Creates the JSON string of the configuration as used in the Hyperion daemon configfile
|
||||||
*
|
*
|
||||||
@ -49,25 +55,30 @@ public class ColorConfig {
|
|||||||
|
|
||||||
strBuf.append("\t/// Color manipulation configuration used to tune the output colors to specific surroundings. Contains the following fields:\n");
|
strBuf.append("\t/// Color manipulation configuration used to tune the output colors to specific surroundings. Contains the following fields:\n");
|
||||||
strBuf.append("\t/// * 'hsv' : The manipulation in the Hue-Saturation-Value color domain with the following tuning parameters:\n");
|
strBuf.append("\t/// * 'hsv' : The manipulation in the Hue-Saturation-Value color domain with the following tuning parameters:\n");
|
||||||
strBuf.append("\t/// - 'saturationGain' The gain adjustement of the saturation\n");
|
strBuf.append("\t/// - 'saturationGain' The gain adjustement of the saturation\n");
|
||||||
strBuf.append("\t/// - 'valueGain' The gain adjustement of the value\n");
|
strBuf.append("\t/// - 'valueGain' The gain adjustement of the value\n");
|
||||||
strBuf.append("\t/// * 'red'/'green'/'blue' : The manipulation in the Red-Green-Blue color domain with the following tuning parameters for each channel:\n");
|
strBuf.append("\t/// * 'red'/'green'/'blue' : The manipulation in the Red-Green-Blue color domain with the following tuning parameters for each channel:\n");
|
||||||
strBuf.append("\t/// - 'threshold' The minimum required input value for the channel to be on (else zero)\n");
|
strBuf.append("\t/// - 'threshold' The minimum required input value for the channel to be on (else zero)\n");
|
||||||
strBuf.append("\t/// - 'gamma' The gamma-curve correction factor\n");
|
strBuf.append("\t/// - 'gamma' The gamma-curve correction factor\n");
|
||||||
strBuf.append("\t/// - 'blacklevel' The lowest possible value (when the channel is black)\n");
|
strBuf.append("\t/// - 'blacklevel' The lowest possible value (when the channel is black)\n");
|
||||||
strBuf.append("\t/// - 'whitelevel' The highest possible value (when the channel is white)\n");
|
strBuf.append("\t/// - 'whitelevel' The highest possible value (when the channel is white)\n");
|
||||||
|
strBuf.append("\t/// * 'smoothing' : Smoothing of the colors in the time-domain with the following tuning parameters:\n");
|
||||||
|
strBuf.append("\t/// - 'type' The type of smoothing algorithm ('linear' or 'none')\n");
|
||||||
|
strBuf.append("\t/// - 'time_ms' The time constant for smoothing algorithm in milliseconds\n");
|
||||||
|
strBuf.append("\t/// - 'updateFrequency' The update frequency of the leds in Hz\n");
|
||||||
|
|
||||||
strBuf.append("\t\"color\" :\n");
|
strBuf.append("\t\"color\" :\n");
|
||||||
strBuf.append("\t{\n");
|
strBuf.append("\t{\n");
|
||||||
strBuf.append(hsvToJsonString() + ",\n");
|
strBuf.append(hsvToJsonString() + ",\n");
|
||||||
strBuf.append(rgbToJsonString() + "\n");
|
strBuf.append(rgbToJsonString() + ",\n");
|
||||||
|
strBuf.append(smoothingToString() + "\n");
|
||||||
strBuf.append("\t}");
|
strBuf.append("\t}");
|
||||||
|
|
||||||
return strBuf.toString();
|
return strBuf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the JSON string of the HSV-subconfiguration as used in the Hyperion deaomn configfile
|
* Creates the JSON string of the HSV-subconfiguration as used in the Hyperion deamon configfile
|
||||||
*
|
*
|
||||||
* @return The JSON string of the HSV-config
|
* @return The JSON string of the HSV-config
|
||||||
*/
|
*/
|
||||||
@ -83,7 +94,7 @@ public class ColorConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the JSON string of the RGB-subconfiguration as used in the Hyperion deaomn configfile
|
* Creates the JSON string of the RGB-subconfiguration as used in the Hyperion deamon configfile
|
||||||
*
|
*
|
||||||
* @return The JSON string of the RGB-config
|
* @return The JSON string of the RGB-config
|
||||||
*/
|
*/
|
||||||
@ -117,4 +128,20 @@ public class ColorConfig {
|
|||||||
return strBuf.toString();
|
return strBuf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the JSON string of the smoothing subconfiguration as used in the Hyperion deamon configfile
|
||||||
|
*
|
||||||
|
* @return The JSON string of the HSV-config
|
||||||
|
*/
|
||||||
|
private String smoothingToString() {
|
||||||
|
StringBuffer strBuf = new StringBuffer();
|
||||||
|
strBuf.append("\t\t\"smoothing\" :\n");
|
||||||
|
strBuf.append("\t\t{\n");
|
||||||
|
strBuf.append(String.format(Locale.ROOT, "\t\t\t\"type\" : \"%s\",\n", mSmoothingType.name()));
|
||||||
|
strBuf.append(String.format(Locale.ROOT, "\t\t\t\"time_ms\" : %d,\n", mSmoothingTime));
|
||||||
|
strBuf.append(String.format(Locale.ROOT, "\t\t\t\"updateFrequency\" : %.4f\n", mSmoothingUpdateFrequency));
|
||||||
|
|
||||||
|
strBuf.append("\t\t}");
|
||||||
|
return strBuf.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package org.hyperion.hypercon.spec;
|
||||||
|
|
||||||
|
enum ColorSmoothingType {
|
||||||
|
/** No smoothing in the time domain */
|
||||||
|
none("None"),
|
||||||
|
|
||||||
|
/** Linear smoothing of led data */
|
||||||
|
linear("Linear smoothing");
|
||||||
|
|
||||||
|
private final String mName;
|
||||||
|
|
||||||
|
private ColorSmoothingType(String name) {
|
||||||
|
mName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return mName;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user