summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-12-21 21:03:36 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-12-22 09:07:27 +0100
commitc24d9447b809416575972585a5ad48e14f8d9ad9 (patch)
tree513939af51445da6058333f907096547c27e2ae3 /vcl
parentdb866805f3eee3a15bc96ffb5ba16aa77a02ddbd (diff)
tdf#138801 vcl: fix lazy-loading of GIF images with logic size
Regression from commit edda1e5fc8113aa4744e32f97c96a3cc311485ca (DOCX import: lazy-read images without external headers, 2018-04-20), the immediate problem is that GIF images from docx are now lazy-loaded. The deeper problem is that GIF images normally only have pixel size and can have an optional logic size as well (LO-specific extension). The bugdoc in question is a DOCX file, which contains a .png stream, which is in fact a GIF image, with that STARDIV extension in it. Now the initial parsing (that only extracts the metadata) didn't read the logic size, so the preferred map mode was pixels, but later when the actual read happened, the preferred map mode changed to mm100. Thid does not play nicely with writerfilter/ code that sets a different wrap polygon depending on if the (assumed to be final) map mode is pixels or not. Fix the problem by reusing the "is this an animation" GIF parser to also extract the logic size of the GIF image, if it has one. This way we still lazy-load the GIF image, but the preferred map mode won't hange from pixels to mm100 during the real read. Change-Id: Ia6c66e1c4fa0cb23a1daf537e7179b081ef90def Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108125 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/CppunitTest_vcl_filter_igif.mk46
-rw-r--r--vcl/Module_vcl.mk1
-rw-r--r--vcl/qa/cppunit/filter/igif/data/logic-lazy-read.gifbin0 -> 1258 bytes
-rw-r--r--vcl/qa/cppunit/filter/igif/igif.cxx47
-rw-r--r--vcl/source/filter/graphicfilter.cxx7
-rw-r--r--vcl/source/filter/igif/gifread.cxx10
-rw-r--r--vcl/source/filter/igif/gifread.hxx2
7 files changed, 110 insertions, 3 deletions
diff --git a/vcl/CppunitTest_vcl_filter_igif.mk b/vcl/CppunitTest_vcl_filter_igif.mk
new file mode 100644
index 000000000000..c6b6759899b0
--- /dev/null
+++ b/vcl/CppunitTest_vcl_filter_igif.mk
@@ -0,0 +1,46 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# 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/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,vcl_filter_igif))
+
+$(eval $(call gb_CppunitTest_use_externals,vcl_filter_igif,\
+ boost_headers \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,vcl_filter_igif, \
+ vcl/qa/cppunit/filter/igif/igif \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,vcl_filter_igif, \
+ comphelper \
+ cppu \
+ sal \
+ test \
+ tl \
+ unotest \
+ utl \
+ vcl \
+))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,vcl_filter_igif))
+
+$(eval $(call gb_CppunitTest_use_ure,vcl_filter_igif))
+$(eval $(call gb_CppunitTest_use_vcl,vcl_filter_igif))
+
+$(eval $(call gb_CppunitTest_use_rdb,vcl_filter_igif,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,vcl_filter_igif,\
+ officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,vcl_filter_igif))
+
+# vim: set noet sw=4 ts=4:
diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index 8bfc67c1e2ef..3a3626157b1f 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -211,6 +211,7 @@ $(eval $(call gb_Module_add_check_targets,vcl,\
CppunitTest_vcl_pdfium_library_test) \
$(if $(filter SKIA,$(BUILD_TYPE)), \
CppunitTest_vcl_skia) \
+ CppunitTest_vcl_filter_igif \
))
ifeq ($(USING_X11),TRUE)
diff --git a/vcl/qa/cppunit/filter/igif/data/logic-lazy-read.gif b/vcl/qa/cppunit/filter/igif/data/logic-lazy-read.gif
new file mode 100644
index 000000000000..3d18891f7b6a
--- /dev/null
+++ b/vcl/qa/cppunit/filter/igif/data/logic-lazy-read.gif
Binary files differ
diff --git a/vcl/qa/cppunit/filter/igif/igif.cxx b/vcl/qa/cppunit/filter/igif/igif.cxx
new file mode 100644
index 000000000000..8dea02ca529b
--- /dev/null
+++ b/vcl/qa/cppunit/filter/igif/igif.cxx
@@ -0,0 +1,47 @@
+/* -*- 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 <sal/config.h>
+
+#include <test/bootstrapfixture.hxx>
+
+#include <tools/stream.hxx>
+#include <unotest/directories.hxx>
+#include <vcl/graph.hxx>
+#include <vcl/graphicfilter.hxx>
+
+using namespace com::sun::star;
+
+namespace
+{
+char const DATA_DIRECTORY[] = "/vcl/qa/cppunit/filter/igif/data/";
+
+/// Covers vcl/source/filter/igif/ fixes.
+class Test : public test::BootstrapFixture
+{
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testLogicLazyRead)
+{
+ GraphicFilter aGraphicFilter;
+ test::Directories aDirectories;
+ OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "logic-lazy-read.gif";
+ SvFileStream aStream(aURL, StreamMode::READ);
+ Graphic aGraphic = aGraphicFilter.ImportUnloadedGraphic(aStream);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 0
+ // - Actual : 10
+ // i.e. the preferred unit was pixels, not mm100.
+ CPPUNIT_ASSERT_EQUAL(MapUnit::Map100thMM, aGraphic.GetPrefMapMode().GetMapUnit());
+}
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index 4d0c4cbd9cc1..65ae12a65931 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1403,10 +1403,15 @@ Graphic GraphicFilter::ImportUnloadedGraphic(SvStream& rIStream, sal_uInt64 size
if( nStatus == ERRCODE_NONE )
{
bool bAnimated = false;
+ Size aLogicSize;
if (eLinkType == GfxLinkType::NativeGif)
{
SvMemoryStream aMemoryStream(pGraphicContent.get(), nGraphicContentSize, StreamMode::READ);
- bAnimated = IsGIFAnimated(aMemoryStream);
+ bAnimated = IsGIFAnimated(aMemoryStream, aLogicSize);
+ if (!pSizeHint && aLogicSize.getWidth() && aLogicSize.getHeight())
+ {
+ pSizeHint = &aLogicSize;
+ }
}
aGraphic.SetGfxLink(std::make_shared<GfxLink>(std::move(pGraphicContent), nGraphicContentSize, eLinkType));
aGraphic.ImplGetImpGraphic()->ImplSetPrepared(bAnimated, pSizeHint);
diff --git a/vcl/source/filter/igif/gifread.cxx b/vcl/source/filter/igif/gifread.cxx
index 7751cc359f85..180e9d6fa1e2 100644
--- a/vcl/source/filter/igif/gifread.cxx
+++ b/vcl/source/filter/igif/gifread.cxx
@@ -115,6 +115,7 @@ public:
ReadState ReadGIF( Graphic& rGraphic );
bool ReadIsAnimated();
+ void GetLogicSize(Size& rLogicSize);
Graphic GetIntermediateGraphic();
explicit GIFReader( SvStream& rStm );
@@ -910,6 +911,12 @@ bool GIFReader::ReadIsAnimated()
return false;
}
+void GIFReader::GetLogicSize(Size& rLogicSize)
+{
+ rLogicSize.setWidth(nLogWidth100);
+ rLogicSize.setHeight(nLogHeight100);
+}
+
ReadState GIFReader::ReadGIF( Graphic& rGraphic )
{
ReadState eReadState;
@@ -946,13 +953,14 @@ ReadState GIFReader::ReadGIF( Graphic& rGraphic )
return eReadState;
}
-bool IsGIFAnimated(SvStream & rStm)
+bool IsGIFAnimated(SvStream & rStm, Size& rLogicSize)
{
GIFReader aReader(rStm);
SvStreamEndian nOldFormat = rStm.GetEndian();
rStm.SetEndian(SvStreamEndian::LITTLE);
bool bResult = aReader.ReadIsAnimated();
+ aReader.GetLogicSize(rLogicSize);
rStm.SetEndian(nOldFormat);
return bResult;
diff --git a/vcl/source/filter/igif/gifread.hxx b/vcl/source/filter/igif/gifread.hxx
index def223483883..de9a506f24b9 100644
--- a/vcl/source/filter/igif/gifread.hxx
+++ b/vcl/source/filter/igif/gifread.hxx
@@ -23,7 +23,7 @@
#include <vcl/graph.hxx>
VCL_DLLPUBLIC bool ImportGIF(SvStream& rStream, Graphic& rGraphic);
-bool IsGIFAnimated(SvStream& rStream);
+bool IsGIFAnimated(SvStream& rStream, Size& rLogicSize);
#endif // INCLUDED_VCL_SOURCE_FILTER_IGIF_GIFREAD_HXX