Kaydet (Commit) d14d1341 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski Kaydeden (comit) Tomaž Vajngerl

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: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst 0a3f9a7e
...@@ -126,7 +126,7 @@ public: ...@@ -126,7 +126,7 @@ public:
return color::extractRGB(mValue); return color::extractRGB(mValue);
} }
sal_uInt8 GetColorError(const Color& rCompareColor) const; sal_uInt16 GetColorError(const Color& rCompareColor) const;
sal_uInt8 GetLuminance() const; sal_uInt8 GetLuminance() const;
void IncreaseLuminance(sal_uInt8 cLumInc); void IncreaseLuminance(sal_uInt8 cLumInc);
...@@ -224,6 +224,14 @@ inline void Color::Invert() ...@@ -224,6 +224,14 @@ inline void Color::Invert()
B = ~B; 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 ) inline void Color::Merge( const Color& rMergeColor, sal_uInt8 cTransparency )
{ {
R = ColorChannelMerge(R, rMergeColor.R, cTransparency); R = ColorChannelMerge(R, rMergeColor.R, cTransparency);
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include <vcl/dllapi.h> #include <vcl/dllapi.h>
#include <tools/color.hxx> #include <tools/color.hxx>
#include <cassert>
#include <memory> #include <memory>
class VCL_DLLPUBLIC BitmapColor final : public Color class VCL_DLLPUBLIC BitmapColor final : public Color
...@@ -39,8 +38,6 @@ public: ...@@ -39,8 +38,6 @@ public:
inline sal_uInt8 GetAlpha() const; inline sal_uInt8 GetAlpha() const;
inline void SetAlpha( sal_uInt8 cAlpha ); inline void SetAlpha( sal_uInt8 cAlpha );
inline sal_uInt16 GetColorError( const BitmapColor& rColor ) const;
}; };
inline BitmapColor::BitmapColor() inline BitmapColor::BitmapColor()
...@@ -82,14 +79,6 @@ inline void BitmapColor::SetAlpha( sal_uInt8 cAlpha ) ...@@ -82,14 +79,6 @@ inline void BitmapColor::SetAlpha( sal_uInt8 cAlpha )
SetTransparency(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 #endif // INCLUDED_VCL_BITMAPCOLOR_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -163,19 +163,19 @@ void Test::test_ApplyTintOrShade() ...@@ -163,19 +163,19 @@ void Test::test_ApplyTintOrShade()
void Test::testGetColorError() 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_uInt16(1), 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_uInt16(1), 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(0xA0, 0xB0, 0xC1)));
CPPUNIT_ASSERT_EQUAL(sal_uInt8(1), Color(0xA0, 0xB0, 0xC0).GetColorError(Color(0xA1, 0xB1, 0xC0))); CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), 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_uInt16(2), 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, 0xB0, 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_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_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)));
} }
void Test::testInvert() void Test::testInvert()
......
...@@ -28,15 +28,6 @@ ...@@ -28,15 +28,6 @@
#include <tools/helpers.hxx> #include <tools/helpers.hxx>
#include <basegfx/color/bcolortools.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) void Color::IncreaseLuminance(sal_uInt8 cLumInc)
{ {
R = sal_uInt8(std::clamp(long(R) + cLumInc, 0L, 255L)); R = sal_uInt8(std::clamp(long(R) + cLumInc, 0L, 255L));
......
...@@ -882,15 +882,15 @@ void DecorationView::DrawHighlightFrame( const tools::Rectangle& rRect, ...@@ -882,15 +882,15 @@ void DecorationView::DrawHighlightFrame( const tools::Rectangle& rRect,
else else
{ {
Color aBackColor = aBackground.GetColor(); Color aBackColor = aBackground.GetColor();
if ( (aLightColor.GetColorError( aBackColor ) < 32) || if ( (aLightColor.GetColorError( aBackColor ) < 96) ||
(aShadowColor.GetColorError( aBackColor ) < 32) ) (aShadowColor.GetColorError( aBackColor ) < 96) )
{ {
aLightColor = COL_WHITE; aLightColor = COL_WHITE;
aShadowColor = COL_BLACK; aShadowColor = COL_BLACK;
if ( aLightColor.GetColorError( aBackColor ) < 32 ) if ( aLightColor.GetColorError( aBackColor ) < 96 )
aLightColor.DecreaseLuminance( 64 ); aLightColor.DecreaseLuminance( 64 );
if ( aShadowColor.GetColorError( aBackColor ) < 32 ) if ( aShadowColor.GetColorError( aBackColor ) < 96 )
aShadowColor.IncreaseLuminance( 64 ); aShadowColor.IncreaseLuminance( 64 );
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment