From ba587ee7a647003823efe29cdc67900e64030ea7 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 9 Dec 2020 19:59:29 +0000 Subject: std::vector seems a more natural container MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I5256e05a6f3c4853a81d9c4a94bbcbf27f0a3ae9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107504 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- vcl/source/bitmap/bitmappaint.cxx | 57 +++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 29 deletions(-) (limited to 'vcl/source/bitmap') diff --git a/vcl/source/bitmap/bitmappaint.cxx b/vcl/source/bitmap/bitmappaint.cxx index 95a6b0af6a3e..215f0e8e137a 100644 --- a/vcl/source/bitmap/bitmappaint.cxx +++ b/vcl/source/bitmap/bitmappaint.cxx @@ -926,12 +926,12 @@ bool Bitmap::Replace(const Color* pSearchColors, const Color* pReplaceColors, sa if (pAcc) { - std::unique_ptr pMinR(new int[nColorCount]); - std::unique_ptr pMaxR(new int[nColorCount]); - std::unique_ptr pMinG(new int[nColorCount]); - std::unique_ptr pMaxG(new int[nColorCount]); - std::unique_ptr pMinB(new int[nColorCount]); - std::unique_ptr pMaxB(new int[nColorCount]); + std::vector aMinR(nColorCount); + std::vector aMaxR(nColorCount); + std::vector aMinG(nColorCount); + std::vector aMaxG(nColorCount); + std::vector aMinB(nColorCount); + std::vector aMaxB(nColorCount); if (pTols) { @@ -940,12 +940,12 @@ bool Bitmap::Replace(const Color* pSearchColors, const Color* pReplaceColors, sa const Color& rCol = pSearchColors[i]; const sal_uInt8 nTol = pTols[i]; - pMinR[i] = std::clamp(rCol.GetRed() - nTol, 0, 255); - pMaxR[i] = std::clamp(rCol.GetRed() + nTol, 0, 255); - pMinG[i] = std::clamp(rCol.GetGreen() - nTol, 0, 255); - pMaxG[i] = std::clamp(rCol.GetGreen() + nTol, 0, 255); - pMinB[i] = std::clamp(rCol.GetBlue() - nTol, 0, 255); - pMaxB[i] = std::clamp(rCol.GetBlue() + nTol, 0, 255); + aMinR[i] = std::clamp(rCol.GetRed() - nTol, 0, 255); + aMaxR[i] = std::clamp(rCol.GetRed() + nTol, 0, 255); + aMinG[i] = std::clamp(rCol.GetGreen() - nTol, 0, 255); + aMaxG[i] = std::clamp(rCol.GetGreen() + nTol, 0, 255); + aMinB[i] = std::clamp(rCol.GetBlue() - nTol, 0, 255); + aMaxB[i] = std::clamp(rCol.GetBlue() + nTol, 0, 255); } } else @@ -954,12 +954,12 @@ bool Bitmap::Replace(const Color* pSearchColors, const Color* pReplaceColors, sa { const Color& rCol = pSearchColors[i]; - pMinR[i] = rCol.GetRed(); - pMaxR[i] = rCol.GetRed(); - pMinG[i] = rCol.GetGreen(); - pMaxG[i] = rCol.GetGreen(); - pMinB[i] = rCol.GetBlue(); - pMaxB[i] = rCol.GetBlue(); + aMinR[i] = rCol.GetRed(); + aMaxR[i] = rCol.GetRed(); + aMinG[i] = rCol.GetGreen(); + aMaxG[i] = rCol.GetGreen(); + aMinB[i] = rCol.GetBlue(); + aMaxB[i] = rCol.GetBlue(); } } @@ -972,9 +972,9 @@ bool Bitmap::Replace(const Color* pSearchColors, const Color* pReplaceColors, sa for (sal_uLong i = 0; i < nColorCount; i++) { - if (pMinR[i] <= rCol.GetRed() && pMaxR[i] >= rCol.GetRed() - && pMinG[i] <= rCol.GetGreen() && pMaxG[i] >= rCol.GetGreen() - && pMinB[i] <= rCol.GetBlue() && pMaxB[i] >= rCol.GetBlue()) + if (aMinR[i] <= rCol.GetRed() && aMaxR[i] >= rCol.GetRed() + && aMinG[i] <= rCol.GetGreen() && aMaxG[i] >= rCol.GetGreen() + && aMinB[i] <= rCol.GetBlue() && aMaxB[i] >= rCol.GetBlue()) { pAcc->SetPaletteColor(nEntry, pReplaceColors[i]); break; @@ -984,26 +984,25 @@ bool Bitmap::Replace(const Color* pSearchColors, const Color* pReplaceColors, sa } else { - BitmapColor aCol; - std::unique_ptr pReplaces(new BitmapColor[nColorCount]); + std::vector aReplaces(nColorCount); for (sal_uLong i = 0; i < nColorCount; i++) - pReplaces[i] = pAcc->GetBestMatchingColor(pReplaceColors[i]); + aReplaces[i] = pAcc->GetBestMatchingColor(pReplaceColors[i]); for (tools::Long nY = 0, nHeight = pAcc->Height(); nY < nHeight; nY++) { Scanline pScanline = pAcc->GetScanline(nY); for (tools::Long nX = 0, nWidth = pAcc->Width(); nX < nWidth; nX++) { - aCol = pAcc->GetPixelFromData(pScanline, nX); + BitmapColor aCol = pAcc->GetPixelFromData(pScanline, nX); for (sal_uLong i = 0; i < nColorCount; i++) { - if (pMinR[i] <= aCol.GetRed() && pMaxR[i] >= aCol.GetRed() - && pMinG[i] <= aCol.GetGreen() && pMaxG[i] >= aCol.GetGreen() - && pMinB[i] <= aCol.GetBlue() && pMaxB[i] >= aCol.GetBlue()) + if (aMinR[i] <= aCol.GetRed() && aMaxR[i] >= aCol.GetRed() + && aMinG[i] <= aCol.GetGreen() && aMaxG[i] >= aCol.GetGreen() + && aMinB[i] <= aCol.GetBlue() && aMaxB[i] >= aCol.GetBlue()) { - pAcc->SetPixelOnData(pScanline, nX, pReplaces[i]); + pAcc->SetPixelOnData(pScanline, nX, aReplaces[i]); break; } } -- cgit