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

@ -87,7 +87,7 @@ if (UNIX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'")
target_link_libraries(${OMNIA_STD_LIB} PUBLIC tinfo boost_regex) target_link_libraries(${OMNIA_STD_LIB} PUBLIC tinfo boost_regex)
target_link_libraries(${OMNIA_GFX_LIB} PUBLIC xcb xcb-randr) target_link_libraries(${OMNIA_GFX_LIB} PUBLIC xcb xcb-randr)
endif (UNIX) endif (UNIX)
target_link_libraries(${OMNIA_GFX_LIB} PUBLIC SDL2main SDL2 SDL2_gfx SDL2_ttf) target_link_libraries(${OMNIA_GFX_LIB} PUBLIC SDL2main SDL2 SDL2_gfx SDL2_ttf)
target_link_libraries(${OMNIA_STD_LIB} PUBLIC ssl crypto) target_link_libraries(${OMNIA_STD_LIB} PUBLIC ssl crypto)
#----------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------

View file

@ -1 +1 @@
1879 1880

View file

@ -181,16 +181,26 @@ namespace ostd
return rgb; return rgb;
} }
uint32_t Color::asInteger(void) const uint32_t Color::asInteger(eColorFormat format) const
{ {
union uC32 { union uC32 {
uint8_t data[4]; uint8_t data[4];
uint32_t value; uint32_t value;
} c32_u; } c32_u;
c32_u.data[0] = a; if (format == eColorFormat::RGBA)
c32_u.data[1] = b; {
c32_u.data[2] = g; c32_u.data[0] = a;
c32_u.data[3] = r; 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; 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) { } 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: public:
Color(void); Color(void);
Color(uint8_t rgb_single_value, uint8_t alpha = 255); 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 hexString(bool include_alpha = false, String prefix = "0x") const;
String rgbString(bool include_parenthesis = true, bool include_alpha = false) 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; FloatCol getNormalizedColor(void) const;
String toString(void) const override; String toString(void) const override;