diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-06-16 11:50:57 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-06-22 17:19:27 +0200 |
commit | e121f7b37c48b6d843dfdd1d774d2a40567c46c7 (patch) | |
tree | f512af867d5653469713613df0b3b12a718ea40f /basegfx | |
parent | cdce0b615a0bd599cd90dfd145d8270287045619 (diff) |
tdf#155735: Add support for matrix type
Change-Id: Icc172c5f47731ddcf0beca64c72c2022313e74a7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153177
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'basegfx')
-rw-r--r-- | basegfx/source/color/bcolormodifier.cxx | 32 | ||||
-rwxr-xr-x | basegfx/test/BColorModifierTest.cxx | 85 |
2 files changed, 117 insertions, 0 deletions
diff --git a/basegfx/source/color/bcolormodifier.cxx b/basegfx/source/color/bcolormodifier.cxx index 8d6f99a3faf5..829b0abda659 100644 --- a/basegfx/source/color/bcolormodifier.cxx +++ b/basegfx/source/color/bcolormodifier.cxx @@ -142,6 +142,38 @@ namespace basegfx return "interpolate"; } + BColorModifier_matrix::~BColorModifier_matrix() + { + } + + bool BColorModifier_matrix::operator==(const BColorModifier& rCompare) const + { + const BColorModifier_matrix* pCompare = dynamic_cast< const BColorModifier_matrix* >(&rCompare); + + if(!pCompare) + { + return false; + } + + return maMatrix == pCompare->maMatrix; + } + + ::basegfx::BColor BColorModifier_matrix::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + basegfx::B3DHomMatrix aColorMatrix; + aColorMatrix.set(0, 0, aSourceColor.getRed()); + aColorMatrix.set(1, 0, aSourceColor.getGreen()); + aColorMatrix.set(2, 0, aSourceColor.getBlue()); + + aColorMatrix = maMatrix * aColorMatrix; + return ::basegfx::BColor(aColorMatrix.get(0, 0), aColorMatrix.get(1, 0), aColorMatrix.get(2, 0)); + } + + OUString BColorModifier_matrix::getModifierName() const + { + return "matrix"; + } + BColorModifier_saturate::BColorModifier_saturate(double fValue) { maSatMatrix.set(0, 0, 0.213 + 0.787 * fValue); diff --git a/basegfx/test/BColorModifierTest.cxx b/basegfx/test/BColorModifierTest.cxx index d6e0648d2c17..17b6a0c22257 100755 --- a/basegfx/test/BColorModifierTest.cxx +++ b/basegfx/test/BColorModifierTest.cxx @@ -269,6 +269,89 @@ public: CPPUNIT_ASSERT(aBColorModifier->operator==(*aBColorModifier2)); } + void testMatrix() + { + // green matrix + basegfx::B3DHomMatrix aMatrix; + aMatrix.set(0, 0, 0.0); + aMatrix.set(0, 1, 0.0); + aMatrix.set(0, 2, 0.0); + aMatrix.set(0, 3, 0.0); + aMatrix.set(1, 0, 1.0); + aMatrix.set(1, 1, 1.0); + aMatrix.set(1, 2, 1.0); + aMatrix.set(1, 3, 1.0); + aMatrix.set(2, 0, 0.0); + aMatrix.set(2, 1, 0.0); + aMatrix.set(2, 2, 0.0); + aMatrix.set(2, 3, 0.0); + + 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(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(aBColorModifier->operator==(*aBColorModifier)); + const basegfx::BColorModifierSharedPtr aBColorModifierInvert + = std::make_shared<basegfx::BColorModifier_invert>(); + CPPUNIT_ASSERT(*aBColorModifier != *aBColorModifierInvert); + + const basegfx::BColorModifierSharedPtr aBColorModifier2 + = std::make_shared<basegfx::BColorModifier_matrix>(aMatrix); + CPPUNIT_ASSERT(aBColorModifier->operator==(*aBColorModifier2)); + } + + void testIdentityMatrix() + { + basegfx::B3DHomMatrix aMatrix; + aMatrix.set(0, 0, 1.0); + aMatrix.set(0, 1, 0.0); + aMatrix.set(0, 2, 0.0); + aMatrix.set(1, 0, 0.0); + aMatrix.set(1, 1, 1.0); + aMatrix.set(1, 2, 0.0); + aMatrix.set(2, 0, 0.0); + aMatrix.set(2, 1, 0.0); + aMatrix.set(2, 2, 1.0); + + const basegfx::BColorModifierSharedPtr aBColorModifier + = std::make_shared<basegfx::BColorModifier_matrix>(aMatrix); + + CPPUNIT_ASSERT_EQUAL(maWhite, aBColorModifier->getModifiedColor(maWhite)); + CPPUNIT_ASSERT_EQUAL(maGray, aBColorModifier->getModifiedColor(maGray)); + CPPUNIT_ASSERT_EQUAL(maBlack, aBColorModifier->getModifiedColor(maBlack)); + + CPPUNIT_ASSERT_EQUAL(maRed, aBColorModifier->getModifiedColor(maRed)); + CPPUNIT_ASSERT_EQUAL(maGreen, aBColorModifier->getModifiedColor(maGreen)); + CPPUNIT_ASSERT_EQUAL(maBlue, aBColorModifier->getModifiedColor(maBlue)); + CPPUNIT_ASSERT_EQUAL(maYellow, aBColorModifier->getModifiedColor(maYellow)); + CPPUNIT_ASSERT_EQUAL(maMagenta, aBColorModifier->getModifiedColor(maMagenta)); + CPPUNIT_ASSERT_EQUAL(maCyan, aBColorModifier->getModifiedColor(maCyan)); + + CPPUNIT_ASSERT(aBColorModifier->operator==(*aBColorModifier)); + const basegfx::BColorModifierSharedPtr aBColorModifierInvert + = std::make_shared<basegfx::BColorModifier_invert>(); + CPPUNIT_ASSERT(*aBColorModifier != *aBColorModifierInvert); + + const basegfx::BColorModifierSharedPtr aBColorModifier2 + = std::make_shared<basegfx::BColorModifier_matrix>(aMatrix); + CPPUNIT_ASSERT(aBColorModifier->operator==(*aBColorModifier2)); + } + CPPUNIT_TEST_SUITE(bcolormodifier); CPPUNIT_TEST(testGray); CPPUNIT_TEST(testInvert); @@ -277,6 +360,8 @@ public: CPPUNIT_TEST(testSaturate); CPPUNIT_TEST(testLuminanceToAlpha); CPPUNIT_TEST(testHueRotate); + CPPUNIT_TEST(testMatrix); + CPPUNIT_TEST(testIdentityMatrix); CPPUNIT_TEST_SUITE_END(); }; |