summaryrefslogtreecommitdiff
path: root/tools/source/generic/color.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'tools/source/generic/color.cxx')
-rw-r--r--tools/source/generic/color.cxx30
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/source/generic/color.cxx b/tools/source/generic/color.cxx
index 741cb159a4bf..453feae9c2e1 100644
--- a/tools/source/generic/color.cxx
+++ b/tools/source/generic/color.cxx
@@ -29,6 +29,8 @@
#include <tools/rcid.h>
#include <tools/resid.hxx>
#include <tools/rc.h>
+#include <tools/helpers.hxx>
+#include <basegfx/color/bcolortools.hxx>
static inline long _FRound( double fVal )
{
@@ -113,6 +115,34 @@ bool Color::IsBright() const
return GetLuminance() >= 245;
}
+void Color::ApplyTintOrShade(sal_Int16 n100thPercent)
+{
+ if (n100thPercent > 0)
+ {
+ basegfx::BColor aBColor = basegfx::tools::rgb2hsl(getBColor());
+
+ double fFactor = std::abs(n100thPercent) / 10000.0;
+ aBColor.setBlue(aBColor.getBlue() * fFactor + (100.0 - aBColor.getBlue()));
+ 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));
+ }
+ else if (n100thPercent < 0)
+ {
+ basegfx::BColor aBColor = basegfx::tools::rgb2hsl(getBColor());
+
+ double fFactor = std::abs(n100thPercent) / 10000.0;
+ aBColor.setBlue(aBColor.getBlue() * fFactor);
+ 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));
+ }
+}
+
// color space conversion
void Color::RGBtoHSB( sal_uInt16& nHue, sal_uInt16& nSat, sal_uInt16& nBri ) const