vcl/qa/cppunit/graphicfilter/data/tiff/tdf74331.tif |binary vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx | 51 ++++++++++++++++++++ 2 files changed, 51 insertions(+)
New commits: commit 49ce19a824700b2011334a6739ae2749e781155f Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Thu Apr 28 13:45:38 2022 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Thu Apr 28 21:20:15 2022 +0200 tdf#74331: vcl_filters: Add unittest Change-Id: Ia93f5f5f3ca5b4ddd51d68335af7f1c7b79b5c31 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133551 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/vcl/qa/cppunit/graphicfilter/data/tiff/tdf74331.tif b/vcl/qa/cppunit/graphicfilter/data/tiff/tdf74331.tif new file mode 100644 index 000000000000..702b8218ca5f Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/tiff/tdf74331.tif differ diff --git a/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx b/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx index 24ce5492d3be..77e412088bf3 100644 --- a/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx +++ b/vcl/qa/cppunit/graphicfilter/filters-tiff-test.cxx @@ -45,6 +45,7 @@ public: void testTdf126460(); void testTdf115863(); void testTdf138818(); + void testTdf74331(); void testRoundtrip(); void testRGB8bits(); void testRGB16bits(); @@ -54,6 +55,7 @@ public: CPPUNIT_TEST(testTdf126460); CPPUNIT_TEST(testTdf115863); CPPUNIT_TEST(testTdf138818); + CPPUNIT_TEST(testTdf74331); CPPUNIT_TEST(testRoundtrip); CPPUNIT_TEST(testRGB8bits); CPPUNIT_TEST(testRGB16bits); @@ -128,6 +130,55 @@ void TiffFilterTest::testTdf138818() CPPUNIT_ASSERT_EQUAL(sal_uInt32(46428), aGraphic.GetGfxLink().GetDataSize()); } +void TiffFilterTest::testTdf74331() +{ + OUString aURL = getUrl() + "tdf74331.tif"; + SvFileStream aFileStream(aURL, StreamMode::READ); + Graphic aGraphic; + GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); + + ErrCode bResult = rFilter.ImportGraphic(aGraphic, aURL, aFileStream); + + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult); + + Bitmap aBitmap = aGraphic.GetBitmapEx().GetBitmap(); + Size aSize = aBitmap.GetSizePixel(); + CPPUNIT_ASSERT_EQUAL(tools::Long(200), aSize.Width()); + CPPUNIT_ASSERT_EQUAL(tools::Long(200), aSize.Height()); + + Bitmap::ScopedReadAccess pReadAccess(aBitmap); + + // Check the image contains different kinds of grays + int nGrayCount = 0; + int nGray3Count = 0; + int nGray7Count = 0; + int nLightGrayCount = 0; + + for (tools::Long nX = 1; nX < aSize.Width() - 1; ++nX) + { + for (tools::Long nY = 1; nY < aSize.Height() - 1; ++nY) + { + const Color aColor = pReadAccess->GetColor(nY, nX); + if (aColor == COL_GRAY) + ++nGrayCount; + else if (aColor == COL_GRAY3) + ++nGray3Count; + else if (aColor == COL_GRAY7) + ++nGray7Count; + else if (aColor == COL_LIGHTGRAY) + ++nLightGrayCount; + } + } + + // Without the fix in place, this test would have failed with + // - Expected: 313 + // - Actual : 0 + CPPUNIT_ASSERT_EQUAL(313, nGrayCount); + CPPUNIT_ASSERT_EQUAL(71, nGray3Count); + CPPUNIT_ASSERT_EQUAL(227, nGray7Count); + CPPUNIT_ASSERT_EQUAL(165, nLightGrayCount); +} + void TiffFilterTest::testRoundtrip() { Bitmap aBitmap(Size(2, 2), vcl::PixelFormat::N24_BPP);