diff options
author | Sarper Akdemir <sarper.akdemir@collabora.com> | 2022-09-01 14:59:51 +0300 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-09-05 10:01:40 +0200 |
commit | 2b902b6203a87bdca7856e17a9c0fcc403de4264 (patch) | |
tree | d9f174e2b6ff6cc91a2b243120455e659aa65a9f /vcl/qa/cppunit/GraphicTest.cxx | |
parent | f438fd7e25254db8f501b86cdf37970194897e8f (diff) |
tdf#149670 fix color change api and adjust tolerance for ooxml
It appears at the start of Graphic::colorChange aBmpColorFrom &
aBmpColorTo gets initialized with wrong colors. Instead of {R,G,B},
they get initialized with {B,G,R}.
Instead of bitshifting use the ::Color constructor so that it is
initialized correctly.
For ooxml import adapt tolerance values of the image format in an
attempt to get similar results on how the results appear in
PowerPoint.
Change-Id: I1fa901691512de82936dba0e47158b7e0ca2223e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139203
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'vcl/qa/cppunit/GraphicTest.cxx')
-rw-r--r-- | vcl/qa/cppunit/GraphicTest.cxx | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/GraphicTest.cxx b/vcl/qa/cppunit/GraphicTest.cxx index 378bc7a7b55b..97ef23eac15d 100644 --- a/vcl/qa/cppunit/GraphicTest.cxx +++ b/vcl/qa/cppunit/GraphicTest.cxx @@ -9,6 +9,8 @@ #include <sal/config.h> #include <config_oox.h> +#include <com/sun/star/graphic/XGraphic.hpp> +#include <com/sun/star/graphic/XGraphicTransformer.hpp> #include <cppunit/TestAssert.h> #include <cppunit/TestFixture.h> #include <cppunit/extensions/HelperMacros.h> @@ -84,6 +86,7 @@ private: void testLoadWEBP(); void testAvailableThreaded(); + void testColorChangeToTransparent(); CPPUNIT_TEST_SUITE(GraphicTest); CPPUNIT_TEST(testUnloadedGraphic); @@ -122,6 +125,7 @@ private: CPPUNIT_TEST(testLoadWEBP); CPPUNIT_TEST(testAvailableThreaded); + CPPUNIT_TEST(testColorChangeToTransparent); CPPUNIT_TEST_SUITE_END(); }; @@ -1345,6 +1349,35 @@ void GraphicTest::testAvailableThreaded() } } +void GraphicTest::testColorChangeToTransparent() +{ + Graphic aGraphic = importUnloadedGraphic(u"testColorChange-red-linear-gradient.png"); + + auto xGraphic = aGraphic.GetXGraphic(); + uno::Reference<graphic::XGraphicTransformer> xGraphicTransformer{ xGraphic, uno::UNO_QUERY }; + ::Color nColorFrom{ ColorTransparency, 0x00, 0xFF, 0x00, 0x00 }; + ::Color nColorTo{ ColorTransparency, 0xFF, 0xFF, 0x00, 0x00 }; + sal_uInt8 nTolerance{ 15 }; + + auto xGraphicAfter = xGraphicTransformer->colorChange( + xGraphic, static_cast<sal_Int32>(nColorFrom), nTolerance, static_cast<sal_Int32>(nColorTo), + static_cast<sal_Int8>(nColorTo.GetAlpha())); + + Graphic aGraphicAfter{ xGraphicAfter }; + const BitmapEx& rBitmapAfter = aGraphicAfter.GetBitmapExRef(); + const BitmapEx& rBitmapBefore = aGraphic.GetBitmapExRef(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: rgba[ff000000] + // - Actual : rgba[f00000ff] + // i.e. the color change to transparent didn't apply correctly + CPPUNIT_ASSERT_EQUAL(nColorTo, rBitmapAfter.GetPixelColor(386, 140)); + + // Test if color stayed same on 410,140 + // colorChange with nTolerance 15 shouldn't change this pixel. + CPPUNIT_ASSERT_EQUAL(rBitmapBefore.GetPixelColor(410, 140), + rBitmapAfter.GetPixelColor(410, 140)); +} + } // namespace CPPUNIT_TEST_SUITE_REGISTRATION(GraphicTest); |