summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-01-08 12:30:15 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2018-01-09 16:46:52 -0800
commite887cda986218ae84317b3ecb5ba81d9b9bb776f (patch)
tree810e31367ba53e8bf0f54600cce662f383005199
parenta4ab4f68e2d2b927dea139b1945f8810ab215a9e (diff)
downloadqtlocation-mapboxgl-e887cda986218ae84317b3ecb5ba81d9b9bb776f.tar.gz
[core] Fix alpha handling in rgba and to-rgba operators
-rw-r--r--platform/node/test/ignores.json3
-rw-r--r--src/mbgl/style/expression/compound_expression.cpp7
-rw-r--r--src/mbgl/style/expression/util.cpp4
-rw-r--r--src/mbgl/util/color.cpp6
4 files changed, 10 insertions, 10 deletions
diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json
index bde950ca9c..06c4d4885d 100644
--- a/platform/node/test/ignores.json
+++ b/platform/node/test/ignores.json
@@ -1,8 +1,5 @@
{
"expression-tests/coalesce/inference": "https://github.com/mapbox/mapbox-gl-native/issues/10588",
- "expression-tests/interpolate/linear-color": "https://github.com/mapbox/mapbox-gl-native/issues/10604",
- "expression-tests/to-rgba/alpha": "https://github.com/mapbox/mapbox-gl-native/issues/10604",
- "expression-tests/to-rgba/basic": "https://github.com/mapbox/mapbox-gl-native/issues/10604",
"query-tests/circle-stroke-width/inside": "https://github.com/mapbox/mapbox-gl-native/issues/10307",
"query-tests/geometry/multilinestring": "needs investigation",
"query-tests/geometry/multipolygon": "needs investigation",
diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp
index ff21157faa..42cb655024 100644
--- a/src/mbgl/style/expression/compound_expression.cpp
+++ b/src/mbgl/style/expression/compound_expression.cpp
@@ -210,7 +210,12 @@ std::unordered_map<std::string, CompoundExpressionRegistry::Definition> initiali
);
});
define("to-rgba", [](const Color& color) -> Result<std::array<double, 4>> {
- return std::array<double, 4> {{ color.r, color.g, color.b, color.a }};
+ return std::array<double, 4> {{
+ 255 * color.r / color.a,
+ 255 * color.g / color.a,
+ 255 * color.b / color.a,
+ color.a
+ }};
});
define("rgba", rgba);
diff --git a/src/mbgl/style/expression/util.cpp b/src/mbgl/style/expression/util.cpp
index f198fb3e1b..ee680dab08 100644
--- a/src/mbgl/style/expression/util.cpp
+++ b/src/mbgl/style/expression/util.cpp
@@ -1,4 +1,3 @@
-
#include <mbgl/style/expression/util.hpp>
#include <mbgl/style/expression/value.hpp>
@@ -30,10 +29,9 @@ Result<Color> rgba(double r, double g, double b, double a) {
"]: 'a' must be between 0 and 1."
};
}
- return Color(r / 255, g / 255, b / 255, a);
+ return Color(r / 255 * a, g / 255 * a, b / 255 * a, a);
}
} // namespace expression
} // namespace style
} // namespace mbgl
-
diff --git a/src/mbgl/util/color.cpp b/src/mbgl/util/color.cpp
index fcb7f4ec16..c8145d36e7 100644
--- a/src/mbgl/util/color.cpp
+++ b/src/mbgl/util/color.cpp
@@ -24,9 +24,9 @@ optional<Color> Color::parse(const std::string& s) {
std::string Color::stringify() const {
return "rgba(" +
- util::toString(r * 255) + "," +
- util::toString(g * 255) + "," +
- util::toString(b * 255) + "," +
+ util::toString(r * 255 / a) + "," +
+ util::toString(g * 255 / a) + "," +
+ util::toString(b * 255 / a) + "," +
util::toString(a) + ")";
}