This commit is contained in:
LordGrey
2024-05-31 17:27:30 +02:00
parent 4e77d4a0d4
commit 1eed23f765
11 changed files with 97 additions and 112 deletions

View File

@@ -48,7 +48,6 @@ class LinearColorSmoothing;
class EffectEngine;
#endif
class MultiColorAdjustment;
class MultiColorCorrection;
class ColorAdjustment;
class SettingsManager;
class BGEffectHandler;
@@ -578,9 +577,6 @@ private:
/// 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;

View File

@@ -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;

View File

@@ -5,28 +5,31 @@
#include <utils/ColorRgb.h>
// Constants
namespace {
const int TEMPERATURE_MINIMUM = 1000;
const int TEMPERATUR_MAXIMUM = 40000;
} //End of 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(TEMPERATURE_MINIMUM, temperature, TEMPERATUR_MAXIMUM);
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, green, blue;
int red;
int green;
int blue;
// red
if (temperature <= 66)
{
red = 255;
red = UINT8_MAX;
}
else
{
@@ -50,7 +53,7 @@ static ColorRgb getRgbFromTemperature(int temperature)
// blue
if (temperature >= 66)
{
blue = 255;
blue = UINT8_MAX;
}
else if (temperature <= 19)
{
@@ -63,9 +66,9 @@ static ColorRgb getRgbFromTemperature(int temperature)
}
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)),
static_cast<uint8_t>(qBound(0, red, UINT8_MAX)),
static_cast<uint8_t>(qBound(0, green, UINT8_MAX)),
static_cast<uint8_t>(qBound(0, blue, UINT8_MAX)),
};
}

View File

@@ -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
@@ -40,6 +44,7 @@ public:
/// @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;
@@ -51,24 +56,28 @@ public:
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];

View File

@@ -3,4 +3,6 @@
#define QSTRING_CSTR(str) str.toUtf8().constData()
typedef QList< int > QIntList;
constexpr uint32_t UINT8_MAX_SQUARED = static_cast<uint32_t>(std::numeric_limits<unsigned char>::max()) * static_cast<uint32_t>(std::numeric_limits<unsigned char>::max());

View File

@@ -5,6 +5,7 @@
#include <hyperion/ColorAdjustment.h>
#include <hyperion/MultiColorAdjustment.h>
#include <hyperion/LedString.h>
#include <utils/KelvinToRgb.h>
#include <QRegularExpression>
// fg effect
@@ -77,7 +78,7 @@ namespace hyperion {
const double gammaR = colorConfig["gammaRed"].toDouble(1.0);
const double gammaG = colorConfig["gammaGreen"].toDouble(1.0);
const double gammaB = colorConfig["gammaBlue"].toDouble(1.0);
const int temperature = colorConfig["temperature"].toInt(6600);
const int temperature = colorConfig["temperature"].toInt(ColorTemperature::DEFAULT);
return RgbTransform(gammaR, gammaG, gammaB, backlightThreshold, backlightColored, static_cast<uint8_t>(brightness), static_cast<uint8_t>(brightnessComp), temperature);
}
@@ -90,13 +91,13 @@ namespace hyperion {
return OkhsvTransform(saturationGain, brightnessGain);
}
static RgbChannelAdjustment createRgbChannelAdjustment(const QJsonObject& colorConfig, const QString& channelName, int defaultR, int defaultG, int defaultB)
static RgbChannelAdjustment createRgbChannelAdjustment(const QJsonObject& colorConfig, const QString& channelName, const ColorRgb& color)
{
const QJsonArray& channelConfig = colorConfig[channelName].toArray();
return RgbChannelAdjustment(
static_cast<uint8_t>(channelConfig[0].toInt(defaultR)),
static_cast<uint8_t>(channelConfig[1].toInt(defaultG)),
static_cast<uint8_t>(channelConfig[2].toInt(defaultB)),
static_cast<uint8_t>(channelConfig[0].toInt(color.red)),
static_cast<uint8_t>(channelConfig[1].toInt(color.green)),
static_cast<uint8_t>(channelConfig[2].toInt(color.blue)),
channelName
);
}
@@ -107,14 +108,14 @@ namespace hyperion {
ColorAdjustment * adjustment = new ColorAdjustment();
adjustment->_id = id;
adjustment->_rgbBlackAdjustment = createRgbChannelAdjustment(adjustmentConfig, "black" , 0, 0, 0);
adjustment->_rgbWhiteAdjustment = createRgbChannelAdjustment(adjustmentConfig, "white" , 255,255,255);
adjustment->_rgbRedAdjustment = createRgbChannelAdjustment(adjustmentConfig, "red" , 255, 0, 0);
adjustment->_rgbGreenAdjustment = createRgbChannelAdjustment(adjustmentConfig, "green" , 0,255, 0);
adjustment->_rgbBlueAdjustment = createRgbChannelAdjustment(adjustmentConfig, "blue" , 0, 0,255);
adjustment->_rgbCyanAdjustment = createRgbChannelAdjustment(adjustmentConfig, "cyan" , 0,255,255);
adjustment->_rgbMagentaAdjustment = createRgbChannelAdjustment(adjustmentConfig, "magenta", 255, 0,255);
adjustment->_rgbYellowAdjustment = createRgbChannelAdjustment(adjustmentConfig, "yellow" , 255,255, 0);
adjustment->_rgbBlackAdjustment = createRgbChannelAdjustment(adjustmentConfig, "black" , ColorRgb::BLACK);
adjustment->_rgbWhiteAdjustment = createRgbChannelAdjustment(adjustmentConfig, "white" , ColorRgb::WHITE);
adjustment->_rgbRedAdjustment = createRgbChannelAdjustment(adjustmentConfig, "red" , ColorRgb::RED);
adjustment->_rgbGreenAdjustment = createRgbChannelAdjustment(adjustmentConfig, "green" , ColorRgb::GREEN);
adjustment->_rgbBlueAdjustment = createRgbChannelAdjustment(adjustmentConfig, "blue" , ColorRgb::BLUE);
adjustment->_rgbCyanAdjustment = createRgbChannelAdjustment(adjustmentConfig, "cyan" , ColorRgb::CYAN);
adjustment->_rgbMagentaAdjustment = createRgbChannelAdjustment(adjustmentConfig, "magenta", ColorRgb::MAGENTA);
adjustment->_rgbYellowAdjustment = createRgbChannelAdjustment(adjustmentConfig, "yellow" , ColorRgb::YELLOW);
adjustment->_rgbTransform = createRgbTransform(adjustmentConfig);
adjustment->_okhsvTransform = createOkhsvTransform(adjustmentConfig);
@@ -150,27 +151,27 @@ namespace hyperion {
continue;
}
std::stringstream ss;
std::stringstream sStream;
const QStringList ledIndexList = ledIndicesStr.split(",");
for (int i=0; i<ledIndexList.size(); ++i) {
if (i > 0)
for (int j=0; j<ledIndexList.size(); ++i) {
if (j > 0)
{
ss << ", ";
sStream << ", ";
}
if (ledIndexList[i].contains("-"))
if (ledIndexList[j].contains("-"))
{
QStringList ledIndices = ledIndexList[i].split("-");
QStringList ledIndices = ledIndexList[j].split("-");
int startInd = ledIndices[0].toInt();
int endInd = ledIndices[1].toInt();
adjustment->setAdjustmentForLed(colorAdjustment->_id, startInd, endInd);
ss << startInd << "-" << endInd;
sStream << startInd << "-" << endInd;
}
else
{
int index = ledIndexList[i].toInt();
adjustment->setAdjustmentForLed(colorAdjustment->_id, index, index);
ss << index;
sStream << index;
}
}
}
@@ -178,44 +179,6 @@ namespace hyperion {
return adjustment;
}
/**
* Construct the 'led-string' with the integration area definition per led and the color
* ordering of the RGB channels
* @param ledsConfig The configuration of the led areas
* @param deviceOrder The default RGB channel ordering
* @return The constructed ledstring
*/
static LedString createLedString(const QJsonArray& ledConfigArray, const ColorOrder deviceOrder)
{
LedString ledString;
const QString deviceOrderStr = colorOrderToString(deviceOrder);
for (signed i = 0; i < ledConfigArray.size(); ++i)
{
const QJsonObject& ledConfig = ledConfigArray[i].toObject();
Led led;
led.minX_frac = qMax(0.0, qMin(1.0, ledConfig["hmin"].toDouble()));
led.maxX_frac = qMax(0.0, qMin(1.0, ledConfig["hmax"].toDouble()));
led.minY_frac = qMax(0.0, qMin(1.0, ledConfig["vmin"].toDouble()));
led.maxY_frac = qMax(0.0, qMin(1.0, ledConfig["vmax"].toDouble()));
// Fix if the user swapped min and max
if (led.minX_frac > led.maxX_frac)
{
std::swap(led.minX_frac, led.maxX_frac);
}
if (led.minY_frac > led.maxY_frac)
{
std::swap(led.minY_frac, led.maxY_frac);
}
// Get the order of the rgb channels for this led (default is device order)
led.colorOrder = stringToColorOrder(ledConfig["colorOrder"].toString(deviceOrderStr));
ledString.leds().push_back(led);
}
return ledString;
}
static QSize getLedLayoutGridSize(const QJsonArray& ledConfigArray)
{
std::vector<int> midPointsX;