ladybird/Tests/LibGfx/TestColor.cpp
Lucas CHOLLET ff2c6cab55 LibGfx: Correctly round values when computing the luminosity of a Color
Truncating the value is mathematically incorrect, this error made the
conversion to grayscale unstable. In other world, calling `to_grayscale`
on a gray value would return a different value. As an example,
`Color::from_string("#686868ff"sv).to_grayscale()` used to return
#676767ff.
2024-05-13 23:43:58 +02:00

16 lines
328 B
C++

/*
* Copyright (c) 2024, Lucas Chollet <lucas.chollet@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibGfx/Color.h>
#include <LibTest/TestCase.h>
TEST_CASE(color)
{
for (u16 i = 0; i < 256; ++i) {
auto const gray = Color(i, i, i);
EXPECT_EQ(gray, gray.to_grayscale());
}
}