diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2024-03-01 15:36:19 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2024-03-20 11:17:52 +0100 |
commit | 3ad680135c8852c896ec7ed7b8ff63fd63ed0621 (patch) | |
tree | 4b4e861d511c59efdfdae3f77881743045532c2f | |
parent | 99bd13feb386587262c40d6c474d4fa817da31bd (diff) |
vcl: move Vectorize out of Bitmap - add Vectorizer class
Change-Id: I991b6e908d4139723c2d408d4ba3586676fded18
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164693
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | include/vcl/bitmap.hxx | 20 | ||||
-rw-r--r-- | include/vcl/bitmap/Vectorizer.hxx (renamed from vcl/source/bitmap/impvect.hxx) | 43 | ||||
-rw-r--r-- | sd/source/ui/dlg/vectdlg.cxx | 16 | ||||
-rw-r--r-- | solenv/clang-format/excludelist | 4 | ||||
-rw-r--r-- | vcl/Library_vcl.mk | 2 | ||||
-rw-r--r-- | vcl/source/bitmap/Vectorizer.cxx (renamed from vcl/source/bitmap/impvect.cxx) | 52 | ||||
-rw-r--r-- | vcl/source/bitmap/bitmap.cxx | 6 |
7 files changed, 77 insertions, 66 deletions
diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx index dbe8a364f712..24cc1245e1f5 100644 --- a/include/vcl/bitmap.hxx +++ b/include/vcl/bitmap.hxx @@ -503,26 +503,6 @@ public: size_t nColorCount, sal_uInt8 const * pTols ); - /** Convert the bitmap to a meta file - - This works by putting continuous areas of the same color into - polygons painted in this color, by tracing the area's bounding - line. - - @param rMtf - The resulting meta file - - @param cReduce - If non-null, minimal size of bound rects for individual polygons. Smaller ones are ignored. - - @param pProgress - A callback for showing the progress of the vectorization - */ - void Vectorize( - GDIMetaFile& rMtf, - sal_uInt8 cReduce, - const Link<tools::Long,void>* pProgress ); - /** Change various global color characteristics @param nLuminancePercent diff --git a/vcl/source/bitmap/impvect.hxx b/include/vcl/bitmap/Vectorizer.hxx index 257d1b5e5a87..225d924233ae 100644 --- a/vcl/source/bitmap/impvect.hxx +++ b/include/vcl/bitmap/Vectorizer.hxx @@ -19,14 +19,47 @@ #pragma once -#include <vcl/gdimtf.hxx> +#include <vcl/dllapi.h> -namespace tools { class PolyPolygon; } +class GDIMetaFile; +class BitmapEx; -namespace ImplVectorizer +namespace vcl { - bool ImplVectorize( const Bitmap& rColorBmp, GDIMetaFile& rMtf, - sal_uInt8 cReduce, const Link<tools::Long,void>* pProgress ); + +/** Convert the bitmap to a meta file + * + * This works by putting continuous areas of the same color into + * polygons painted in this color, by tracing the area's bounding + * line. + * + * @param rMetafile + * The resulting meta file + * + */ +class VCL_DLLPUBLIC Vectorizer +{ +private: + /** If not 0, minimal size of bound rects for individual polygons. Smaller ones are ignored. */ + sal_uInt8 mnReduce = 0; + /** A callback for showing the progress of the vectorization */ + Link<tools::Long, void> const* mpProgress = nullptr; + +public: + Vectorizer(sal_uInt8 nReduce) + : mnReduce(nReduce) + {} + + bool vectorize(BitmapEx const& rBitmap, GDIMetaFile& rMetafile); + + void setProgressCallback(const Link<tools::Long,void>* pProgress) + { + mpProgress = pProgress; + } + + void updateProgress(tools::Long nProgress); }; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/dlg/vectdlg.cxx b/sd/source/ui/dlg/vectdlg.cxx index 92961bb432a9..3ef7aa9ac494 100644 --- a/sd/source/ui/dlg/vectdlg.cxx +++ b/sd/source/ui/dlg/vectdlg.cxx @@ -19,6 +19,7 @@ #include <vcl/vclenum.hxx> #include <vcl/BitmapReadAccess.hxx> +#include <vcl/bitmap/Vectorizer.hxx> #include <vcl/metaact.hxx> #include <vcl/BitmapSimpleColorQuantizationFilter.hxx> #include <vcl/svapp.hxx> @@ -132,18 +133,21 @@ void SdVectorizeDlg::Calculate( Bitmap const & rBmp, GDIMetaFile& rMtf ) m_pDocSh->SetWaitCursor( true ); m_xPrgs->set_percentage(0); - Fraction aScale; - Bitmap aTmp( GetPreparedBitmap( rBmp, aScale ) ); + Fraction aScale; + BitmapEx aBitmapEx(GetPreparedBitmap(rBmp, aScale)); - if( !aTmp.IsEmpty() ) + if (!aBitmapEx.IsEmpty()) { const Link<::tools::Long,void> aPrgsHdl( LINK( this, SdVectorizeDlg, ProgressHdl ) ); - aTmp.Vectorize( rMtf, static_cast<sal_uInt8>(m_xMtReduce->get_value(FieldUnit::NONE)), &aPrgsHdl ); + sal_uInt8 nReduce = sal_uInt8(m_xMtReduce->get_value(FieldUnit::NONE)); + vcl::Vectorizer aVecotrizer(nReduce); + aVecotrizer.vectorize(aBitmapEx, rMtf); + aVecotrizer.setProgressCallback(&aPrgsHdl); if (m_xCbFillHoles->get_active()) { - GDIMetaFile aNewMtf; - BitmapScopedReadAccess pRAcc(aTmp); + GDIMetaFile aNewMtf; + BitmapScopedReadAccess pRAcc(aBitmapEx.GetBitmap()); if( pRAcc ) { diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index f2b9905bda3a..a4f7c15fa4b9 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -6347,6 +6347,7 @@ include/vcl/textview.hxx include/vcl/threadex.hxx include/vcl/timer.hxx include/vcl/toolbox.hxx +include/vcl/bitmap/Vectorizer.hxx include/vcl/toolkit/button.hxx include/vcl/toolkit/calendar.hxx include/vcl/toolkit/combobox.hxx @@ -14504,9 +14505,8 @@ vcl/source/bitmap/bmpfast.cxx vcl/source/bitmap/checksum.cxx vcl/source/bitmap/dibtools.cxx vcl/source/bitmap/floyd.hxx -vcl/source/bitmap/impvect.cxx -vcl/source/bitmap/impvect.hxx vcl/source/bitmap/salbmp.cxx +vcl/source/bitmap/Vectorizer.cxx vcl/source/cnttype/mcnttfactory.cxx vcl/source/cnttype/mcnttfactory.hxx vcl/source/cnttype/mcnttype.cxx diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 1bdb0fa700e5..a3c2581ae6b7 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -329,7 +329,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/graphic/UnoGraphicProvider \ vcl/source/graphic/VectorGraphicSearch \ vcl/source/graphic/VectorGraphicLoader \ - vcl/source/bitmap/impvect \ + vcl/source/bitmap/Vectorizer \ vcl/source/bitmap/bitmap \ vcl/source/bitmap/bitmappalette \ vcl/source/bitmap/BitmapEx \ diff --git a/vcl/source/bitmap/impvect.cxx b/vcl/source/bitmap/Vectorizer.cxx index 3f8f8471a6bd..f385fa36cacb 100644 --- a/vcl/source/bitmap/impvect.cxx +++ b/vcl/source/bitmap/Vectorizer.cxx @@ -25,7 +25,7 @@ #include <vcl/gdimtf.hxx> #include <vcl/metaact.hxx> #include <vcl/virdev.hxx> -#include "impvect.hxx" +#include <vcl/bitmap/Vectorizer.hxx> #include <array> #include <memory> @@ -49,11 +49,6 @@ static constexpr tools::Long BACK_MAP( tools::Long _def_nVal ) { return ((_def_nVal + 2) >> 2) - 1; } -static void VECT_PROGRESS( const Link<tools::Long, void>* pProgress, tools::Long _def_nVal ) -{ - if(pProgress) - pProgress->Call(_def_nVal); -} namespace { @@ -62,7 +57,7 @@ class ImplChain; } -namespace ImplVectorizer +namespace vcl { static void ImplExpand( std::optional<ImplVectMap>& rMap, const BitmapReadAccess* pRAcc, const Color& rColor ); static void ImplCalculate( ImplVectMap& rMap, tools::PolyPolygon& rPolyPoly, sal_uInt8 cReduce ); @@ -639,16 +634,21 @@ void ImplChain::ImplPostProcess( const ImplPointArray& rArr ) aNewArr2.ImplCreatePoly( maPoly ); } -namespace ImplVectorizer { +namespace vcl +{ +void Vectorizer::updateProgress(tools::Long nProgress) +{ + if (mpProgress) + mpProgress->Call(nProgress); +} -bool ImplVectorize( const Bitmap& rColorBmp, GDIMetaFile& rMtf, - sal_uInt8 cReduce, const Link<tools::Long,void>* pProgress ) +bool Vectorizer::vectorize(BitmapEx const& rBitmap, GDIMetaFile& rMetafile) { bool bRet = false; - VECT_PROGRESS( pProgress, 0 ); + updateProgress(0); - std::optional<Bitmap> xBmp(std::in_place, rColorBmp ); + std::optional<Bitmap> xBmp(std::in_place, rBitmap.GetBitmap()); BitmapScopedReadAccess pRAcc(*xBmp); if( pRAcc ) @@ -661,7 +661,7 @@ bool ImplVectorize( const Bitmap& rColorBmp, GDIMetaFile& rMtf, sal_uInt16 n; std::array<ImplColorSet, 256> aColorSet; - rMtf.Clear(); + rMetafile.Clear(); // get used palette colors and sort them from light to dark colors for( n = 0; n < nColorCount; n++ ) @@ -687,7 +687,7 @@ bool ImplVectorize( const Bitmap& rColorBmp, GDIMetaFile& rMtf, fPercentStep_2 = 45.0 / n; fPercent += 10.0; - VECT_PROGRESS( pProgress, FRound( fPercent ) ); + updateProgress(FRound(fPercent)); for( sal_uInt16 i = 0; i < n; i++ ) { @@ -697,12 +697,12 @@ bool ImplVectorize( const Bitmap& rColorBmp, GDIMetaFile& rMtf, ImplExpand( oMap, pRAcc.get(), aFindColor ); fPercent += fPercentStep_2; - VECT_PROGRESS( pProgress, FRound( fPercent ) ); + updateProgress(FRound(fPercent)); if( oMap ) { tools::PolyPolygon aPolyPoly; - ImplCalculate( *oMap, aPolyPoly, cReduce ); + ImplCalculate(*oMap, aPolyPoly, mnReduce); oMap.reset(); if( aPolyPoly.Count() ) @@ -713,34 +713,34 @@ bool ImplVectorize( const Bitmap& rColorBmp, GDIMetaFile& rMtf, if( aPolyPoly.Count() ) { - rMtf.AddAction( new MetaLineColorAction( aFindColor, true ) ); - rMtf.AddAction( new MetaFillColorAction( aFindColor, true ) ); - rMtf.AddAction( new MetaPolyPolygonAction( std::move(aPolyPoly) ) ); + rMetafile.AddAction( new MetaLineColorAction( aFindColor, true ) ); + rMetafile.AddAction( new MetaFillColorAction( aFindColor, true ) ); + rMetafile.AddAction( new MetaPolyPolygonAction( std::move(aPolyPoly) ) ); } } } fPercent += fPercentStep_2; - VECT_PROGRESS( pProgress, FRound( fPercent ) ); + updateProgress(FRound(fPercent)); } - if( rMtf.GetActionSize() ) + if (rMetafile.GetActionSize()) { MapMode aMap( MapUnit::Map100thMM ); ScopedVclPtrInstance< VirtualDevice > aVDev; const Size aLogSize1( aVDev->PixelToLogic( Size( 1, 1 ), aMap ) ); - rMtf.SetPrefMapMode( aMap ); - rMtf.SetPrefSize( Size( nWidth + 2, nHeight + 2 ) ); - rMtf.Move( 1, 1 ); - rMtf.Scale( aLogSize1.Width(), aLogSize1.Height() ); + rMetafile.SetPrefMapMode( aMap ); + rMetafile.SetPrefSize( Size( nWidth + 2, nHeight + 2 ) ); + rMetafile.Move( 1, 1 ); + rMetafile.Scale( aLogSize1.Width(), aLogSize1.Height() ); bRet = true; } } pRAcc.reset(); xBmp.reset(); - VECT_PROGRESS( pProgress, 100 ); + updateProgress(100); return bRet; } diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx index 53b30d0b3114..914e49295524 100644 --- a/vcl/source/bitmap/bitmap.cxx +++ b/vcl/source/bitmap/bitmap.cxx @@ -44,7 +44,6 @@ #include <bitmap/impoctree.hxx> #include <bitmap/Octree.hxx> -#include "impvect.hxx" #include "floyd.hxx" #include <math.h> @@ -1456,11 +1455,6 @@ bool Bitmap::Dither() return true; } -void Bitmap::Vectorize( GDIMetaFile& rMtf, sal_uInt8 cReduce, const Link<tools::Long,void>* pProgress ) -{ - ImplVectorizer::ImplVectorize( *this, rMtf, cReduce, pProgress ); -} - bool Bitmap::Adjust( short nLuminancePercent, short nContrastPercent, short nChannelRPercent, short nChannelGPercent, short nChannelBPercent, double fGamma, bool bInvert, bool msoBrightness ) |