diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-07-26 10:48:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-26 10:48:47 +0200 |
commit | 47a7dc7b3c935e3b764f1b32fea50ff3b6d7edc3 (patch) | |
tree | 27d0ba4b69492017a5570b3b366355a4dc901984 /core | |
parent | 5c8919aac6877f49f8a113557b2e87422eda72c9 (diff) | |
parent | 55d976467da4d2ff580240a62ba3e031314fe8ea (diff) |
Merge pull request #18282 from aaronfranke/better-mathf
[Core] [Mono] Fix Color missing int export methods, added 64-bit
Diffstat (limited to 'core')
-rw-r--r-- | core/color.cpp | 53 | ||||
-rw-r--r-- | core/color.h | 4 | ||||
-rw-r--r-- | core/variant_call.cpp | 12 |
3 files changed, 67 insertions, 2 deletions
diff --git a/core/color.cpp b/core/color.cpp index 88e57ec6e2..fcfcf20355 100644 --- a/core/color.cpp +++ b/core/color.cpp @@ -49,6 +49,7 @@ uint32_t Color::to_argb32() const { } uint32_t Color::to_abgr32() const { + uint32_t c = (uint8_t)Math::round(a * 255); c <<= 8; c |= (uint8_t)Math::round(b * 255); @@ -73,6 +74,45 @@ uint32_t Color::to_rgba32() const { return c; } +uint64_t Color::to_abgr64() const { + + uint64_t c = (uint16_t)Math::round(a * 65535); + c <<= 16; + c |= (uint16_t)Math::round(b * 65535); + c <<= 16; + c |= (uint16_t)Math::round(g * 65535); + c <<= 16; + c |= (uint16_t)Math::round(r * 65535); + + return c; +} + +uint64_t Color::to_argb64() const { + + uint64_t c = (uint16_t)Math::round(a * 65535); + c <<= 16; + c |= (uint16_t)Math::round(r * 65535); + c <<= 16; + c |= (uint16_t)Math::round(g * 65535); + c <<= 16; + c |= (uint16_t)Math::round(b * 65535); + + return c; +} + +uint64_t Color::to_rgba64() const { + + uint64_t c = (uint16_t)Math::round(r * 65535); + c <<= 16; + c |= (uint16_t)Math::round(g * 65535); + c <<= 16; + c |= (uint16_t)Math::round(b * 65535); + c <<= 16; + c |= (uint16_t)Math::round(a * 65535); + + return c; +} + float Color::get_h() const { float min = MIN(r, g); @@ -200,6 +240,19 @@ Color Color::hex(uint32_t p_hex) { return Color(r, g, b, a); } +Color Color::hex64(uint64_t p_hex) { + + float a = (p_hex & 0xFFFF) / 65535.0; + p_hex >>= 16; + float b = (p_hex & 0xFFFF) / 65535.0; + p_hex >>= 16; + float g = (p_hex & 0xFFFF) / 65535.0; + p_hex >>= 16; + float r = (p_hex & 0xFFFF) / 65535.0; + + return Color(r, g, b, a); +} + static float _parse_col(const String &p_str, int p_ofs) { int ig = 0; diff --git a/core/color.h b/core/color.h index a2015a34d6..c0516e55fe 100644 --- a/core/color.h +++ b/core/color.h @@ -55,6 +55,9 @@ struct Color { uint32_t to_rgba32() const; uint32_t to_argb32() const; uint32_t to_abgr32() const; + uint64_t to_rgba64() const; + uint64_t to_argb64() const; + uint64_t to_abgr64() const; float gray() const; float get_h() const; float get_s() const; @@ -186,6 +189,7 @@ struct Color { } static Color hex(uint32_t p_hex); + static Color hex64(uint64_t p_hex); static Color html(const String &p_color); static bool html_is_valid(const String &p_color); static Color named(const String &p_name); diff --git a/core/variant_call.cpp b/core/variant_call.cpp index c150ea9c00..20a2929dc0 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -446,8 +446,12 @@ struct _VariantCall { VCALL_LOCALMEM1(Quat, set_euler); VCALL_LOCALMEM2(Quat, set_axis_angle); - VCALL_LOCALMEM0R(Color, to_rgba32); VCALL_LOCALMEM0R(Color, to_argb32); + VCALL_LOCALMEM0R(Color, to_abgr32); + VCALL_LOCALMEM0R(Color, to_rgba32); + VCALL_LOCALMEM0R(Color, to_argb64); + VCALL_LOCALMEM0R(Color, to_abgr64); + VCALL_LOCALMEM0R(Color, to_rgba64); VCALL_LOCALMEM0R(Color, gray); VCALL_LOCALMEM0R(Color, inverted); VCALL_LOCALMEM0R(Color, contrasted); @@ -1613,8 +1617,12 @@ void register_variant_methods() { ADDFUNC1(QUAT, NIL, Quat, set_euler, VECTOR3, "euler", varray()); ADDFUNC2(QUAT, NIL, Quat, set_axis_angle, VECTOR3, "axis", REAL, "angle", varray()); - ADDFUNC0R(COLOR, INT, Color, to_rgba32, varray()); ADDFUNC0R(COLOR, INT, Color, to_argb32, varray()); + ADDFUNC0R(COLOR, INT, Color, to_abgr32, varray()); + ADDFUNC0R(COLOR, INT, Color, to_rgba32, varray()); + ADDFUNC0R(COLOR, INT, Color, to_argb64, varray()); + ADDFUNC0R(COLOR, INT, Color, to_abgr64, varray()); + ADDFUNC0R(COLOR, INT, Color, to_rgba64, varray()); ADDFUNC0R(COLOR, REAL, Color, gray, varray()); ADDFUNC0R(COLOR, COLOR, Color, inverted, varray()); ADDFUNC0R(COLOR, COLOR, Color, contrasted, varray()); |