From 2113c50b455ae67874eb61ff0dcd75c766b17002 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Sun, 21 Sep 2014 21:34:01 +0200 Subject: fdo#62104 Optimize thumbnail size by using PNG8 and other tricks Change-Id: I54ece4a1977fe93c0e7bbb11774bd8657912c6bb --- sfx2/source/doc/graphhelp.cxx | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'sfx2/source/doc') diff --git a/sfx2/source/doc/graphhelp.cxx b/sfx2/source/doc/graphhelp.cxx index f1d0bc5047c7..27411314f978 100644 --- a/sfx2/source/doc/graphhelp.cxx +++ b/sfx2/source/doc/graphhelp.cxx @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -52,7 +53,7 @@ #include "graphhelp.hxx" #include "doc.hrc" -using namespace ::com::sun::star; +using namespace css; SvMemoryStream* GraphicHelper::getFormatStrFromGDI_Impl( const GDIMetaFile* pGDIMeta, sal_uInt32 nFormat ) { @@ -192,30 +193,33 @@ bool GraphicHelper::supportsMetaFileHandle_Impl() // static -bool GraphicHelper::getThumbnailFormatFromGDI_Impl( GDIMetaFile* pMetaFile, - const uno::Reference< io::XStream >& xStream ) +bool GraphicHelper::getThumbnailFormatFromGDI_Impl(GDIMetaFile* pMetaFile, const uno::Reference& xStream) { bool bResult = false; - SvStream* pStream = NULL; - if ( xStream.is() ) - pStream = ::utl::UcbStreamHelper::CreateStream( xStream ); + if (!pMetaFile || !xStream.is()) + return false; - if ( pMetaFile && pStream && !pStream->GetError() ) - { - BitmapEx aResultBitmap; + boost::scoped_ptr pStream(utl::UcbStreamHelper::CreateStream(xStream)); - bResult = pMetaFile->CreateThumbnail(aResultBitmap); + if (pStream->GetError()) + return false; - if ( bResult ) - bResult = ( !aResultBitmap.IsEmpty() - && GraphicConverter::Export( *pStream, aResultBitmap, CVT_PNG ) == 0 - && ( pStream->Flush(), !pStream->GetError() ) ); + BitmapEx aResultBitmap; - delete pStream; - } + bResult = pMetaFile->CreateThumbnail(aResultBitmap, 256, BMP_CONVERSION_8BIT_COLORS, BMP_SCALE_DEFAULT); - return bResult; + if (!bResult || aResultBitmap.IsEmpty()) + return false; + + GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); + + if (rFilter.compressAsPNG(aResultBitmap, *pStream.get(), 9) != GRFILTER_OK) + return false; + + pStream->Flush(); + + return !pStream->GetError(); } // static -- cgit