Added color mode parameter to ostd::Color::asInteger()

This commit is contained in:
OmniaX 2024-09-15 08:52:53 +02:00
parent f92b90ae9a
commit a622db4b1a
4 changed files with 20 additions and 8 deletions

View file

@ -1 +1 @@
1879
1880

View file

@ -181,16 +181,26 @@ namespace ostd
return rgb;
}
uint32_t Color::asInteger(void) const
uint32_t Color::asInteger(eColorFormat format) const
{
union uC32 {
uint8_t data[4];
uint32_t value;
} c32_u;
if (format == eColorFormat::RGBA)
{
c32_u.data[0] = a;
c32_u.data[1] = b;
c32_u.data[2] = g;
c32_u.data[3] = r;
}
else if (format == eColorFormat::ARGB)
{
c32_u.data[0] = r;
c32_u.data[1] = g;
c32_u.data[2] = b;
c32_u.data[3] = a;
}
return c32_u.value;
}

View file

@ -21,6 +21,8 @@ namespace ostd
FloatCol(float _r, float _g, float _b, float _a) : r(_r), g(_g), b(_b), a(_a) { }
};
public: enum class eColorFormat { RGBA = 0, ARGB };
public:
Color(void);
Color(uint8_t rgb_single_value, uint8_t alpha = 255);
@ -41,7 +43,7 @@ namespace ostd
String hexString(bool include_alpha = false, String prefix = "0x") const;
String rgbString(bool include_parenthesis = true, bool include_alpha = false) const;
uint32_t asInteger(void) const;
uint32_t asInteger(eColorFormat format = eColorFormat::RGBA) const;
FloatCol getNormalizedColor(void) const;
String toString(void) const override;