summaryrefslogtreecommitdiff
path: root/tools/source/generic/color.cxx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-05-27 12:20:49 +0900
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2015-08-27 08:30:49 +0900
commita0ab7c31a254285856f6520d069570647c56af22 (patch)
tree94e9145f5a36c0341cd7cf71975a420d4f0736b5 /tools/source/generic/color.cxx
parentbba73f9e0f286f48fe02f7e232c53de79fc5f12c (diff)
Again add ability to change tint/shade of a color + unit test
Change-Id: I4c06290f09e5bfecd2c1de896e19cb5036a3a0e9
Diffstat (limited to 'tools/source/generic/color.cxx')
-rw-r--r--tools/source/generic/color.cxx26
1 files changed, 26 insertions, 0 deletions
diff --git a/tools/source/generic/color.cxx b/tools/source/generic/color.cxx
index 07fdd00fd7c4..4ab32d471ea1 100644
--- a/tools/source/generic/color.cxx
+++ b/tools/source/generic/color.cxx
@@ -312,6 +312,32 @@ SvStream& ReadColor( SvStream& rIStream, Color& rColor )
return rIStream;
}
+void Color::ApplyTintOrShade(sal_Int16 n100thPercent)
+{
+ if (n100thPercent == 0)
+ return;
+
+ basegfx::BColor aBColor = basegfx::tools::rgb2hsl(getBColor());
+ double fFactor = 1.0 - (std::abs(double(n100thPercent)) / 10000.0);
+ double fResult;
+
+ if (n100thPercent > 0) // tint
+ {
+ fResult = aBColor.getBlue() * fFactor + (1.0 - fFactor);
+ }
+ else if (n100thPercent < 0) // shade
+ {
+ fResult = aBColor.getBlue() * fFactor;
+ }
+
+ aBColor.setBlue(fResult);
+ aBColor = basegfx::tools::hsl2rgb(aBColor);
+
+ SetRed(sal_uInt8(( aBColor.getRed() * 255.0) + 0.5));
+ SetGreen(sal_uInt8((aBColor.getGreen() * 255.0) + 0.5));
+ SetBlue(sal_uInt8(( aBColor.getBlue() * 255.0) + 0.5));
+}
+
SvStream& WriteColor( SvStream& rOStream, const Color& rColor )
{
DBG_ASSERTWARNING( rOStream.GetVersion(), "Color::<< - Solar-Version not set on rOStream" );