summaryrefslogtreecommitdiff
path: root/src/mbgl/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/util')
-rw-r--r--src/mbgl/util/color.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/mbgl/util/color.cpp b/src/mbgl/util/color.cpp
new file mode 100644
index 0000000000..eea897d3ab
--- /dev/null
+++ b/src/mbgl/util/color.cpp
@@ -0,0 +1,20 @@
+#include <mbgl/util/color.hpp>
+
+#include <csscolorparser/csscolorparser.hpp>
+
+namespace mbgl {
+
+optional<Color> Color::parse(const std::string& s) {
+ CSSColorParser::Color css_color = CSSColorParser::parse(s);
+
+ // Premultiply the color.
+ const float factor = css_color.a / 255;
+ return {{
+ css_color.r * factor,
+ css_color.g * factor,
+ css_color.b * factor,
+ css_color.a
+ }};
+}
+
+} // namespace mbgl