Add Color::MakeRGBA8 (flutter/engine#36200)

This commit is contained in:
Brandon DeRosier
2022-09-16 11:40:22 -07:00
committed by GitHub
parent 1aab774fb0
commit 56369e8182
2 changed files with 26 additions and 1 deletions

View File

@@ -41,11 +41,16 @@ struct Color {
constexpr Color() {}
Color(const ColorHSB& hsbColor);
explicit Color(const ColorHSB& hsbColor);
constexpr Color(Scalar r, Scalar g, Scalar b, Scalar a)
: red(r), green(g), blue(b), alpha(a) {}
static constexpr Color MakeRGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
return Color(static_cast<Scalar>(r) / 255, static_cast<Scalar>(g) / 255,
static_cast<Scalar>(b) / 255, static_cast<Scalar>(a) / 255);
}
constexpr bool operator==(const Color& c) const {
return red == c.red && green == c.green && blue == c.blue &&
alpha == c.alpha;

View File

@@ -964,6 +964,26 @@ TEST(GeometryTest, ColorLerp) {
}
}
TEST(GeometryTest, ColorMakeRGBA8) {
{
Color a = Color::MakeRGBA8(0, 0, 0, 0);
Color b = Color::BlackTransparent();
ASSERT_COLOR_NEAR(a, b);
}
{
Color a = Color::MakeRGBA8(255, 255, 255, 255);
Color b = Color::White();
ASSERT_COLOR_NEAR(a, b);
}
{
Color a = Color::MakeRGBA8(63, 127, 191, 127);
Color b(0.247059, 0.498039, 0.74902, 0.498039);
ASSERT_COLOR_NEAR(a, b);
}
}
TEST(GeometryTest, CanConvertBetweenDegressAndRadians) {
{
auto deg = Degrees{90.0};