diff --git a/include/utils/FileUtils.h b/include/utils/FileUtils.h index cac8bf8b..d1e87f57 100644 --- a/include/utils/FileUtils.h +++ b/include/utils/FileUtils.h @@ -10,8 +10,8 @@ namespace FileUtils { -QString getBaseName( QString sourceFile); -QString getDirName( QString sourceFile); +QString getBaseName(QString sourceFile); +QString getDirName(QString sourceFile); /// /// @brief remove directory recursive given by path diff --git a/include/utils/GlobalSignals.h b/include/utils/GlobalSignals.h index 4b2e56b8..f89eaaf6 100644 --- a/include/utils/GlobalSignals.h +++ b/include/utils/GlobalSignals.h @@ -24,8 +24,8 @@ private: GlobalSignals() {} public: - GlobalSignals(GlobalSignals const&) = delete; - void operator=(GlobalSignals const&) = delete; + GlobalSignals(GlobalSignals const&) = delete; + void operator=(GlobalSignals const&) = delete; signals: /////////////////////////////////////// diff --git a/include/utils/NetUtils.h b/include/utils/NetUtils.h index 85835648..57294acc 100644 --- a/include/utils/NetUtils.h +++ b/include/utils/NetUtils.h @@ -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; diff --git a/include/utils/RgbChannelAdjustment.h b/include/utils/RgbChannelAdjustment.h index 9d53b290..cf01c3e2 100644 --- a/include/utils/RgbChannelAdjustment.h +++ b/include/utils/RgbChannelAdjustment.h @@ -12,16 +12,16 @@ class RgbChannelAdjustment public: /// Default constructor RgbChannelAdjustment(QString channelName=""); - + /// Constructor - /// @param adjustR - /// @param adjustG - /// @param adjustB + /// @param adjustR + /// @param adjustG + /// @param adjustB RgbChannelAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB, QString channelName=""); /// Destructor ~RgbChannelAdjustment(); - + /// /// Transform the given array value /// @@ -38,9 +38,9 @@ public: /// /// setAdjustment RGB /// - /// @param adjustR - /// @param adjustG - /// @param adjustB + /// @param adjustR + /// @param adjustG + /// @param adjustB /// void setAdjustment(uint8_t adjustR, uint8_t adjustG, uint8_t adjustB); @@ -62,7 +62,7 @@ private: /// The adjustment of RGB channel uint8_t _adjust[3]; - + /// The mapping from input color to output color uint8_t _mapping[3][256]; diff --git a/include/utils/RgbTransform.h b/include/utils/RgbTransform.h index 14f1093e..078a1cd2 100644 --- a/include/utils/RgbTransform.h +++ b/include/utils/RgbTransform.h @@ -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. @@ -126,7 +126,7 @@ private: double _gammaR , _gammaG , _gammaB; - + /// The mapping from input color to output color uint8_t _mappingR[256] , _mappingG[256] diff --git a/include/utils/hyperion.h b/include/utils/hyperion.h index 9921cff8..42337465 100644 --- a/include/utils/hyperion.h +++ b/include/utils/hyperion.h @@ -58,68 +58,45 @@ 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); - const double brightness = colorConfig["brightness"].toInt(100); - const double brightnessComp= colorConfig["brightnessCompensation"].toInt(100); - 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 double brightness = colorConfig["brightness"].toInt(100); + const double brightnessComp = colorConfig["brightnessCompensation"].toInt(100); + const double gammaR = colorConfig["gammaRed"].toDouble(1.0); + 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() + "ChannelAdjust_" + channelName.toUpper() ); - return adjustment; } - ColorAdjustment * createColorAdjustment(const QJsonObject & adjustmentConfig) + 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; } diff --git a/libsrc/utils/ColorSys.cpp b/libsrc/utils/ColorSys.cpp index 52e8ab08..5ba00254 100644 --- a/libsrc/utils/ColorSys.cpp +++ b/libsrc/utils/ColorSys.cpp @@ -1,6 +1,7 @@ #include #include + void ColorSys::rgb2hsl(uint8_t red, uint8_t green, uint8_t blue, uint16_t & hue, float & saturation, float & luminance) { QColor color(red,green,blue); diff --git a/libsrc/utils/FileUtils.cpp b/libsrc/utils/FileUtils.cpp index eb2e6209..5ee8bb2a 100644 --- a/libsrc/utils/FileUtils.cpp +++ b/libsrc/utils/FileUtils.cpp @@ -10,21 +10,20 @@ namespace FileUtils { - QString getBaseName( QString sourceFile) + QString getBaseName(QString sourceFile) { - QFileInfo fi( sourceFile ); + QFileInfo fi(sourceFile); return fi.fileName(); } - QString getDirName( QString sourceFile) + QString getDirName(QString sourceFile) { - QFileInfo fi( sourceFile ); + QFileInfo fi(sourceFile); return fi.path(); } 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; diff --git a/libsrc/utils/ImageResampler.cpp b/libsrc/utils/ImageResampler.cpp index 38c3f7cb..fcc1eab6 100644 --- a/libsrc/utils/ImageResampler.cpp +++ b/libsrc/utils/ImageResampler.cpp @@ -68,7 +68,7 @@ void ImageResampler::processImage(const uint8_t * data, int width, int height, i for (int xDest = 0, xSource = _cropLeft + (_horizontalDecimation >> 1); xDest < outputWidth; xSource += _horizontalDecimation, ++xDest) { ColorRgb & rgb = outputImage(xDest, yDest); - + switch (pixelFormat) { case PixelFormat::UYVY: @@ -144,7 +144,7 @@ void ImageResampler::yuv2rgb(uint8_t y, uint8_t u, uint8_t v, uint8_t &r, uint8_ int c = y - 16; int d = u - 128; int e = v - 128; - + r = clamp((298 * c + 409 * e + 128) >> 8); g = clamp((298 * c - 100 * d - 208 * e + 128) >> 8); b = clamp((298 * c + 516 * d + 128) >> 8); diff --git a/libsrc/utils/Logger.cpp b/libsrc/utils/Logger.cpp index 351a6c5b..896ec62a 100644 --- a/libsrc/utils/Logger.cpp +++ b/libsrc/utils/Logger.cpp @@ -37,7 +37,7 @@ Logger* Logger::getInstance(QString name, Logger::LogLevel minLevel) LoggerMap = new std::map; } - if ( LoggerMap->find(name) == LoggerMap->end() ) + if (LoggerMap->find(name) == LoggerMap->end()) { log = new Logger(name,minLevel); LoggerMap->insert(std::pair(name,log)); // compat version, replace it with following line if we have 100% c++11 @@ -57,10 +57,10 @@ void Logger::deleteInstance(QString name) if (LoggerMap == nullptr) return; - if ( name.isEmpty() ) + if (name.isEmpty()) { std::map::iterator it; - for ( it=LoggerMap->begin(); it != LoggerMap->end(); it++) + for (it = LoggerMap->begin(); it != LoggerMap->end(); it++) { delete it->second; } @@ -76,7 +76,7 @@ void Logger::deleteInstance(QString name) void Logger::setLogLevel(LogLevel level,QString name) { - if ( name.isEmpty() ) + if (name.isEmpty()) { GLOBAL_MIN_LOG_LEVEL = level; } @@ -89,7 +89,7 @@ void Logger::setLogLevel(LogLevel level,QString name) Logger::LogLevel Logger::getLogLevel(QString name) { - if ( name.isEmpty() ) + if (name.isEmpty()) { return GLOBAL_MIN_LOG_LEVEL; } @@ -98,7 +98,7 @@ Logger::LogLevel Logger::getLogLevel(QString name) return log->getMinLevel(); } -Logger::Logger ( QString name, LogLevel minLevel ) +Logger::Logger (QString name, LogLevel minLevel) : QObject() , _name(name) , _minLevel(minLevel) @@ -125,7 +125,7 @@ Logger::Logger ( QString name, LogLevel minLevel ) loggerCount++; - if (_syslogEnabled && loggerCount == 1 ) + if (_syslogEnabled && loggerCount == 1) { #ifndef _WIN32 openlog (_appname_char, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL0); @@ -138,7 +138,7 @@ Logger::~Logger() //Debug(this, "logger '%s' destroyed", QSTRING_CSTR(_name) ); loggerCount--; #ifndef _WIN32 - if ( loggerCount == 0 ) + if (loggerCount == 0) closelog(); #endif } @@ -237,7 +237,7 @@ void LoggerManager::handleNewLogMessage(const Logger::T_LOG_MESSAGE &msg) LoggerManager* LoggerManager::getInstance() { - if ( _instance == nullptr ) + if (_instance == nullptr) _instance = new LoggerManager(); return _instance; } diff --git a/libsrc/utils/Process.cpp b/libsrc/utils/Process.cpp index 31155440..eaa3c71a 100644 --- a/libsrc/utils/Process.cpp +++ b/libsrc/utils/Process.cpp @@ -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()); } @@ -45,7 +45,7 @@ void restartHyperion(bool asNewProcess) { int str_size = qargs[i].toLocal8Bit().size(); args[i] = new char[str_size+1]; - strncpy(args[i], qargs[i].toLocal8Bit().constData(),str_size ); + strncpy(args[i], qargs[i].toLocal8Bit().constData(),str_size); args[i][str_size] = '\0'; } @@ -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 pipe(popen(cmd.toLocal8Bit().constData(), "r"), pclose); if (pipe) @@ -72,4 +72,4 @@ QByteArray command_exec(QString cmd, QByteArray data) }; -#endif \ No newline at end of file +#endif diff --git a/libsrc/utils/Profiler.cpp b/libsrc/utils/Profiler.cpp index c478fb06..e5975a55 100644 --- a/libsrc/utils/Profiler.cpp +++ b/libsrc/utils/Profiler.cpp @@ -18,7 +18,7 @@ Logger* Profiler::_logger = nullptr; double getClockDelta(clock_t start) { - return ((double)(clock() - start) / CLOCKS_PER_SEC) ; + return ((double)(clock() - start) / CLOCKS_PER_SEC); } Profiler::Profiler(const char* sourceFile, const char* func, unsigned int line) @@ -35,12 +35,12 @@ Profiler::Profiler(const char* sourceFile, const char* func, unsigned int line) Profiler::~Profiler() { - _logger->Message( Logger::DEBUG, _file,_func, _line, "<<< exit block %d, executed for %f s", _blockId, getClockDelta(_startTime) ); + _logger->Message( Logger::DEBUG, _file,_func, _line, "<<< exit block %d, executed for %f s", _blockId, getClockDelta(_startTime)); } void Profiler::initLogger() { - if (_logger == nullptr ) + if (_logger == nullptr) _logger = Logger::getInstance("PROFILER", Logger::DEBUG); } @@ -52,22 +52,22 @@ void Profiler::TimerStart(const QString timerName, const char* sourceFile, const StopWatchItem item = {sourceFile, func, line}; ret = GlobalProfilerMap.emplace(timerName, item); - if ( ! ret.second ) + if (!ret.second) { - if ( ret.first->second.sourceFile == sourceFile && ret.first->second.func == func && ret.first->second.line == line ) + if (ret.first->second.sourceFile == sourceFile && ret.first->second.func == func && ret.first->second.line == line) { - _logger->Message(Logger::DEBUG, sourceFile, func, line, "restart timer '%s'", QSTRING_CSTR(timerName) ); + _logger->Message(Logger::DEBUG, sourceFile, func, line, "restart timer '%s'", QSTRING_CSTR(timerName)); ret.first->second.startTime = clock(); } else { _logger->Message(Logger::DEBUG, sourceFile, func, line, "ERROR timer '%s' started in multiple locations. First occurence %s:%d:%s()", - QSTRING_CSTR(timerName), FileUtils::getBaseName(ret.first->second.sourceFile).toLocal8Bit().constData(), ret.first->second.line, ret.first->second.func ); + QSTRING_CSTR(timerName), FileUtils::getBaseName(ret.first->second.sourceFile).toLocal8Bit().constData(), ret.first->second.line, ret.first->second.func); } } else { - _logger->Message(Logger::DEBUG, sourceFile, func, line, "start timer '%s'", QSTRING_CSTR(timerName) ); + _logger->Message(Logger::DEBUG, sourceFile, func, line, "start timer '%s'", QSTRING_CSTR(timerName)); } } @@ -79,11 +79,11 @@ void Profiler::TimerGetTime(const QString timerName, const char* sourceFile, con if (ret != GlobalProfilerMap.end()) { _logger->Message(Logger::DEBUG, sourceFile, func, line, "timer '%s' started at %s:%d:%s() took %f s execution time until here", QSTRING_CSTR(timerName), - FileUtils::getBaseName(ret->second.sourceFile).toLocal8Bit().constData(), ret->second.line, ret->second.func, getClockDelta(ret->second.startTime) ); + FileUtils::getBaseName(ret->second.sourceFile).toLocal8Bit().constData(), ret->second.line, ret->second.func, getClockDelta(ret->second.startTime)); } else { - _logger->Message(Logger::DEBUG, sourceFile, func, line, "ERROR timer '%s' not started", QSTRING_CSTR(timerName) ); + _logger->Message(Logger::DEBUG, sourceFile, func, line, "ERROR timer '%s' not started", QSTRING_CSTR(timerName)); } } diff --git a/libsrc/utils/RgbToRgbw.cpp b/libsrc/utils/RgbToRgbw.cpp index 8f2fa8b7..1542ae22 100644 --- a/libsrc/utils/RgbToRgbw.cpp +++ b/libsrc/utils/RgbToRgbw.cpp @@ -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 diff --git a/libsrc/utils/RgbTransform.cpp b/libsrc/utils/RgbTransform.cpp index 7c891dfc..0c2ae63b 100644 --- a/libsrc/utils/RgbTransform.cpp +++ b/libsrc/utils/RgbTransform.cpp @@ -98,7 +98,7 @@ uint8_t RgbTransform::getBrightness() const void RgbTransform::setBrightness(uint8_t brightness) { - _brightness = brightness; + _brightness = brightness; updateBrightnessComponents(); } @@ -117,7 +117,7 @@ void RgbTransform::updateBrightnessComponents() { double Fw = _brightnessCompensation*2.0/100.0+1.0; double Fcmy = _brightnessCompensation/100.0+1.0; - + double B_in= 0; _brightness_rgb = 0; _brightness_cmy = 0; @@ -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; diff --git a/libsrc/utils/SysInfo.cpp b/libsrc/utils/SysInfo.cpp index 5b73b8ea..88c03b49 100644 --- a/libsrc/utils/SysInfo.cpp +++ b/libsrc/utils/SysInfo.cpp @@ -25,7 +25,7 @@ SysInfo::~SysInfo() SysInfo::HyperionSysInfo SysInfo::get() { - if ( SysInfo::_instance == nullptr ) + if (SysInfo::_instance == nullptr) SysInfo::_instance = new SysInfo(); return SysInfo::_instance->_sysinfo;