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-08 12:43:03 -0800
commitf108066ce8ffa4a56b0e76092e58af5f4640b93d (patch)
tree7956f4c8265850da47f5cea6ffc7377d7621504a
parentdcd7019e7deeff1cb2a7bcaa7748d0f80461a190 (diff)
downloadqtlocation-mapboxgl-upstream/fix-10604.tar.gz
[core] Fix alpha handling in rgba and to-rgba operatorsupstream/fix-10604
-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 62e042cd4d..ebc059833f 100644
--- a/platform/node/test/ignores.json
+++ b/platform/node/test/ignores.json
@@ -16,9 +16,6 @@
"expression-tests/not_equal/number": "https://github.com/mapbox/mapbox-gl-native/issues/10678",
"expression-tests/not_equal/string": "https://github.com/mapbox/mapbox-gl-native/issues/10678",
"expression-tests/not_equal/value": "https://github.com/mapbox/mapbox-gl-native/issues/10678",
- "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 70bc6dfd95..e5f849144b 100644
--- a/src/mbgl/style/expression/compound_expression.cpp
+++ b/src/mbgl/style/expression/compound_expression.cpp
@@ -216,7 +216,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) + ")";
}