diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-07-07 14:44:00 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-07-07 17:50:28 +0200 |
commit | 22e46544eebe027654bb4ecfc42e8d8ebb41ec48 (patch) | |
tree | 157dfc95f87b6d2c3b0384f8a468b7ca700eff6d /basegfx | |
parent | 04e90103b9a031af4073967228c6ccfc59438ec0 (diff) |
related: tdf#155735: clamp RGB values
So when a green matrix is used, everything becomes green.
Also set alpha to 1.0 so at least a green matrix on black returns
green and not black
Change-Id: I9104c7511545fb244750b066bb1e996b6ce229f2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154167
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'basegfx')
-rw-r--r-- | basegfx/source/color/bcolormodifier.cxx | 6 | ||||
-rwxr-xr-x | basegfx/test/BColorModifierTest.cxx | 17 |
2 files changed, 11 insertions, 12 deletions
diff --git a/basegfx/source/color/bcolormodifier.cxx b/basegfx/source/color/bcolormodifier.cxx index 9c9a196bb7f8..4d3f277c6cc5 100644 --- a/basegfx/source/color/bcolormodifier.cxx +++ b/basegfx/source/color/bcolormodifier.cxx @@ -164,10 +164,14 @@ namespace basegfx aColorMatrix.set(0, 0, aSourceColor.getRed()); aColorMatrix.set(1, 0, aSourceColor.getGreen()); aColorMatrix.set(2, 0, aSourceColor.getBlue()); + aColorMatrix.set(3, 0, 1.0); // TODO: add support for alpha aColorMatrix = maMatrix * aColorMatrix; - return ::basegfx::BColor(aColorMatrix.get(0, 0), aColorMatrix.get(1, 0), aColorMatrix.get(2, 0)); + return ::basegfx::BColor( + std::clamp(aColorMatrix.get(0, 0), 0.0, 1.0), + std::clamp(aColorMatrix.get(1, 0), 0.0, 1.0), + std::clamp(aColorMatrix.get(2, 0), 0.0, 1.0)); } OUString BColorModifier_matrix::getModifierName() const diff --git a/basegfx/test/BColorModifierTest.cxx b/basegfx/test/BColorModifierTest.cxx index 3a08958018da..237f6a982266 100755 --- a/basegfx/test/BColorModifierTest.cxx +++ b/basegfx/test/BColorModifierTest.cxx @@ -293,21 +293,16 @@ public: const basegfx::BColorModifierSharedPtr aBColorModifier = std::make_shared<basegfx::BColorModifier_matrix>(aMatrix); - BColor aExpectedWhite(0.0, 3.0, 0.0); - CPPUNIT_ASSERT_EQUAL(aExpectedWhite, aBColorModifier->getModifiedColor(maWhite)); - BColor aExpectedGray(0.0, 1.5, 0.0); - CPPUNIT_ASSERT_EQUAL(aExpectedGray, aBColorModifier->getModifiedColor(maGray)); - CPPUNIT_ASSERT_EQUAL(maBlack, aBColorModifier->getModifiedColor(maBlack)); + CPPUNIT_ASSERT_EQUAL(maGreen, aBColorModifier->getModifiedColor(maWhite)); + CPPUNIT_ASSERT_EQUAL(maGreen, aBColorModifier->getModifiedColor(maGray)); + CPPUNIT_ASSERT_EQUAL(maGreen, aBColorModifier->getModifiedColor(maBlack)); CPPUNIT_ASSERT_EQUAL(maGreen, aBColorModifier->getModifiedColor(maRed)); CPPUNIT_ASSERT_EQUAL(maGreen, aBColorModifier->getModifiedColor(maGreen)); CPPUNIT_ASSERT_EQUAL(maGreen, aBColorModifier->getModifiedColor(maBlue)); - BColor aExpectedYellow(0.0, 2.0, 0.0); - CPPUNIT_ASSERT_EQUAL(aExpectedYellow, aBColorModifier->getModifiedColor(maYellow)); - BColor aExpectedMagenta = aExpectedYellow; - CPPUNIT_ASSERT_EQUAL(aExpectedMagenta, aBColorModifier->getModifiedColor(maMagenta)); - BColor aExpectedCyan = aExpectedYellow; - CPPUNIT_ASSERT_EQUAL(aExpectedCyan, aBColorModifier->getModifiedColor(maCyan)); + CPPUNIT_ASSERT_EQUAL(maGreen, aBColorModifier->getModifiedColor(maYellow)); + CPPUNIT_ASSERT_EQUAL(maGreen, aBColorModifier->getModifiedColor(maMagenta)); + CPPUNIT_ASSERT_EQUAL(maGreen, aBColorModifier->getModifiedColor(maCyan)); CPPUNIT_ASSERT(aBColorModifier->operator==(*aBColorModifier)); const basegfx::BColorModifierSharedPtr aBColorModifierInvert |