From c61623028b79f918d0ed2bc2ca47db17e68a26cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Wed, 27 Mar 2019 11:47:06 +0100 Subject: [PATCH] check that jpeg export of 8bit non-grayscale works MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This checks what I fixed in 1893024c54ab173ec6262d77a05cad285c17a617 (related to tdf#116888). Change-Id: I721017fd037d62ba75cbc962fdd9316e02085624 Reviewed-on: https://gerrit.libreoffice.org/69819 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- vcl/CppunitTest_vcl_jpeg_read_write_test.mk | 1 + vcl/qa/cppunit/jpeg/JpegWriterTest.cxx | 88 ++++++++++++++++++ vcl/qa/cppunit/jpeg/data/8BitNonGrayscale.gif | Bin 0 -> 1875 bytes 3 files changed, 89 insertions(+) create mode 100644 vcl/qa/cppunit/jpeg/JpegWriterTest.cxx create mode 100644 vcl/qa/cppunit/jpeg/data/8BitNonGrayscale.gif diff --git a/vcl/CppunitTest_vcl_jpeg_read_write_test.mk b/vcl/CppunitTest_vcl_jpeg_read_write_test.mk index e741916bba0f..88385872b311 100644 --- a/vcl/CppunitTest_vcl_jpeg_read_write_test.mk +++ b/vcl/CppunitTest_vcl_jpeg_read_write_test.mk @@ -11,6 +11,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,vcl_jpeg_read_write_test)) $(eval $(call gb_CppunitTest_add_exception_objects,vcl_jpeg_read_write_test, \ vcl/qa/cppunit/jpeg/JpegReaderTest \ + vcl/qa/cppunit/jpeg/JpegWriterTest \ )) $(eval $(call gb_CppunitTest_use_external,vcl_jpeg_read_write_test,boost_headers)) diff --git a/vcl/qa/cppunit/jpeg/JpegWriterTest.cxx b/vcl/qa/cppunit/jpeg/JpegWriterTest.cxx new file mode 100644 index 000000000000..a81d0c478ff9 --- /dev/null +++ b/vcl/qa/cppunit/jpeg/JpegWriterTest.cxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include +#include +#include +#include +#include +#include + +static OUString const gaDataUrl("/vcl/qa/cppunit/jpeg/data/"); + +class JpegWriterTest : public test::BootstrapFixtureBase +{ + OUString getFullUrl(const OUString& sFileName) + { + return m_directories.getURLFromSrc(gaDataUrl) + sFileName; + } + + BitmapEx load(const OUString& aURL); + BitmapEx roundtripJPG(const BitmapEx& bitmap); + BitmapEx roundtripJPG(const OUString& aURL); + +public: + void testWrite8BitNonGrayscale(); + + CPPUNIT_TEST_SUITE(JpegWriterTest); + CPPUNIT_TEST(testWrite8BitNonGrayscale); + CPPUNIT_TEST_SUITE_END(); +}; + +BitmapEx JpegWriterTest::load(const OUString& aURL) +{ + GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); + Graphic aGraphic; + SvFileStream aFileStream(aURL, StreamMode::READ); + ErrCode bResult = rFilter.ImportGraphic(aGraphic, aURL, aFileStream); + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult); + return aGraphic.GetBitmapEx(); +} + +BitmapEx JpegWriterTest::roundtripJPG(const OUString& aURL) { return roundtripJPG(load(aURL)); } + +BitmapEx JpegWriterTest::roundtripJPG(const BitmapEx& bitmap) +{ + SvMemoryStream stream; + GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); + sal_uInt16 exportFormatJPG = rFilter.GetExportFormatNumberForShortName(JPG_SHORTNAME); + Graphic aExportGraphic(bitmap); + ErrCode bResult = rFilter.ExportGraphic(aExportGraphic, "memory", stream, exportFormatJPG); + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult); + stream.Seek(0); + Graphic aImportGraphic; + sal_uInt16 importFormatJPG = rFilter.GetImportFormatNumberForShortName(JPG_SHORTNAME); + bResult = rFilter.ImportGraphic(aImportGraphic, "memory", stream, importFormatJPG); + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult); + return aImportGraphic.GetBitmapEx(); +} + +void JpegWriterTest::testWrite8BitNonGrayscale() +{ + Bitmap bitmap = roundtripJPG(getFullUrl("8BitNonGrayscale.gif")).GetBitmap(); + Bitmap::ScopedReadAccess access(bitmap); + const ScanlineFormat format = access->GetScanlineFormat(); + // Check that it's still 8bit grayscale. + CPPUNIT_ASSERT_EQUAL(ScanlineFormat::N8BitPal, format); + // The original image has grayscale palette, just with entries in a different order, + // so do not check for non-grayscale, the roundtrip apparently fixes that. What's important + // is the content. + // CPPUNIT_ASSERT(!bitmap.HasGreyPalette()); + // Check that the content is valid. + CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_WHITE), access->GetColor(0, 0)); + CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_WHITE), access->GetColor(0, access->Width() - 1)); + CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_WHITE), access->GetColor(access->Height() - 1, 0)); + CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_BLACK), + access->GetColor(access->Height() - 1, access->Width() - 1)); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(JpegWriterTest); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qa/cppunit/jpeg/data/8BitNonGrayscale.gif b/vcl/qa/cppunit/jpeg/data/8BitNonGrayscale.gif new file mode 100644 index 0000000000000000000000000000000000000000..2953109491c464e877d5d028b8c3f644db6c6a13 GIT binary patch literal 1875 zcmV-Z2dwxT0e}Di|Ns90001li0001m1%?3t0{(=LsmtvTqnxzbi?iOm z`wxcVNS5Y_rs~SJ?hD8AOxN~}=lag~{tpZahs2`sh)gP%%%<}RjY_A~s`ZM^YPa03 z_X`e-$K-YS={|^`_I7nD%c!-#&xX9S(_y`#(IZ0V* zd5M{+xyjk-`3V{-I!an`U)E>J4;(@dyAW^yUW|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