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

Jan-Marek Glogowski (via logerrit) logerrit at kemper.freedesktop.org
Tue May 14 01:21:40 UTC 2019


 include/tools/color.hxx         |   10 +++++++++-
 include/vcl/BitmapColor.hxx     |   11 -----------
 tools/qa/cppunit/test_color.cxx |   20 ++++++++++----------
 tools/source/generic/color.cxx  |    9 ---------
 vcl/source/window/decoview.cxx  |    8 ++++----
 5 files changed, 23 insertions(+), 35 deletions(-)

New commits:
commit d14d1341f2b0cd62098425b36438ae20b887fe93
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Mon May 13 14:00:10 2019 +0000
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Tue May 14 03:20:50 2019 +0200

    Switch everyone to stricter GetColorError
    
    This replaces the variant in Color with the stricter one of
    BitmapColor. I couldn't find any reasoning for the lazy variant
    used in Color.
    
    Change-Id: I6dab3ab94a7f24ef5e80299d64267e3be8df888c
    Reviewed-on: https://gerrit.libreoffice.org/72234
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/tools/color.hxx b/include/tools/color.hxx
index ed8b8813afee..fa62f28f362b 100644
--- a/include/tools/color.hxx
+++ b/include/tools/color.hxx
@@ -126,7 +126,7 @@ public:
         return color::extractRGB(mValue);
     }
 
-    sal_uInt8 GetColorError(const Color& rCompareColor) const;
+    sal_uInt16 GetColorError(const Color& rCompareColor) const;
 
     sal_uInt8 GetLuminance() const;
     void IncreaseLuminance(sal_uInt8 cLumInc);
@@ -224,6 +224,14 @@ inline void Color::Invert()
     B = ~B;
 }
 
+inline sal_uInt16 Color::GetColorError( const Color& rColor ) const
+{
+    return static_cast<sal_uInt16>(
+        abs(static_cast<int>(GetBlue()) - rColor.GetBlue()) +
+        abs(static_cast<int>(GetGreen()) - rColor.GetGreen()) +
+        abs(static_cast<int>(GetRed()) - rColor.GetRed()));
+}
+
 inline void Color::Merge( const Color& rMergeColor, sal_uInt8 cTransparency )
 {
     R = ColorChannelMerge(R, rMergeColor.R, cTransparency);
diff --git a/include/vcl/BitmapColor.hxx b/include/vcl/BitmapColor.hxx
index 4344a7bd242f..f6e1751a3be5 100644
--- a/include/vcl/BitmapColor.hxx
+++ b/include/vcl/BitmapColor.hxx
@@ -22,7 +22,6 @@
 
 #include <vcl/dllapi.h>
 #include <tools/color.hxx>
-#include <cassert>
 #include <memory>
 
 class VCL_DLLPUBLIC BitmapColor final : public Color
@@ -39,8 +38,6 @@ public:
 
     inline sal_uInt8    GetAlpha() const;
     inline void         SetAlpha( sal_uInt8 cAlpha );
-
-    inline sal_uInt16 GetColorError( const BitmapColor& rColor ) const;
 };
 
 inline BitmapColor::BitmapColor()
@@ -82,14 +79,6 @@ inline void BitmapColor::SetAlpha( sal_uInt8 cAlpha )
     SetTransparency(cAlpha);
 }
 
-inline sal_uInt16 BitmapColor::GetColorError( const BitmapColor& rColor ) const
-{
-    return static_cast<sal_uInt16>(
-        abs( static_cast<int>(GetBlue()) - static_cast<int>(rColor.GetBlue()) ) +
-        abs( static_cast<int>(GetGreen()) - static_cast<int>(rColor.GetGreen()) ) +
-        abs( static_cast<int>(GetRed()) - static_cast<int>(rColor.GetRed()) ) );
-}
-
 #endif // INCLUDED_VCL_BITMAPCOLOR_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/tools/qa/cppunit/test_color.cxx b/tools/qa/cppunit/test_color.cxx
index 9c2a4d9c7049..5bec65027b94 100644
--- a/tools/qa/cppunit/test_color.cxx
+++ b/tools/qa/cppunit/test_color.cxx
@@ -163,19 +163,19 @@ void Test::test_ApplyTintOrShade()
 
 void Test::testGetColorError()
 {
-    CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), Color(0xAA, 0xBB, 0xCC).GetColorError(Color(0xAA, 0xBB, 0xCC)));
+    CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), Color(0xAA, 0xBB, 0xCC).GetColorError(Color(0xAA, 0xBB, 0xCC)));
 
-    CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA1, 0xB0, 0xC0)));
-    CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA0, 0xB1, 0xC0)));
-    CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA0, 0xB0, 0xC1)));
+    CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA1, 0xB0, 0xC0)));
+    CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA0, 0xB1, 0xC0)));
+    CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA0, 0xB0, 0xC1)));
 
-    CPPUNIT_ASSERT_EQUAL(sal_uInt8(1), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA1, 0xB1, 0xC0)));
-    CPPUNIT_ASSERT_EQUAL(sal_uInt8(1), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA0, 0xB1, 0xC1)));
-    CPPUNIT_ASSERT_EQUAL(sal_uInt8(1), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA1, 0xB0, 0xC1)));
+    CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA1, 0xB1, 0xC0)));
+    CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA0, 0xB1, 0xC1)));
+    CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA1, 0xB0, 0xC1)));
 
-    CPPUNIT_ASSERT_EQUAL(sal_uInt8(1), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA1, 0xB1, 0xC1)));
-    CPPUNIT_ASSERT_EQUAL(sal_uInt8(1), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA1, 0xB1, 0xC1)));
-    CPPUNIT_ASSERT_EQUAL(sal_uInt8(1), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA1, 0xB1, 0xC1)));
+    CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA1, 0xB1, 0xC1)));
+    CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA1, 0xB1, 0xC1)));
+    CPPUNIT_ASSERT_EQUAL(sal_uInt16(3), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA1, 0xB1, 0xC1)));
 }
 
 void Test::testInvert()
diff --git a/tools/source/generic/color.cxx b/tools/source/generic/color.cxx
index 4640ef85f290..061435ed61c9 100644
--- a/tools/source/generic/color.cxx
+++ b/tools/source/generic/color.cxx
@@ -28,15 +28,6 @@
 #include <tools/helpers.hxx>
 #include <basegfx/color/bcolortools.hxx>
 
-sal_uInt8 Color::GetColorError( const Color& rCompareColor ) const
-{
-    const long nErrAbs = labs(long(rCompareColor.R) - R) +
-                         labs(long(rCompareColor.G) - G) +
-                         labs(long(rCompareColor.B) - B);
-
-    return sal_uInt8(FRound(double(nErrAbs) / 3.0));
-}
-
 void Color::IncreaseLuminance(sal_uInt8 cLumInc)
 {
     R = sal_uInt8(std::clamp(long(R) + cLumInc, 0L, 255L));
diff --git a/vcl/source/window/decoview.cxx b/vcl/source/window/decoview.cxx
index 939ed22f237e..9111f74027f6 100644
--- a/vcl/source/window/decoview.cxx
+++ b/vcl/source/window/decoview.cxx
@@ -882,15 +882,15 @@ void DecorationView::DrawHighlightFrame( const tools::Rectangle& rRect,
         else
         {
             Color aBackColor = aBackground.GetColor();
-            if ( (aLightColor.GetColorError( aBackColor ) < 32) ||
-                 (aShadowColor.GetColorError( aBackColor ) < 32) )
+            if ( (aLightColor.GetColorError( aBackColor ) < 96) ||
+                 (aShadowColor.GetColorError( aBackColor ) < 96) )
             {
                 aLightColor = COL_WHITE;
                 aShadowColor = COL_BLACK;
 
-                if ( aLightColor.GetColorError( aBackColor ) < 32 )
+                if ( aLightColor.GetColorError( aBackColor ) < 96 )
                     aLightColor.DecreaseLuminance( 64 );
-                if ( aShadowColor.GetColorError( aBackColor ) < 32 )
+                if ( aShadowColor.GetColorError( aBackColor ) < 96 )
                     aShadowColor.IncreaseLuminance( 64 );
             }
         }


More information about the Libreoffice-commits mailing list