diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-02-25 11:28:44 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-05-13 09:17:04 +0200 |
commit | c5b3e28cc60e3e93564427424013d3cbe0531369 (patch) | |
tree | b9f92577d324bac217c31188c76e3072b9dae706 /filter/source/svg | |
parent | 4f1cf7a1205485ca7b011c5dd7c2031f498d5c7c (diff) |
SVG export: try to reuse original bitmap data for JPG and PNG bitmaps
This has a number of benefits:
1) For a sample JPG photo, the SVG output is now 4,9MB, not 20MB.
2) Even the first export to SVG is fast, see commit
570be56b37e4ff105649e604ff4c8a6c368e2e79 (svx: cache PNG export of
graphic shapes, 2020-02-25) for exact numbers.
3) Allow using less memory as the SdrGrafObj doesn't have to store a PNG
result till the document is closed.
We still require matching checksums, so in case anything problematic
happens with the bitmap (grayscale filter applied, etc), then the
optimization is meant to not help, but still produces correct output.
(cherry picked from commit c7af36a6504a192f72fcd3a30712ca8c14e12fa5)
Change-Id: Id3bc359a8dcc4c4d12d3b66ffb512cfa71939a26
Diffstat (limited to 'filter/source/svg')
-rw-r--r-- | filter/source/svg/svgwriter.cxx | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx index dfb203360b4e..cc3aa84d61e4 100644 --- a/filter/source/svg/svgwriter.cxx +++ b/filter/source/svg/svgwriter.cxx @@ -2714,29 +2714,52 @@ void SVGActionWriter::ImplWriteBmp( const BitmapEx& rBmpEx, bool bCached = false; SdrGrafObj* pGrafObj = nullptr; + bool bPNG = false; + bool bJPG = false; if (pShape) { pGrafObj = GetSdrGrafObjFromXShape(pShape); - if (pGrafObj && pGrafObj->GetPNGPreviewChecksum() == rBmpEx.GetChecksum()) + if (pGrafObj) { - const std::vector<sal_Int8>& rPreviewData = pGrafObj->GetPNGPreviewData(); - aOStm.WriteBytes(rPreviewData.data(), rPreviewData.size()); - bCached = true; + const Graphic& rGraphic = pGrafObj->GetGraphic(); + if (rGraphic.GetType() == GraphicType::Bitmap) + { + const BitmapEx& rGraphicBitmap = rGraphic.GetBitmapExRef(); + if (rGraphicBitmap.GetChecksum() == rBmpEx.GetChecksum()) + { + GfxLink aGfxLink = rGraphic.GetGfxLink(); + if (aGfxLink.GetType() == GfxLinkType::NativePng) + { + bPNG = true; + } + else if (aGfxLink.GetType() == GfxLinkType::NativeJpg) + { + bJPG = true; + } + if (bPNG || bJPG) + { + aOStm.WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize()); + 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() ); - OUStringBuffer aBuffer( "data:image/png;base64," ); + OUStringBuffer aBuffer; + if (bJPG) + { + aBuffer.append("data:image/jpeg;base64,"); + } + else + { + aBuffer.append("data:image/png;base64,"); + } ::comphelper::Base64::encode( aBuffer, aSeq ); ImplMap( rPt, aPt ); |