diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-09-21 21:34:01 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-09-22 00:31:49 +0200 |
commit | 2113c50b455ae67874eb61ff0dcd75c766b17002 (patch) | |
tree | 74d304ba65cc346422d182c5ebce66b2dec9b7c7 | |
parent | 3a7e54f5d2020ea1f6f2b27a51f5ca065844837f (diff) |
fdo#62104 Optimize thumbnail size by using PNG8 and other tricks
Change-Id: I54ece4a1977fe93c0e7bbb11774bd8657912c6bb
-rw-r--r-- | include/vcl/gdimtf.hxx | 6 | ||||
-rw-r--r-- | sfx2/source/doc/graphhelp.cxx | 38 | ||||
-rw-r--r-- | vcl/source/gdi/gdimtf.cxx | 21 |
3 files changed, 36 insertions, 29 deletions
diff --git a/include/vcl/gdimtf.hxx b/include/vcl/gdimtf.hxx index 4d863aa548b3..414f4306ac8f 100644 --- a/include/vcl/gdimtf.hxx +++ b/include/vcl/gdimtf.hxx @@ -24,6 +24,7 @@ #include <tools/gen.hxx> #include <tools/link.hxx> #include <vcl/mapmod.hxx> +#include <vcl/bitmap.hxx> #include <vector> class OutputDevice; @@ -214,7 +215,10 @@ public: friend VCL_DLLPUBLIC SvStream& WriteGDIMetaFile( SvStream& rOStm, const GDIMetaFile& rGDIMetaFile ); /// Creates an antialiased thumbnail, with maximum width or height of nMaximumExtent. - bool CreateThumbnail(BitmapEx& rBmpEx, sal_uInt32 nMaximumSize = 256) const; + bool CreateThumbnail(BitmapEx& rBitmapEx, + sal_uInt32 nMaximumExtent = 256, + BmpConversion nColorConversion = BMP_CONVERSION_24BIT, + long nScaleFlag = BMP_SCALE_BESTQUALITY) const; void UseCanvas( bool _bUseCanvas ); bool GetUseCanvas() const { return bUseCanvas; } 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 <vcl/outdev.hxx> #include <vcl/virdev.hxx> #include <vcl/bitmapex.hxx> +#include <vcl/graphicfilter.hxx> #include <tools/stream.hxx> #include <tools/helpers.hxx> @@ -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<io::XStream>& 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<SvStream> 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 diff --git a/vcl/source/gdi/gdimtf.cxx b/vcl/source/gdi/gdimtf.cxx index 3bd6eb2ccb36..3b0d9d007fcb 100644 --- a/vcl/source/gdi/gdimtf.cxx +++ b/vcl/source/gdi/gdimtf.cxx @@ -2879,7 +2879,7 @@ SvStream& GDIMetaFile::Write( SvStream& rOStm ) return rOStm; } -bool GDIMetaFile::CreateThumbnail(BitmapEx& rBmpEx, sal_uInt32 nMaximumExtent) const +bool GDIMetaFile::CreateThumbnail(BitmapEx& rBitmapEx, sal_uInt32 nMaximumExtent, BmpConversion eColorConversion, long nScaleFlag) const { // initialization seems to be complicated but is used to avoid rounding errors VirtualDevice aVDev; @@ -2889,8 +2889,8 @@ bool GDIMetaFile::CreateThumbnail(BitmapEx& rBmpEx, sal_uInt32 nMaximumExtent) c Size aDrawSize( aVDev.LogicToPixel( GetPrefSize(), GetPrefMapMode() ) ); Size aSizePix( labs( aBRPix.X() - aTLPix.X() ) + 1, labs( aBRPix.Y() - aTLPix.Y() ) + 1 ); - if ( !rBmpEx.IsEmpty() ) - rBmpEx.SetEmpty(); + if (!rBitmapEx.IsEmpty()) + rBitmapEx.SetEmpty(); // determine size that has the same aspect ratio as image size and // fits into the rectangle determined by nMaximumExtent @@ -2932,19 +2932,18 @@ bool GDIMetaFile::CreateThumbnail(BitmapEx& rBmpEx, sal_uInt32 nMaximumExtent) c const_cast<GDIMetaFile *>(this)->Play(&aVDev, aBackPosPix, aAntialias); // get paint bitmap - Bitmap aBmp( aVDev.GetBitmap( aNullPt, aVDev.GetOutputSizePixel() ) ); + Bitmap aBitmap( aVDev.GetBitmap( aNullPt, aVDev.GetOutputSizePixel() ) ); - // assure that we have a true color image - if ( aBmp.GetBitCount() != 24 ) - aBmp.Convert( BMP_CONVERSION_24BIT ); + // scale down the image to the desired size - use the input scaler for the scaling operation + aBitmap.Scale(aDrawSize, nScaleFlag); - // downsize, to get the antialiased picture - aBmp.Scale(aDrawSize, BMP_SCALE_BESTQUALITY); + // convert to desired bitmap color format + aBitmap.Convert(eColorConversion); - rBmpEx = BitmapEx(aBmp); + rBitmapEx = BitmapEx(aBitmap); } - return !rBmpEx.IsEmpty(); + return !rBitmapEx.IsEmpty(); } void GDIMetaFile::UseCanvas( bool _bUseCanvas ) |