diff options
author | Chris Sherlock <chris.sherlock79@gmail.com> | 2024-09-01 03:08:27 +1000 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2024-09-10 13:30:04 +0200 |
commit | eb3d1b3cade22c323d83973e8a087fe2d1b7bff0 (patch) | |
tree | 59a6de3fb0c8ff798443e893739c2ea78ac573cb /vcl | |
parent | 4529ffc6439250bf3edc705117f9af1ad116dc36 (diff) |
vcl: variable refactoring BitmapConvolutionMatrixFilter::execute()
Renamed variables, moved to declare closer to first use.
Change-Id: I60b909c79d7c12c81247af2013228be84b42991e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172916
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Jenkins
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx | 68 |
1 files changed, 36 insertions, 32 deletions
diff --git a/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx b/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx index ea11a1c0a2c5..4caed2b7b3be 100644 --- a/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx +++ b/vcl/source/bitmap/BitmapConvolutionMatrixFilter.cxx @@ -22,7 +22,6 @@ BitmapEx BitmapConvolutionMatrixFilter::execute(BitmapEx const& rBitmapEx) const { Bitmap aBitmap(rBitmapEx.GetBitmap()); - const sal_Int32 nDivisor = 8; BitmapScopedReadAccess pReadAcc(aBitmap); if (!pReadAcc) return BitmapEx(); @@ -32,66 +31,69 @@ BitmapEx BitmapConvolutionMatrixFilter::execute(BitmapEx const& rBitmapEx) const if (!pWriteAcc) return BitmapEx(); - const sal_Int32 nWidth = pWriteAcc->Width(), nWidth2 = nWidth + 2; - const sal_Int32 nHeight = pWriteAcc->Height(), nHeight2 = nHeight + 2; - std::unique_ptr<sal_Int32[]> pColm(new sal_Int32[nWidth2]); - std::unique_ptr<sal_Int32[]> pRows(new sal_Int32[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; - sal_Int32 nY, nX, i, nSumR, nSumG, nSumB, nMatrixVal, nTmp; std::array<std::array<sal_Int32, 256>, 9> aKoeff; - sal_Int32* pTmp; // create LUT of products of matrix value and possible color component values - for (nY = 0; nY < 9; nY++) + for (sal_Int32 nY = 0; nY < 9; nY++) { - for (nX = nTmp = 0, nMatrixVal = mrMatrix[nY]; nX < 256; nX++, nTmp += nMatrixVal) + for (sal_Int32 nX = 0, nTmp = 0, nMatrixVal = mrMatrix[nY]; nX < 256; + nX++, nTmp += nMatrixVal) { aKoeff[nY][nX] = nTmp; } } + const sal_Int32 nWidth = pWriteAcc->Width(); + const sal_Int32 nWidth2 = nWidth + 2; + std::unique_ptr<sal_Int32[]> pColm(new sal_Int32[nWidth2]); + // create column LUT - for (i = 0; i < nWidth2; i++) + for (sal_Int32 nColIdx = 0; nColIdx < nWidth2; nColIdx++) { - pColm[i] = (i > 0) ? (i - 1) : 0; + pColm[nColIdx] = (nColIdx > 0) ? (nColIdx - 1) : 0; } pColm[nWidth + 1] = pColm[nWidth]; + const sal_Int32 nHeight = pWriteAcc->Height(); + const sal_Int32 nHeight2 = nHeight + 2; + std::unique_ptr<sal_Int32[]> pRows(new sal_Int32[nHeight2]); + // create row LUT - for (i = 0; i < nHeight2; i++) + for (sal_Int32 nRowIdx = 0; nRowIdx < nHeight2; nRowIdx++) { - pRows[i] = (i > 0) ? (i - 1) : 0; + pRows[nRowIdx] = (nRowIdx > 0) ? (nRowIdx - 1) : 0; } pRows[nHeight + 1] = pRows[nHeight]; + 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(); + // read first three rows of bitmap color - for (i = 0; i < nWidth2; i++) + for (sal_Int32 nRowIdx = 0; nRowIdx < nWidth2; nRowIdx++) { - pColRow1[i] = pReadAcc->GetColor(pRows[0], pColm[i]); - pColRow2[i] = pReadAcc->GetColor(pRows[1], pColm[i]); - pColRow3[i] = pReadAcc->GetColor(pRows[2], pColm[i]); + pColRow1[nRowIdx] = pReadAcc->GetColor(pRows[0], pColm[nRowIdx]); + pColRow2[nRowIdx] = pReadAcc->GetColor(pRows[1], pColm[nRowIdx]); + pColRow3[nRowIdx] = pReadAcc->GetColor(pRows[2], pColm[nRowIdx]); } // do convolution - for (nY = 0; nY < nHeight;) + for (sal_Int32 nY = 0; nY < nHeight;) { Scanline pScanline = pWriteAcc->GetScanline(nY); - for (nX = 0; nX < nWidth; nX++) + for (sal_Int32 nX = 0; nX < nWidth; nX++) { // first row - pTmp = aKoeff[0].data(); - pColor = pRowTmp1 + nX; - nSumR = pTmp[pColor->GetRed()]; - nSumG = pTmp[pColor->GetGreen()]; - nSumB = pTmp[pColor->GetBlue()]; + sal_Int32* pTmp = aKoeff[0].data(); + BitmapColor* pColor = pRowTmp1 + nX; + sal_Int32 nSumR = pTmp[pColor->GetRed()]; + sal_Int32 nSumG = pTmp[pColor->GetGreen()]; + sal_Int32 nSumB = pTmp[pColor->GetBlue()]; pTmp = aKoeff[1].data(); nSumR += pTmp[(++pColor)->GetRed()]; @@ -137,6 +139,8 @@ BitmapEx BitmapConvolutionMatrixFilter::execute(BitmapEx const& rBitmapEx) const nSumG += pTmp[pColor->GetGreen()]; nSumB += pTmp[pColor->GetBlue()]; + const sal_Int32 nDivisor = 8; + // calculate destination color pWriteAcc->SetPixelOnData( pScanline, nX, @@ -169,7 +173,7 @@ BitmapEx BitmapConvolutionMatrixFilter::execute(BitmapEx const& rBitmapEx) const pRowTmp3 = pColRow3.get(); } - for (i = 0; i < nWidth2; i++) + for (sal_Int32 i = 0; i < nWidth2; i++) { pRowTmp3[i] = pReadAcc->GetColor(pRows[nY + 2], pColm[i]); } |