Kaydet (Commit) 2113c50b authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

fdo#62104 Optimize thumbnail size by using PNG8 and other tricks

Change-Id: I54ece4a1977fe93c0e7bbb11774bd8657912c6bb
üst 3a7e54f5
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <tools/gen.hxx> #include <tools/gen.hxx>
#include <tools/link.hxx> #include <tools/link.hxx>
#include <vcl/mapmod.hxx> #include <vcl/mapmod.hxx>
#include <vcl/bitmap.hxx>
#include <vector> #include <vector>
class OutputDevice; class OutputDevice;
...@@ -214,7 +215,10 @@ public: ...@@ -214,7 +215,10 @@ public:
friend VCL_DLLPUBLIC SvStream& WriteGDIMetaFile( SvStream& rOStm, const GDIMetaFile& rGDIMetaFile ); friend VCL_DLLPUBLIC SvStream& WriteGDIMetaFile( SvStream& rOStm, const GDIMetaFile& rGDIMetaFile );
/// Creates an antialiased thumbnail, with maximum width or height of nMaximumExtent. /// 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 ); void UseCanvas( bool _bUseCanvas );
bool GetUseCanvas() const { return bUseCanvas; } bool GetUseCanvas() const { return bUseCanvas; }
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <vcl/outdev.hxx> #include <vcl/outdev.hxx>
#include <vcl/virdev.hxx> #include <vcl/virdev.hxx>
#include <vcl/bitmapex.hxx> #include <vcl/bitmapex.hxx>
#include <vcl/graphicfilter.hxx>
#include <tools/stream.hxx> #include <tools/stream.hxx>
#include <tools/helpers.hxx> #include <tools/helpers.hxx>
...@@ -52,7 +53,7 @@ ...@@ -52,7 +53,7 @@
#include "graphhelp.hxx" #include "graphhelp.hxx"
#include "doc.hrc" #include "doc.hrc"
using namespace ::com::sun::star; using namespace css;
SvMemoryStream* GraphicHelper::getFormatStrFromGDI_Impl( const GDIMetaFile* pGDIMeta, sal_uInt32 nFormat ) SvMemoryStream* GraphicHelper::getFormatStrFromGDI_Impl( const GDIMetaFile* pGDIMeta, sal_uInt32 nFormat )
{ {
...@@ -192,30 +193,33 @@ bool GraphicHelper::supportsMetaFileHandle_Impl() ...@@ -192,30 +193,33 @@ bool GraphicHelper::supportsMetaFileHandle_Impl()
// static // static
bool GraphicHelper::getThumbnailFormatFromGDI_Impl( GDIMetaFile* pMetaFile, bool GraphicHelper::getThumbnailFormatFromGDI_Impl(GDIMetaFile* pMetaFile, const uno::Reference<io::XStream>& xStream)
const uno::Reference< io::XStream >& xStream )
{ {
bool bResult = false; bool bResult = false;
SvStream* pStream = NULL;
if ( xStream.is() ) if (!pMetaFile || !xStream.is())
pStream = ::utl::UcbStreamHelper::CreateStream( xStream ); return false;
if ( pMetaFile && pStream && !pStream->GetError() ) boost::scoped_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xStream));
{
BitmapEx aResultBitmap;
bResult = pMetaFile->CreateThumbnail(aResultBitmap); if (pStream->GetError())
return false;
if ( bResult ) BitmapEx aResultBitmap;
bResult = ( !aResultBitmap.IsEmpty()
&& GraphicConverter::Export( *pStream, aResultBitmap, CVT_PNG ) == 0
&& ( pStream->Flush(), !pStream->GetError() ) );
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 // static
......
...@@ -2879,7 +2879,7 @@ SvStream& GDIMetaFile::Write( SvStream& rOStm ) ...@@ -2879,7 +2879,7 @@ SvStream& GDIMetaFile::Write( SvStream& rOStm )
return 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 // initialization seems to be complicated but is used to avoid rounding errors
VirtualDevice aVDev; VirtualDevice aVDev;
...@@ -2889,8 +2889,8 @@ bool GDIMetaFile::CreateThumbnail(BitmapEx& rBmpEx, sal_uInt32 nMaximumExtent) c ...@@ -2889,8 +2889,8 @@ bool GDIMetaFile::CreateThumbnail(BitmapEx& rBmpEx, sal_uInt32 nMaximumExtent) c
Size aDrawSize( aVDev.LogicToPixel( GetPrefSize(), GetPrefMapMode() ) ); Size aDrawSize( aVDev.LogicToPixel( GetPrefSize(), GetPrefMapMode() ) );
Size aSizePix( labs( aBRPix.X() - aTLPix.X() ) + 1, labs( aBRPix.Y() - aTLPix.Y() ) + 1 ); Size aSizePix( labs( aBRPix.X() - aTLPix.X() ) + 1, labs( aBRPix.Y() - aTLPix.Y() ) + 1 );
if ( !rBmpEx.IsEmpty() ) if (!rBitmapEx.IsEmpty())
rBmpEx.SetEmpty(); rBitmapEx.SetEmpty();
// determine size that has the same aspect ratio as image size and // determine size that has the same aspect ratio as image size and
// fits into the rectangle determined by nMaximumExtent // fits into the rectangle determined by nMaximumExtent
...@@ -2932,19 +2932,18 @@ bool GDIMetaFile::CreateThumbnail(BitmapEx& rBmpEx, sal_uInt32 nMaximumExtent) c ...@@ -2932,19 +2932,18 @@ bool GDIMetaFile::CreateThumbnail(BitmapEx& rBmpEx, sal_uInt32 nMaximumExtent) c
const_cast<GDIMetaFile *>(this)->Play(&aVDev, aBackPosPix, aAntialias); const_cast<GDIMetaFile *>(this)->Play(&aVDev, aBackPosPix, aAntialias);
// get paint bitmap // 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 // scale down the image to the desired size - use the input scaler for the scaling operation
if ( aBmp.GetBitCount() != 24 ) aBitmap.Scale(aDrawSize, nScaleFlag);
aBmp.Convert( BMP_CONVERSION_24BIT );
// downsize, to get the antialiased picture // convert to desired bitmap color format
aBmp.Scale(aDrawSize, BMP_SCALE_BESTQUALITY); aBitmap.Convert(eColorConversion);
rBmpEx = BitmapEx(aBmp); rBitmapEx = BitmapEx(aBitmap);
} }
return !rBmpEx.IsEmpty(); return !rBitmapEx.IsEmpty();
} }
void GDIMetaFile::UseCanvas( bool _bUseCanvas ) void GDIMetaFile::UseCanvas( bool _bUseCanvas )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment