summaryrefslogtreecommitdiff
path: root/vcl/qa
diff options
context:
space:
mode:
authorofftkp <parisoplop@gmail.com>2022-07-16 12:34:47 +0300
committerTomaž Vajngerl <quikee@gmail.com>2022-07-19 10:00:10 +0200
commit089b101e5447aac42e6fc79345e60da3ec63893d (patch)
tree23a1a96092b6b77c07d3e968a622a81f35ca2df3 /vcl/qa
parent3d1032cf6b67f3f6fa539d1d42d681080517d38c (diff)
Add ms-gif PNG chunk export support in PngImageWriter
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 <quikee@gmail.com>
Diffstat (limited to 'vcl/qa')
-rw-r--r--vcl/qa/cppunit/png/PngFilterTest.cxx67
-rw-r--r--vcl/qa/cppunit/png/data/dummy.gifbin0 -> 101 bytes
2 files changed, 58 insertions, 9 deletions
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<sal_Int8> 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<beans::PropertyValue> aAdditionalChunkSequence{ aChunkProperty };
+ aFilterProperty.Name = "AdditionalChunks";
+ aFilterProperty.Value <<= aAdditionalChunkSequence;
+ uno::Sequence<beans::PropertyValue> 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
--- /dev/null
+++ b/vcl/qa/cppunit/png/data/dummy.gif
Binary files differ