diff options
author | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2020-04-29 02:02:08 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2020-04-29 09:23:04 +0200 |
commit | f9598b27815dbf9fa4010eda24e4f3f7cc90e3f2 (patch) | |
tree | 175ec06ef727b8509f019a5322abefb99acce02a /vcl/source | |
parent | 8b9c26218cb2c9526f69b40ff6f72ce757a464c2 (diff) |
improve: pdf export caching of jpeg bitmaps
* make cache size configurable (defaults to 15)
* have one cache object per PDFWriter instance, thus avoiding
accidentally caching JPEGs with different compression settings
Change-Id: I6664fc09b382f471cbe7c3e7aaedb3ebb5883b47
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93112
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 3 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.hxx | 5 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl2.cxx | 10 |
3 files changed, 11 insertions, 7 deletions
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index cb7f4cc17027..10758d84d639 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -41,6 +41,7 @@ #include <cppuhelper/implbase.hxx> #include <i18nlangtag/languagetag.hxx> #include <o3tl/numeric.hxx> +#include <officecfg/Office/Common.hxx> #include <osl/file.hxx> #include <osl/thread.h> #include <rtl/digest.h> @@ -1152,6 +1153,8 @@ PDFWriterImpl::PDFWriterImpl( const PDFWriter::PDFWriterContext& rContext, m_nCurrentStructElement( 0 ), m_bEmitStructure( true ), m_nNextFID( 1 ), + m_aPDFBmpCache( + officecfg::Office::Common::VCL::PDFExportImageCacheSize::get() ), m_nCurrentPage( -1 ), m_nCatalogObject(0), m_nSignatureObject( -1 ), diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx index e775fc92a4af..6261a391ba3c 100644 --- a/vcl/source/gdi/pdfwriter_impl.hxx +++ b/vcl/source/gdi/pdfwriter_impl.hxx @@ -46,6 +46,7 @@ #include <vcl/wall.hxx> #include <o3tl/safeint.hxx> #include <o3tl/typed_flags_set.hxx> +#include <o3tl/lru_map.hxx> #include <comphelper/hash.hxx> #include <tools/stream.hxx> @@ -709,6 +710,10 @@ private: sal_Int32 m_nNextFID; PDFFontCache m_aFontCache; + /// Cache some most recent bitmaps we've exported, in case we encounter them again.. + o3tl::lru_map<BitmapChecksum, + std::shared_ptr<SvMemoryStream>> m_aPDFBmpCache; + sal_Int32 m_nCurrentPage; sal_Int32 m_nCatalogObject; diff --git a/vcl/source/gdi/pdfwriter_impl2.cxx b/vcl/source/gdi/pdfwriter_impl2.cxx index f84ab684c24c..443e51e3aebb 100644 --- a/vcl/source/gdi/pdfwriter_impl2.cxx +++ b/vcl/source/gdi/pdfwriter_impl2.cxx @@ -43,7 +43,6 @@ #include <com/sun/star/beans/XMaterialHolder.hpp> #include <cppuhelper/implbase.hxx> -#include <o3tl/lru_map.hxx> #include <sal/log.hxx> #include <memory> @@ -55,9 +54,6 @@ using namespace com::sun::star::beans; static bool lcl_canUsePDFAxialShading(const Gradient& rGradient); -/// Cache some last 15 bitmaps we've exported, in case we encounter them again.. -static o3tl::lru_map<BitmapChecksum, std::shared_ptr<SvMemoryStream>> lcl_PDFBmpCache(15); - void PDFWriterImpl::implWriteGradient( const tools::PolyPolygon& i_rPolyPoly, const Gradient& i_rGradient, VirtualDevice* i_pDummyVDev, const vcl::PDFWriter::PlayMetafileContext& i_rContext ) { @@ -182,9 +178,9 @@ void PDFWriterImpl::implWriteBitmapEx( const Point& i_rPoint, const Size& i_rSiz // from trying conversion & stores before... if ( !aBitmapEx.IsTransparent() ) { - const auto& rCacheEntry=lcl_PDFBmpCache.find( + const auto& rCacheEntry=m_aPDFBmpCache.find( aBitmapEx.GetChecksum()); - if ( rCacheEntry != lcl_PDFBmpCache.end() ) + if ( rCacheEntry != m_aPDFBmpCache.end() ) { m_rOuterFace.DrawJPGBitmap( *rCacheEntry->second, true, aSizePixel, tools::Rectangle( aPoint, aSize ), aMask, i_Graphic ); @@ -266,7 +262,7 @@ void PDFWriterImpl::implWriteBitmapEx( const Point& i_rPoint, const Size& i_rSiz if (!aBitmapEx.IsTransparent() && bTrueColorJPG) { // Cache last jpeg export - lcl_PDFBmpCache.insert( + m_aPDFBmpCache.insert( {aBitmapEx.GetChecksum(), pStrm}); } } |