Bläddra i källkod

[Core] 64-bit int Color methods

Aaron Franke 7 år sedan
förälder
incheckning
de4b096898
2 ändrade filer med 57 tillägg och 0 borttagningar
  1. 53 0
      core/color.cpp
  2. 4 0
      core/color.h

+ 53 - 0
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;

+ 4 - 0
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);