Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-add Temperture adjustment #1710

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 20 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ set(DEFAULT_USE_SYSTEM_QMDNS_LIBS OFF)
set(DEFAULT_TESTS OFF)

# Build Hyperion with a reduced set of functionality, overwrites other default values
set(DEFAULT_HYPERION_LIGHT OFF)
set(DEFAULT_HYPERION_LIGHT ON )

if(${CMAKE_SYSTEM} MATCHES "Linux")
set(DEFAULT_FB ON)
Expand Down Expand Up @@ -232,23 +232,34 @@ if(HYPERION_LIGHT)
SET ( DEFAULT_OSX OFF )
SET ( DEFAULT_QT OFF )
SET ( DEFAULT_V4L2 OFF )
SET ( DEFAULT_AUDIO OFF )
SET ( DEFAULT_X11 OFF )
SET ( DEFAULT_XCB OFF )

SET ( DEFAULT_AUDIO OFF )
# LED-Devices
SET ( DEFAULT_DEV_NETWORK OFF )
SET ( DEFAULT_DEV_SERIAL OFF )
SET ( DEFAULT_DEV_SPI OFF )
SET ( DEFAULT_DEV_TINKERFORGE OFF )
SET ( DEFAULT_DEV_USB_HID OFF )
SET ( DEFAULT_DEV_WS281XPWM OFF )

# Disable Input Servers
set(DEFAULT_BOBLIGHT_SERVER OFF)
set(DEFAULT_CEC OFF)
set(DEFAULT_FLATBUF_SERVER OFF)
set(DEFAULT_PROTOBUF_SERVER OFF)
SET ( DEFAULT_BOBLIGHT_SERVER OFF )
SET ( DEFAULT_CEC OFF )
SET ( DEFAULT_FLATBUF_SERVER OFF )
SET ( DEFAULT_PROTOBUF_SERVER OFF )

# Disable Output Connectors
set(DEFAULT_FORWARDER OFF)
set(DEFAULT_FLATBUF_CONNECT OFF)
SET ( DEFAULT_FORWARDER OFF )
SET ( DEFAULT_FLATBUF_CONNECT OFF )

# Disable Services
set(DEFAULT_EFFECTENGINE OFF)
SET ( DEFAULT_EXPERIMENTAL OFF )
SET ( DEFAULT_MDNS ON )
SET ( DEFAULT_REMOTE_CTL OFF )
SET ( DEFAULT_EFFECTENGINE OFF )

endif()

message(STATUS "Grabber options:")
Expand Down
9 changes: 7 additions & 2 deletions assets/webconfig/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
"edt_append_degree": "°",
"edt_append_frames": "frames",
"edt_append_hz": "Hz",
"edt_append_kelvin": "K",
"edt_append_leds": "LEDs",
"edt_append_ms": "ms",
"edt_append_ns": "ns",
Expand Down Expand Up @@ -316,6 +317,8 @@
"edt_conf_color_blue_title": "Blue",
"edt_conf_color_brightnessComp_expl": "Compensates brightness differences between red green blue, cyan magenta yellow and white. 100 means full compensation, 0 no compensation",
"edt_conf_color_brightnessComp_title": "Brightness compensation",
"edt_conf_color_brightnessGain_expl": "Adjusts the brightness of colors. 1.0 means no change, over 1.0 increases brightness, under 1.0 decreases brightness.",
"edt_conf_color_brightnessGain_title": "Brightness gain",
"edt_conf_color_brightness_expl": "set overall brightness of LEDs",
"edt_conf_color_brightness_title": "Brightness",
"edt_conf_color_channelAdjustment_header_expl": "Create color profiles that could be assigned to a specific component. Adjust color, gamma, brightness, compensation and more.",
Expand All @@ -342,10 +345,10 @@
"edt_conf_color_magenta_title": "Magenta",
"edt_conf_color_red_expl": "The calibrated red value.",
"edt_conf_color_red_title": "Red",
"edt_conf_color_temperature_expl": "Adjusts the corlor temperature.",
"edt_conf_color_temperature_title": "Temperature",
"edt_conf_color_saturationGain_expl": "Adjusts the saturation of colors. 1.0 means no change, over 1.0 increases saturation, under 1.0 desaturates.",
"edt_conf_color_saturationGain_title": "Saturation gain",
"edt_conf_color_brightnessGain_expl": "Adjusts the brightness of colors. 1.0 means no change, over 1.0 increases brightness, under 1.0 decreases brightness.",
"edt_conf_color_brightnessGain_title": "Brightness gain",
"edt_conf_color_reducedPixelSetFactorFactor_expl": "Evaluate only a set of pixels per LED area defined, Low ~25%, Medium ~10%, High ~6%",
"edt_conf_color_reducedPixelSetFactorFactor_title": "Reduced pixel processing",
"edt_conf_color_white_expl": "The calibrated white value.",
Expand Down Expand Up @@ -532,6 +535,8 @@
"edt_conf_smooth_heading_title": "Smoothing",
"edt_conf_smooth_interpolationRate_expl": "Speed of the calculation of smooth intermediate frames.",
"edt_conf_smooth_interpolationRate_title": "Interpolation Rate",
"edt_conf_smooth_outputRate_expl": "The output speed to your LED controller.",
"edt_conf_smooth_outputRate_title": "Output Rate",
"edt_conf_smooth_time_ms_expl": "How long should the smoothing gather pictures?",
"edt_conf_smooth_time_ms_title": "Time",
"edt_conf_smooth_type_expl": "Type of smoothing.",
Expand Down
7 changes: 4 additions & 3 deletions assets/webconfig/js/content_remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ $(document).ready(function () {
sColor[key].key == "brightnessCompensation" ||
sColor[key].key == "backlightThreshold" ||
sColor[key].key == "saturationGain" ||
sColor[key].key == "brightnessGain") {
sColor[key].key == "brightnessGain" ||
sColor[key].key == "temperature" ) {

property = '<input id="cr_' + sColor[key].key + '" type="number" class="form-control" min="' + sColor[key].minimum + '" max="' + sColor[key].maximum + '" step="' + sColor[key].step + '" value="' + value + '"/>';
if (sColor[key].append === "edt_append_percent") {
property = '<div class="input-group">' + property + '<span class="input-group-addon">' + $.i18n("edt_append_percent") + '</span></div>';
if (sColor[key].append && sColor[key].append !== "" ) {
property = '<div class="input-group">' + property + '<span class="input-group-addon">' + $.i18n(sColor[key].append) + '</span></div>';
}
}
else {
Expand Down
3 changes: 2 additions & 1 deletion config/hyperion.config.json.default
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"brightness": 100,
"brightnessCompensation": 100,
"saturationGain": 1.0,
"brightnessGain": 1.0
"brightnessGain": 1.0,
"temperature" : 6600
}
]
},
Expand Down
1 change: 1 addition & 0 deletions include/api/JsonAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ private slots:
void applyColorAdjustments(const QJsonObject &adjustment, ColorAdjustment *colorAdjustment);
void applyColorAdjustment(const QString &colorName, const QJsonObject &adjustment, RgbChannelAdjustment &rgbAdjustment);
void applyGammaTransform(const QString &transformName, const QJsonObject &adjustment, RgbTransform &rgbTransform, char channel);
void applyTemperatureAdjustment(const QJsonObject &adjustment, ColorCorrection *colorCorrection);

void applyTransforms(const QJsonObject &adjustment, ColorAdjustment *colorAdjustment);
template<typename T>
Expand Down
2 changes: 1 addition & 1 deletion include/hyperion/ColorAdjustment.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef COLORADJUSTMENT_H
#define COLORADJUSTMENT_H

// STL includes
// Qt includes
#include <QString>

// Utils includes
Expand Down
18 changes: 18 additions & 0 deletions include/hyperion/ColorCorrection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

// Qt includes
#include <QString>

// Utils includes
#include <utils/RgbChannelCorrection.h>

class ColorCorrection
{
public:

/// Unique identifier for this color correction
QString _id;

/// The RGB correction
RgbChannelCorrection _rgbCorrection;
};
20 changes: 20 additions & 0 deletions include/hyperion/Hyperion.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <hyperion/LedString.h>
#include <hyperion/PriorityMuxer.h>
#include <hyperion/ColorAdjustment.h>
#include <hyperion/ColorCorrection.h>
#include <hyperion/ComponentRegister.h>

#if defined(ENABLE_EFFECTENGINE)
Expand All @@ -48,6 +49,7 @@ class LinearColorSmoothing;
class EffectEngine;
#endif
class MultiColorAdjustment;
class MultiColorCorrection;
class ColorAdjustment;
class SettingsManager;
class BGEffectHandler;
Expand Down Expand Up @@ -182,15 +184,30 @@ public slots:
///
QStringList getAdjustmentIds() const;

///
/// Returns the list with unique correction identifiers
/// @return The list with correction identifiers
///
QStringList getTemperatureIds() const;

///
/// Returns the ColorAdjustment with the given identifier
/// @return The adjustment with the given identifier (or nullptr if the identifier does not exist)
///
ColorAdjustment * getAdjustment(const QString& id) const;

///
/// Returns the ColorCorrection with the given identifier
/// @return The correction with the given identifier (or nullptr if the identifier does not exist)
///
ColorCorrection * getTemperature(const QString& id) const;

/// Tell Hyperion that the corrections have changed and the leds need to be updated
void adjustmentsUpdated();

/// Tell Hyperion that the corrections have changed and the leds need to be updated
void temperaturesUpdated();

///
/// Clears the given priority channel. This will switch the led-colors to the colors of the next
/// lower priority channel (or off if no more channels are set)
Expand Down Expand Up @@ -577,6 +594,9 @@ private slots:
/// The adjustment from raw colors to led colors
MultiColorAdjustment * _raw2ledAdjustment;

/// The temperature from raw colors to led colors
MultiColorCorrection * _raw2ledTemperature;

/// The actual LedDeviceWrapper
LedDeviceWrapper* _ledDeviceWrapper;

Expand Down
69 changes: 69 additions & 0 deletions include/hyperion/MultiColorCorrection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#pragma once

// STL includes

#include <vector>

// Utils includes
#include <utils/ColorRgb.h>
#include "utils/Logger.h"

// Hyperion includes
#include <hyperion/ColorCorrection.h>

///
/// The LedColorCorrection is responsible for performing color correction from 'raw' colors
/// received as input to colors mapped to match the color-properties of the leds.
///
class MultiColorCorrection
{
public:
MultiColorCorrection(int ledCnt);
~MultiColorCorrection();

/**
* Adds a new ColorCorrection to this MultiColorCorrection
*
* @param Correction The new ColorCorrection (ownership is transfered)
*/
void addCorrection(ColorCorrection * correction);

void setCorrectionForLed(const QString& id, int startLed, int endLed);

bool verifyCorrections() const;

///
/// Returns the identifier of all the unique ColorCorrection
///
/// @return The list with unique id's of the ColorCorrections
QStringList & getCorrectionIds();

///
/// Returns the pointer to the ColorCorrection with the given id
///
/// @param id The identifier of the ColorCorrection
///
/// @return The ColorCorrection with the given id (or nullptr if it does not exist)
///
ColorCorrection* getCorrection(const QString& id);

///
/// Performs the color transoformation from raw-color to led-color
///
/// @param ledColors The list with raw colors
///
void applyCorrection(std::vector<ColorRgb>& ledColors);

private:
/// List with Correction ids
QStringList _correctionIds;

/// List with unique ColorCorrections
std::vector<ColorCorrection*> _correction;

/// List with a pointer to the ColorCorrection for each individual led
std::vector<ColorCorrection*> _ledCorrections;

// logger instance
Logger * _log;
};
72 changes: 72 additions & 0 deletions include/utils/KelvinToRgb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#ifndef KELVINTORGB_H
#define KELVINTORGB_H

#include <cmath>

#include <utils/ColorRgb.h>


// Constants
namespace {
const int TEMPERATURE_MINIMUM = 1000;
Fixed Show fixed Hide fixed
const int TEMPERATUR_MAXIMUM = 40000;
Fixed Show fixed Hide fixed
} //End of constants

static ColorRgb getRgbFromTemperature(int temperature)
{
//Temperature input in Kelvin valid in the range 1000 K to 40000 K. White light = 6600K
temperature = qBound(TEMPERATURE_MINIMUM, temperature, TEMPERATUR_MAXIMUM);

// All calculations require temperature / 100, so only do the conversion once.
temperature /= 100;

// Compute each color in turn.
int red, green, blue;

// red
if (temperature <= 66)
{
red = 255;
}
else
{
// Note: the R-squared value for this approximation is 0.988.
red = static_cast<int>(329.698727446 * (pow(temperature - 60, -0.1332047592)));
}

// green
if (temperature <= 66)
{
// Note: the R-squared value for this approximation is 0.996.
green = static_cast<int>(99.4708025861 * log(temperature) - 161.1195681661);

}
else
{
// Note: the R-squared value for this approximation is 0.987.
green = static_cast<int>(288.1221695283 * (pow(temperature - 60, -0.0755148492)));
}

// blue
if (temperature >= 66)
{
blue = 255;
}
else if (temperature <= 19)
{
blue = 0;
}
else
{
// Note: the R-squared value for this approximation is 0.998.
blue = static_cast<int>(138.5177312231 * log(temperature - 10) - 305.0447927307);
}

return {
static_cast<uint8_t>(qBound(0, red, 255)),
static_cast<uint8_t>(qBound(0, green, 255)),
static_cast<uint8_t>(qBound(0, blue, 255)),
};
}

#endif // KELVINTORGB_H