diff --git a/Tests/LibGfx/CMakeLists.txt b/Tests/LibGfx/CMakeLists.txt index f9582f16f0f..b0705db1665 100644 --- a/Tests/LibGfx/CMakeLists.txt +++ b/Tests/LibGfx/CMakeLists.txt @@ -1,6 +1,7 @@ set(TEST_SOURCES BenchmarkGfxPainter.cpp BenchmarkJPEGLoader.cpp + TestColor.cpp TestDeltaE.cpp TestFontHandling.cpp TestGfxBitmap.cpp diff --git a/Tests/LibGfx/TestColor.cpp b/Tests/LibGfx/TestColor.cpp new file mode 100644 index 00000000000..e300d5beaa7 --- /dev/null +++ b/Tests/LibGfx/TestColor.cpp @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024, Lucas Chollet + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +TEST_CASE(color) +{ + for (u16 i = 0; i < 256; ++i) { + auto const gray = Color(i, i, i); + EXPECT_EQ(gray, gray.to_grayscale()); + } +} diff --git a/Userland/Libraries/LibGfx/Color.h b/Userland/Libraries/LibGfx/Color.h index 60e1a136fc6..853387b6f25 100644 --- a/Userland/Libraries/LibGfx/Color.h +++ b/Userland/Libraries/LibGfx/Color.h @@ -316,7 +316,7 @@ public: constexpr u8 luminosity() const { - return (red() * 0.2126f + green() * 0.7152f + blue() * 0.0722f); + return round_to(red() * 0.2126f + green() * 0.7152f + blue() * 0.0722f); } constexpr float contrast_ratio(Color other)