mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00: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:
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -37,7 +37,7 @@ Logger* Logger::getInstance(QString name, Logger::LogLevel minLevel)
|
||||
LoggerMap = new std::map<QString,Logger*>;
|
||||
}
|
||||
|
||||
if ( LoggerMap->find(name) == LoggerMap->end() )
|
||||
if (LoggerMap->find(name) == LoggerMap->end())
|
||||
{
|
||||
log = new Logger(name,minLevel);
|
||||
LoggerMap->insert(std::pair<QString,Logger*>(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<QString,Logger*>::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;
|
||||
}
|
||||
|
@@ -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<FILE> pipe(popen(cmd.toLocal8Bit().constData(), "r"), pclose);
|
||||
if (pipe)
|
||||
@@ -72,4 +72,4 @@ QByteArray command_exec(QString cmd, QByteArray data)
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user