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>
This commit is contained in:
@@ -908,6 +908,14 @@
|
||||
</info>
|
||||
<value>25</value>
|
||||
</prop>
|
||||
<prop oor:name="PDFExportImageCacheSize" oor:type="xs:int" oor:nillable="false">
|
||||
<info>
|
||||
<desc>Specifies number of PDF image instances to cache on
|
||||
export - can save potentially huge amount of CPU time on
|
||||
re-compressing the same JPEG image over and over again.</desc>
|
||||
</info>
|
||||
<value>15</value>
|
||||
</prop>
|
||||
</group>
|
||||
<group oor:name="InternalMSExport">
|
||||
<info>
|
||||
|
||||
@@ -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 ),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user