Browse Source

Added Color::ToUIntArgb() for converting colors to format profiler expects

Rokas Kupstys 8 years ago
parent
commit
d24c4882b0
2 changed files with 19 additions and 0 deletions
  1. 12 0
      Source/Atomic/Math/Color.cpp
  2. 7 0
      Source/Atomic/Math/Color.h

+ 12 - 0
Source/Atomic/Math/Color.cpp

@@ -331,6 +331,17 @@ void Color::FromHCM(float h, float c, float m)
     b_ += m;
 }
 
+/// ATOMIC BEGIN
+unsigned Color::ToUIntArgb() const
+{
+    unsigned r = (unsigned)Clamp(((int)(r_ * 255.0f)), 0, 255);
+    unsigned g = (unsigned)Clamp(((int)(g_ * 255.0f)), 0, 255);
+    unsigned b = (unsigned)Clamp(((int)(b_ * 255.0f)), 0, 255);
+    unsigned a = (unsigned)Clamp(((int)(a_ * 255.0f)), 0, 255);
+    return (a << 24) | (r << 16) | (g << 8) | b;
+}
+/// ATOMIC END
+
 
 const Color Color::WHITE;
 const Color Color::GRAY(0.5f, 0.5f, 0.5f);
@@ -342,4 +353,5 @@ const Color Color::CYAN(0.0f, 1.0f, 1.0f);
 const Color Color::MAGENTA(1.0f, 0.0f, 1.0f);
 const Color Color::YELLOW(1.0f, 1.0f, 0.0f);
 const Color Color::TRANSPARENT(0.0f, 0.0f, 0.0f, 0.0f);
+
 }

+ 7 - 0
Source/Atomic/Math/Color.h

@@ -200,6 +200,13 @@ public:
     /// Return as string.
     String ToString() const;
 
+    // ATOMIC BEGIN
+
+    /// Return color packed to a 32-bit integer, with B component in the lowest 8 bits. Components are clamped to [0, 1] range.
+    unsigned ToUIntArgb() const;
+
+    // ATOMIC END
+
     /// Red value.
     float r_;
     /// Green value.