summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-12-10 11:28:59 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-12-11 06:26:48 +0100
commit1cd32bcf1b92bd53320717626601135623dadd55 (patch)
tree5f33c3b070ac297bdba6bacb904d4ecd9644bef8
parent34d5e910adba4094bba1303284f9552028d0b019 (diff)
loplugin:useuniqueptr in vcl
Change-Id: I24eca813321fd3919bba9d37c285484f865ea2ea Reviewed-on: https://gerrit.libreoffice.org/64877 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--compilerplugins/clang/useuniqueptr.cxx11
-rw-r--r--vcl/inc/svdata.hxx2
-rw-r--r--vcl/source/app/svapp.cxx16
-rw-r--r--vcl/source/app/svdata.cxx1
-rw-r--r--vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx71
-rw-r--r--vcl/source/bitmap/BitmapEmbossGreyFilter.cxx8
-rw-r--r--vcl/source/bitmap/BitmapMedianFilter.cxx47
-rw-r--r--vcl/source/bitmap/BitmapMosaicFilter.cxx7
-rw-r--r--vcl/source/bitmap/BitmapPopArtFilter.cxx57
-rw-r--r--vcl/source/bitmap/BitmapSobelGreyFilter.cxx8
-rw-r--r--vcl/source/bitmap/bitmap.cxx21
-rw-r--r--vcl/source/gdi/bitmapex.cxx8
-rw-r--r--vcl/source/gdi/impvect.cxx37
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx6
-rw-r--r--vcl/source/gdi/print.cxx24
15 files changed, 142 insertions, 182 deletions
diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx
index 1f0f9d649317..71f842bde07e 100644
--- a/compilerplugins/clang/useuniqueptr.cxx
+++ b/compilerplugins/clang/useuniqueptr.cxx
@@ -477,14 +477,15 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C
// linked list
if (parentName == "ScFunctionList" || parentName == "SwNodes"
|| parentName == "SwUnoCursor" || parentName == "SortedResultSet"
- || parentName == "Atom")
+ || parentName == "Atom" || parentName == "RegionBand" || parentName == "WMFWriter"
+ || parentName == "Scheduler" || parentName == "OpenGLContext")
return;
// manual ref counting
if (parentName == "ScBroadcastAreaSlot")
return;
// complicated
if (parentName == "SwFormatField" || parentName == "FontPropertyBox" || parentName == "SdFontPropertyBox"
- || parentName == "SwHTMLParser")
+ || parentName == "SwHTMLParser" || parentName == "PDFWriterImpl")
return;
if (functionDecl->getIdentifier())
@@ -516,6 +517,12 @@ void UseUniquePtr::CheckDeleteLocalVar(const FunctionDecl* functionDecl, const C
// very dodgy
if (name == "UCBStorage::OpenStorage_Impl")
return;
+ // complicated ownership
+ if (name == "ParseCMAP" || name == "OpenGLSalBitmap::CreateTexture" || name == "X11SalGraphicsImpl::drawAlphaBitmap")
+ return;
+ // complicated delete
+ if (name == "X11SalObject::CreateObject")
+ return;
}
report(
diff --git a/vcl/inc/svdata.hxx b/vcl/inc/svdata.hxx
index 208e180ceeba..beb877f728ff 100644
--- a/vcl/inc/svdata.hxx
+++ b/vcl/inc/svdata.hxx
@@ -191,7 +191,7 @@ struct ImplSVGDIData
OpenGLContext* mpLastContext = nullptr; // Last OpenGLContext
VclPtr<Printer> mpFirstPrinter; // First Printer
VclPtr<Printer> mpLastPrinter; // Last Printer
- ImplPrnQueueList* mpPrinterQueueList = nullptr; // List of all printer queue
+ std::unique_ptr<ImplPrnQueueList> mpPrinterQueueList; // List of all printer queue
std::shared_ptr<PhysicalFontCollection> mxScreenFontList; // Screen-Font-List
std::shared_ptr<ImplFontCache> mxScreenFontCache; // Screen-Font-Cache
ImplDirectFontSubstitution* mpDirectFontSubst = nullptr; // Font-Substitutions defined in Tools->Options->Fonts
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index 41a342635437..c73769ebcc8a 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -813,19 +813,17 @@ ImplSVEvent * Application::PostKeyEvent( VclEventId nEvent, vcl::Window *pWin, K
if( pWin && pKeyEvent )
{
- ImplPostEventData* pPostEventData = new ImplPostEventData( nEvent, pWin, *pKeyEvent );
+ std::unique_ptr<ImplPostEventData> pPostEventData(new ImplPostEventData( nEvent, pWin, *pKeyEvent ));
nEventId = PostUserEvent(
LINK( nullptr, Application, PostEventHandler ),
- pPostEventData );
+ pPostEventData.get() );
if( nEventId )
{
pPostEventData->mnEventId = nEventId;
- ImplGetSVData()->maAppData.maPostedEventList.emplace_back( pWin, pPostEventData );
+ ImplGetSVData()->maAppData.maPostedEventList.emplace_back( pWin, pPostEventData.release() );
}
- else
- delete pPostEventData;
}
return nEventId;
@@ -846,19 +844,17 @@ ImplSVEvent * Application::PostMouseEvent( VclEventId nEvent, vcl::Window *pWin,
const MouseEvent aTransformedEvent( aTransformedPos, pMouseEvent->GetClicks(), pMouseEvent->GetMode(),
pMouseEvent->GetButtons(), pMouseEvent->GetModifier() );
- ImplPostEventData* pPostEventData = new ImplPostEventData( nEvent, pWin, aTransformedEvent );
+ std::unique_ptr<ImplPostEventData> pPostEventData(new ImplPostEventData( nEvent, pWin, aTransformedEvent ));
nEventId = PostUserEvent(
LINK( nullptr, Application, PostEventHandler ),
- pPostEventData );
+ pPostEventData.get() );
if( nEventId )
{
pPostEventData->mnEventId = nEventId;
- ImplGetSVData()->maAppData.maPostedEventList.emplace_back( pWin, pPostEventData );
+ ImplGetSVData()->maAppData.maPostedEventList.emplace_back( pWin, pPostEventData.release() );
}
- else
- delete pPostEventData;
}
return nEventId;
diff --git a/vcl/source/app/svdata.cxx b/vcl/source/app/svdata.cxx
index 529eb676e3ad..491bf03621d8 100644
--- a/vcl/source/app/svdata.cxx
+++ b/vcl/source/app/svdata.cxx
@@ -50,6 +50,7 @@
#include <salsys.hxx>
#include <strings.hrc>
#include <units.hrc>
+#include <print.h>
#include <com/sun/star/accessibility/MSAAService.hpp>
diff --git a/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx b/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx
index a04ab5b08652..7ccbe1b450d2 100644
--- a/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx
+++ b/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx
@@ -18,6 +18,7 @@
#include <vcl/BitmapSharpenFilter.hxx>
#include <bitmapwriteaccess.hxx>
+#include <array>
BitmapEx BitmapConvolutionMatrixFilter::execute(BitmapEx const& rBitmapEx) const
{
@@ -36,20 +37,17 @@ BitmapEx BitmapConvolutionMatrixFilter::execute(BitmapEx const& rBitmapEx) const
{
const long nWidth = pWriteAcc->Width(), nWidth2 = nWidth + 2;
const long nHeight = pWriteAcc->Height(), nHeight2 = nHeight + 2;
- long* pColm = new long[nWidth2];
- long* pRows = new long[nHeight2];
- BitmapColor* pColRow1
- = reinterpret_cast<BitmapColor*>(new sal_uInt8[sizeof(BitmapColor) * nWidth2]);
- BitmapColor* pColRow2
- = reinterpret_cast<BitmapColor*>(new sal_uInt8[sizeof(BitmapColor) * nWidth2]);
- BitmapColor* pColRow3
- = reinterpret_cast<BitmapColor*>(new sal_uInt8[sizeof(BitmapColor) * nWidth2]);
- BitmapColor* pRowTmp1 = pColRow1;
- BitmapColor* pRowTmp2 = pColRow2;
- BitmapColor* pRowTmp3 = pColRow3;
+ std::unique_ptr<long[]> pColm(new long[nWidth2]);
+ std::unique_ptr<long[]> pRows(new long[nHeight2]);
+ std::unique_ptr<BitmapColor[]> pColRow1(new BitmapColor[nWidth2]);
+ std::unique_ptr<BitmapColor[]> pColRow2(new BitmapColor[nWidth2]);
+ std::unique_ptr<BitmapColor[]> pColRow3(new BitmapColor[nWidth2]);
+ BitmapColor* pRowTmp1 = pColRow1.get();
+ BitmapColor* pRowTmp2 = pColRow2.get();
+ BitmapColor* pRowTmp3 = pColRow3.get();
BitmapColor* pColor;
long nY, nX, i, nSumR, nSumG, nSumB, nMatrixVal, nTmp;
- long(*pKoeff)[256] = new long[9][256];
+ std::array<std::array<long, 256>, 9> aKoeff;
long* pTmp;
// create LUT of products of matrix value and possible color component values
@@ -57,7 +55,7 @@ BitmapEx BitmapConvolutionMatrixFilter::execute(BitmapEx const& rBitmapEx) const
{
for (nX = nTmp = 0, nMatrixVal = mrMatrix[nY]; nX < 256; nX++, nTmp += nMatrixVal)
{
- pKoeff[nY][nX] = nTmp;
+ aKoeff[nY][nX] = nTmp;
}
}
@@ -92,52 +90,52 @@ BitmapEx BitmapConvolutionMatrixFilter::execute(BitmapEx const& rBitmapEx) const
for (nX = 0; nX < nWidth; nX++)
{
// first row
- pTmp = pKoeff[0];
+ pTmp = aKoeff[0].data();
pColor = pRowTmp1 + nX;
nSumR = pTmp[pColor->GetRed()];
nSumG = pTmp[pColor->GetGreen()];
nSumB = pTmp[pColor->GetBlue()];
- pTmp = pKoeff[1];
+ pTmp = aKoeff[1].data();
nSumR += pTmp[(++pColor)->GetRed()];
nSumG += pTmp[pColor->GetGreen()];
nSumB += pTmp[pColor->GetBlue()];
- pTmp = pKoeff[2];
+ pTmp = aKoeff[2].data();
nSumR += pTmp[(++pColor)->GetRed()];
nSumG += pTmp[pColor->GetGreen()];
nSumB += pTmp[pColor->GetBlue()];
// second row
- pTmp = pKoeff[3];
+ pTmp = aKoeff[3].data();
pColor = pRowTmp2 + nX;
nSumR += pTmp[pColor->GetRed()];
nSumG += pTmp[pColor->GetGreen()];
nSumB += pTmp[pColor->GetBlue()];
- pTmp = pKoeff[4];
+ pTmp = aKoeff[4].data();
nSumR += pTmp[(++pColor)->GetRed()];
nSumG += pTmp[pColor->GetGreen()];
nSumB += pTmp[pColor->GetBlue()];
- pTmp = pKoeff[5];
+ pTmp = aKoeff[5].data();
nSumR += pTmp[(++pColor)->GetRed()];
nSumG += pTmp[pColor->GetGreen()];
nSumB += pTmp[pColor->GetBlue()];
// third row
- pTmp = pKoeff[6];
+ pTmp = aKoeff[6].data();
pColor = pRowTmp3 + nX;
nSumR += pTmp[pColor->GetRed()];
nSumG += pTmp[pColor->GetGreen()];
nSumB += pTmp[pColor->GetBlue()];
- pTmp = pKoeff[7];
+ pTmp = aKoeff[7].data();
nSumR += pTmp[(++pColor)->GetRed()];
nSumG += pTmp[pColor->GetGreen()];
nSumB += pTmp[pColor->GetBlue()];
- pTmp = pKoeff[8];
+ pTmp = aKoeff[8].data();
nSumR += pTmp[(++pColor)->GetRed()];
nSumG += pTmp[pColor->GetGreen()];
nSumB += pTmp[pColor->GetBlue()];
@@ -152,23 +150,23 @@ BitmapEx BitmapConvolutionMatrixFilter::execute(BitmapEx const& rBitmapEx) const
if (++nY < nHeight)
{
- if (pRowTmp1 == pColRow1)
+ if (pRowTmp1 == pColRow1.get())
{
- pRowTmp1 = pColRow2;
- pRowTmp2 = pColRow3;
- pRowTmp3 = pColRow1;
+ pRowTmp1 = pColRow2.get();
+ pRowTmp2 = pColRow3.get();
+ pRowTmp3 = pColRow1.get();
}
- else if (pRowTmp1 == pColRow2)
+ else if (pRowTmp1 == pColRow2.get())
{
- pRowTmp1 = pColRow3;
- pRowTmp2 = pColRow1;
- pRowTmp3 = pColRow2;
+ pRowTmp1 = pColRow3.get();
+ pRowTmp2 = pColRow1.get();
+ pRowTmp3 = pColRow2.get();
}
else
{
- pRowTmp1 = pColRow1;
- pRowTmp2 = pColRow2;
- pRowTmp3 = pColRow3;
+ pRowTmp1 = pColRow1.get();
+ pRowTmp2 = pColRow2.get();
+ pRowTmp3 = pColRow3.get();
}
for (i = 0; i < nWidth2; i++)
@@ -178,13 +176,6 @@ BitmapEx BitmapConvolutionMatrixFilter::execute(BitmapEx const& rBitmapEx) const
}
}
- delete[] pKoeff;
- delete[] reinterpret_cast<sal_uInt8*>(pColRow1);
- delete[] reinterpret_cast<sal_uInt8*>(pColRow2);
- delete[] reinterpret_cast<sal_uInt8*>(pColRow3);
- delete[] pColm;
- delete[] pRows;
-
pWriteAcc.reset();
bRet = true;
diff --git a/vcl/source/bitmap/BitmapEmbossGreyFilter.cxx b/vcl/source/bitmap/BitmapEmbossGreyFilter.cxx
index 6af3dfa2bf7c..3b20d14657df 100644
--- a/vcl/source/bitmap/BitmapEmbossGreyFilter.cxx
+++ b/vcl/source/bitmap/BitmapEmbossGreyFilter.cxx
@@ -46,8 +46,8 @@ BitmapEx BitmapEmbossGreyFilter::execute(BitmapEx const& rBitmapEx) const
long nGrey31, nGrey32, nGrey33;
double fAzim = basegfx::deg2rad(mnAzimuthAngle100 * 0.01);
double fElev = basegfx::deg2rad(mnElevationAngle100 * 0.01);
- long* pHMap = new long[nWidth + 2];
- long* pVMap = new long[nHeight + 2];
+ std::unique_ptr<long[]> pHMap(new long[nWidth + 2]);
+ std::unique_ptr<long[]> pVMap(new long[nHeight + 2]);
long nX, nY, nNx, nNy, nDotL;
const long nLx = FRound(cos(fAzim) * cos(fElev) * 255.0);
const long nLy = FRound(sin(fAzim) * cos(fElev) * 255.0);
@@ -127,8 +127,8 @@ BitmapEx BitmapEmbossGreyFilter::execute(BitmapEx const& rBitmapEx) const
}
}
- delete[] pHMap;
- delete[] pVMap;
+ pHMap.reset();
+ pVMap.reset();
pWriteAcc.reset();
bRet = true;
}
diff --git a/vcl/source/bitmap/BitmapMedianFilter.cxx b/vcl/source/bitmap/BitmapMedianFilter.cxx
index 47a298dd6039..a8a6e7c9f233 100644
--- a/vcl/source/bitmap/BitmapMedianFilter.cxx
+++ b/vcl/source/bitmap/BitmapMedianFilter.cxx
@@ -68,17 +68,14 @@ BitmapEx BitmapMedianFilter::execute(BitmapEx const& rBitmapEx) const
{
const long nWidth = pWriteAcc->Width(), nWidth2 = nWidth + 2;
const long nHeight = pWriteAcc->Height(), nHeight2 = nHeight + 2;
- long* pColm = new long[nWidth2];
- long* pRows = new long[nHeight2];
- BitmapColor* pColRow1
- = reinterpret_cast<BitmapColor*>(new sal_uInt8[sizeof(BitmapColor) * nWidth2]);
- BitmapColor* pColRow2
- = reinterpret_cast<BitmapColor*>(new sal_uInt8[sizeof(BitmapColor) * nWidth2]);
- BitmapColor* pColRow3
- = reinterpret_cast<BitmapColor*>(new sal_uInt8[sizeof(BitmapColor) * nWidth2]);
- BitmapColor* pRowTmp1 = pColRow1;
- BitmapColor* pRowTmp2 = pColRow2;
- BitmapColor* pRowTmp3 = pColRow3;
+ std::unique_ptr<long[]> pColm(new long[nWidth2]);
+ std::unique_ptr<long[]> pRows(new long[nHeight2]);
+ std::unique_ptr<BitmapColor[]> pColRow1(new BitmapColor[nWidth2]);
+ std::unique_ptr<BitmapColor[]> pColRow2(new BitmapColor[nWidth2]);
+ std::unique_ptr<BitmapColor[]> pColRow3(new BitmapColor[nWidth2]);
+ BitmapColor* pRowTmp1 = pColRow1.get();
+ BitmapColor* pRowTmp2 = pColRow2.get();
+ BitmapColor* pRowTmp3 = pColRow3.get();
BitmapColor* pColor;
long nY, nX, i;
long nR1, nR2, nR3, nR4, nR5, nR6, nR7, nR8, nR9;
@@ -171,23 +168,23 @@ BitmapEx BitmapMedianFilter::execute(BitmapEx const& rBitmapEx) const
if (++nY < nHeight)
{
- if (pRowTmp1 == pColRow1)
+ if (pRowTmp1 == pColRow1.get())
{
- pRowTmp1 = pColRow2;
- pRowTmp2 = pColRow3;
- pRowTmp3 = pColRow1;
+ pRowTmp1 = pColRow2.get();
+ pRowTmp2 = pColRow3.get();
+ pRowTmp3 = pColRow1.get();
}
- else if (pRowTmp1 == pColRow2)
+ else if (pRowTmp1 == pColRow2.get())
{
- pRowTmp1 = pColRow3;
- pRowTmp2 = pColRow1;
- pRowTmp3 = pColRow2;
+ pRowTmp1 = pColRow3.get();
+ pRowTmp2 = pColRow1.get();
+ pRowTmp3 = pColRow2.get();
}
else
{
- pRowTmp1 = pColRow1;
- pRowTmp2 = pColRow2;
- pRowTmp3 = pColRow3;
+ pRowTmp1 = pColRow1.get();
+ pRowTmp2 = pColRow2.get();
+ pRowTmp3 = pColRow3.get();
}
for (i = 0; i < nWidth2; i++)
@@ -195,12 +192,6 @@ BitmapEx BitmapMedianFilter::execute(BitmapEx const& rBitmapEx) const
}
}
- delete[] reinterpret_cast<sal_uInt8*>(pColRow1);
- delete[] reinterpret_cast<sal_uInt8*>(pColRow2);
- delete[] reinterpret_cast<sal_uInt8*>(pColRow3);
- delete[] pColm;
- delete[] pRows;
-
pWriteAcc.reset();
bRet = true;
diff --git a/vcl/source/bitmap/BitmapMosaicFilter.cxx b/vcl/source/bitmap/BitmapMosaicFilter.cxx
index 0b94cf845f7c..ee0d102750dc 100644
--- a/vcl/source/bitmap/BitmapMosaicFilter.cxx
+++ b/vcl/source/bitmap/BitmapMosaicFilter.cxx
@@ -23,18 +23,17 @@ BitmapEx BitmapMosaicFilter::execute(BitmapEx const& rBitmapEx) const
if (mnTileWidth > 1 || mnTileHeight > 1)
{
- Bitmap* pNewBmp;
+ std::unique_ptr<Bitmap> pNewBmp;
BitmapReadAccess* pReadAcc;
BitmapWriteAccess* pWriteAcc;
if (aBitmap.GetBitCount() > 8)
{
- pNewBmp = nullptr;
pReadAcc = pWriteAcc = aBitmap.AcquireWriteAccess();
}
else
{
- pNewBmp = new Bitmap(aBitmap.GetSizePixel(), 24);
+ pNewBmp.reset(new Bitmap(aBitmap.GetSizePixel(), 24));
pReadAcc = aBitmap.AcquireReadAccess();
pWriteAcc = pNewBmp->AcquireWriteAccess();
}
@@ -174,8 +173,6 @@ BitmapEx BitmapMosaicFilter::execute(BitmapEx const& rBitmapEx) const
aBitmap.SetPrefMapMode(aMap);
aBitmap.SetPrefSize(aPrefSize);
}
-
- delete pNewBmp;
}
}
diff --git a/vcl/source/bitmap/BitmapPopArtFilter.cxx b/vcl/source/bitmap/BitmapPopArtFilter.cxx
index 271cb658258b..6f83ad47c566 100644
--- a/vcl/source/bitmap/BitmapPopArtFilter.cxx
+++ b/vcl/source/bitmap/BitmapPopArtFilter.cxx
@@ -35,11 +35,11 @@ BitmapEx BitmapPopArtFilter::execute(BitmapEx const& rBitmapEx) const
const long nHeight = pWriteAcc->Height();
const int nEntryCount = 1 << pWriteAcc->GetBitCount();
int n = 0;
- PopArtEntry* pPopArtTable = new PopArtEntry[nEntryCount];
+ std::vector<PopArtEntry> aPopArtTable(nEntryCount);
for (n = 0; n < nEntryCount; n++)
{
- PopArtEntry& rEntry = pPopArtTable[n];
+ PopArtEntry& rEntry = aPopArtTable[n];
rEntry.mnIndex = static_cast<sal_uInt16>(n);
rEntry.mnCount = 0;
}
@@ -50,32 +50,30 @@ BitmapEx BitmapPopArtFilter::execute(BitmapEx const& rBitmapEx) const
Scanline pScanline = pWriteAcc->GetScanline(nY);
for (long nX = 0; nX < nWidth; nX++)
{
- pPopArtTable[pWriteAcc->GetIndexFromData(pScanline, nX)].mnCount++;
+ aPopArtTable[pWriteAcc->GetIndexFromData(pScanline, nX)].mnCount++;
}
}
// sort table
- std::qsort(pPopArtTable, nEntryCount, sizeof(PopArtEntry),
- [](const void* p1, const void* p2) {
- int nRet;
-
- if (static_cast<PopArtEntry const*>(p1)->mnCount
- < static_cast<PopArtEntry const*>(p2)->mnCount)
- {
- nRet = 1;
- }
- else if (static_cast<PopArtEntry const*>(p1)->mnCount
- == static_cast<PopArtEntry const*>(p2)->mnCount)
- {
- nRet = 0;
- }
- else
- {
- nRet = -1;
- }
-
- return nRet;
- });
+ std::sort(aPopArtTable.begin(), aPopArtTable.end(),
+ [](const PopArtEntry& lhs, const PopArtEntry& rhs) {
+ int nRet;
+
+ if (lhs.mnCount < rhs.mnCount)
+ {
+ nRet = 1;
+ }
+ else if (lhs.mnCount == rhs.mnCount)
+ {
+ nRet = 0;
+ }
+ else
+ {
+ nRet = -1;
+ }
+
+ return nRet;
+ });
// get last used entry
sal_uLong nFirstEntry;
@@ -83,27 +81,26 @@ BitmapEx BitmapPopArtFilter::execute(BitmapEx const& rBitmapEx) const
for (n = 0; n < nEntryCount; n++)
{
- if (pPopArtTable[n].mnCount)
+ if (aPopArtTable[n].mnCount)
nLastEntry = n;
}
// rotate palette (one entry)
const BitmapColor aFirstCol(pWriteAcc->GetPaletteColor(
- sal::static_int_cast<sal_uInt16>(pPopArtTable[0].mnIndex)));
+ sal::static_int_cast<sal_uInt16>(aPopArtTable[0].mnIndex)));
for (nFirstEntry = 0; nFirstEntry < nLastEntry; nFirstEntry++)
{
pWriteAcc->SetPaletteColor(
- sal::static_int_cast<sal_uInt16>(pPopArtTable[nFirstEntry].mnIndex),
+ sal::static_int_cast<sal_uInt16>(aPopArtTable[nFirstEntry].mnIndex),
pWriteAcc->GetPaletteColor(
- sal::static_int_cast<sal_uInt16>(pPopArtTable[nFirstEntry + 1].mnIndex)));
+ sal::static_int_cast<sal_uInt16>(aPopArtTable[nFirstEntry + 1].mnIndex)));
}
pWriteAcc->SetPaletteColor(
- sal::static_int_cast<sal_uInt16>(pPopArtTable[nLastEntry].mnIndex), aFirstCol);
+ sal::static_int_cast<sal_uInt16>(aPopArtTable[nLastEntry].mnIndex), aFirstCol);
// cleanup
- delete[] pPopArtTable;
pWriteAcc.reset();
bRet = true;
}
diff --git a/vcl/source/bitmap/BitmapSobelGreyFilter.cxx b/vcl/source/bitmap/BitmapSobelGreyFilter.cxx
index a631fe4f30a2..397d0e6d1d5c 100644
--- a/vcl/source/bitmap/BitmapSobelGreyFilter.cxx
+++ b/vcl/source/bitmap/BitmapSobelGreyFilter.cxx
@@ -49,8 +49,8 @@ BitmapEx BitmapSobelGreyFilter::execute(BitmapEx const& rBitmapEx) const
long nGrey11, nGrey12, nGrey13;
long nGrey21, nGrey22, nGrey23;
long nGrey31, nGrey32, nGrey33;
- long* pHMap = new long[nWidth + 2];
- long* pVMap = new long[nHeight + 2];
+ std::unique_ptr<long[]> pHMap(new long[nWidth + 2]);
+ std::unique_ptr<long[]> pVMap(new long[nHeight + 2]);
long nX, nY, nSum1, nSum2;
// fill mapping tables
@@ -139,8 +139,8 @@ BitmapEx BitmapSobelGreyFilter::execute(BitmapEx const& rBitmapEx) const
}
}
- delete[] pHMap;
- delete[] pVMap;
+ pHMap.reset();
+ pVMap.reset();
pWriteAcc.reset();
bRet = true;
}
diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx
index a63c0b49d590..d76ae3950b4d 100644
--- a/vcl/source/bitmap/bitmap.cxx
+++ b/vcl/source/bitmap/bitmap.cxx
@@ -348,41 +348,38 @@ void Bitmap::ImplSetSalBitmap(const std::shared_ptr<SalBitmap>& xImpBmp)
BitmapInfoAccess* Bitmap::AcquireInfoAccess()
{
- BitmapInfoAccess* pInfoAccess = new BitmapInfoAccess( *this );
+ std::unique_ptr<BitmapInfoAccess> pInfoAccess(new BitmapInfoAccess( *this ));
if( !*pInfoAccess )
{
- delete pInfoAccess;
- pInfoAccess = nullptr;
+ return nullptr;;
}
- return pInfoAccess;
+ return pInfoAccess.release();
}
BitmapReadAccess* Bitmap::AcquireReadAccess()
{
- BitmapReadAccess* pReadAccess = new BitmapReadAccess( *this );
+ std::unique_ptr<BitmapReadAccess> pReadAccess(new BitmapReadAccess( *this ));
if( !*pReadAccess )
{
- delete pReadAccess;
- pReadAccess = nullptr;
+ return nullptr;
}
- return pReadAccess;
+ return pReadAccess.release();
}
BitmapWriteAccess* Bitmap::AcquireWriteAccess()
{
- BitmapWriteAccess* pWriteAccess = new BitmapWriteAccess( *this );
+ std::unique_ptr<BitmapWriteAccess> pWriteAccess(new BitmapWriteAccess( *this ));
if( !*pWriteAccess )
{
- delete pWriteAccess;
- pWriteAccess = nullptr;
+ return nullptr;
}
- return pWriteAccess;
+ return pWriteAccess.release();
}
void Bitmap::ReleaseAccess( BitmapInfoAccess* pBitmapAccess )
diff --git a/vcl/source/gdi/bitmapex.cxx b/vcl/source/gdi/bitmapex.cxx
index d5cf8178c34f..3db94e9171f3 100644
--- a/vcl/source/gdi/bitmapex.cxx
+++ b/vcl/source/gdi/bitmapex.cxx
@@ -503,20 +503,20 @@ bool BitmapEx::CopyPixel( const tools::Rectangle& rRectDst, const tools::Rectang
maMask.CopyPixel_AlphaOptimized( rRectDst, rRectSrc, &pBmpExSrc->maMask );
else if( IsTransparent() )
{
- AlphaMask* pAlpha = new AlphaMask( maMask );
+ std::unique_ptr<AlphaMask> pAlpha(new AlphaMask( maMask ));
maMask = pAlpha->ImplGetBitmap();
- delete pAlpha;
+ pAlpha.reset();
mbAlpha = true;
maMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->maMask );
}
else
{
sal_uInt8 cBlack = 0;
- AlphaMask* pAlpha = new AlphaMask(GetSizePixel(), &cBlack);
+ std::unique_ptr<AlphaMask> pAlpha(new AlphaMask(GetSizePixel(), &cBlack));
maMask = pAlpha->ImplGetBitmap();
- delete pAlpha;
+ pAlpha.reset();
meTransparent = TransparentType::Bitmap;
mbAlpha = true;
maMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->maMask );
diff --git a/vcl/source/gdi/impvect.cxx b/vcl/source/gdi/impvect.cxx
index 67d54d5fe77e..2b959aee204b 100644
--- a/vcl/source/gdi/impvect.cxx
+++ b/vcl/source/gdi/impvect.cxx
@@ -30,6 +30,7 @@
#include <vcl/wrkwin.hxx>
#include <vcl/virdev.hxx>
#include "impvect.hxx"
+#include <array>
#include <memory>
#define VECT_POLY_MAX 8192
@@ -112,23 +113,19 @@ struct ImplColorSet
bool mbSet = false;
};
-extern "C" {
-
-static int ImplColorSetCmpFnc( const void* p1, const void* p2 )
+static int ImplColorSetCmpFnc( const ImplColorSet& lhs, const ImplColorSet& rhs)
{
- ImplColorSet const * pSet1 = static_cast<ImplColorSet const *>(p1);
- ImplColorSet const * pSet2 = static_cast<ImplColorSet const *>(p2);
int nRet;
- if( pSet1->mbSet && pSet2->mbSet )
+ if( lhs.mbSet && rhs.mbSet )
{
- const sal_uInt8 cLum1 = pSet1->maColor.GetLuminance();
- const sal_uInt8 cLum2 = pSet2->maColor.GetLuminance();
- nRet = ( ( cLum1 > cLum2 ) ? -1 : ( ( cLum1 == cLum2 ) ? 0 : 1 ) );
+ const sal_uInt8 cLum1 = lhs.maColor.GetLuminance();
+ const sal_uInt8 cLum2 = rhs.maColor.GetLuminance();
+ nRet = ( cLum1 > cLum2 ) ? -1 : ( ( cLum1 == cLum2 ) ? 0 : 1 );
}
- else if( pSet1->mbSet )
+ else if( lhs.mbSet )
nRet = -1;
- else if( pSet2->mbSet )
+ else if( rhs.mbSet )
nRet = 1;
else
nRet = 0;
@@ -136,8 +133,6 @@ static int ImplColorSetCmpFnc( const void* p1, const void* p2 )
return nRet;
}
-}
-
class ImplPointArray
{
std::unique_ptr<Point[]> mpArray;
@@ -652,28 +647,28 @@ bool ImplVectorize( const Bitmap& rColorBmp, GDIMetaFile& rMtf,
const long nHeight = pRAcc->Height();
const sal_uInt16 nColorCount = pRAcc->GetPaletteEntryCount();
sal_uInt16 n;
- ImplColorSet* pColorSet = new ImplColorSet[ 256 ];
+ std::array<ImplColorSet, 256> aColorSet;
rMtf.Clear();
// get used palette colors and sort them from light to dark colors
for( n = 0; n < nColorCount; n++ )
{
- pColorSet[ n ].mnIndex = n;
- pColorSet[ n ].maColor = pRAcc->GetPaletteColor( n );
+ aColorSet[ n ].mnIndex = n;
+ aColorSet[ n ].maColor = pRAcc->GetPaletteColor( n );
}
for( long nY = 0; nY < nHeight; nY++ )
{
Scanline pScanlineRead = pRAcc->GetScanline( nY );
for( long nX = 0; nX < nWidth; nX++ )
- pColorSet[ pRAcc->GetIndexFromData( pScanlineRead, nX ) ].mbSet = true;
+ aColorSet[ pRAcc->GetIndexFromData( pScanlineRead, nX ) ].mbSet = true;
}
- qsort( pColorSet, 256, sizeof( ImplColorSet ), ImplColorSetCmpFnc );
+ std::sort( aColorSet.begin(), aColorSet.end(), ImplColorSetCmpFnc );
for( n = 0; n < 256; n++ )
- if( !pColorSet[ n ].mbSet )
+ if( !aColorSet[ n ].mbSet )
break;
if( n )
@@ -684,7 +679,7 @@ bool ImplVectorize( const Bitmap& rColorBmp, GDIMetaFile& rMtf,
for( sal_uInt16 i = 0; i < n; i++ )
{
- const BitmapColor aBmpCol( pRAcc->GetPaletteColor( pColorSet[ i ].mnIndex ) );
+ const BitmapColor aBmpCol( pRAcc->GetPaletteColor( aColorSet[ i ].mnIndex ) );
const Color aFindColor( aBmpCol.GetRed(), aBmpCol.GetGreen(), aBmpCol.GetBlue() );
std::unique_ptr<ImplVectMap> xMap(ImplExpand( pRAcc.get(), aFindColor ));
@@ -716,8 +711,6 @@ bool ImplVectorize( const Bitmap& rColorBmp, GDIMetaFile& rMtf,
VECT_PROGRESS( pProgress, FRound( fPercent ) );
}
- delete[] pColorSet;
-
if( rMtf.GetActionSize() )
{
MapMode aMap( MapUnit::Map100thMM );
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 085381e6fae0..3afb4c509abf 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -9727,7 +9727,7 @@ void PDFWriterImpl::drawJPGBitmap( SvStream& rDCTData, bool bIsTrueColor, const
return;
}
- SvMemoryStream* pStream = new SvMemoryStream;
+ std::unique_ptr<SvMemoryStream> pStream(new SvMemoryStream);
pStream->WriteStream( rDCTData );
pStream->Seek( STREAM_SEEK_TO_END );
@@ -9748,7 +9748,7 @@ void PDFWriterImpl::drawJPGBitmap( SvStream& rDCTData, bool bIsTrueColor, const
if (!rGraphic.hasPdfData() || m_aContext.UseReferenceXObject)
rEmit.m_nObject = createObject();
rEmit.m_aID = aID;
- rEmit.m_pStream.reset( pStream );
+ rEmit.m_pStream = std::move( pStream );
rEmit.m_bTrueColor = bIsTrueColor;
if( !! rMask && rMask.GetSizePixel() == rSizePixel )
rEmit.m_aMask = rMask;
@@ -9756,8 +9756,6 @@ void PDFWriterImpl::drawJPGBitmap( SvStream& rDCTData, bool bIsTrueColor, const
it = m_aJPGs.begin();
}
- else
- delete pStream;
aLine.append( "q " );
sal_Int32 nCheckWidth = 0;
diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx
index 0d72b18e1231..2443b6877e22 100644
--- a/vcl/source/gdi/print.cxx
+++ b/vcl/source/gdi/print.cxx
@@ -381,23 +381,17 @@ static void ImplInitPrnQueueList()
{
ImplSVData* pSVData = ImplGetSVData();
- pSVData->maGDIData.mpPrinterQueueList = new ImplPrnQueueList;
+ pSVData->maGDIData.mpPrinterQueueList.reset(new ImplPrnQueueList);
static const char* pEnv = getenv( "SAL_DISABLE_PRINTERLIST" );
if( !pEnv || !*pEnv )
- pSVData->mpDefInst->GetPrinterQueueInfo( pSVData->maGDIData.mpPrinterQueueList );
+ pSVData->mpDefInst->GetPrinterQueueInfo( pSVData->maGDIData.mpPrinterQueueList.get() );
}
void ImplDeletePrnQueueList()
{
ImplSVData* pSVData = ImplGetSVData();
- ImplPrnQueueList* pPrnList = pSVData->maGDIData.mpPrinterQueueList;
-
- if ( pPrnList )
- {
- delete pPrnList;
- pSVData->maGDIData.mpPrinterQueueList = nullptr;
- }
+ pSVData->maGDIData.mpPrinterQueueList.reset();
}
const std::vector<OUString>& Printer::GetPrinterQueues()
@@ -781,7 +775,7 @@ SalPrinterQueueInfo* Printer::ImplGetQueueInfo( const OUString& rPrinterName,
if ( !pSVData->maGDIData.mpPrinterQueueList )
ImplInitPrnQueueList();
- ImplPrnQueueList* pPrnList = pSVData->maGDIData.mpPrinterQueueList;
+ ImplPrnQueueList* pPrnList = pSVData->maGDIData.mpPrinterQueueList.get();
if ( pPrnList && !pPrnList->m_aQueueInfos.empty() )
{
// first search for the printer name directly
@@ -1624,12 +1618,12 @@ void Printer::ImplEndPage()
void Printer::updatePrinters()
{
ImplSVData* pSVData = ImplGetSVData();
- ImplPrnQueueList* pPrnList = pSVData->maGDIData.mpPrinterQueueList;
+ ImplPrnQueueList* pPrnList = pSVData->maGDIData.mpPrinterQueueList.get();
if ( pPrnList )
{
- ImplPrnQueueList* pNewList = new ImplPrnQueueList;
- pSVData->mpDefInst->GetPrinterQueueInfo( pNewList );
+ std::unique_ptr<ImplPrnQueueList> pNewList(new ImplPrnQueueList);
+ pSVData->mpDefInst->GetPrinterQueueInfo( pNewList.get() );
bool bChanged = pPrnList->m_aQueueInfos.size() != pNewList->m_aQueueInfos.size();
for( decltype(pPrnList->m_aQueueInfos)::size_type i = 0; ! bChanged && i < pPrnList->m_aQueueInfos.size(); i++ )
@@ -1645,7 +1639,7 @@ void Printer::updatePrinters()
if( bChanged )
{
ImplDeletePrnQueueList();
- pSVData->maGDIData.mpPrinterQueueList = pNewList;
+ pSVData->maGDIData.mpPrinterQueueList = std::move(pNewList);
Application* pApp = GetpApp();
if( pApp )
@@ -1655,8 +1649,6 @@ void Printer::updatePrinters()
Application::NotifyAllWindows( aDCEvt );
}
}
- else
- delete pNewList;
}
}