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@gmail.com>
This commit is contained in:
committed by
Tomaž Vajngerl
parent
0a3f9a7e11
commit
d14d1341f2
@@ -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);
|
||||
|
||||
@@ -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: */
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user