diff options
author | Marco Cecchetti <marco.cecchetti@collabora.com> | 2016-02-19 13:42:24 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2016-02-24 14:41:51 +0000 |
commit | 8a039afb1f3f345c748b2e7cc9b76ca030c23abb (patch) | |
tree | dc80e128e178b358870f5577b750da66400ee55c | |
parent | abbf4777f29374025d576ef8daa3f6dcba02ddf5 (diff) |
tdf#97662 - Try to preserve original compressed JPEGs harder.
Avoiding de-compressing and re-compressing them saves lots of
time too. Avoid PNG compressing de-compressed JPEGs.
Change-Id: I7fe7db8e294e38d3240d284f73183a34ee48fb2d
Reviewed-on: https://gerrit.libreoffice.org/22657
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
-rw-r--r-- | include/vcl/pdfextoutdevdata.hxx | 2 | ||||
-rw-r--r-- | vcl/source/gdi/pdfextoutdevdata.cxx | 14 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.hxx | 2 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl2.cxx | 36 |
4 files changed, 41 insertions, 13 deletions
diff --git a/include/vcl/pdfextoutdevdata.hxx b/include/vcl/pdfextoutdevdata.hxx index d681ab072730..3c3d49a88522 100644 --- a/include/vcl/pdfextoutdevdata.hxx +++ b/include/vcl/pdfextoutdevdata.hxx @@ -152,6 +152,8 @@ public: std::vector< PDFExtOutDevBookmarkEntry >& GetBookmarks() { return maBookmarks;} + Graphic GetCurrentGraphic() const; + /** Start a new group of render output Use this method to group render output. diff --git a/vcl/source/gdi/pdfextoutdevdata.cxx b/vcl/source/gdi/pdfextoutdevdata.cxx index 247176bb430e..c5df5b65c003 100644 --- a/vcl/source/gdi/pdfextoutdevdata.cxx +++ b/vcl/source/gdi/pdfextoutdevdata.cxx @@ -294,13 +294,17 @@ struct PageSyncData std::deque< PDFWriter::StructAttribute > mParaStructAttributes; std::deque< PDFWriter::StructAttributeValue > mParaStructAttributeValues; std::deque< Graphic > mGraphics; + Graphic mCurrentGraphic; std::deque< std::shared_ptr< PDFWriter::AnyWidget > > mControls; GlobalSyncData* mpGlobalData; bool mbGroupIgnoreGDIMtfActions; - explicit PageSyncData( GlobalSyncData* pGlobal ) : mbGroupIgnoreGDIMtfActions ( false ) { mpGlobalData = pGlobal; } + + explicit PageSyncData( GlobalSyncData* pGlobal ) + : mbGroupIgnoreGDIMtfActions ( false ) + { mpGlobalData = pGlobal; } void PushAction( const OutputDevice& rOutDev, const PDFExtOutDevDataSync::Action eAct ); bool PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rCurGDIMtfAction, const PDFExtOutDevData& rOutDevData ); @@ -412,6 +416,8 @@ bool PageSyncData::PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rCurGDIMtfAc mbGroupIgnoreGDIMtfActions = rOutDevData.HasAdequateCompression( rGraphic, mParaRects[0], mParaRects[1]); + if ( !mbGroupIgnoreGDIMtfActions ) + mCurrentGraphic = rGraphic; } break; } @@ -466,6 +472,7 @@ bool PageSyncData::PlaySyncPageAct( PDFWriter& rWriter, sal_uInt32& rCurGDIMtfAc } mbGroupIgnoreGDIMtfActions = false; } + mCurrentGraphic.Clear(); } break; case PDFExtOutDevDataSync::CreateNamedDest: @@ -520,6 +527,11 @@ PDFExtOutDevData::~PDFExtOutDevData() delete mpGlobalSyncData; } +Graphic PDFExtOutDevData::GetCurrentGraphic() const +{ + return mpPageSyncData->mCurrentGraphic; +} + void PDFExtOutDevData::SetDocumentLocale( const css::lang::Locale& rLoc ) { maDocLocale = rLoc; diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx index 895aa7b2ed2c..b8c8bf92e321 100644 --- a/vcl/source/gdi/pdfwriter_impl.hxx +++ b/vcl/source/gdi/pdfwriter_impl.hxx @@ -1010,7 +1010,7 @@ i12626 // helper for playMetafile void implWriteGradient( const tools::PolyPolygon& rPolyPoly, const Gradient& rGradient, VirtualDevice* pDummyVDev, const vcl::PDFWriter::PlayMetafileContext& ); - void implWriteBitmapEx( const Point& rPoint, const Size& rSize, const BitmapEx& rBitmapEx, + void implWriteBitmapEx( const Point& rPoint, const Size& rSize, const BitmapEx& rBitmapEx, Graphic i_pGraphic, VirtualDevice* pDummyVDev, const vcl::PDFWriter::PlayMetafileContext& ); // helpers for CCITT 1bit bitmap stream diff --git a/vcl/source/gdi/pdfwriter_impl2.cxx b/vcl/source/gdi/pdfwriter_impl2.cxx index 991d364ac869..f78f52e92ecd 100644 --- a/vcl/source/gdi/pdfwriter_impl2.cxx +++ b/vcl/source/gdi/pdfwriter_impl2.cxx @@ -65,7 +65,7 @@ void PDFWriterImpl::implWriteGradient( const tools::PolyPolygon& i_rPolyPoly, co m_rOuterFace.Pop(); } -void PDFWriterImpl::implWriteBitmapEx( const Point& i_rPoint, const Size& i_rSize, const BitmapEx& i_rBitmapEx, +void PDFWriterImpl::implWriteBitmapEx( const Point& i_rPoint, const Size& i_rSize, const BitmapEx& i_rBitmapEx, Graphic i_Graphic, VirtualDevice* i_pDummyVDev, const vcl::PDFWriter::PlayMetafileContext& i_rContext ) { if ( !i_rBitmapEx.IsEmpty() && i_rSize.Width() && i_rSize.Height() ) @@ -95,6 +95,9 @@ void PDFWriterImpl::implWriteBitmapEx( const Point& i_rPoint, const Size& i_rSiz { aBitmapEx.Mirror( nMirrorFlags ); } + + bool bIsJpeg = (i_Graphic.GetType() != GRAPHIC_NONE) && (i_Graphic.GetBitmapEx() == aBitmapEx); + if( i_rContext.m_nMaxImageResolution > 50 ) { // do downsampling if necessary @@ -160,8 +163,10 @@ void PDFWriterImpl::implWriteBitmapEx( const Point& i_rPoint, const Size& i_rSiz bool bTrueColorJPG = true; if ( bUseJPGCompression ) { - sal_uInt32 nZippedFileSize; // sj: we will calculate the filesize of a zipped bitmap - { // to determine if jpeg compression is useful + + sal_uInt32 nZippedFileSize = 0; // sj: we will calculate the filesize of a zipped bitmap + if ( !bIsJpeg ) // to determine if jpeg compression is useful + { SvMemoryStream aTemp; aTemp.SetCompressMode( aTemp.GetCompressMode() | SvStreamCompressFlags::ZBITMAP ); aTemp.SetVersion( SOFFICE_FILEFORMAT_40 ); // sj: up from version 40 our bitmap stream operator @@ -203,7 +208,7 @@ void PDFWriterImpl::implWriteBitmapEx( const Point& i_rPoint, const Size& i_rSiz aOutMediaProperties[2].Value <<= aFilterData; xGraphicProvider->storeGraphic( xGraphic, aOutMediaProperties ); xOut->flush(); - if ( xSeekable->getLength() > nZippedFileSize ) + if ( !bIsJpeg && xSeekable->getLength() > nZippedFileSize ) { bUseJPGCompression = false; } @@ -482,7 +487,9 @@ void PDFWriterImpl::playMetafile( const GDIMetaFile& i_rMtf, vcl::PDFExtOutDevDa xVDev->EnableMapMode( false ); xVDev->DrawMask( aPoint, aDstSizePixel, aMask, Color( COL_WHITE ) ); aAlpha = xVDev->GetBitmap( aPoint, aDstSizePixel ); - implWriteBitmapEx( rPos, rSize, BitmapEx( aPaint, aAlpha ), pDummyVDev, i_rContext ); + + Graphic aGraphic = i_pOutDevData ? i_pOutDevData->GetCurrentGraphic() : Graphic(); + implWriteBitmapEx( rPos, rSize, BitmapEx( aPaint, aAlpha ), aGraphic, pDummyVDev, i_rContext ); } } } @@ -781,14 +788,17 @@ void PDFWriterImpl::playMetafile( const GDIMetaFile& i_rMtf, vcl::PDFExtOutDevDa aBitmapEx.GetPrefMapMode(), pDummyVDev->GetMapMode() ) ); if( ! ( aSize.Width() && aSize.Height() ) ) aSize = pDummyVDev->PixelToLogic( aBitmapEx.GetSizePixel() ); - implWriteBitmapEx( pA->GetPoint(), aSize, aBitmapEx, pDummyVDev, i_rContext ); + + Graphic aGraphic = i_pOutDevData ? i_pOutDevData->GetCurrentGraphic() : Graphic(); + implWriteBitmapEx( pA->GetPoint(), aSize, aBitmapEx, aGraphic, pDummyVDev, i_rContext ); } break; case( MetaActionType::BMPSCALE ): { const MetaBmpScaleAction* pA = static_cast<const MetaBmpScaleAction*>(pAction); - implWriteBitmapEx( pA->GetPoint(), pA->GetSize(), BitmapEx( pA->GetBitmap() ), pDummyVDev, i_rContext ); + Graphic aGraphic = i_pOutDevData ? i_pOutDevData->GetCurrentGraphic() : Graphic(); + implWriteBitmapEx( pA->GetPoint(), pA->GetSize(), BitmapEx( pA->GetBitmap() ), aGraphic, pDummyVDev, i_rContext ); } break; @@ -797,7 +807,8 @@ void PDFWriterImpl::playMetafile( const GDIMetaFile& i_rMtf, vcl::PDFExtOutDevDa const MetaBmpScalePartAction* pA = static_cast<const MetaBmpScalePartAction*>(pAction); BitmapEx aBitmapEx( pA->GetBitmap() ); aBitmapEx.Crop( Rectangle( pA->GetSrcPoint(), pA->GetSrcSize() ) ); - implWriteBitmapEx( pA->GetDestPoint(), pA->GetDestSize(), aBitmapEx, pDummyVDev, i_rContext ); + Graphic aGraphic = i_pOutDevData ? i_pOutDevData->GetCurrentGraphic() : Graphic(); + implWriteBitmapEx( pA->GetDestPoint(), pA->GetDestSize(), aBitmapEx, aGraphic, pDummyVDev, i_rContext ); } break; @@ -807,14 +818,16 @@ void PDFWriterImpl::playMetafile( const GDIMetaFile& i_rMtf, vcl::PDFExtOutDevDa BitmapEx aBitmapEx( pA->GetBitmapEx() ); Size aSize( OutputDevice::LogicToLogic( aBitmapEx.GetPrefSize(), aBitmapEx.GetPrefMapMode(), pDummyVDev->GetMapMode() ) ); - implWriteBitmapEx( pA->GetPoint(), aSize, aBitmapEx, pDummyVDev, i_rContext ); + Graphic aGraphic = i_pOutDevData ? i_pOutDevData->GetCurrentGraphic() : Graphic(); + implWriteBitmapEx( pA->GetPoint(), aSize, aBitmapEx, aGraphic, pDummyVDev, i_rContext ); } break; case( MetaActionType::BMPEXSCALE ): { const MetaBmpExScaleAction* pA = static_cast<const MetaBmpExScaleAction*>(pAction); - implWriteBitmapEx( pA->GetPoint(), pA->GetSize(), pA->GetBitmapEx(), pDummyVDev, i_rContext ); + Graphic aGraphic = i_pOutDevData ? i_pOutDevData->GetCurrentGraphic() : Graphic(); + implWriteBitmapEx( pA->GetPoint(), pA->GetSize(), pA->GetBitmapEx(), aGraphic, pDummyVDev, i_rContext ); } break; @@ -823,7 +836,8 @@ void PDFWriterImpl::playMetafile( const GDIMetaFile& i_rMtf, vcl::PDFExtOutDevDa const MetaBmpExScalePartAction* pA = static_cast<const MetaBmpExScalePartAction*>(pAction); BitmapEx aBitmapEx( pA->GetBitmapEx() ); aBitmapEx.Crop( Rectangle( pA->GetSrcPoint(), pA->GetSrcSize() ) ); - implWriteBitmapEx( pA->GetDestPoint(), pA->GetDestSize(), aBitmapEx, pDummyVDev, i_rContext ); + Graphic aGraphic = i_pOutDevData ? i_pOutDevData->GetCurrentGraphic() : Graphic(); + implWriteBitmapEx( pA->GetDestPoint(), pA->GetDestSize(), aBitmapEx, aGraphic, pDummyVDev, i_rContext ); } break; |