diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-02-25 09:04:10 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-02-25 10:59:18 +0100 |
commit | 22394a468eb8d594501e443bdb84608b6552a8a1 (patch) | |
tree | 7b208686c007b7912b22fa5d84768d2ff1870dbb /filter | |
parent | 968fe71f654937727e0708d1070ffabf90b9e527 (diff) |
svx: cache PNG export of graphic shapes
One scenario where this is useful is: manipulate a JPEG photo in
Online's Impress, e.g. resize it multiple times. Each time we generate
an SVG preview of the shape, which includes the PNG export of the bitmap
itself.
This helps with a desktop CPU:
debug:9976:9974: SVGFilter::filter finished in 3422 ms
debug:9976:9974: SVGFilter::filter finished in 176 ms
But it is meant to help on mobile, too, where writing such a bitmap as
PNG takes 16-17 seconds without this.
(This works because SVG writes the original bitmap, even if it's scaled.
If that invariant will be broken in the future, we still emit correct
output, but then the cache will be less useful.)
Conflicts:
filter/source/svg/svgwriter.cxx
include/svx/svdograf.hxx
include/svx/unoshape.hxx
Change-Id: I7204b04efeeb42c6eec67f04dfdb8a4ed50443a9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89411
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'filter')
-rw-r--r-- | filter/source/svg/svgwriter.cxx | 58 | ||||
-rw-r--r-- | filter/source/svg/svgwriter.hxx | 2 |
2 files changed, 50 insertions, 10 deletions
diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx index 1030c041ff1c..956651e41d01 100644 --- a/filter/source/svg/svgwriter.cxx +++ b/filter/source/svg/svgwriter.cxx @@ -30,6 +30,8 @@ #include <tools/helpers.hxx> #include <xmloff/unointerfacetouniqueidentifiermapper.hxx> #include <sax/tools/converter.hxx> +#include <svx/unoshape.hxx> +#include <svx/svdograf.hxx> #include <memory> @@ -2675,10 +2677,29 @@ void SVGActionWriter::ImplWriteText( const Point& rPos, const OUString& rText, } } +namespace +{ +SdrGrafObj* GetSdrGrafObjFromXShape(const css::uno::Reference<css::drawing::XShape>* pShape) +{ + if (!pShape) + { + return nullptr; + } + + auto pObject = dynamic_cast<SvxGraphicObject*>(pShape->get()); + if (!pObject) + { + return nullptr; + } + + return dynamic_cast<SdrGrafObj*>(pObject->GetSdrObject()); +} +} void SVGActionWriter::ImplWriteBmp( const BitmapEx& rBmpEx, const Point& rPt, const Size& rSz, - const Point& rSrcPt, const Size& rSrcSz ) + const Point& rSrcPt, const Size& rSrcSz, + const css::uno::Reference<css::drawing::XShape>* pShape ) { if( !!rBmpEx ) { @@ -2693,8 +2714,27 @@ void SVGActionWriter::ImplWriteBmp( const BitmapEx& rBmpEx, { SvMemoryStream aOStm( 65535, 65535 ); - if( GraphicConverter::Export( aOStm, rBmpEx, ConvertDataFormat::PNG ) == ERRCODE_NONE ) + bool bCached = false; + SdrGrafObj* pGrafObj = nullptr; + if (pShape) { + pGrafObj = GetSdrGrafObjFromXShape(pShape); + if (pGrafObj && pGrafObj->GetPNGPreviewChecksum() == rBmpEx.GetChecksum()) + { + const std::vector<sal_Int8>& rPreviewData = pGrafObj->GetPNGPreviewData(); + aOStm.WriteBytes(rPreviewData.data(), rPreviewData.size()); + bCached = true; + } + } + + if( bCached || GraphicConverter::Export( aOStm, rBmpEx, ConvertDataFormat::PNG ) == ERRCODE_NONE ) + { + if (!bCached && pGrafObj) + { + pGrafObj->SetPNGPreviewChecksum(rBmpEx.GetChecksum()); + pGrafObj->SetPNGPreviewData(aOStm); + } + Point aPt; Size aSz; Sequence< sal_Int8 > aSeq( static_cast<sal_Int8 const *>(aOStm.GetData()), aOStm.Tell() ); @@ -3038,7 +3078,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf, const MetaBmpScaleAction* pBmpScaleAction = static_cast<const MetaBmpScaleAction*>(pSubstAct); ImplWriteBmp( BitmapEx(pBmpScaleAction->GetBitmap()), pA->GetPoint(), pA->GetSize(), - Point(), pBmpScaleAction->GetBitmap().GetSizePixel() ); + Point(), pBmpScaleAction->GetBitmap().GetSizePixel(), pxShape ); } } } @@ -3421,7 +3461,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf, ImplWriteBmp( BitmapEx(pA->GetBitmap()), pA->GetPoint(), mpVDev->PixelToLogic( pA->GetBitmap().GetSizePixel() ), - Point(), pA->GetBitmap().GetSizePixel() ); + Point(), pA->GetBitmap().GetSizePixel(), pxShape ); } } break; @@ -3441,7 +3481,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf, { ImplWriteBmp( BitmapEx(pA->GetBitmap()), pA->GetPoint(), pA->GetSize(), - Point(), pA->GetBitmap().GetSizePixel() ); + Point(), pA->GetBitmap().GetSizePixel(), pxShape ); } } } @@ -3455,7 +3495,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf, ImplWriteBmp( BitmapEx(pA->GetBitmap()), pA->GetDestPoint(), pA->GetDestSize(), - pA->GetSrcPoint(), pA->GetSrcSize() ); + pA->GetSrcPoint(), pA->GetSrcSize(), pxShape ); } } break; @@ -3468,7 +3508,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf, ImplWriteBmp( pA->GetBitmapEx(), pA->GetPoint(), mpVDev->PixelToLogic( pA->GetBitmapEx().GetSizePixel() ), - Point(), pA->GetBitmapEx().GetSizePixel() ); + Point(), pA->GetBitmapEx().GetSizePixel(), pxShape ); } } break; @@ -3488,7 +3528,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf, { ImplWriteBmp( pA->GetBitmapEx(), pA->GetPoint(), pA->GetSize(), - Point(), pA->GetBitmapEx().GetSizePixel() ); + Point(), pA->GetBitmapEx().GetSizePixel(), pxShape ); } } } @@ -3502,7 +3542,7 @@ void SVGActionWriter::ImplWriteActions( const GDIMetaFile& rMtf, ImplWriteBmp( pA->GetBitmapEx(), pA->GetDestPoint(), pA->GetDestSize(), - pA->GetSrcPoint(), pA->GetSrcSize() ); + pA->GetSrcPoint(), pA->GetSrcSize(), pxShape ); } } break; diff --git a/filter/source/svg/svgwriter.hxx b/filter/source/svg/svgwriter.hxx index 68339d2a43c2..687f6cae5676 100644 --- a/filter/source/svg/svgwriter.hxx +++ b/filter/source/svg/svgwriter.hxx @@ -360,7 +360,7 @@ private: void ImplWriteMask( GDIMetaFile& rMtf, const Point& rDestPt, const Size& rDestSize, const Gradient& rGradient, sal_uInt32 nWriteFlags ); void ImplWriteText( const Point& rPos, const OUString& rText, const long* pDXArray, long nWidth ); void ImplWriteText( const Point& rPos, const OUString& rText, const long* pDXArray, long nWidth, Color aTextColor ); - void ImplWriteBmp( const BitmapEx& rBmpEx, const Point& rPt, const Size& rSz, const Point& rSrcPt, const Size& rSrcSz ); + void ImplWriteBmp( const BitmapEx& rBmpEx, const Point& rPt, const Size& rSz, const Point& rSrcPt, const Size& rSrcSz, const css::uno::Reference<css::drawing::XShape>* pShape); void ImplWriteActions( const GDIMetaFile& rMtf, sal_uInt32 nWriteFlags, |