From 089b101e5447aac42e6fc79345e60da3ec63893d Mon Sep 17 00:00:00 2001 From: offtkp Date: Sat, 16 Jul 2022 12:34:47 +0300 Subject: Add ms-gif PNG chunk export support in PngImageWriter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added export support for msOG chunks in the new PngImageWriter and unit test Change-Id: I258c9ca23e41c1d5ce01fc6711bc55c13636db17 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137093 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- vcl/qa/cppunit/png/PngFilterTest.cxx | 67 ++++++++++++++++++++++++++++++----- vcl/qa/cppunit/png/data/dummy.gif | Bin 0 -> 101 bytes 2 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 vcl/qa/cppunit/png/data/dummy.gif (limited to 'vcl/qa') diff --git a/vcl/qa/cppunit/png/PngFilterTest.cxx b/vcl/qa/cppunit/png/PngFilterTest.cxx index 64a99756aa89..33af620eb08a 100644 --- a/vcl/qa/cppunit/png/PngFilterTest.cxx +++ b/vcl/qa/cppunit/png/PngFilterTest.cxx @@ -1696,16 +1696,65 @@ void PngFilterTest::testPngSuite() void PngFilterTest::testMsGifInPng() { - Graphic aGraphic; - const OUString aURL(getFullUrl(u"ms-gif.png")); - SvFileStream aFileStream(aURL, StreamMode::READ); GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); - ErrCode aResult = rFilter.ImportGraphic(aGraphic, aURL, aFileStream); - CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, aResult); - CPPUNIT_ASSERT(aGraphic.IsGfxLink()); - // The image is technically a PNG, but it has an animated Gif as a chunk (Microsoft extension). - CPPUNIT_ASSERT_EQUAL(GfxLinkType::NativeGif, aGraphic.GetSharedGfxLink()->GetType()); - CPPUNIT_ASSERT(aGraphic.IsAnimated()); + { + Graphic aGraphic; + const OUString aURL(getFullUrl(u"ms-gif.png")); + SvFileStream aFileStream(aURL, StreamMode::READ); + ErrCode aResult = rFilter.ImportGraphic(aGraphic, aURL, aFileStream); + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, aResult); + CPPUNIT_ASSERT(aGraphic.IsGfxLink()); + // The image is technically a PNG, but it has an animated Gif as a chunk (Microsoft extension). + CPPUNIT_ASSERT_EQUAL(GfxLinkType::NativeGif, aGraphic.GetSharedGfxLink()->GetType()); + CPPUNIT_ASSERT(aGraphic.IsAnimated()); + } + { + // Tests msOG chunk export support + const OUString aURL(getFullUrl(u"dummy.gif")); + SvFileStream aGIFStream(aURL, StreamMode::READ); + sal_uInt32 nGIFSize = aGIFStream.TellEnd(); + const char* const pHeader = "MSOFFICE9.0"; + auto nHeaderSize = strlen(pHeader); + uno::Sequence aGIFSequence(nHeaderSize + nGIFSize); + sal_Int8* pSequence = aGIFSequence.getArray(); + for (size_t i = 0; i < nHeaderSize; i++) + *pSequence++ = pHeader[i]; + aGIFStream.Seek(STREAM_SEEK_TO_BEGIN); + aGIFStream.ReadBytes(pSequence, nGIFSize); + // Create msOG chunk + beans::PropertyValue aChunkProperty, aFilterProperty; + aChunkProperty.Name = "msOG"; + aChunkProperty.Value <<= aGIFSequence; + uno::Sequence aAdditionalChunkSequence{ aChunkProperty }; + aFilterProperty.Name = "AdditionalChunks"; + aFilterProperty.Value <<= aAdditionalChunkSequence; + uno::Sequence aPNGParameters{ aFilterProperty }; + // Export the png with the chunk + OUString ext = u".png"; + utl::TempFile aTempFile(u"testPngExportMsGif", true, &ext); + if (!bKeepTemp) + aTempFile.EnableKillingFile(); + { + SvStream& rStream = *aTempFile.GetStream(StreamMode::WRITE); + BitmapEx aDummyBitmap(Size(8, 8), vcl::PixelFormat::N24_BPP); + vcl::PngImageWriter aPngWriter(rStream); + aPngWriter.setParameters(aPNGParameters); + bool bWriteSuccess = aPngWriter.write(aDummyBitmap); + CPPUNIT_ASSERT_EQUAL(true, bWriteSuccess); + aTempFile.CloseStream(); + } + { + SvStream& rStream = *aTempFile.GetStream(StreamMode::READ); + rStream.Seek(0); + // Import the png and check that it is a gif + Graphic aGraphic; + ErrCode aResult = rFilter.ImportGraphic(aGraphic, aTempFile.GetURL(), rStream); + CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, aResult); + CPPUNIT_ASSERT(aGraphic.IsGfxLink()); + CPPUNIT_ASSERT_EQUAL(GfxLinkType::NativeGif, aGraphic.GetSharedGfxLink()->GetType()); + CPPUNIT_ASSERT(aGraphic.IsAnimated()); + } + } } void PngFilterTest::testPngRoundtrip8BitGrey() diff --git a/vcl/qa/cppunit/png/data/dummy.gif b/vcl/qa/cppunit/png/data/dummy.gif new file mode 100644 index 000000000000..fd5c62dcdcb6 Binary files /dev/null and b/vcl/qa/cppunit/png/data/dummy.gif differ -- cgit