[Libreoffice-commits] core.git: include/tools tools/qa

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Tue Apr 20 12:19:28 UTC 2021


 include/tools/color.hxx         |    4 ++--
 tools/qa/cppunit/test_color.cxx |   14 ++++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

New commits:
commit 17e9789f6c0b676484609b61e3abbebca8c93f88
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Mon Apr 19 16:25:58 2021 +0200
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Tue Apr 20 14:18:42 2021 +0200

    reduce copy pasta with Color::GetLuminance()
    
    Change-Id: I2eda3607a3be6ee56f0a9ddd14131be783b9698a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114294
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/include/tools/color.hxx b/include/tools/color.hxx
index 59ac4381de03..4770efee7b0a 100644
--- a/include/tools/color.hxx
+++ b/include/tools/color.hxx
@@ -311,7 +311,7 @@ public:
       */
     bool IsDark() const
     {
-        return sal_uInt8((B * 29UL + G * 151UL + R * 76UL) >> 8) <= 60;
+        return GetLuminance() <= 60;
     }
 
     /** Comparison with luminance thresholds.
@@ -319,7 +319,7 @@ public:
       */
     bool IsBright() const
     {
-        return sal_uInt8((B * 29UL + G * 151UL + R * 76UL) >> 8) >= 245;
+        return GetLuminance() >= 245;
     }
 
     /* Color filters */
diff --git a/tools/qa/cppunit/test_color.cxx b/tools/qa/cppunit/test_color.cxx
index 05616b8f64a2..f3ffd9c692cd 100644
--- a/tools/qa/cppunit/test_color.cxx
+++ b/tools/qa/cppunit/test_color.cxx
@@ -25,6 +25,7 @@ public:
     void testGetColorError();
     void testInvert();
     void testBColor();
+    void testLuminance();
 
     CPPUNIT_TEST_SUITE(Test);
     CPPUNIT_TEST(testVariables);
@@ -33,6 +34,7 @@ public:
     CPPUNIT_TEST(testGetColorError);
     CPPUNIT_TEST(testInvert);
     CPPUNIT_TEST(testBColor);
+    CPPUNIT_TEST(testLuminance);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -218,6 +220,18 @@ void Test::testBColor()
 
 }
 
+void Test::testLuminance()
+{
+    CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), COL_BLACK.GetLuminance());
+    CPPUNIT_ASSERT_EQUAL(sal_uInt8(255), COL_WHITE.GetLuminance());
+    CPPUNIT_ASSERT_EQUAL(sal_uInt8(128), Color(128, 128, 128).GetLuminance());
+    CPPUNIT_ASSERT(COL_WHITE.IsBright());
+    CPPUNIT_ASSERT(COL_BLACK.IsDark());
+    CPPUNIT_ASSERT(Color(249, 250, 251).IsBright());
+    CPPUNIT_ASSERT(Color(9, 10, 11).IsDark());
+    CPPUNIT_ASSERT(COL_WHITE.GetLuminance() > COL_BLACK.GetLuminance());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 }


More information about the Libreoffice-commits mailing list