Skip to content

Commit

Permalink
Cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Lord-Grey committed May 31, 2024
1 parent 4e77d4a commit 1eed23f
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 112 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,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 ON )
set(DEFAULT_HYPERION_LIGHT OFF)

if(${CMAKE_SYSTEM} MATCHES "Linux")
set(DEFAULT_FB ON)
Expand Down
4 changes: 0 additions & 4 deletions include/hyperion/Hyperion.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class LinearColorSmoothing;
class EffectEngine;
#endif
class MultiColorAdjustment;
class MultiColorCorrection;
class ColorAdjustment;
class SettingsManager;
class BGEffectHandler;
Expand Down Expand Up @@ -578,9 +577,6 @@ 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
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
27 changes: 15 additions & 12 deletions include/utils/KelvinToRgb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -50,7 +53,7 @@ static ColorRgb getRgbFromTemperature(int temperature)
// blue
if (temperature >= 66)
{
blue = 255;
blue = UINT8_MAX;
}
else if (temperature <= 19)
{
Expand All @@ -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)),
};
}

Expand Down
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
2 changes: 2 additions & 0 deletions include/utils/global_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());


81 changes: 22 additions & 59 deletions include/utils/hyperion.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <hyperion/ColorAdjustment.h>
#include <hyperion/MultiColorAdjustment.h>
#include <hyperion/LedString.h>
#include <utils/KelvinToRgb.h>
#include <QRegularExpression>

// fg effect
Expand Down Expand Up @@ -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);
}
Expand All @@ -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
);
}
Expand All @@ -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);

Expand Down Expand Up @@ -150,72 +151,34 @@ 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;
}
}
}

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;
Expand Down
3 changes: 0 additions & 3 deletions libsrc/hyperion/MultiColorAdjustment.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#include <algorithm>
#include <limits>

// Hyperion includes

#include <utils/Logger.h>
#include <hyperion/MultiColorAdjustment.h>

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());

MultiColorAdjustment::MultiColorAdjustment(int ledCnt)
: _ledAdjustments(static_cast<size_t>(ledCnt), nullptr)
, _log(Logger::getInstance("ADJUSTMENT"))
Expand Down
2 changes: 2 additions & 0 deletions libsrc/utils/ColorRgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ const ColorRgb ColorRgb::GREEN = { 0, 255, 0 };
const ColorRgb ColorRgb::BLUE = { 0, 0, 255 };
const ColorRgb ColorRgb::YELLOW = { 255, 255, 0 };
const ColorRgb ColorRgb::WHITE = { 255, 255, 255 };
const ColorRgb ColorRgb::CYAN = { 0, 255, 255 };
const ColorRgb ColorRgb::MAGENTA= { 255, 0, 255 };
Loading

0 comments on commit 1eed23f

Please sign in to comment.