diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-07-10 11:52:30 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-07-10 13:52:56 +0200 |
commit | fa61e8b220aa1f34b022b9af485f0209b2cb25d1 (patch) | |
tree | 5f91a5b0f214633895454452368dde057395c75d /basegfx | |
parent | f8c15850dbfaa46605e1e353ae1f49e69184e8a1 (diff) |
tdf#99562: Do not ignore last column from matrix
Change-Id: I1dff65963e2c414d1771a1592159930150c513e0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154241
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'basegfx')
-rw-r--r-- | basegfx/source/color/bcolormodifier.cxx | 40 | ||||
-rwxr-xr-x | basegfx/test/BColorModifierTest.cxx | 88 |
2 files changed, 79 insertions, 49 deletions
diff --git a/basegfx/source/color/bcolormodifier.cxx b/basegfx/source/color/bcolormodifier.cxx index 4d3f277c6cc5..75c06f5cb8f3 100644 --- a/basegfx/source/color/bcolormodifier.cxx +++ b/basegfx/source/color/bcolormodifier.cxx @@ -155,23 +155,41 @@ namespace basegfx return false; } - return maMatrix == pCompare->maMatrix; + return maVector == pCompare->maVector; } ::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.set(3, 0, 1.0); - // TODO: add support for alpha + if (maVector.size() != 20) + return aSourceColor; + + const double aRed = maVector[0] * aSourceColor.getRed() + + maVector[1] * aSourceColor.getGreen() + + maVector[2] * aSourceColor.getBlue() + + maVector[3] * 1.0 + + maVector[4]; + const double aGreen = maVector[5] * aSourceColor.getRed() + + maVector[6] * aSourceColor.getGreen() + + maVector[7] * aSourceColor.getBlue() + + maVector[8] * 1.0 + + maVector[9]; + const double aBlue = maVector[10] * aSourceColor.getRed() + + maVector[11] * aSourceColor.getGreen() + + maVector[12] * aSourceColor.getBlue() + + maVector[13] * 1.0 + + maVector[14]; + /*TODO: add support for alpha + const double aAlpha = maVector[15] * aSourceColor.getRed() + + maVector[16] * aSourceColor.getGreen() + + maVector[17] * aSourceColor.getBlue() + + maVector[18] * 1.0 + + maVector[19]); + */ - aColorMatrix = maMatrix * aColorMatrix; 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)); + std::clamp(aRed, 0.0, 1.0), + std::clamp(aGreen, 0.0, 1.0), + std::clamp(aBlue, 0.0, 1.0)); } OUString BColorModifier_matrix::getModifierName() const diff --git a/basegfx/test/BColorModifierTest.cxx b/basegfx/test/BColorModifierTest.cxx index 237f6a982266..4a84c3662a6b 100755 --- a/basegfx/test/BColorModifierTest.cxx +++ b/basegfx/test/BColorModifierTest.cxx @@ -272,26 +272,15 @@ public: 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); - aMatrix.set(3, 0, 0.0); - aMatrix.set(3, 1, 0.0); - aMatrix.set(3, 2, 0.0); - aMatrix.set(3, 3, 1.0); + // clang-format off + std::vector<double> aVector = {0.0, 0.0, 0.0, 0.0, 0.0, + 1.0, 1.0, 1.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 1.0, 0.0}; + // clang-format on const basegfx::BColorModifierSharedPtr aBColorModifier - = std::make_shared<basegfx::BColorModifier_matrix>(aMatrix); + = std::make_shared<basegfx::BColorModifier_matrix>(aVector); CPPUNIT_ASSERT_EQUAL(maGreen, aBColorModifier->getModifiedColor(maWhite)); CPPUNIT_ASSERT_EQUAL(maGreen, aBColorModifier->getModifiedColor(maGray)); @@ -310,32 +299,54 @@ public: CPPUNIT_ASSERT(*aBColorModifier != *aBColorModifierInvert); const basegfx::BColorModifierSharedPtr aBColorModifier2 - = std::make_shared<basegfx::BColorModifier_matrix>(aMatrix); + = std::make_shared<basegfx::BColorModifier_matrix>(aVector); + CPPUNIT_ASSERT(aBColorModifier->operator==(*aBColorModifier2)); + } + + void testMatrixShift() + { + // clang-format off + std::vector<double> aVector = {0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 1.0, + 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 1.0, 0.0}; + // clang-format on + + const basegfx::BColorModifierSharedPtr aBColorModifier + = std::make_shared<basegfx::BColorModifier_matrix>(aVector); + + 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)); + 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 + = std::make_shared<basegfx::BColorModifier_invert>(); + CPPUNIT_ASSERT(*aBColorModifier != *aBColorModifierInvert); + + const basegfx::BColorModifierSharedPtr aBColorModifier2 + = std::make_shared<basegfx::BColorModifier_matrix>(aVector); 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(0, 3, 0.0); - aMatrix.set(1, 0, 0.0); - aMatrix.set(1, 1, 1.0); - aMatrix.set(1, 2, 0.0); - aMatrix.set(1, 3, 0.0); - aMatrix.set(2, 0, 0.0); - aMatrix.set(2, 1, 0.0); - aMatrix.set(2, 2, 1.0); - aMatrix.set(2, 3, 0.0); - aMatrix.set(3, 0, 0.0); - aMatrix.set(3, 1, 0.0); - aMatrix.set(3, 2, 0.0); - aMatrix.set(3, 3, 1.0); + // clang-format off + std::vector<double> aVector = {1.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 1.0, 0.0}; + // clang-format on const basegfx::BColorModifierSharedPtr aBColorModifier - = std::make_shared<basegfx::BColorModifier_matrix>(aMatrix); + = std::make_shared<basegfx::BColorModifier_matrix>(aVector); CPPUNIT_ASSERT_EQUAL(maWhite, aBColorModifier->getModifiedColor(maWhite)); CPPUNIT_ASSERT_EQUAL(maGray, aBColorModifier->getModifiedColor(maGray)); @@ -354,7 +365,7 @@ public: CPPUNIT_ASSERT(*aBColorModifier != *aBColorModifierInvert); const basegfx::BColorModifierSharedPtr aBColorModifier2 - = std::make_shared<basegfx::BColorModifier_matrix>(aMatrix); + = std::make_shared<basegfx::BColorModifier_matrix>(aVector); CPPUNIT_ASSERT(aBColorModifier->operator==(*aBColorModifier2)); } @@ -393,6 +404,7 @@ public: CPPUNIT_TEST(testLuminanceToAlpha); CPPUNIT_TEST(testHueRotate); CPPUNIT_TEST(testMatrix); + CPPUNIT_TEST(testMatrixShift); CPPUNIT_TEST(testIdentityMatrix); CPPUNIT_TEST(testBlackAndWhite); CPPUNIT_TEST_SUITE_END(); |