diff options
author | Armin Le Grand (allotropia) <armin.le.grand.extern@allotropia.de> | 2022-12-19 18:10:03 +0100 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@me.com> | 2022-12-20 12:25:10 +0000 |
commit | 74f51d5ecd0bbeedff7b52d28294828c0726def4 (patch) | |
tree | 0c6878a97a396705977897496c3cbdf2bc9aa230 /basegfx | |
parent | 5f29cb2fad3481889adec0c2dd242f7288ad169d (diff) |
Added BColorModifier_randomize for visualization testing
This BColorModifier is able to blend a color against a
randomized one, by the given amount. This is useful for
testing purposes in th eliving office when making
interactive tests with it.
Change-Id: I96d8b83397783201080682cd4bd75779ef77b238
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144541
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Diffstat (limited to 'basegfx')
-rw-r--r-- | basegfx/source/color/bcolormodifier.cxx | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/basegfx/source/color/bcolormodifier.cxx b/basegfx/source/color/bcolormodifier.cxx index 8620a94fe2c7..bd6157f373d5 100644 --- a/basegfx/source/color/bcolormodifier.cxx +++ b/basegfx/source/color/bcolormodifier.cxx @@ -270,6 +270,53 @@ namespace basegfx } } + BColorModifier_randomize::BColorModifier_randomize(double fRandomPart) + : mfRandomPart(fRandomPart) + { + } + + BColorModifier_randomize::~BColorModifier_randomize() + { + } + + // compare operator + bool BColorModifier_randomize::operator==(const BColorModifier& rCompare) const + { + const BColorModifier_randomize* pCompare = dynamic_cast< const BColorModifier_randomize* >(&rCompare); + + if(!pCompare) + { + return false; + } + + return mfRandomPart == pCompare->mfRandomPart; + } + + // compute modified color + ::basegfx::BColor BColorModifier_randomize::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + if(0.0 >= mfRandomPart) + { + // no randomizing, use orig color + return aSourceColor; + } + + if(1.0 <= mfRandomPart) + { + // full randomized color + const double fMul(1.0 / RAND_MAX); + return basegfx::BColor(rand() * fMul, rand() * fMul, rand() * fMul); + } + + // mixed color + const double fMulA(1.0 - mfRandomPart); + const double fMulB(mfRandomPart / RAND_MAX); + return basegfx::BColor( + aSourceColor.getRed() * fMulA + rand() * fMulB, + aSourceColor.getGreen() * fMulA + rand() * fMulB, + aSourceColor.getBlue() * fMulA + rand() * fMulB); + } + ::basegfx::BColor BColorModifierStack::getModifiedColor(const ::basegfx::BColor& rSource) const { if(maBColorModifiers.empty()) |