forked from firka/flutter
Add Color::MakeRGBA8 (flutter/engine#36200)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user