mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Refactor color utils (#955)
Co-authored-by: Paulchen Panther <16664240+Paulchen-Panther@users.noreply.github.com>
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
|
||||
struct ColorArgb
|
||||
{
|
||||
|
||||
/// The alpha mask channel
|
||||
uint8_t alpha;
|
||||
|
||||
@@ -18,20 +17,19 @@ struct ColorArgb
|
||||
uint8_t blue;
|
||||
|
||||
/// 'Black' RgbColor (255, 0, 0, 0)
|
||||
static ColorArgb BLACK;
|
||||
static const ColorArgb BLACK;
|
||||
/// 'Red' RgbColor (255, 255, 0, 0)
|
||||
static ColorArgb RED;
|
||||
static const ColorArgb RED;
|
||||
/// 'Green' RgbColor (255, 0, 255, 0)
|
||||
static ColorArgb GREEN;
|
||||
static const ColorArgb GREEN;
|
||||
/// 'Blue' RgbColor (255, 0, 0, 255)
|
||||
static ColorArgb BLUE;
|
||||
static const ColorArgb BLUE;
|
||||
/// 'Yellow' RgbColor (255, 255, 255, 0)
|
||||
static ColorArgb YELLOW;
|
||||
static const ColorArgb YELLOW;
|
||||
/// 'White' RgbColor (255, 255, 255, 255)
|
||||
static ColorArgb WHITE;
|
||||
static const ColorArgb WHITE;
|
||||
};
|
||||
|
||||
|
||||
/// Assert to ensure that the size of the structure is 'only' 3 bytes
|
||||
static_assert(sizeof(ColorArgb) == 4, "Incorrect size of ColorARGB");
|
||||
|
||||
@@ -44,6 +42,12 @@ static_assert(sizeof(ColorArgb) == 4, "Incorrect size of ColorARGB");
|
||||
///
|
||||
inline std::ostream& operator<<(std::ostream& os, const ColorArgb& color)
|
||||
{
|
||||
os << "{" << unsigned(color.alpha) << "," << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}";
|
||||
os << "{"
|
||||
<< color.alpha << ","
|
||||
<< color.red << ","
|
||||
<< color.green << ","
|
||||
<< color.blue
|
||||
<< "}";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
@@ -17,18 +17,19 @@ struct ColorBgr
|
||||
/// The red color channel
|
||||
uint8_t red;
|
||||
|
||||
|
||||
/// 'Black' RgbColor (0, 0, 0)
|
||||
static ColorBgr BLACK;
|
||||
static const ColorBgr BLACK;
|
||||
/// 'Red' RgbColor (255, 0, 0)
|
||||
static ColorBgr RED;
|
||||
static const ColorBgr RED;
|
||||
/// 'Green' RgbColor (0, 255, 0)
|
||||
static ColorBgr GREEN;
|
||||
static const ColorBgr GREEN;
|
||||
/// 'Blue' RgbColor (0, 0, 255)
|
||||
static ColorBgr BLUE;
|
||||
static const ColorBgr BLUE;
|
||||
/// 'Yellow' RgbColor (255, 255, 0)
|
||||
static ColorBgr YELLOW;
|
||||
static const ColorBgr YELLOW;
|
||||
/// 'White' RgbColor (255, 255, 255)
|
||||
static ColorBgr WHITE;
|
||||
static const ColorBgr WHITE;
|
||||
};
|
||||
|
||||
/// Assert to ensure that the size of the structure is 'only' 3 bytes
|
||||
@@ -43,19 +44,33 @@ static_assert(sizeof(ColorBgr) == 3, "Incorrect size of ColorBgr");
|
||||
///
|
||||
inline std::ostream& operator<<(std::ostream& os, const ColorBgr& color)
|
||||
{
|
||||
os << "{" << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}";
|
||||
os << "{"
|
||||
<< color.red << ","
|
||||
<< color.green << ","
|
||||
<< color.blue
|
||||
<< "}";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
/// Compare operator to check if a color is 'equal' to another color
|
||||
inline bool operator==(const ColorBgr & lhs, const ColorBgr & rhs)
|
||||
{
|
||||
return (lhs.red == rhs.red) &&
|
||||
(lhs.green == rhs.green) &&
|
||||
(lhs.blue == rhs.blue);
|
||||
}
|
||||
|
||||
/// Compare operator to check if a color is 'smaller' than another color
|
||||
inline bool operator<(const ColorBgr & lhs, const ColorBgr & rhs)
|
||||
{
|
||||
return (lhs.red < rhs.red) && (lhs.green < rhs.green) && (lhs.blue < rhs.blue);
|
||||
return (lhs.red < rhs.red) &&
|
||||
(lhs.green < rhs.green) &&
|
||||
(lhs.blue < rhs.blue);
|
||||
}
|
||||
|
||||
/// Compare operator to check if a color is 'smaller' than or 'equal' to another color
|
||||
inline bool operator<=(const ColorBgr & lhs, const ColorBgr & rhs)
|
||||
{
|
||||
return (lhs.red <= rhs.red) && (lhs.green <= rhs.green) && (lhs.blue <= rhs.blue);
|
||||
return lhs < rhs || lhs == rhs;
|
||||
}
|
||||
|
@@ -20,17 +20,17 @@ struct ColorRgb
|
||||
uint8_t blue;
|
||||
|
||||
/// 'Black' RgbColor (0, 0, 0)
|
||||
static ColorRgb BLACK;
|
||||
static const ColorRgb BLACK;
|
||||
/// 'Red' RgbColor (255, 0, 0)
|
||||
static ColorRgb RED;
|
||||
static const ColorRgb RED;
|
||||
/// 'Green' RgbColor (0, 255, 0)
|
||||
static ColorRgb GREEN;
|
||||
static const ColorRgb GREEN;
|
||||
/// 'Blue' RgbColor (0, 0, 255)
|
||||
static ColorRgb BLUE;
|
||||
static const ColorRgb BLUE;
|
||||
/// 'Yellow' RgbColor (255, 255, 0)
|
||||
static ColorRgb YELLOW;
|
||||
static const ColorRgb YELLOW;
|
||||
/// 'White' RgbColor (255, 255, 255)
|
||||
static ColorRgb WHITE;
|
||||
static const ColorRgb WHITE;
|
||||
};
|
||||
|
||||
/// Assert to ensure that the size of the structure is 'only' 3 bytes
|
||||
@@ -45,7 +45,12 @@ static_assert(sizeof(ColorRgb) == 3, "Incorrect size of ColorRgb");
|
||||
///
|
||||
inline std::ostream& operator<<(std::ostream& os, const ColorRgb& color)
|
||||
{
|
||||
os << "{" << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}";
|
||||
os << "{"
|
||||
<< color.red << ","
|
||||
<< color.green << ","
|
||||
<< color.blue
|
||||
<< "}";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
@@ -58,30 +63,51 @@ inline std::ostream& operator<<(std::ostream& os, const ColorRgb& color)
|
||||
///
|
||||
inline QTextStream& operator<<(QTextStream &os, const ColorRgb& color)
|
||||
{
|
||||
os << "{" << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}";
|
||||
os << "{"
|
||||
<< color.red << ","
|
||||
<< color.green << ","
|
||||
<< color.blue
|
||||
<< "}";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
/// Compare operator to check if a color is 'equal' to another color
|
||||
inline bool operator==(const ColorRgb & lhs, const ColorRgb & rhs)
|
||||
{
|
||||
return lhs.red == rhs.red &&
|
||||
lhs.green == rhs.green &&
|
||||
lhs.blue == rhs.blue;
|
||||
}
|
||||
|
||||
/// Compare operator to check if a color is 'smaller' than another color
|
||||
inline bool operator<(const ColorRgb & lhs, const ColorRgb & rhs)
|
||||
{
|
||||
return (lhs.red < rhs.red) && (lhs.green < rhs.green) && (lhs.blue < rhs.blue);
|
||||
return lhs.red < rhs.red &&
|
||||
lhs.green < rhs.green &&
|
||||
lhs.blue < rhs.blue;
|
||||
}
|
||||
|
||||
/// Compare operator to check if a color is 'not equal' to another color
|
||||
inline bool operator!=(const ColorRgb & lhs, const ColorRgb & rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
/// Compare operator to check if a color is 'smaller' than or 'equal' to another color
|
||||
inline bool operator<=(const ColorRgb & lhs, const ColorRgb & rhs)
|
||||
{
|
||||
return (lhs.red <= rhs.red) && (lhs.green <= rhs.green) && (lhs.blue <= rhs.blue);
|
||||
return lhs < rhs || lhs == rhs;
|
||||
}
|
||||
|
||||
/// Compare operator to check if a color is 'greater' to another color
|
||||
inline bool operator>(const ColorRgb & lhs, const ColorRgb & rhs)
|
||||
{
|
||||
return (lhs.red > rhs.red) && (lhs.green > rhs.green) && (lhs.blue > rhs.blue);
|
||||
return !(lhs < rhs) && lhs != rhs;
|
||||
}
|
||||
|
||||
/// Compare operator to check if a color is 'greater' than or 'equal' to another color
|
||||
inline bool operator>=(const ColorRgb & lhs, const ColorRgb & rhs)
|
||||
{
|
||||
return (lhs.red >= rhs.red) && (lhs.green >= rhs.green) && (lhs.blue >= rhs.blue);
|
||||
return lhs > rhs || lhs == rhs;
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@
|
||||
|
||||
struct ColorRgba
|
||||
{
|
||||
|
||||
/// The red color channel
|
||||
uint8_t red;
|
||||
/// The green color channel
|
||||
@@ -18,20 +17,19 @@ struct ColorRgba
|
||||
uint8_t alpha;
|
||||
|
||||
/// 'Black' RgbColor (0, 0, 0, 255)
|
||||
static ColorRgba BLACK;
|
||||
static const ColorRgba BLACK;
|
||||
/// 'Red' RgbColor (255, 0, 0, 255)
|
||||
static ColorRgba RED;
|
||||
static const ColorRgba RED;
|
||||
/// 'Green' RgbColor (0, 255, 0, 255)
|
||||
static ColorRgba GREEN;
|
||||
static const ColorRgba GREEN;
|
||||
/// 'Blue' RgbColor (0, 0, 255, 255)
|
||||
static ColorRgba BLUE;
|
||||
static const ColorRgba BLUE;
|
||||
/// 'Yellow' RgbColor (255, 255, 0, 255)
|
||||
static ColorRgba YELLOW;
|
||||
static const ColorRgba YELLOW;
|
||||
/// 'White' RgbColor (255, 255, 255, 255
|
||||
static ColorRgba WHITE;
|
||||
static const ColorRgba WHITE;
|
||||
};
|
||||
|
||||
|
||||
/// Assert to ensure that the size of the structure is 'only' 3 bytes
|
||||
static_assert(sizeof(ColorRgba) == 4, "Incorrect size of ColorARGB");
|
||||
|
||||
@@ -44,6 +42,12 @@ static_assert(sizeof(ColorRgba) == 4, "Incorrect size of ColorARGB");
|
||||
///
|
||||
inline std::ostream& operator<<(std::ostream& os, const ColorRgba& color)
|
||||
{
|
||||
os << "{" << unsigned(color.alpha) << "," << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "}";
|
||||
os << "{"
|
||||
<< color.alpha << ","
|
||||
<< color.red << ","
|
||||
<< color.green << ","
|
||||
<< color.blue
|
||||
<< "}";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
@@ -20,17 +20,17 @@ struct ColorRgbw
|
||||
uint8_t white;
|
||||
|
||||
/// 'Black' RgbColor (0, 0, 0, 0)
|
||||
static ColorRgbw BLACK;
|
||||
static const ColorRgbw BLACK;
|
||||
/// 'Red' RgbColor (255, 0, 0, 0)
|
||||
static ColorRgbw RED;
|
||||
static const ColorRgbw RED;
|
||||
/// 'Green' RgbColor (0, 255, 0, 0)
|
||||
static ColorRgbw GREEN;
|
||||
static const ColorRgbw GREEN;
|
||||
/// 'Blue' RgbColor (0, 0, 255, 0)
|
||||
static ColorRgbw BLUE;
|
||||
static const ColorRgbw BLUE;
|
||||
/// 'Yellow' RgbColor (255, 255, 0, 0)
|
||||
static ColorRgbw YELLOW;
|
||||
static const ColorRgbw YELLOW;
|
||||
/// 'White' RgbColor (0, 0, 0, 255)
|
||||
static ColorRgbw WHITE;
|
||||
static const ColorRgbw WHITE;
|
||||
};
|
||||
|
||||
/// Assert to ensure that the size of the structure is 'only' 4 bytes
|
||||
@@ -45,19 +45,36 @@ static_assert(sizeof(ColorRgbw) == 4, "Incorrect size of ColorRgbw");
|
||||
///
|
||||
inline std::ostream& operator<<(std::ostream& os, const ColorRgbw& color)
|
||||
{
|
||||
os << "{" << unsigned(color.red) << "," << unsigned(color.green) << "," << unsigned(color.blue) << "," << unsigned(color.white) << "}";
|
||||
os << "{"
|
||||
<< color.red << ","
|
||||
<< color.green << ","
|
||||
<< color.blue << ","
|
||||
<< color.white <<
|
||||
"}";
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
/// Compare operator to check if a color is 'equal' than another color
|
||||
inline bool operator==(const ColorRgbw & lhs, const ColorRgbw & rhs)
|
||||
{
|
||||
return lhs.red == rhs.red &&
|
||||
lhs.green == rhs.green &&
|
||||
lhs.blue == rhs.blue &&
|
||||
lhs.white == rhs.white;
|
||||
}
|
||||
|
||||
/// Compare operator to check if a color is 'smaller' than another color
|
||||
inline bool operator<(const ColorRgbw & lhs, const ColorRgbw & rhs)
|
||||
{
|
||||
return (lhs.red < rhs.red) && (lhs.green < rhs.green) && (lhs.blue < rhs.blue) && (lhs.white < rhs.white);
|
||||
return lhs.red < rhs.red &&
|
||||
lhs.green < rhs.green &&
|
||||
lhs.blue < rhs.blue &&
|
||||
lhs.white < rhs.white;
|
||||
}
|
||||
|
||||
/// Compare operator to check if a color is 'smaller' than or 'equal' to another color
|
||||
inline bool operator<=(const ColorRgbw & lhs, const ColorRgbw & rhs)
|
||||
{
|
||||
return (lhs.red <= rhs.red) && (lhs.green <= rhs.green) && (lhs.blue <= rhs.blue) && (lhs.white < rhs.white);
|
||||
return lhs < rhs || lhs == rhs;
|
||||
}
|
||||
|
@@ -65,4 +65,15 @@ public:
|
||||
/// number and scaled between 0 and 360
|
||||
///
|
||||
static void hsv2rgb(uint16_t hue, uint8_t saturation, uint8_t value, uint8_t & red, uint8_t & green, uint8_t & blue);
|
||||
|
||||
///
|
||||
/// Translates a YUV (luminance, chrominance, chrominance) color to an RGB (red, green, blue) color
|
||||
///
|
||||
/// @param[in] y The luminance YUV-component
|
||||
/// @param[in] u The chrominance YUV-component
|
||||
/// @param[in] v The chrominance YUV-component
|
||||
/// @param[out] red The red RGB-component
|
||||
/// @param[out] green The green RGB-component
|
||||
/// @param[out] blue The blue RGB-component
|
||||
static void yuv2rgb(uint8_t y, uint8_t u, uint8_t v, uint8_t & r, uint8_t & g, uint8_t & b);
|
||||
};
|
||||
|
@@ -20,6 +20,7 @@ public:
|
||||
static GlobalSignals instance;
|
||||
return & instance;
|
||||
}
|
||||
|
||||
private:
|
||||
GlobalSignals() = default;
|
||||
|
||||
|
@@ -12,22 +12,11 @@ public:
|
||||
~ImageResampler();
|
||||
|
||||
void setHorizontalPixelDecimation(int decimator);
|
||||
|
||||
void setVerticalPixelDecimation(int decimator);
|
||||
|
||||
void setCropping(int cropLeft,
|
||||
int cropRight,
|
||||
int cropTop,
|
||||
int cropBottom);
|
||||
|
||||
void setCropping(int cropLeft, int cropRight, int cropTop, int cropBottom);
|
||||
void setVideoMode(VideoMode mode);
|
||||
|
||||
void processImage(const uint8_t * data, int width, int height, int lineLength, PixelFormat pixelFormat, Image<ColorRgb> & outputImage) const;
|
||||
|
||||
private:
|
||||
static inline uint8_t clamp(int x);
|
||||
static void yuv2rgb(uint8_t y, uint8_t u, uint8_t v, uint8_t & r, uint8_t & g, uint8_t & b);
|
||||
|
||||
private:
|
||||
int _horizontalDecimation;
|
||||
int _verticalDecimation;
|
||||
@@ -37,3 +26,4 @@ private:
|
||||
int _cropBottom;
|
||||
VideoMode _videoMode;
|
||||
};
|
||||
|
||||
|
@@ -5,7 +5,7 @@
|
||||
#include <QJsonObject>
|
||||
#include <utils/Logger.h>
|
||||
|
||||
namespace JsonUtils{
|
||||
namespace JsonUtils {
|
||||
///
|
||||
/// @brief read a json file and get the parsed result on success
|
||||
/// @param[in] path The file path to read
|
||||
|
@@ -30,7 +30,6 @@ For more profiler function see the macros listed below
|
||||
#define PROFILER_TIMER_GET(stopWatchName) Profiler::TimerGetTime(stopWatchName, __FILE__, __FUNCTION__, __LINE__);
|
||||
#define PROFILER_TIMER_GET_IF(condition, stopWatchName) { if (condition) {Profiler::TimerGetTime(stopWatchName, __FILE__, __FUNCTION__, __LINE__);} }
|
||||
|
||||
|
||||
class Profiler
|
||||
{
|
||||
public:
|
||||
|
@@ -15,6 +15,6 @@ namespace RGBW {
|
||||
};
|
||||
|
||||
WhiteAlgorithm stringToWhiteAlgorithm(QString str);
|
||||
void Rgb_to_Rgbw(ColorRgb input, ColorRgbw * output, const WhiteAlgorithm algorithm);
|
||||
void Rgb_to_Rgbw(ColorRgb input, ColorRgbw * output, WhiteAlgorithm algorithm);
|
||||
|
||||
}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
|
||||
class SysInfo : public QObject
|
||||
{
|
||||
|
||||
public:
|
||||
struct HyperionSysInfo
|
||||
{
|
||||
|
Reference in New Issue
Block a user