mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
refactor: Improve utils code style (#841)
* Improve utils code style * Fix indendation Co-authored-by: brindosch <edeltraud70@gmx.de>
This commit is contained in:
parent
bfb50b8d91
commit
458113f8f9
@ -15,15 +15,13 @@ namespace NetUtils {
|
||||
{
|
||||
const quint16 prevPort = port;
|
||||
QTcpServer server;
|
||||
bool corrected = false;
|
||||
while (!server.listen(QHostAddress::Any, port))
|
||||
{
|
||||
corrected = true;
|
||||
Warning(log,"Port '%d' is already in use, will increment", port);
|
||||
port ++;
|
||||
}
|
||||
server.close();
|
||||
if(corrected)
|
||||
if(port != prevPort)
|
||||
{
|
||||
Warning(log, "The requested Port '%d' was already in use, will use Port '%d' instead", prevPort, port);
|
||||
return false;
|
||||
|
@ -84,7 +84,7 @@ public:
|
||||
///
|
||||
/// @note The values are updated in place.
|
||||
///
|
||||
void getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & w );
|
||||
void getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & w) const;
|
||||
|
||||
///
|
||||
/// Apply the transform the the given RGB values.
|
||||
|
@ -58,7 +58,7 @@ namespace hyperion {
|
||||
return stringToColorOrder(deviceConfig["colorOrder"].toString("rgb"));
|
||||
}
|
||||
|
||||
RgbTransform* createRgbTransform(const QJsonObject& colorConfig)
|
||||
RgbTransform createRgbTransform(const QJsonObject& colorConfig)
|
||||
{
|
||||
const double backlightThreshold = colorConfig["backlightThreshold"].toDouble(0.0);
|
||||
const bool backlightColored = colorConfig["backlightColored"].toBool(false);
|
||||
@ -68,58 +68,35 @@ namespace hyperion {
|
||||
const double gammaG = colorConfig["gammaGreen"].toDouble(1.0);
|
||||
const double gammaB = colorConfig["gammaBlue"].toDouble(1.0);
|
||||
|
||||
RgbTransform* transform = new RgbTransform(gammaR, gammaG, gammaB, backlightThreshold, backlightColored, brightness, brightnessComp);
|
||||
return transform;
|
||||
return RgbTransform(gammaR, gammaG, gammaB, backlightThreshold, backlightColored, brightness, brightnessComp);
|
||||
}
|
||||
|
||||
RgbChannelAdjustment* createRgbChannelAdjustment(const QJsonObject& colorConfig, const QString channelName, const int defaultR, const int defaultG, const int defaultB)
|
||||
RgbChannelAdjustment createRgbChannelAdjustment(const QJsonObject& colorConfig, const QString& channelName, const int defaultR, const int defaultG, const int defaultB)
|
||||
{
|
||||
const QJsonArray& channelConfig = colorConfig[channelName].toArray();
|
||||
RgbChannelAdjustment* adjustment = new RgbChannelAdjustment(
|
||||
return RgbChannelAdjustment(
|
||||
channelConfig[0].toInt(defaultR),
|
||||
channelConfig[1].toInt(defaultG),
|
||||
channelConfig[2].toInt(defaultB),
|
||||
"ChannelAdjust_" + channelName.toUpper()
|
||||
);
|
||||
return adjustment;
|
||||
}
|
||||
|
||||
ColorAdjustment* createColorAdjustment(const QJsonObject & adjustmentConfig)
|
||||
{
|
||||
const QString id = adjustmentConfig["id"].toString("default");
|
||||
|
||||
RgbChannelAdjustment * blackAdjustment = createRgbChannelAdjustment(adjustmentConfig, "black" , 0, 0, 0);
|
||||
RgbChannelAdjustment * whiteAdjustment = createRgbChannelAdjustment(adjustmentConfig, "white" , 255,255,255);
|
||||
RgbChannelAdjustment * redAdjustment = createRgbChannelAdjustment(adjustmentConfig, "red" , 255, 0, 0);
|
||||
RgbChannelAdjustment * greenAdjustment = createRgbChannelAdjustment(adjustmentConfig, "green" , 0,255, 0);
|
||||
RgbChannelAdjustment * blueAdjustment = createRgbChannelAdjustment(adjustmentConfig, "blue" , 0, 0,255);
|
||||
RgbChannelAdjustment * cyanAdjustment = createRgbChannelAdjustment(adjustmentConfig, "cyan" , 0,255,255);
|
||||
RgbChannelAdjustment * magentaAdjustment = createRgbChannelAdjustment(adjustmentConfig, "magenta", 255, 0,255);
|
||||
RgbChannelAdjustment * yellowAdjustment = createRgbChannelAdjustment(adjustmentConfig, "yellow" , 255,255, 0);
|
||||
RgbTransform * rgbTransform = createRgbTransform(adjustmentConfig);
|
||||
|
||||
ColorAdjustment * adjustment = new ColorAdjustment();
|
||||
adjustment->_id = id;
|
||||
adjustment->_rgbBlackAdjustment = *blackAdjustment;
|
||||
adjustment->_rgbWhiteAdjustment = *whiteAdjustment;
|
||||
adjustment->_rgbRedAdjustment = *redAdjustment;
|
||||
adjustment->_rgbGreenAdjustment = *greenAdjustment;
|
||||
adjustment->_rgbBlueAdjustment = *blueAdjustment;
|
||||
adjustment->_rgbCyanAdjustment = *cyanAdjustment;
|
||||
adjustment->_rgbMagentaAdjustment = *magentaAdjustment;
|
||||
adjustment->_rgbYellowAdjustment = *yellowAdjustment;
|
||||
adjustment->_rgbTransform = *rgbTransform;
|
||||
|
||||
// Cleanup the allocated individual adjustments
|
||||
delete blackAdjustment;
|
||||
delete whiteAdjustment;
|
||||
delete redAdjustment;
|
||||
delete greenAdjustment;
|
||||
delete blueAdjustment;
|
||||
delete cyanAdjustment;
|
||||
delete magentaAdjustment;
|
||||
delete yellowAdjustment;
|
||||
delete rgbTransform;
|
||||
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->_rgbTransform = createRgbTransform(adjustmentConfig);
|
||||
|
||||
return adjustment;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <utils/ColorSys.h>
|
||||
|
||||
#include <QColor>
|
||||
|
||||
void ColorSys::rgb2hsl(uint8_t red, uint8_t green, uint8_t blue, uint16_t & hue, float & saturation, float & luminance)
|
||||
{
|
||||
QColor color(red,green,blue);
|
||||
|
@ -24,7 +24,6 @@ namespace FileUtils {
|
||||
|
||||
bool removeDir(const QString& path, Logger* log)
|
||||
{
|
||||
//QDir dir(path);
|
||||
if(!QDir(path).removeRecursively())
|
||||
{
|
||||
Error(log, "Failed to remove directory: %s", QSTRING_CSTR(path));
|
||||
@ -35,8 +34,7 @@ namespace FileUtils {
|
||||
|
||||
bool fileExists(const QString& path, Logger* log, bool ignError)
|
||||
{
|
||||
QFile file(path);
|
||||
if(!file.exists())
|
||||
if(!QFile::exists(path))
|
||||
{
|
||||
ErrorIf((!ignError), log,"File does not exist: %s",QSTRING_CSTR(path));
|
||||
return false;
|
||||
|
@ -6,7 +6,7 @@ namespace Process {
|
||||
|
||||
void restartHyperion(bool asNewProcess){}
|
||||
|
||||
QByteArray command_exec(QString cmd, QByteArray data)
|
||||
QByteArray command_exec(QString /*cmd*/, QByteArray /*data*/)
|
||||
{
|
||||
return QSTRING_CSTR(QString());
|
||||
}
|
||||
@ -56,7 +56,7 @@ void restartHyperion(bool asNewProcess)
|
||||
QByteArray command_exec(QString cmd, QByteArray data)
|
||||
{
|
||||
char buffer[128];
|
||||
QString result = "";
|
||||
QString result;
|
||||
|
||||
std::shared_ptr<FILE> pipe(popen(cmd.toLocal8Bit().constData(), "r"), pclose);
|
||||
if (pipe)
|
||||
|
@ -26,7 +26,6 @@ void Rgb_to_Rgbw(ColorRgb input, ColorRgbw * output, const WhiteAlgorithm algori
|
||||
output->blue = input.blue - output->white;
|
||||
break;
|
||||
}
|
||||
|
||||
case WhiteAlgorithm::SUB_MIN_WARM_ADJUST:
|
||||
{
|
||||
// http://forum.garagecube.com/viewtopic.php?t=10178
|
||||
|
@ -133,7 +133,7 @@ void RgbTransform::updateBrightnessComponents()
|
||||
}
|
||||
}
|
||||
|
||||
void RgbTransform::getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & w )
|
||||
void RgbTransform::getBrightnessComponents(uint8_t & rgb, uint8_t & cmy, uint8_t & w) const
|
||||
{
|
||||
rgb = _brightness_rgb;
|
||||
cmy = _brightness_cmy;
|
||||
|
Loading…
Reference in New Issue
Block a user