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 @@
#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; }
......
......@@ -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
......
......@@ -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 )
......
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