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 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,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
2 changes: 1 addition & 1 deletion assets/webconfig/js/content_leds.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ $(document).ready(function () {
//Only update Image, if LED Layout Tab is visible
if (onLedLayoutTab && window.imageStreamActive) {
setClassByBool('#leds_prev_toggle_live_video', window.imageStreamActive, "btn-danger", "btn-success");
var imageData = (event.response.result.image);
var imageData = (event.response.data.image);

var image = new Image();
image.onload = function () {
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
3 changes: 2 additions & 1 deletion include/api/JsonAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ private slots:
///
void handleSystemCommand(const QJsonObject &message, const JsonApiCommand& cmd);


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);
Expand All @@ -288,6 +287,8 @@ private slots:
template<typename T>
void applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(double));
template<typename T>
void applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(int));
template<typename T>
void applyTransform(const QString &transformName, const QJsonObject &adjustment, T &transform, void (T::*setFunction)(uint8_t));

void handleTokenRequired(const JsonApiCommand& cmd);
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
6 changes: 3 additions & 3 deletions include/hyperion/MultiColorAdjustment.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MultiColorAdjustment
*/
void addAdjustment(ColorAdjustment * adjustment);

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

bool verifyAdjustments() const;

Expand All @@ -41,11 +41,11 @@ class MultiColorAdjustment
///
/// Returns the pointer to the ColorAdjustment with the given id
///
/// @param id The identifier of the ColorAdjustment
/// @param adjutmentId The identifier of the ColorAdjustment
///
/// @return The ColorAdjustment with the given id (or nullptr if it does not exist)
///
ColorAdjustment* getAdjustment(const QString& id);
ColorAdjustment* getAdjustment(const QString& adjutmentId);

///
/// Performs the color adjustment from raw-color to led-color
Expand Down
4 changes: 4 additions & 0 deletions include/utils/ColorRgb.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ struct ColorRgb
static const ColorRgb YELLOW;
/// 'White' RgbColor (255, 255, 255)
static const ColorRgb WHITE;
/// 'Cyan' RgbColor (0, 255, 255)
static const ColorRgb CYAN;
/// 'Magenta' RgbColor (255, 0,255)
static const ColorRgb MAGENTA;

ColorRgb() = default;

Expand Down
75 changes: 75 additions & 0 deletions include/utils/KelvinToRgb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#ifndef KELVINTORGB_H
#define KELVINTORGB_H

#include <cmath>

#include <utils/ColorRgb.h>

// Constants
namespace ColorTemperature {
constexpr int MINIMUM {1000};
constexpr int MAXIMUM {40000};
constexpr int DEFAULT {6600};
}
//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(ColorTemperature::MINIMUM, temperature, ColorTemperature::MAXIMUM);

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

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

// red
if (temperature <= 66)
{
red = UINT8_MAX;
}
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 = UINT8_MAX;
}
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, static_cast<int>(UINT8_MAX))),
static_cast<uint8_t>(qBound(0, green, static_cast<int>(UINT8_MAX))),
static_cast<uint8_t>(qBound(0, blue, static_cast<int>(UINT8_MAX))),
};
}

#endif // KELVINTORGB_H
31 changes: 20 additions & 11 deletions include/utils/RgbChannelAdjustment.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
#pragma once

// STL includes
#include <cstdint>

#include <QString>
#include <utils/Logger.h>
#include <utils/ColorRgb.h>

/// Correction for a single color byte value
/// All configuration values are unsigned int and assume the color value to be between 0 and 255
class RgbChannelAdjustment
{
public:

/// Default constructor
RgbChannelAdjustment(QString channelName="");
explicit RgbChannelAdjustment(const QString& channelName="");

explicit RgbChannelAdjustment(const ColorRgb& adjust, const QString& channelName="");

/// Constructor
/// @param adjustR
/// @param adjustG
/// @param adjustB
RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB, QString channelName="");
explicit RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB, const QString& channelName="");

///
/// Transform the given array value
Expand All @@ -40,6 +44,7 @@ class RgbChannelAdjustment
/// @param adjustB
///
void setAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB);
void setAdjustment(const ColorRgb& adjust);

/// @return The current adjustR value
uint8_t getAdjustmentR() const;
Expand All @@ -51,24 +56,28 @@ class RgbChannelAdjustment
uint8_t getAdjustmentB() const;

private:
/// color channels
enum ColorChannel { RED=0, GREEN=1, BLUE=2 };

struct ColorMapping {
uint8_t red[256];
uint8_t green[256];
uint8_t blue[256];
};

/// reset init of color mapping
void resetInitialized();

/// The adjustment of RGB channel
uint8_t _adjust[3];

/// The mapping from input color to output color
uint8_t _mapping[3][256];

/// Name of this channel, usefull for debug messages
QString _channelName;

/// Logger instance
Logger * _log;

/// The adjustment of RGB channel
ColorRgb _adjust;

/// The mapping from input color to output color
ColorMapping _mapping;

/// bitfield to determine white value is alreade initialized
bool _initialized[256];

Expand Down
Loading
Loading