[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-4.3' - 2 commits - include/vcl sfx2/source vcl/source
Tomaž Vajngerl
tomaz.vajngerl at collabora.com
Tue Feb 3 07:07:10 PST 2015
include/vcl/gdimtf.hxx | 6 ++++-
include/vcl/graphicfilter.hxx | 2 +
sfx2/source/doc/graphhelp.cxx | 38 +++++++++++++++++++-----------------
vcl/source/filter/graphicfilter.cxx | 12 +++++++++++
vcl/source/gdi/gdimtf.cxx | 21 +++++++++----------
5 files changed, 50 insertions(+), 29 deletions(-)
New commits:
commit 5904e16762c68ef8f9e7e8e02dfa5e9d2a131e2b
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Sun Sep 21 21:29:19 2014 +0200
Convenient function to compress a Graphic to PNG image
Change-Id: I3d30dd4337b6bd3b5b0c7cdf97a8787c4bc37fa3
(cherry picked from commit 3a7e54f5d2020ea1f6f2b27a51f5ca065844837f)
diff --git a/include/vcl/graphicfilter.hxx b/include/vcl/graphicfilter.hxx
index a27fcbe..fcc213d 100644
--- a/include/vcl/graphicfilter.hxx
+++ b/include/vcl/graphicfilter.hxx
@@ -320,6 +320,8 @@ public:
Graphic& rGraphic,
GraphicFilter* pFilter = NULL,
sal_uInt16* pDeterminedFormat = NULL );
+
+ sal_uInt16 compressAsPNG(const Graphic& rGraphic, SvStream& rOutputStream, sal_uInt32 nCompression = 5);
};
#endif // INCLUDED_VCL_GRAPHICFILTER_HXX
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index 6a8dc5b..8b0ffb9 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -2307,4 +2307,16 @@ int GraphicFilter::LoadGraphic( const OUString &rPath, const OUString &rFilterNa
return nRes;
}
+sal_uInt16 GraphicFilter::compressAsPNG(const Graphic& rGraphic, SvStream& rOutputStream, sal_uInt32 nCompression)
+{
+ nCompression = MinMax(nCompression, 0, 100);
+
+ uno::Sequence<beans::PropertyValue> aFilterData(1);
+ aFilterData[0].Name = "Compression";
+ aFilterData[0].Value <<= nCompression;
+
+ sal_uInt16 nFilterFormat = GetExportFormatNumberForShortName("PNG");
+ return ExportGraphic(rGraphic, OUString(), rOutputStream, nFilterFormat, &aFilterData);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 1e5e26346f8f5825278d72820a861ee1fe3986c1
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date: Sun Sep 21 21:34:01 2014 +0200
fdo#62104 Optimize thumbnail size by using PNG8 and other tricks
Change-Id: I54ece4a1977fe93c0e7bbb11774bd8657912c6bb
(cherry picked from commit 2113c50b455ae67874eb61ff0dcd75c766b17002)
diff --git a/include/vcl/gdimtf.hxx b/include/vcl/gdimtf.hxx
index 4d863aa..414f430 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 f1d0bc5..2741131 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 7107023..a804374 100644
--- a/vcl/source/gdi/gdimtf.cxx
+++ b/vcl/source/gdi/gdimtf.cxx
@@ -2880,7 +2880,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;
@@ -2890,8 +2890,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
@@ -2933,19 +2933,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 )
More information about the Libreoffice-commits
mailing list