[core] Fix alpha handling in rgba and to-rgba operators
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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) + ")";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user