diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2023-01-03 20:14:21 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-01-04 15:35:56 +0000 |
commit | a76a135c9e9bdecd38970e293e72eeeeca000d27 (patch) | |
tree | 6848576c7410cc1b3e1d868ecd7e1cb0ae608eb9 /vcl/source | |
parent | 23d8f732cbc40f008e3ae673cbb3cacacb105420 (diff) |
flatten some vcl code
Change-Id: I3747c9ccc97ac59a2e41c1fe4427d1a2f458352a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145017
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/bitmap/BitmapMedianFilter.cxx | 274 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapMonochromeFilter.cxx | 108 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapScaleConvolutionFilter.cxx | 116 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapSepiaFilter.cxx | 119 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapSimpleColorQuantizationFilter.cxx | 127 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapSobelGreyFilter.cxx | 243 | ||||
-rw-r--r-- | vcl/source/bitmap/bitmap.cxx | 1222 | ||||
-rw-r--r-- | vcl/source/bitmap/bitmappaint.cxx | 559 | ||||
-rw-r--r-- | vcl/source/bitmap/dibtools.cxx | 50 |
9 files changed, 1337 insertions, 1481 deletions
diff --git a/vcl/source/bitmap/BitmapMedianFilter.cxx b/vcl/source/bitmap/BitmapMedianFilter.cxx index 567bc6ef20c3..a820158fa5a0 100644 --- a/vcl/source/bitmap/BitmapMedianFilter.cxx +++ b/vcl/source/bitmap/BitmapMedianFilter.cxx @@ -54,164 +54,152 @@ BitmapEx BitmapMedianFilter::execute(BitmapEx const& rBitmapEx) const Bitmap aBitmap(rBitmapEx.GetBitmap()); Bitmap::ScopedReadAccess pReadAcc(aBitmap); - bool bRet = false; - - if (pReadAcc) + if (!pReadAcc) + return BitmapEx(); + + Bitmap aNewBmp(aBitmap.GetSizePixel(), vcl::PixelFormat::N24_BPP); + BitmapScopedWriteAccess pWriteAcc(aNewBmp); + 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; + sal_Int32 nR1, nR2, nR3, nR4, nR5, nR6, nR7, nR8, nR9; + sal_Int32 nG1, nG2, nG3, nG4, nG5, nG6, nG7, nG8, nG9; + sal_Int32 nB1, nB2, nB3, nB4, nB5, nB6, nB7, nB8, nB9; + + // create column LUT + for (i = 0; i < nWidth2; i++) + pColm[i] = (i > 0) ? (i - 1) : 0; + + pColm[nWidth + 1] = pColm[nWidth]; + + // create row LUT + for (i = 0; i < nHeight2; i++) + pRows[i] = (i > 0) ? (i - 1) : 0; + + pRows[nHeight + 1] = pRows[nHeight]; + + // read first three rows of bitmap color + if (nHeight2 > 2) { - Bitmap aNewBmp(aBitmap.GetSizePixel(), vcl::PixelFormat::N24_BPP); - BitmapScopedWriteAccess pWriteAcc(aNewBmp); - - if (pWriteAcc) + for (i = 0; i < nWidth2; i++) { - 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; - sal_Int32 nR1, nR2, nR3, nR4, nR5, nR6, nR7, nR8, nR9; - sal_Int32 nG1, nG2, nG3, nG4, nG5, nG6, nG7, nG8, nG9; - sal_Int32 nB1, nB2, nB3, nB4, nB5, nB6, nB7, nB8, nB9; - - // create column LUT - for (i = 0; i < nWidth2; i++) - pColm[i] = (i > 0) ? (i - 1) : 0; - - pColm[nWidth + 1] = pColm[nWidth]; - - // create row LUT - for (i = 0; i < nHeight2; i++) - pRows[i] = (i > 0) ? (i - 1) : 0; + pColRow1[i] = pReadAcc->GetColor(pRows[0], pColm[i]); + pColRow2[i] = pReadAcc->GetColor(pRows[1], pColm[i]); + pColRow3[i] = pReadAcc->GetColor(pRows[2], pColm[i]); + } + } - pRows[nHeight + 1] = pRows[nHeight]; + // do median filtering + for (nY = 0; nY < nHeight;) + { + Scanline pScanline = pWriteAcc->GetScanline(nY); + for (nX = 0; nX < nWidth; nX++) + { + pColor = pRowTmp1 + nX; + nR1 = pColor->GetRed(); + nG1 = pColor->GetGreen(); + nB1 = pColor->GetBlue(); + nR2 = (++pColor)->GetRed(); + nG2 = pColor->GetGreen(); + nB2 = pColor->GetBlue(); + nR3 = (++pColor)->GetRed(); + nG3 = pColor->GetGreen(); + nB3 = pColor->GetBlue(); + + pColor = pRowTmp2 + nX; + nR4 = pColor->GetRed(); + nG4 = pColor->GetGreen(); + nB4 = pColor->GetBlue(); + nR5 = (++pColor)->GetRed(); + nG5 = pColor->GetGreen(); + nB5 = pColor->GetBlue(); + nR6 = (++pColor)->GetRed(); + nG6 = pColor->GetGreen(); + nB6 = pColor->GetBlue(); + + pColor = pRowTmp3 + nX; + nR7 = pColor->GetRed(); + nG7 = pColor->GetGreen(); + nB7 = pColor->GetBlue(); + nR8 = (++pColor)->GetRed(); + nG8 = pColor->GetGreen(); + nB8 = pColor->GetBlue(); + nR9 = (++pColor)->GetRed(); + nG9 = pColor->GetGreen(); + nB9 = pColor->GetBlue(); + + MNMX6(nR1, nR2, nR3, nR4, nR5, nR6); + MNMX5(nR7, nR2, nR3, nR4, nR5); + MNMX4(nR8, nR2, nR3, nR4); + MNMX3(nR9, nR2, nR3); + + MNMX6(nG1, nG2, nG3, nG4, nG5, nG6); + MNMX5(nG7, nG2, nG3, nG4, nG5); + MNMX4(nG8, nG2, nG3, nG4); + MNMX3(nG9, nG2, nG3); + + MNMX6(nB1, nB2, nB3, nB4, nB5, nB6); + MNMX5(nB7, nB2, nB3, nB4, nB5); + MNMX4(nB8, nB2, nB3, nB4); + MNMX3(nB9, nB2, nB3); + + // set destination color + pWriteAcc->SetPixelOnData(pScanline, nX, + BitmapColor(static_cast<sal_uInt8>(nR2), + static_cast<sal_uInt8>(nG2), + static_cast<sal_uInt8>(nB2))); + } - // read first three rows of bitmap color - if (nHeight2 > 2) + if (++nY < nHeight) + { + if (pRowTmp1 == pColRow1.get()) { - for (i = 0; i < nWidth2; i++) - { - pColRow1[i] = pReadAcc->GetColor(pRows[0], pColm[i]); - pColRow2[i] = pReadAcc->GetColor(pRows[1], pColm[i]); - pColRow3[i] = pReadAcc->GetColor(pRows[2], pColm[i]); - } + pRowTmp1 = pColRow2.get(); + pRowTmp2 = pColRow3.get(); + pRowTmp3 = pColRow1.get(); } - - // do median filtering - for (nY = 0; nY < nHeight;) + else if (pRowTmp1 == pColRow2.get()) { - Scanline pScanline = pWriteAcc->GetScanline(nY); - for (nX = 0; nX < nWidth; nX++) - { - pColor = pRowTmp1 + nX; - nR1 = pColor->GetRed(); - nG1 = pColor->GetGreen(); - nB1 = pColor->GetBlue(); - nR2 = (++pColor)->GetRed(); - nG2 = pColor->GetGreen(); - nB2 = pColor->GetBlue(); - nR3 = (++pColor)->GetRed(); - nG3 = pColor->GetGreen(); - nB3 = pColor->GetBlue(); - - pColor = pRowTmp2 + nX; - nR4 = pColor->GetRed(); - nG4 = pColor->GetGreen(); - nB4 = pColor->GetBlue(); - nR5 = (++pColor)->GetRed(); - nG5 = pColor->GetGreen(); - nB5 = pColor->GetBlue(); - nR6 = (++pColor)->GetRed(); - nG6 = pColor->GetGreen(); - nB6 = pColor->GetBlue(); - - pColor = pRowTmp3 + nX; - nR7 = pColor->GetRed(); - nG7 = pColor->GetGreen(); - nB7 = pColor->GetBlue(); - nR8 = (++pColor)->GetRed(); - nG8 = pColor->GetGreen(); - nB8 = pColor->GetBlue(); - nR9 = (++pColor)->GetRed(); - nG9 = pColor->GetGreen(); - nB9 = pColor->GetBlue(); - - MNMX6(nR1, nR2, nR3, nR4, nR5, nR6); - MNMX5(nR7, nR2, nR3, nR4, nR5); - MNMX4(nR8, nR2, nR3, nR4); - MNMX3(nR9, nR2, nR3); - - MNMX6(nG1, nG2, nG3, nG4, nG5, nG6); - MNMX5(nG7, nG2, nG3, nG4, nG5); - MNMX4(nG8, nG2, nG3, nG4); - MNMX3(nG9, nG2, nG3); - - MNMX6(nB1, nB2, nB3, nB4, nB5, nB6); - MNMX5(nB7, nB2, nB3, nB4, nB5); - MNMX4(nB8, nB2, nB3, nB4); - MNMX3(nB9, nB2, nB3); - - // set destination color - pWriteAcc->SetPixelOnData(pScanline, nX, - BitmapColor(static_cast<sal_uInt8>(nR2), - static_cast<sal_uInt8>(nG2), - static_cast<sal_uInt8>(nB2))); - } - - if (++nY < nHeight) - { - if (pRowTmp1 == pColRow1.get()) - { - pRowTmp1 = pColRow2.get(); - pRowTmp2 = pColRow3.get(); - pRowTmp3 = pColRow1.get(); - } - else if (pRowTmp1 == pColRow2.get()) - { - pRowTmp1 = pColRow3.get(); - pRowTmp2 = pColRow1.get(); - pRowTmp3 = pColRow2.get(); - } - else - { - pRowTmp1 = pColRow1.get(); - pRowTmp2 = pColRow2.get(); - pRowTmp3 = pColRow3.get(); - } - - for (i = 0; i < nWidth2; i++) - pRowTmp3[i] = pReadAcc->GetColor(pRows[nY + 2], pColm[i]); - } + pRowTmp1 = pColRow3.get(); + pRowTmp2 = pColRow1.get(); + pRowTmp3 = pColRow2.get(); + } + else + { + pRowTmp1 = pColRow1.get(); + pRowTmp2 = pColRow2.get(); + pRowTmp3 = pColRow3.get(); } - pWriteAcc.reset(); - - bRet = true; + for (i = 0; i < nWidth2; i++) + pRowTmp3[i] = pReadAcc->GetColor(pRows[nY + 2], pColm[i]); } + } - pReadAcc.reset(); - - if (bRet) - { - const MapMode aMap(aBitmap.GetPrefMapMode()); - const Size aPrefSize(aBitmap.GetPrefSize()); + pWriteAcc.reset(); + pReadAcc.reset(); - aBitmap = aNewBmp; + const MapMode aMap(aBitmap.GetPrefMapMode()); + const Size aPrefSize(aBitmap.GetPrefSize()); - aBitmap.SetPrefMapMode(aMap); - aBitmap.SetPrefSize(aPrefSize); - } - } + aBitmap = aNewBmp; - if (bRet) - return BitmapEx(aBitmap); + aBitmap.SetPrefMapMode(aMap); + aBitmap.SetPrefSize(aPrefSize); - return BitmapEx(); + return BitmapEx(aBitmap); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/bitmap/BitmapMonochromeFilter.cxx b/vcl/source/bitmap/BitmapMonochromeFilter.cxx index 1e4e6edf4cb1..5c294544aa1e 100644 --- a/vcl/source/bitmap/BitmapMonochromeFilter.cxx +++ b/vcl/source/bitmap/BitmapMonochromeFilter.cxx @@ -18,83 +18,71 @@ BitmapEx BitmapMonochromeFilter::execute(BitmapEx const& aBitmapEx) const { Bitmap aBitmap = aBitmapEx.GetBitmap(); Bitmap::ScopedReadAccess pReadAcc(aBitmap); - bool bRet = false; + if (!pReadAcc) + return BitmapEx(); - if (pReadAcc) - { - Bitmap aNewBmp(aBitmap.GetSizePixel(), vcl::PixelFormat::N1_BPP); - BitmapScopedWriteAccess pWriteAcc(aNewBmp); + Bitmap aNewBmp(aBitmap.GetSizePixel(), vcl::PixelFormat::N1_BPP); + BitmapScopedWriteAccess pWriteAcc(aNewBmp); + if (!pWriteAcc) + return BitmapEx(); - if (pWriteAcc) - { - const BitmapColor aBlack(pWriteAcc->GetBestMatchingColor(COL_BLACK)); - const BitmapColor aWhite(pWriteAcc->GetBestMatchingColor(COL_WHITE)); - const sal_Int32 nWidth = pWriteAcc->Width(); - const sal_Int32 nHeight = pWriteAcc->Height(); + const BitmapColor aBlack(pWriteAcc->GetBestMatchingColor(COL_BLACK)); + const BitmapColor aWhite(pWriteAcc->GetBestMatchingColor(COL_WHITE)); + const sal_Int32 nWidth = pWriteAcc->Width(); + const sal_Int32 nHeight = pWriteAcc->Height(); - if (pReadAcc->HasPalette()) + if (pReadAcc->HasPalette()) + { + for (sal_Int32 nY = 0; nY < nHeight; nY++) + { + Scanline pScanline = pWriteAcc->GetScanline(nY); + Scanline pScanlineRead = pReadAcc->GetScanline(nY); + for (sal_Int32 nX = 0; nX < nWidth; nX++) { - for (sal_Int32 nY = 0; nY < nHeight; nY++) + const sal_uInt8 cIndex = pReadAcc->GetIndexFromData(pScanlineRead, nX); + if (pReadAcc->GetPaletteColor(cIndex).GetLuminance() >= mcThreshold) { - Scanline pScanline = pWriteAcc->GetScanline(nY); - Scanline pScanlineRead = pReadAcc->GetScanline(nY); - for (sal_Int32 nX = 0; nX < nWidth; nX++) - { - const sal_uInt8 cIndex = pReadAcc->GetIndexFromData(pScanlineRead, nX); - if (pReadAcc->GetPaletteColor(cIndex).GetLuminance() >= mcThreshold) - { - pWriteAcc->SetPixelOnData(pScanline, nX, aWhite); - } - else - { - pWriteAcc->SetPixelOnData(pScanline, nX, aBlack); - } - } + pWriteAcc->SetPixelOnData(pScanline, nX, aWhite); + } + else + { + pWriteAcc->SetPixelOnData(pScanline, nX, aBlack); } } - else + } + } + else + { + for (sal_Int32 nY = 0; nY < nHeight; nY++) + { + Scanline pScanline = pWriteAcc->GetScanline(nY); + Scanline pScanlineRead = pReadAcc->GetScanline(nY); + for (sal_Int32 nX = 0; nX < nWidth; nX++) { - for (sal_Int32 nY = 0; nY < nHeight; nY++) + if (pReadAcc->GetPixelFromData(pScanlineRead, nX).GetLuminance() >= mcThreshold) + { + pWriteAcc->SetPixelOnData(pScanline, nX, aWhite); + } + else { - Scanline pScanline = pWriteAcc->GetScanline(nY); - Scanline pScanlineRead = pReadAcc->GetScanline(nY); - for (sal_Int32 nX = 0; nX < nWidth; nX++) - { - if (pReadAcc->GetPixelFromData(pScanlineRead, nX).GetLuminance() - >= mcThreshold) - { - pWriteAcc->SetPixelOnData(pScanline, nX, aWhite); - } - else - { - pWriteAcc->SetPixelOnData(pScanline, nX, aBlack); - } - } + pWriteAcc->SetPixelOnData(pScanline, nX, aBlack); } } - - pWriteAcc.reset(); - bRet = true; } + } - pReadAcc.reset(); - - if (bRet) - { - const MapMode aMap(aBitmap.GetPrefMapMode()); - const Size aSize(aBitmap.GetPrefSize()); + pWriteAcc.reset(); + pReadAcc.reset(); - aBitmap = aNewBmp; + const MapMode aMap(aBitmap.GetPrefMapMode()); + const Size aSize(aBitmap.GetPrefSize()); - aBitmap.SetPrefMapMode(aMap); - aBitmap.SetPrefSize(aSize); - } - } + aBitmap = aNewBmp; - if (bRet) - return BitmapEx(aBitmap); + aBitmap.SetPrefMapMode(aMap); + aBitmap.SetPrefSize(aSize); - return BitmapEx(); + return BitmapEx(aBitmap); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/bitmap/BitmapScaleConvolutionFilter.cxx b/vcl/source/bitmap/BitmapScaleConvolutionFilter.cxx index bb40e9846708..6ee56d14a366 100644 --- a/vcl/source/bitmap/BitmapScaleConvolutionFilter.cxx +++ b/vcl/source/bitmap/BitmapScaleConvolutionFilter.cxx @@ -188,79 +188,71 @@ bool ImplScaleConvolutionVer(Bitmap& rSource, Bitmap& rTarget, const double& rSc } Bitmap::ScopedReadAccess pReadAcc(rSource); + if(!pReadAcc) + return false; - if(pReadAcc) - { - std::vector<sal_Int16> aWeights; - std::vector<sal_Int32> aPixels; - std::vector<sal_Int32> aCounts; - sal_Int32 aNumberOfContributions(0); - - const sal_Int32 nWidth(rSource.GetSizePixel().Width()); - ImplCalculateContributions(nHeight, nNewHeight, aNumberOfContributions, aWeights, aPixels, aCounts, aKernel); - rTarget = Bitmap(Size(nWidth, nNewHeight), vcl::PixelFormat::N24_BPP); - BitmapScopedWriteAccess pWriteAcc(rTarget); - bool bResult(pWriteAcc); + std::vector<sal_Int16> aWeights; + std::vector<sal_Int32> aPixels; + std::vector<sal_Int32> aCounts; + sal_Int32 aNumberOfContributions(0); - if(pWriteAcc) + const sal_Int32 nWidth(rSource.GetSizePixel().Width()); + ImplCalculateContributions(nHeight, nNewHeight, aNumberOfContributions, aWeights, aPixels, aCounts, aKernel); + rTarget = Bitmap(Size(nWidth, nNewHeight), vcl::PixelFormat::N24_BPP); + BitmapScopedWriteAccess pWriteAcc(rTarget); + if(!pWriteAcc) + return false; + + std::vector<BitmapColor> aScanline(nHeight); + for(sal_Int32 x(0); x < nWidth; x++) + { + for(sal_Int32 y(0); y < nHeight; y++) + if(pReadAcc->HasPalette()) + aScanline[y] = pReadAcc->GetPaletteColor(pReadAcc->GetPixelIndex(y, x)); + else + aScanline[y] = pReadAcc->GetPixel(y, x); + for(sal_Int32 y(0); y < nNewHeight; y++) { - std::vector<BitmapColor> aScanline(nHeight); - for(sal_Int32 x(0); x < nWidth; x++) - { - for(sal_Int32 y(0); y < nHeight; y++) - if(pReadAcc->HasPalette()) - aScanline[y] = pReadAcc->GetPaletteColor(pReadAcc->GetPixelIndex(y, x)); - else - aScanline[y] = pReadAcc->GetPixel(y, x); - for(sal_Int32 y(0); y < nNewHeight; y++) - { - const sal_Int32 aBaseIndex(y * aNumberOfContributions); - sal_Int32 aSum(0); - sal_Int32 aValueRed(0); - sal_Int32 aValueGreen(0); - sal_Int32 aValueBlue(0); + const sal_Int32 aBaseIndex(y * aNumberOfContributions); + sal_Int32 aSum(0); + sal_Int32 aValueRed(0); + sal_Int32 aValueGreen(0); + sal_Int32 aValueBlue(0); - for(sal_Int32 j(0); j < aCounts[y]; j++) - { - const sal_Int32 aIndex(aBaseIndex + j); - const sal_Int16 aWeight(aWeights[aIndex]); - aSum += aWeight; - const BitmapColor & aColor = aScanline[aPixels[aIndex]]; - aValueRed += aWeight * aColor.GetRed(); - aValueGreen += aWeight * aColor.GetGreen(); - aValueBlue += aWeight * aColor.GetBlue(); - } + for(sal_Int32 j(0); j < aCounts[y]; j++) + { + const sal_Int32 aIndex(aBaseIndex + j); + const sal_Int16 aWeight(aWeights[aIndex]); + aSum += aWeight; + const BitmapColor & aColor = aScanline[aPixels[aIndex]]; + aValueRed += aWeight * aColor.GetRed(); + aValueGreen += aWeight * aColor.GetGreen(); + aValueBlue += aWeight * aColor.GetBlue(); + } - assert(aSum != 0); + assert(aSum != 0); - const BitmapColor aResultColor( - static_cast< sal_uInt8 >(MinMax(static_cast< sal_Int32 >(aValueRed / aSum), 0, 255)), - static_cast< sal_uInt8 >(MinMax(static_cast< sal_Int32 >(aValueGreen / aSum), 0, 255)), - static_cast< sal_uInt8 >(MinMax(static_cast< sal_Int32 >(aValueBlue / aSum), 0, 255))); + const BitmapColor aResultColor( + static_cast< sal_uInt8 >(MinMax(static_cast< sal_Int32 >(aValueRed / aSum), 0, 255)), + static_cast< sal_uInt8 >(MinMax(static_cast< sal_Int32 >(aValueGreen / aSum), 0, 255)), + static_cast< sal_uInt8 >(MinMax(static_cast< sal_Int32 >(aValueBlue / aSum), 0, 255))); - if(pWriteAcc->HasPalette()) - { - pWriteAcc->SetPixelIndex(y, x, static_cast< sal_uInt8 >(pWriteAcc->GetBestPaletteIndex(aResultColor))); - } - else - { - pWriteAcc->SetPixel(y, x, aResultColor); - } - } + if(pWriteAcc->HasPalette()) + { + pWriteAcc->SetPixelIndex(y, x, static_cast< sal_uInt8 >(pWriteAcc->GetBestPaletteIndex(aResultColor))); + } + else + { + pWriteAcc->SetPixel(y, x, aResultColor); } - } - - aWeights.clear(); - aCounts.clear(); - aPixels.clear(); - - if(bResult) - { - return true; } } - return false; + aWeights.clear(); + aCounts.clear(); + aPixels.clear(); + + return true; } bool ImplScaleConvolution(Bitmap& rBitmap, const double& rScaleX, const double& rScaleY, const Kernel& aKernel) diff --git a/vcl/source/bitmap/BitmapSepiaFilter.cxx b/vcl/source/bitmap/BitmapSepiaFilter.cxx index 1554def4d96b..714250932be8 100644 --- a/vcl/source/bitmap/BitmapSepiaFilter.cxx +++ b/vcl/source/bitmap/BitmapSepiaFilter.cxx @@ -22,89 +22,78 @@ BitmapEx BitmapSepiaFilter::execute(BitmapEx const& rBitmapEx) const { Bitmap aBitmap(rBitmapEx.GetBitmap()); Bitmap::ScopedReadAccess pReadAcc(aBitmap); - bool bRet = false; + if (!pReadAcc) + return BitmapEx(); - if (pReadAcc) + const sal_Int32 nSepia + = 10000 - 100 * std::clamp(mnSepiaPercent, sal_uInt16(0), sal_uInt16(100)); + BitmapPalette aSepiaPal(256); + + for (sal_uInt16 i = 0; i < 256; i++) { - const sal_Int32 nSepia - = 10000 - 100 * std::clamp(mnSepiaPercent, sal_uInt16(0), sal_uInt16(100)); - BitmapPalette aSepiaPal(256); + BitmapColor& rCol = aSepiaPal[i]; + const sal_uInt8 cSepiaValue = static_cast<sal_uInt8>(nSepia * i / 10000); - for (sal_uInt16 i = 0; i < 256; i++) - { - BitmapColor& rCol = aSepiaPal[i]; - const sal_uInt8 cSepiaValue = static_cast<sal_uInt8>(nSepia * i / 10000); + rCol.SetRed(static_cast<sal_uInt8>(i)); + rCol.SetGreen(cSepiaValue); + rCol.SetBlue(cSepiaValue); + } - rCol.SetRed(static_cast<sal_uInt8>(i)); - rCol.SetGreen(cSepiaValue); - rCol.SetBlue(cSepiaValue); - } + Bitmap aNewBmp(aBitmap.GetSizePixel(), vcl::PixelFormat::N8_BPP, &aSepiaPal); + BitmapScopedWriteAccess pWriteAcc(aNewBmp); + if (!pWriteAcc) + return BitmapEx(); - Bitmap aNewBmp(aBitmap.GetSizePixel(), vcl::PixelFormat::N8_BPP, &aSepiaPal); - BitmapScopedWriteAccess pWriteAcc(aNewBmp); + BitmapColor aCol(sal_uInt8(0)); + const sal_Int32 nWidth = pWriteAcc->Width(); + const sal_Int32 nHeight = pWriteAcc->Height(); - if (pWriteAcc) + if (pReadAcc->HasPalette()) + { + const sal_uInt16 nPalCount = pReadAcc->GetPaletteEntryCount(); + std::unique_ptr<sal_uInt8[]> pIndexMap(new sal_uInt8[nPalCount]); + for (sal_uInt16 i = 0; i < nPalCount; i++) { - BitmapColor aCol(sal_uInt8(0)); - const sal_Int32 nWidth = pWriteAcc->Width(); - const sal_Int32 nHeight = pWriteAcc->Height(); + pIndexMap[i] = pReadAcc->GetPaletteColor(i).GetLuminance(); + } - if (pReadAcc->HasPalette()) + for (sal_Int32 nY = 0; nY < nHeight; nY++) + { + Scanline pScanline = pWriteAcc->GetScanline(nY); + Scanline pScanlineRead = pReadAcc->GetScanline(nY); + for (sal_Int32 nX = 0; nX < nWidth; nX++) { - const sal_uInt16 nPalCount = pReadAcc->GetPaletteEntryCount(); - std::unique_ptr<sal_uInt8[]> pIndexMap(new sal_uInt8[nPalCount]); - for (sal_uInt16 i = 0; i < nPalCount; i++) - { - pIndexMap[i] = pReadAcc->GetPaletteColor(i).GetLuminance(); - } - - for (sal_Int32 nY = 0; nY < nHeight; nY++) - { - Scanline pScanline = pWriteAcc->GetScanline(nY); - Scanline pScanlineRead = pReadAcc->GetScanline(nY); - for (sal_Int32 nX = 0; nX < nWidth; nX++) - { - aCol.SetIndex(pIndexMap[pReadAcc->GetIndexFromData(pScanlineRead, nX)]); - pWriteAcc->SetPixelOnData(pScanline, nX, aCol); - } - } + aCol.SetIndex(pIndexMap[pReadAcc->GetIndexFromData(pScanlineRead, nX)]); + pWriteAcc->SetPixelOnData(pScanline, nX, aCol); } - else + } + } + else + { + for (sal_Int32 nY = 0; nY < nHeight; nY++) + { + Scanline pScanline = pWriteAcc->GetScanline(nY); + Scanline pScanlineRead = pReadAcc->GetScanline(nY); + for (sal_Int32 nX = 0; nX < nWidth; nX++) { - for (sal_Int32 nY = 0; nY < nHeight; nY++) - { - Scanline pScanline = pWriteAcc->GetScanline(nY); - Scanline pScanlineRead = pReadAcc->GetScanline(nY); - for (sal_Int32 nX = 0; nX < nWidth; nX++) - { - aCol.SetIndex(pReadAcc->GetPixelFromData(pScanlineRead, nX).GetLuminance()); - pWriteAcc->SetPixelOnData(pScanline, nX, aCol); - } - } + aCol.SetIndex(pReadAcc->GetPixelFromData(pScanlineRead, nX).GetLuminance()); + pWriteAcc->SetPixelOnData(pScanline, nX, aCol); } - - pWriteAcc.reset(); - bRet = true; } + } - pReadAcc.reset(); - - if (bRet) - { - const MapMode aMap(aBitmap.GetPrefMapMode()); - const Size aPrefSize(aBitmap.GetPrefSize()); + pWriteAcc.reset(); + pReadAcc.reset(); - aBitmap = aNewBmp; + const MapMode aMap(aBitmap.GetPrefMapMode()); + const Size aPrefSize(aBitmap.GetPrefSize()); - aBitmap.SetPrefMapMode(aMap); - aBitmap.SetPrefSize(aPrefSize); - } - } + aBitmap = aNewBmp; - if (bRet) - return BitmapEx(aBitmap); + aBitmap.SetPrefMapMode(aMap); + aBitmap.SetPrefSize(aPrefSize); - return BitmapEx(); + return BitmapEx(aBitmap); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/bitmap/BitmapSimpleColorQuantizationFilter.cxx b/vcl/source/bitmap/BitmapSimpleColorQuantizationFilter.cxx index f825013d4cef..97511ed323b6 100644 --- a/vcl/source/bitmap/BitmapSimpleColorQuantizationFilter.cxx +++ b/vcl/source/bitmap/BitmapSimpleColorQuantizationFilter.cxx @@ -19,92 +19,75 @@ BitmapEx BitmapSimpleColorQuantizationFilter::execute(BitmapEx const& aBitmapEx) { Bitmap aBitmap = aBitmapEx.GetBitmap(); - bool bRet = false; + if (vcl::numberOfColors(aBitmap.getPixelFormat()) > sal_Int64(mnNewColorCount)) + return BitmapEx(aBitmap); - if (vcl::numberOfColors(aBitmap.getPixelFormat()) <= sal_Int64(mnNewColorCount)) - { - bRet = true; - } + Bitmap aNewBmp; + Bitmap::ScopedReadAccess pRAcc(aBitmap); + if (!pRAcc) + return BitmapEx(); + + const sal_uInt16 nColorCount = std::min(mnNewColorCount, sal_uInt16(256)); + auto ePixelFormat = vcl::PixelFormat::INVALID; + if (nColorCount <= 2) + ePixelFormat = vcl::PixelFormat::N1_BPP; else - { - Bitmap aNewBmp; - Bitmap::ScopedReadAccess pRAcc(aBitmap); - const sal_uInt16 nColorCount = std::min(mnNewColorCount, sal_uInt16(256)); - auto ePixelFormat = vcl::PixelFormat::INVALID; + ePixelFormat = vcl::PixelFormat::N8_BPP; - if (nColorCount <= 2) - ePixelFormat = vcl::PixelFormat::N1_BPP; - else - ePixelFormat = vcl::PixelFormat::N8_BPP; + Octree aOct(*pRAcc, nColorCount); + const BitmapPalette& rPal = aOct.GetPalette(); - if (pRAcc) - { - Octree aOct(*pRAcc, nColorCount); - const BitmapPalette& rPal = aOct.GetPalette(); + aNewBmp = Bitmap(aBitmap.GetSizePixel(), ePixelFormat, &rPal); + BitmapScopedWriteAccess pWAcc(aNewBmp); + if (!pWAcc) + return BitmapEx(); - aNewBmp = Bitmap(aBitmap.GetSizePixel(), ePixelFormat, &rPal); - BitmapScopedWriteAccess pWAcc(aNewBmp); + const sal_Int32 nWidth = pRAcc->Width(); + const sal_Int32 nHeight = pRAcc->Height(); - if (pWAcc) + if (pRAcc->HasPalette()) + { + for (sal_Int32 nY = 0; nY < nHeight; nY++) + { + Scanline pScanline = pWAcc->GetScanline(nY); + Scanline pScanlineRead = pRAcc->GetScanline(nY); + for (sal_Int32 nX = 0; nX < nWidth; nX++) { - const sal_Int32 nWidth = pRAcc->Width(); - const sal_Int32 nHeight = pRAcc->Height(); - - if (pRAcc->HasPalette()) - { - for (sal_Int32 nY = 0; nY < nHeight; nY++) - { - Scanline pScanline = pWAcc->GetScanline(nY); - Scanline pScanlineRead = pRAcc->GetScanline(nY); - for (sal_Int32 nX = 0; nX < nWidth; nX++) - { - auto c = pRAcc->GetPaletteColor( - pRAcc->GetIndexFromData(pScanlineRead, nX)); - pWAcc->SetPixelOnData( - pScanline, nX, - BitmapColor(static_cast<sal_uInt8>(aOct.GetBestPaletteIndex(c)))); - } - } - } - else - { - for (sal_Int32 nY = 0; nY < nHeight; nY++) - { - Scanline pScanline = pWAcc->GetScanline(nY); - Scanline pScanlineRead = pRAcc->GetScanline(nY); - for (sal_Int32 nX = 0; nX < nWidth; nX++) - { - auto c = pRAcc->GetPixelFromData(pScanlineRead, nX); - pWAcc->SetPixelOnData( - pScanline, nX, - BitmapColor(static_cast<sal_uInt8>(aOct.GetBestPaletteIndex(c)))); - } - } - } - - pWAcc.reset(); - bRet = true; + auto c = pRAcc->GetPaletteColor(pRAcc->GetIndexFromData(pScanlineRead, nX)); + pWAcc->SetPixelOnData( + pScanline, nX, + BitmapColor(static_cast<sal_uInt8>(aOct.GetBestPaletteIndex(c)))); } - - pRAcc.reset(); } - - if (bRet) + } + else + { + for (sal_Int32 nY = 0; nY < nHeight; nY++) { - const MapMode aMap(aBitmap.GetPrefMapMode()); - const Size aSize(aBitmap.GetPrefSize()); - - aBitmap = aNewBmp; - - aBitmap.SetPrefMapMode(aMap); - aBitmap.SetPrefSize(aSize); + Scanline pScanline = pWAcc->GetScanline(nY); + Scanline pScanlineRead = pRAcc->GetScanline(nY); + for (sal_Int32 nX = 0; nX < nWidth; nX++) + { + auto c = pRAcc->GetPixelFromData(pScanlineRead, nX); + pWAcc->SetPixelOnData( + pScanline, nX, + BitmapColor(static_cast<sal_uInt8>(aOct.GetBestPaletteIndex(c)))); + } } } - if (bRet) - return BitmapEx(aBitmap); + pWAcc.reset(); + pRAcc.reset(); + + const MapMode aMap(aBitmap.GetPrefMapMode()); + const Size aSize(aBitmap.GetPrefSize()); + + aBitmap = aNewBmp; + + aBitmap.SetPrefMapMode(aMap); + aBitmap.SetPrefSize(aSize); - return BitmapEx(); + return BitmapEx(aBitmap); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/bitmap/BitmapSobelGreyFilter.cxx b/vcl/source/bitmap/BitmapSobelGreyFilter.cxx index dd77d633acb6..80daebedf949 100644 --- a/vcl/source/bitmap/BitmapSobelGreyFilter.cxx +++ b/vcl/source/bitmap/BitmapSobelGreyFilter.cxx @@ -22,150 +22,135 @@ BitmapEx BitmapSobelGreyFilter::execute(BitmapEx const& rBitmapEx) const { Bitmap aBitmap(rBitmapEx.GetBitmap()); - bool bRet = aBitmap.ImplMakeGreyscales(); + if (!aBitmap.ImplMakeGreyscales()) + return BitmapEx(); + + Bitmap::ScopedReadAccess pReadAcc(aBitmap); + if (!pReadAcc) + return BitmapEx(); + + Bitmap aNewBmp(aBitmap.GetSizePixel(), vcl::PixelFormat::N8_BPP, &pReadAcc->GetPalette()); + BitmapScopedWriteAccess pWriteAcc(aNewBmp); + if (!pWriteAcc) + return BitmapEx(); + + BitmapColor aGrey(sal_uInt8(0)); + const sal_Int32 nWidth = pWriteAcc->Width(); + const sal_Int32 nHeight = pWriteAcc->Height(); + const sal_Int32 nMask111 = -1, nMask121 = 0, nMask131 = 1; + const sal_Int32 nMask211 = -2, nMask221 = 0, nMask231 = 2; + const sal_Int32 nMask311 = -1, nMask321 = 0, nMask331 = 1; + const sal_Int32 nMask112 = 1, nMask122 = 2, nMask132 = 1; + const sal_Int32 nMask212 = 0, nMask222 = 0, nMask232 = 0; + const sal_Int32 nMask312 = -1, nMask322 = -2, nMask332 = -1; + sal_Int32 nGrey11, nGrey12, nGrey13; + sal_Int32 nGrey21, nGrey22, nGrey23; + sal_Int32 nGrey31, nGrey32, nGrey33; + std::unique_ptr<long[]> pHMap(new long[nWidth + 2]); + std::unique_ptr<long[]> pVMap(new long[nHeight + 2]); + sal_Int32 nX, nY, nSum1, nSum2; + + // fill mapping tables + pHMap[0] = 0; + + for (nX = 1; nX <= nWidth; nX++) + { + pHMap[nX] = nX - 1; + } + + pHMap[nWidth + 1] = nWidth - 1; - if (bRet) + pVMap[0] = 0; + + for (nY = 1; nY <= nHeight; nY++) { - bRet = false; + pVMap[nY] = nY - 1; + } - Bitmap::ScopedReadAccess pReadAcc(aBitmap); + pVMap[nHeight + 1] = nHeight - 1; - if (pReadAcc) + for (nY = 0; nY < nHeight; nY++) + { + nGrey11 = pReadAcc->GetPixel(pVMap[nY], pHMap[0]).GetIndex(); + nGrey12 = pReadAcc->GetPixel(pVMap[nY], pHMap[1]).GetIndex(); + nGrey13 = pReadAcc->GetPixel(pVMap[nY], pHMap[2]).GetIndex(); + nGrey21 = pReadAcc->GetPixel(pVMap[nY + 1], pHMap[0]).GetIndex(); + nGrey22 = pReadAcc->GetPixel(pVMap[nY + 1], pHMap[1]).GetIndex(); + nGrey23 = pReadAcc->GetPixel(pVMap[nY + 1], pHMap[2]).GetIndex(); + nGrey31 = pReadAcc->GetPixel(pVMap[nY + 2], pHMap[0]).GetIndex(); + nGrey32 = pReadAcc->GetPixel(pVMap[nY + 2], pHMap[1]).GetIndex(); + nGrey33 = pReadAcc->GetPixel(pVMap[nY + 2], pHMap[2]).GetIndex(); + + Scanline pScanline = pWriteAcc->GetScanline(nY); + for (nX = 0; nX < nWidth; nX++) { - Bitmap aNewBmp(aBitmap.GetSizePixel(), vcl::PixelFormat::N8_BPP, - &pReadAcc->GetPalette()); - BitmapScopedWriteAccess pWriteAcc(aNewBmp); + nSum1 = nSum2 = 0; - if (pWriteAcc) - { - BitmapColor aGrey(sal_uInt8(0)); - const sal_Int32 nWidth = pWriteAcc->Width(); - const sal_Int32 nHeight = pWriteAcc->Height(); - const sal_Int32 nMask111 = -1, nMask121 = 0, nMask131 = 1; - const sal_Int32 nMask211 = -2, nMask221 = 0, nMask231 = 2; - const sal_Int32 nMask311 = -1, nMask321 = 0, nMask331 = 1; - const sal_Int32 nMask112 = 1, nMask122 = 2, nMask132 = 1; - const sal_Int32 nMask212 = 0, nMask222 = 0, nMask232 = 0; - const sal_Int32 nMask312 = -1, nMask322 = -2, nMask332 = -1; - sal_Int32 nGrey11, nGrey12, nGrey13; - sal_Int32 nGrey21, nGrey22, nGrey23; - sal_Int32 nGrey31, nGrey32, nGrey33; - std::unique_ptr<long[]> pHMap(new long[nWidth + 2]); - std::unique_ptr<long[]> pVMap(new long[nHeight + 2]); - sal_Int32 nX, nY, nSum1, nSum2; - - // fill mapping tables - pHMap[0] = 0; - - for (nX = 1; nX <= nWidth; nX++) - { - pHMap[nX] = nX - 1; - } - - pHMap[nWidth + 1] = nWidth - 1; - - pVMap[0] = 0; - - for (nY = 1; nY <= nHeight; nY++) - { - pVMap[nY] = nY - 1; - } - - pVMap[nHeight + 1] = nHeight - 1; - - for (nY = 0; nY < nHeight; nY++) - { - nGrey11 = pReadAcc->GetPixel(pVMap[nY], pHMap[0]).GetIndex(); - nGrey12 = pReadAcc->GetPixel(pVMap[nY], pHMap[1]).GetIndex(); - nGrey13 = pReadAcc->GetPixel(pVMap[nY], pHMap[2]).GetIndex(); - nGrey21 = pReadAcc->GetPixel(pVMap[nY + 1], pHMap[0]).GetIndex(); - nGrey22 = pReadAcc->GetPixel(pVMap[nY + 1], pHMap[1]).GetIndex(); - nGrey23 = pReadAcc->GetPixel(pVMap[nY + 1], pHMap[2]).GetIndex(); - nGrey31 = pReadAcc->GetPixel(pVMap[nY + 2], pHMap[0]).GetIndex(); - nGrey32 = pReadAcc->GetPixel(pVMap[nY + 2], pHMap[1]).GetIndex(); - nGrey33 = pReadAcc->GetPixel(pVMap[nY + 2], pHMap[2]).GetIndex(); - - Scanline pScanline = pWriteAcc->GetScanline(nY); - for (nX = 0; nX < nWidth; nX++) - { - nSum1 = nSum2 = 0; - - nSum1 += nMask111 * nGrey11; - nSum2 += nMask112 * nGrey11; - - nSum1 += nMask121 * nGrey12; - nSum2 += nMask122 * nGrey12; - - nSum1 += nMask131 * nGrey13; - nSum2 += nMask132 * nGrey13; - - nSum1 += nMask211 * nGrey21; - nSum2 += nMask212 * nGrey21; - - nSum1 += nMask221 * nGrey22; - nSum2 += nMask222 * nGrey22; - - nSum1 += nMask231 * nGrey23; - nSum2 += nMask232 * nGrey23; - - nSum1 += nMask311 * nGrey31; - nSum2 += nMask312 * nGrey31; - - nSum1 += nMask321 * nGrey32; - nSum2 += nMask322 * nGrey32; - - nSum1 += nMask331 * nGrey33; - nSum2 += nMask332 * nGrey33; - - nSum1 = static_cast<sal_Int32>( - sqrt(static_cast<double>(nSum1 * nSum1 + nSum2 * nSum2))); - - aGrey.SetIndex(~static_cast<sal_uInt8>( - std::clamp(nSum1, sal_Int32(0), sal_Int32(255)))); - pWriteAcc->SetPixelOnData(pScanline, nX, aGrey); - - if (nX < (nWidth - 1)) - { - const sal_Int32 nNextX = pHMap[nX + 3]; - - nGrey11 = nGrey12; - nGrey12 = nGrey13; - nGrey13 = pReadAcc->GetPixel(pVMap[nY], nNextX).GetIndex(); - nGrey21 = nGrey22; - nGrey22 = nGrey23; - nGrey23 = pReadAcc->GetPixel(pVMap[nY + 1], nNextX).GetIndex(); - nGrey31 = nGrey32; - nGrey32 = nGrey33; - nGrey33 = pReadAcc->GetPixel(pVMap[nY + 2], nNextX).GetIndex(); - } - } - } - - pHMap.reset(); - pVMap.reset(); - pWriteAcc.reset(); - bRet = true; - } + nSum1 += nMask111 * nGrey11; + nSum2 += nMask112 * nGrey11; - pReadAcc.reset(); + nSum1 += nMask121 * nGrey12; + nSum2 += nMask122 * nGrey12; - if (bRet) - { - const MapMode aMap(aBitmap.GetPrefMapMode()); - const Size aPrefSize(aBitmap.GetPrefSize()); + nSum1 += nMask131 * nGrey13; + nSum2 += nMask132 * nGrey13; + + nSum1 += nMask211 * nGrey21; + nSum2 += nMask212 * nGrey21; - aBitmap = aNewBmp; + nSum1 += nMask221 * nGrey22; + nSum2 += nMask222 * nGrey22; - aBitmap.SetPrefMapMode(aMap); - aBitmap.SetPrefSize(aPrefSize); + nSum1 += nMask231 * nGrey23; + nSum2 += nMask232 * nGrey23; + + nSum1 += nMask311 * nGrey31; + nSum2 += nMask312 * nGrey31; + + nSum1 += nMask321 * nGrey32; + nSum2 += nMask322 * nGrey32; + + nSum1 += nMask331 * nGrey33; + nSum2 += nMask332 * nGrey33; + + nSum1 + = static_cast<sal_Int32>(sqrt(static_cast<double>(nSum1 * nSum1 + nSum2 * nSum2))); + + aGrey.SetIndex( + ~static_cast<sal_uInt8>(std::clamp(nSum1, sal_Int32(0), sal_Int32(255)))); + pWriteAcc->SetPixelOnData(pScanline, nX, aGrey); + + if (nX < (nWidth - 1)) + { + const sal_Int32 nNextX = pHMap[nX + 3]; + + nGrey11 = nGrey12; + nGrey12 = nGrey13; + nGrey13 = pReadAcc->GetPixel(pVMap[nY], nNextX).GetIndex(); + nGrey21 = nGrey22; + nGrey22 = nGrey23; + nGrey23 = pReadAcc->GetPixel(pVMap[nY + 1], nNextX).GetIndex(); + nGrey31 = nGrey32; + nGrey32 = nGrey33; + nGrey33 = pReadAcc->GetPixel(pVMap[nY + 2], nNextX).GetIndex(); } } } - if (bRet) - return BitmapEx(aBitmap); + pHMap.reset(); + pVMap.reset(); + pWriteAcc.reset(); + pReadAcc.reset(); + + const MapMode aMap(aBitmap.GetPrefMapMode()); + const Size aPrefSize(aBitmap.GetPrefSize()); + + aBitmap = aNewBmp; + + aBitmap.SetPrefMapMode(aMap); + aBitmap.SetPrefSize(aPrefSize); - return BitmapEx(); + return BitmapEx(aBitmap); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx index a92c4a41d793..fb73e4bb0d48 100644 --- a/vcl/source/bitmap/bitmap.cxx +++ b/vcl/source/bitmap/bitmap.cxx @@ -417,47 +417,41 @@ bool Bitmap::Crop( const tools::Rectangle& rRectPixel ) { const Size aSizePix( GetSizePixel() ); tools::Rectangle aRect( rRectPixel ); - bool bRet = false; aRect.Intersection( tools::Rectangle( Point(), aSizePix ) ); - if( !aRect.IsEmpty() && aSizePix != aRect.GetSize()) - { - ScopedReadAccess pReadAcc(*this); + if( aRect.IsEmpty() || aSizePix == aRect.GetSize()) + return false; - if( pReadAcc ) - { - const tools::Rectangle aNewRect( Point(), aRect.GetSize() ); - Bitmap aNewBmp(aNewRect.GetSize(), getPixelFormat(), &pReadAcc->GetPalette()); - BitmapScopedWriteAccess pWriteAcc(aNewBmp); + ScopedReadAccess pReadAcc(*this); + if( !pReadAcc ) + return false; - if( pWriteAcc ) - { - const tools::Long nOldX = aRect.Left(); - const tools::Long nOldY = aRect.Top(); - const tools::Long nNewWidth = aNewRect.GetWidth(); - const tools::Long nNewHeight = aNewRect.GetHeight(); + const tools::Rectangle aNewRect( Point(), aRect.GetSize() ); + Bitmap aNewBmp(aNewRect.GetSize(), getPixelFormat(), &pReadAcc->GetPalette()); + BitmapScopedWriteAccess pWriteAcc(aNewBmp); + if( !pWriteAcc ) + return false; - for( tools::Long nY = 0, nY2 = nOldY; nY < nNewHeight; nY++, nY2++ ) - { - Scanline pScanline = pWriteAcc->GetScanline(nY); - Scanline pScanlineRead = pReadAcc->GetScanline(nY2); - for( tools::Long nX = 0, nX2 = nOldX; nX < nNewWidth; nX++, nX2++ ) - pWriteAcc->SetPixelOnData( pScanline, nX, pReadAcc->GetPixelFromData( pScanlineRead, nX2 ) ); - } + const tools::Long nOldX = aRect.Left(); + const tools::Long nOldY = aRect.Top(); + const tools::Long nNewWidth = aNewRect.GetWidth(); + const tools::Long nNewHeight = aNewRect.GetHeight(); - pWriteAcc.reset(); - bRet = true; - } + for( tools::Long nY = 0, nY2 = nOldY; nY < nNewHeight; nY++, nY2++ ) + { + Scanline pScanline = pWriteAcc->GetScanline(nY); + Scanline pScanlineRead = pReadAcc->GetScanline(nY2); + for( tools::Long nX = 0, nX2 = nOldX; nX < nNewWidth; nX++, nX2++ ) + pWriteAcc->SetPixelOnData( pScanline, nX, pReadAcc->GetPixelFromData( pScanlineRead, nX2 ) ); + } - pReadAcc.reset(); + pWriteAcc.reset(); + pReadAcc.reset(); - if( bRet ) - ReassignWithSize( aNewBmp ); - } - } + ReassignWithSize( aNewBmp ); - return bRet; + return true; }; bool Bitmap::CopyPixel( const tools::Rectangle& rRectDst, @@ -469,194 +463,194 @@ bool Bitmap::CopyPixel( const tools::Rectangle& rRectDst, aRectDst.Intersection( tools::Rectangle( Point(), aSizePix ) ); - if( !aRectDst.IsEmpty() ) + if( aRectDst.IsEmpty() ) + return false; + + if( pBmpSrc && ( pBmpSrc->mxSalBmp != mxSalBmp ) ) { - if( pBmpSrc && ( pBmpSrc->mxSalBmp != mxSalBmp ) ) + Bitmap* pSrc = const_cast<Bitmap*>(pBmpSrc); + const Size aCopySizePix( pSrc->GetSizePixel() ); + tools::Rectangle aRectSrc( rRectSrc ); + const sal_uInt16 nSrcBitCount = vcl::pixelFormatBitCount(pBmpSrc->getPixelFormat()); + const sal_uInt16 nDstBitCount = vcl::pixelFormatBitCount(getPixelFormat()); + + if( nSrcBitCount > nDstBitCount ) { - Bitmap* pSrc = const_cast<Bitmap*>(pBmpSrc); - const Size aCopySizePix( pSrc->GetSizePixel() ); - tools::Rectangle aRectSrc( rRectSrc ); - const sal_uInt16 nSrcBitCount = vcl::pixelFormatBitCount(pBmpSrc->getPixelFormat()); - const sal_uInt16 nDstBitCount = vcl::pixelFormatBitCount(getPixelFormat()); + int nNextIndex = 0; - if( nSrcBitCount > nDstBitCount ) + if (nSrcBitCount == 24) + Convert( BmpConversion::N24Bit ); + else if (nSrcBitCount == 8) + { + Convert( BmpConversion::N8BitColors ); + nNextIndex = 16; + } + else if (nSrcBitCount == 4) { - int nNextIndex = 0; + assert(false); + } - if (nSrcBitCount == 24) - Convert( BmpConversion::N24Bit ); - else if (nSrcBitCount == 8) - { - Convert( BmpConversion::N8BitColors ); - nNextIndex = 16; - } - else if (nSrcBitCount == 4) - { - assert(false); - } + if( nNextIndex ) + { + ScopedReadAccess pSrcAcc(*pSrc); + BitmapScopedWriteAccess pDstAcc(*this); - if( nNextIndex ) + if( pSrcAcc && pDstAcc ) { - ScopedReadAccess pSrcAcc(*pSrc); - BitmapScopedWriteAccess pDstAcc(*this); + const int nSrcCount = pSrcAcc->GetPaletteEntryCount(); + const int nDstCount = 1 << nDstBitCount; - if( pSrcAcc && pDstAcc ) + for (int i = 0; ( i < nSrcCount ) && ( nNextIndex < nDstCount ); ++i) { - const int nSrcCount = pSrcAcc->GetPaletteEntryCount(); - const int nDstCount = 1 << nDstBitCount; + const BitmapColor& rSrcCol = pSrcAcc->GetPaletteColor( static_cast<sal_uInt16>(i) ); - for (int i = 0; ( i < nSrcCount ) && ( nNextIndex < nDstCount ); ++i) - { - const BitmapColor& rSrcCol = pSrcAcc->GetPaletteColor( static_cast<sal_uInt16>(i) ); - - bool bFound = false; + bool bFound = false; - for (int j = 0; j < nDstCount; ++j) + for (int j = 0; j < nDstCount; ++j) + { + if( rSrcCol == pDstAcc->GetPaletteColor( static_cast<sal_uInt16>(j) ) ) { - if( rSrcCol == pDstAcc->GetPaletteColor( static_cast<sal_uInt16>(j) ) ) - { - bFound = true; - break; - } + bFound = true; + break; } - - if( !bFound ) - pDstAcc->SetPaletteColor( static_cast<sal_uInt16>(nNextIndex++), rSrcCol ); } + + if( !bFound ) + pDstAcc->SetPaletteColor( static_cast<sal_uInt16>(nNextIndex++), rSrcCol ); } } } + } + + aRectSrc.Intersection( tools::Rectangle( Point(), aCopySizePix ) ); - aRectSrc.Intersection( tools::Rectangle( Point(), aCopySizePix ) ); + if( !aRectSrc.IsEmpty() ) + { + ScopedReadAccess pReadAcc(*pSrc); - if( !aRectSrc.IsEmpty() ) + if( pReadAcc ) { - ScopedReadAccess pReadAcc(*pSrc); + BitmapScopedWriteAccess pWriteAcc(*this); - if( pReadAcc ) + if( pWriteAcc ) { - BitmapScopedWriteAccess pWriteAcc(*this); + const tools::Long nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() ); + const tools::Long nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() ); + const tools::Long nSrcEndX = aRectSrc.Left() + nWidth; + const tools::Long nSrcEndY = aRectSrc.Top() + nHeight; + tools::Long nDstY = aRectDst.Top(); - if( pWriteAcc ) + if( pReadAcc->HasPalette() && pWriteAcc->HasPalette() ) { - const tools::Long nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() ); - const tools::Long nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() ); - const tools::Long nSrcEndX = aRectSrc.Left() + nWidth; - const tools::Long nSrcEndY = aRectSrc.Top() + nHeight; - tools::Long nDstY = aRectDst.Top(); + const sal_uInt16 nCount = pReadAcc->GetPaletteEntryCount(); + std::unique_ptr<sal_uInt8[]> pMap(new sal_uInt8[ nCount ]); - if( pReadAcc->HasPalette() && pWriteAcc->HasPalette() ) - { - const sal_uInt16 nCount = pReadAcc->GetPaletteEntryCount(); - std::unique_ptr<sal_uInt8[]> pMap(new sal_uInt8[ nCount ]); - - // Create index map for the color table, as the bitmap should be copied - // retaining it's color information relatively well - for( sal_uInt16 i = 0; i < nCount; i++ ) - pMap[ i ] = static_cast<sal_uInt8>(pWriteAcc->GetBestPaletteIndex( pReadAcc->GetPaletteColor( i ) )); + // Create index map for the color table, as the bitmap should be copied + // retaining it's color information relatively well + for( sal_uInt16 i = 0; i < nCount; i++ ) + pMap[ i ] = static_cast<sal_uInt8>(pWriteAcc->GetBestPaletteIndex( pReadAcc->GetPaletteColor( i ) )); - for( tools::Long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++ ) - { - Scanline pScanline = pWriteAcc->GetScanline(nDstY); - Scanline pScanlineRead = pReadAcc->GetScanline(nSrcY); - for( tools::Long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ ) - pWriteAcc->SetPixelOnData( pScanline, nDstX, BitmapColor( pMap[ pReadAcc->GetIndexFromData( pScanlineRead, nSrcX ) ] )); - } + for( tools::Long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++ ) + { + Scanline pScanline = pWriteAcc->GetScanline(nDstY); + Scanline pScanlineRead = pReadAcc->GetScanline(nSrcY); + for( tools::Long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ ) + pWriteAcc->SetPixelOnData( pScanline, nDstX, BitmapColor( pMap[ pReadAcc->GetIndexFromData( pScanlineRead, nSrcX ) ] )); } - else if( pReadAcc->HasPalette() ) + } + else if( pReadAcc->HasPalette() ) + { + for( tools::Long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++ ) { - for( tools::Long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++ ) - { - Scanline pScanline = pWriteAcc->GetScanline(nDstY); - Scanline pScanlineRead = pReadAcc->GetScanline(nSrcY); - for( tools::Long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ ) - pWriteAcc->SetPixelOnData( pScanline, nDstX, pReadAcc->GetPaletteColor( pReadAcc->GetIndexFromData( pScanlineRead, nSrcX ) ) ); - } + Scanline pScanline = pWriteAcc->GetScanline(nDstY); + Scanline pScanlineRead = pReadAcc->GetScanline(nSrcY); + for( tools::Long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ ) + pWriteAcc->SetPixelOnData( pScanline, nDstX, pReadAcc->GetPaletteColor( pReadAcc->GetIndexFromData( pScanlineRead, nSrcX ) ) ); } - else - for( tools::Long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++ ) - { - Scanline pScanline = pWriteAcc->GetScanline(nDstY); - Scanline pScanlineRead = pReadAcc->GetScanline(nSrcY); - for( tools::Long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ ) - pWriteAcc->SetPixelOnData( pScanline, nDstX, pReadAcc->GetPixelFromData( pScanlineRead, nSrcX ) ); - } - - pWriteAcc.reset(); - bRet = ( nWidth > 0 ) && ( nHeight > 0 ); } + else + for( tools::Long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++ ) + { + Scanline pScanline = pWriteAcc->GetScanline(nDstY); + Scanline pScanlineRead = pReadAcc->GetScanline(nSrcY); + for( tools::Long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ ) + pWriteAcc->SetPixelOnData( pScanline, nDstX, pReadAcc->GetPixelFromData( pScanlineRead, nSrcX ) ); + } - pReadAcc.reset(); + pWriteAcc.reset(); + bRet = ( nWidth > 0 ) && ( nHeight > 0 ); } + + pReadAcc.reset(); } } - else - { - tools::Rectangle aRectSrc( rRectSrc ); + } + else + { + tools::Rectangle aRectSrc( rRectSrc ); - aRectSrc.Intersection( tools::Rectangle( Point(), aSizePix ) ); + aRectSrc.Intersection( tools::Rectangle( Point(), aSizePix ) ); - if( !aRectSrc.IsEmpty() && ( aRectSrc != aRectDst ) ) - { - BitmapScopedWriteAccess pWriteAcc(*this); + if( !aRectSrc.IsEmpty() && ( aRectSrc != aRectDst ) ) + { + BitmapScopedWriteAccess pWriteAcc(*this); - if( pWriteAcc ) + if( pWriteAcc ) + { + const tools::Long nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() ); + const tools::Long nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() ); + const tools::Long nSrcX = aRectSrc.Left(); + const tools::Long nSrcY = aRectSrc.Top(); + const tools::Long nSrcEndX1 = nSrcX + nWidth - 1; + const tools::Long nSrcEndY1 = nSrcY + nHeight - 1; + const tools::Long nDstX = aRectDst.Left(); + const tools::Long nDstY = aRectDst.Top(); + const tools::Long nDstEndX1 = nDstX + nWidth - 1; + const tools::Long nDstEndY1 = nDstY + nHeight - 1; + + if( ( nDstX <= nSrcX ) && ( nDstY <= nSrcY ) ) { - const tools::Long nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() ); - const tools::Long nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() ); - const tools::Long nSrcX = aRectSrc.Left(); - const tools::Long nSrcY = aRectSrc.Top(); - const tools::Long nSrcEndX1 = nSrcX + nWidth - 1; - const tools::Long nSrcEndY1 = nSrcY + nHeight - 1; - const tools::Long nDstX = aRectDst.Left(); - const tools::Long nDstY = aRectDst.Top(); - const tools::Long nDstEndX1 = nDstX + nWidth - 1; - const tools::Long nDstEndY1 = nDstY + nHeight - 1; - - if( ( nDstX <= nSrcX ) && ( nDstY <= nSrcY ) ) + for( tools::Long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ ) { - for( tools::Long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ ) - { - Scanline pScanline = pWriteAcc->GetScanline(nYN); - Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); - for( tools::Long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ ) - pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); - } + Scanline pScanline = pWriteAcc->GetScanline(nYN); + Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); + for( tools::Long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ ) + pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); } - else if( ( nDstX <= nSrcX ) && ( nDstY >= nSrcY ) ) + } + else if( ( nDstX <= nSrcX ) && ( nDstY >= nSrcY ) ) + { + for( tools::Long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- ) { - for( tools::Long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- ) - { - Scanline pScanline = pWriteAcc->GetScanline(nYN); - Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); - for( tools::Long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ ) - pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); - } + Scanline pScanline = pWriteAcc->GetScanline(nYN); + Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); + for( tools::Long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ ) + pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); } - else if( ( nDstX >= nSrcX ) && ( nDstY <= nSrcY ) ) + } + else if( ( nDstX >= nSrcX ) && ( nDstY <= nSrcY ) ) + { + for( tools::Long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ ) { - for( tools::Long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ ) - { - Scanline pScanline = pWriteAcc->GetScanline(nYN); - Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); - for( tools::Long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- ) - pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); - } + Scanline pScanline = pWriteAcc->GetScanline(nYN); + Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); + for( tools::Long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- ) + pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); } - else + } + else + { + for( tools::Long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- ) { - for( tools::Long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- ) - { - Scanline pScanline = pWriteAcc->GetScanline(nYN); - Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); - for( tools::Long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- ) - pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); - } + Scanline pScanline = pWriteAcc->GetScanline(nYN); + Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); + for( tools::Long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- ) + pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); } - - pWriteAcc.reset(); - bRet = true; } + + pWriteAcc.reset(); + bRet = true; } } } @@ -675,115 +669,115 @@ bool Bitmap::CopyPixel_AlphaOptimized( const tools::Rectangle& rRectDst, const t aRectDst.Intersection( tools::Rectangle( Point(), aSizePix ) ); - if( !aRectDst.IsEmpty() ) + if( aRectDst.IsEmpty() ) + return false; + + if( pBmpSrc && ( pBmpSrc->mxSalBmp != mxSalBmp ) ) { - if( pBmpSrc && ( pBmpSrc->mxSalBmp != mxSalBmp ) ) - { - Bitmap* pSrc = const_cast<Bitmap*>(pBmpSrc); - const Size aCopySizePix( pSrc->GetSizePixel() ); - tools::Rectangle aRectSrc( rRectSrc ); + Bitmap* pSrc = const_cast<Bitmap*>(pBmpSrc); + const Size aCopySizePix( pSrc->GetSizePixel() ); + tools::Rectangle aRectSrc( rRectSrc ); - aRectSrc.Intersection( tools::Rectangle( Point(), aCopySizePix ) ); + aRectSrc.Intersection( tools::Rectangle( Point(), aCopySizePix ) ); - if( !aRectSrc.IsEmpty() ) + if( !aRectSrc.IsEmpty() ) + { + ScopedReadAccess pReadAcc(*pSrc); + + if( pReadAcc ) { - ScopedReadAccess pReadAcc(*pSrc); + BitmapScopedWriteAccess pWriteAcc(*this); - if( pReadAcc ) + if( pWriteAcc ) { - BitmapScopedWriteAccess pWriteAcc(*this); + const tools::Long nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() ); + const tools::Long nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() ); + const tools::Long nSrcEndX = aRectSrc.Left() + nWidth; + const tools::Long nSrcEndY = aRectSrc.Top() + nHeight; + tools::Long nDstY = aRectDst.Top(); - if( pWriteAcc ) + for( tools::Long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++) { - const tools::Long nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() ); - const tools::Long nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() ); - const tools::Long nSrcEndX = aRectSrc.Left() + nWidth; - const tools::Long nSrcEndY = aRectSrc.Top() + nHeight; - tools::Long nDstY = aRectDst.Top(); - - for( tools::Long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++) - { - Scanline pScanline = pWriteAcc->GetScanline(nDstY); - Scanline pScanlineRead = pReadAcc->GetScanline(nSrcY); - for( tools::Long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ ) - pWriteAcc->SetPixelOnData( pScanline, nDstX, pReadAcc->GetPixelFromData( pScanlineRead, nSrcX ) ); - } - - pWriteAcc.reset(); - bRet = ( nWidth > 0 ) && ( nHeight > 0 ); + Scanline pScanline = pWriteAcc->GetScanline(nDstY); + Scanline pScanlineRead = pReadAcc->GetScanline(nSrcY); + for( tools::Long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ ) + pWriteAcc->SetPixelOnData( pScanline, nDstX, pReadAcc->GetPixelFromData( pScanlineRead, nSrcX ) ); } - pReadAcc.reset(); + pWriteAcc.reset(); + bRet = ( nWidth > 0 ) && ( nHeight > 0 ); } + + pReadAcc.reset(); } } - else - { - tools::Rectangle aRectSrc( rRectSrc ); + } + else + { + tools::Rectangle aRectSrc( rRectSrc ); - aRectSrc.Intersection( tools::Rectangle( Point(), aSizePix ) ); + aRectSrc.Intersection( tools::Rectangle( Point(), aSizePix ) ); - if( !aRectSrc.IsEmpty() && ( aRectSrc != aRectDst ) ) - { - BitmapScopedWriteAccess pWriteAcc(*this); + if( !aRectSrc.IsEmpty() && ( aRectSrc != aRectDst ) ) + { + BitmapScopedWriteAccess pWriteAcc(*this); - if( pWriteAcc ) + if( pWriteAcc ) + { + const tools::Long nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() ); + const tools::Long nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() ); + const tools::Long nSrcX = aRectSrc.Left(); + const tools::Long nSrcY = aRectSrc.Top(); + const tools::Long nSrcEndX1 = nSrcX + nWidth - 1; + const tools::Long nSrcEndY1 = nSrcY + nHeight - 1; + const tools::Long nDstX = aRectDst.Left(); + const tools::Long nDstY = aRectDst.Top(); + const tools::Long nDstEndX1 = nDstX + nWidth - 1; + const tools::Long nDstEndY1 = nDstY + nHeight - 1; + + if( ( nDstX <= nSrcX ) && ( nDstY <= nSrcY ) ) { - const tools::Long nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() ); - const tools::Long nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() ); - const tools::Long nSrcX = aRectSrc.Left(); - const tools::Long nSrcY = aRectSrc.Top(); - const tools::Long nSrcEndX1 = nSrcX + nWidth - 1; - const tools::Long nSrcEndY1 = nSrcY + nHeight - 1; - const tools::Long nDstX = aRectDst.Left(); - const tools::Long nDstY = aRectDst.Top(); - const tools::Long nDstEndX1 = nDstX + nWidth - 1; - const tools::Long nDstEndY1 = nDstY + nHeight - 1; - - if( ( nDstX <= nSrcX ) && ( nDstY <= nSrcY ) ) + for( tools::Long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ ) { - for( tools::Long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ ) - { - Scanline pScanline = pWriteAcc->GetScanline(nYN); - Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); - for( tools::Long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ ) - pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); - } + Scanline pScanline = pWriteAcc->GetScanline(nYN); + Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); + for( tools::Long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ ) + pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); } - else if( ( nDstX <= nSrcX ) && ( nDstY >= nSrcY ) ) + } + else if( ( nDstX <= nSrcX ) && ( nDstY >= nSrcY ) ) + { + for( tools::Long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- ) { - for( tools::Long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- ) - { - Scanline pScanline = pWriteAcc->GetScanline(nYN); - Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); - for( tools::Long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ ) - pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); - } + Scanline pScanline = pWriteAcc->GetScanline(nYN); + Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); + for( tools::Long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ ) + pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); } - else if( ( nDstX >= nSrcX ) && ( nDstY <= nSrcY ) ) + } + else if( ( nDstX >= nSrcX ) && ( nDstY <= nSrcY ) ) + { + for( tools::Long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ ) { - for( tools::Long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ ) - { - Scanline pScanline = pWriteAcc->GetScanline(nYN); - Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); - for( tools::Long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- ) - pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); - } + Scanline pScanline = pWriteAcc->GetScanline(nYN); + Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); + for( tools::Long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- ) + pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); } - else + } + else + { + for( tools::Long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- ) { - for( tools::Long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- ) - { - Scanline pScanline = pWriteAcc->GetScanline(nYN); - Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); - for( tools::Long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- ) - pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); - } + Scanline pScanline = pWriteAcc->GetScanline(nYN); + Scanline pScanlineSrc = pWriteAcc->GetScanline(nY); + for( tools::Long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- ) + pWriteAcc->SetPixelOnData( pScanline, nXN, pWriteAcc->GetPixelFromData( pScanlineSrc, nX ) ); } - - pWriteAcc.reset(); - bRet = true; } + + pWriteAcc.reset(); + bRet = true; } } } @@ -794,67 +788,60 @@ bool Bitmap::CopyPixel_AlphaOptimized( const tools::Rectangle& rRectDst, const t bool Bitmap::Expand( sal_Int32 nDX, sal_Int32 nDY, const Color* pInitColor ) { - bool bRet = false; - - if( nDX || nDY ) - { - const Size aSizePixel( GetSizePixel() ); - const tools::Long nWidth = aSizePixel.Width(); - const tools::Long nHeight = aSizePixel.Height(); - const Size aNewSize( nWidth + nDX, nHeight + nDY ); - ScopedReadAccess pReadAcc(*this); - - if( pReadAcc ) - { - BitmapPalette aBmpPal( pReadAcc->GetPalette() ); - Bitmap aNewBmp(aNewSize, getPixelFormat(), &aBmpPal); - BitmapScopedWriteAccess pWriteAcc(aNewBmp); + if( !nDX && !nDY ) + return false; - if( pWriteAcc ) - { - BitmapColor aColor; - const tools::Long nNewX = nWidth; - const tools::Long nNewY = nHeight; - const tools::Long nNewWidth = pWriteAcc->Width(); - const tools::Long nNewHeight = pWriteAcc->Height(); - tools::Long nX; - tools::Long nY; - - if( pInitColor ) - aColor = pWriteAcc->GetBestMatchingColor( *pInitColor ); - - for( nY = 0; nY < nHeight; nY++ ) - { - pWriteAcc->CopyScanline( nY, *pReadAcc ); + const Size aSizePixel( GetSizePixel() ); + const tools::Long nWidth = aSizePixel.Width(); + const tools::Long nHeight = aSizePixel.Height(); + const Size aNewSize( nWidth + nDX, nHeight + nDY ); + ScopedReadAccess pReadAcc(*this); + if( !pReadAcc ) + return false; - if( pInitColor && nDX ) - { - Scanline pScanline = pWriteAcc->GetScanline(nY); - for( nX = nNewX; nX < nNewWidth; nX++ ) - pWriteAcc->SetPixelOnData( pScanline, nX, aColor ); - } - } + BitmapPalette aBmpPal( pReadAcc->GetPalette() ); + Bitmap aNewBmp(aNewSize, getPixelFormat(), &aBmpPal); + BitmapScopedWriteAccess pWriteAcc(aNewBmp); + if( !pWriteAcc ) + return false; - if( pInitColor && nDY ) - for( nY = nNewY; nY < nNewHeight; nY++ ) - { - Scanline pScanline = pWriteAcc->GetScanline(nY); - for( nX = 0; nX < nNewWidth; nX++ ) - pWriteAcc->SetPixelOnData( pScanline, nX, aColor ); - } + BitmapColor aColor; + const tools::Long nNewX = nWidth; + const tools::Long nNewY = nHeight; + const tools::Long nNewWidth = pWriteAcc->Width(); + const tools::Long nNewHeight = pWriteAcc->Height(); + tools::Long nX; + tools::Long nY; - pWriteAcc.reset(); - bRet = true; - } + if( pInitColor ) + aColor = pWriteAcc->GetBestMatchingColor( *pInitColor ); - pReadAcc.reset(); + for( nY = 0; nY < nHeight; nY++ ) + { + pWriteAcc->CopyScanline( nY, *pReadAcc ); - if (bRet) - ReassignWithSize(aNewBmp); + if( pInitColor && nDX ) + { + Scanline pScanline = pWriteAcc->GetScanline(nY); + for( nX = nNewX; nX < nNewWidth; nX++ ) + pWriteAcc->SetPixelOnData( pScanline, nX, aColor ); } } - return bRet; + if( pInitColor && nDY ) + for( nY = nNewY; nY < nNewHeight; nY++ ) + { + Scanline pScanline = pWriteAcc->GetScanline(nY); + for( nX = 0; nX < nNewWidth; nX++ ) + pWriteAcc->SetPixelOnData( pScanline, nX, aColor ); + } + + pWriteAcc.reset(); + pReadAcc.reset(); + + ReassignWithSize(aNewBmp); + + return true; } Bitmap Bitmap::CreateDisplayBitmap( OutputDevice* pDisplay ) const @@ -979,118 +966,104 @@ bool Bitmap::Convert( BmpConversion eConversion ) bool Bitmap::ImplMakeGreyscales() { ScopedReadAccess pReadAcc(*this); - bool bRet = false; - - if( pReadAcc ) - { - const BitmapPalette& rPal = GetGreyPalette(256); - sal_uLong nShift = 0; - bool bPalDiffers = !pReadAcc->HasPalette() || ( rPal.GetEntryCount() != pReadAcc->GetPaletteEntryCount() ); - - if( !bPalDiffers ) - bPalDiffers = ( rPal != pReadAcc->GetPalette() ); - - if( bPalDiffers ) - { - const auto ePixelFormat = vcl::PixelFormat::N8_BPP; - Bitmap aNewBmp(GetSizePixel(), ePixelFormat, &rPal ); - BitmapScopedWriteAccess pWriteAcc(aNewBmp); - - if( pWriteAcc ) - { - const tools::Long nWidth = pWriteAcc->Width(); - const tools::Long nHeight = pWriteAcc->Height(); + if( !pReadAcc ) + return false; - if( pReadAcc->HasPalette() ) - { - for( tools::Long nY = 0; nY < nHeight; nY++ ) - { - Scanline pScanline = pWriteAcc->GetScanline(nY); - Scanline pScanlineRead = pReadAcc->GetScanline(nY); - for( tools::Long nX = 0; nX < nWidth; nX++ ) - { - const sal_uInt8 cIndex = pReadAcc->GetIndexFromData( pScanlineRead, nX ); - pWriteAcc->SetPixelOnData( pScanline, nX, - BitmapColor(pReadAcc->GetPaletteColor( cIndex ).GetLuminance() >> nShift) ); - } - } - } - else if( pReadAcc->GetScanlineFormat() == ScanlineFormat::N24BitTcBgr && - pWriteAcc->GetScanlineFormat() == ScanlineFormat::N8BitPal ) - { - nShift += 8; + const BitmapPalette& rPal = GetGreyPalette(256); + sal_uLong nShift = 0; + bool bPalDiffers = !pReadAcc->HasPalette() || ( rPal.GetEntryCount() != pReadAcc->GetPaletteEntryCount() ); - for( tools::Long nY = 0; nY < nHeight; nY++ ) - { - Scanline pReadScan = pReadAcc->GetScanline( nY ); - Scanline pWriteScan = pWriteAcc->GetScanline( nY ); + if( !bPalDiffers ) + bPalDiffers = ( rPal != pReadAcc->GetPalette() ); + if( !bPalDiffers ) + return true; - for( tools::Long nX = 0; nX < nWidth; nX++ ) - { - const sal_uLong nB = *pReadScan++; - const sal_uLong nG = *pReadScan++; - const sal_uLong nR = *pReadScan++; + const auto ePixelFormat = vcl::PixelFormat::N8_BPP; + Bitmap aNewBmp(GetSizePixel(), ePixelFormat, &rPal ); + BitmapScopedWriteAccess pWriteAcc(aNewBmp); + if( !pWriteAcc ) + return false; - *pWriteScan++ = static_cast<sal_uInt8>( ( nB * 28UL + nG * 151UL + nR * 77UL ) >> nShift ); - } - } - } - else if( pReadAcc->GetScanlineFormat() == ScanlineFormat::N24BitTcRgb && - pWriteAcc->GetScanlineFormat() == ScanlineFormat::N8BitPal ) - { - nShift += 8; + const tools::Long nWidth = pWriteAcc->Width(); + const tools::Long nHeight = pWriteAcc->Height(); - for( tools::Long nY = 0; nY < nHeight; nY++ ) - { - Scanline pReadScan = pReadAcc->GetScanline( nY ); - Scanline pWriteScan = pWriteAcc->GetScanline( nY ); + if( pReadAcc->HasPalette() ) + { + for( tools::Long nY = 0; nY < nHeight; nY++ ) + { + Scanline pScanline = pWriteAcc->GetScanline(nY); + Scanline pScanlineRead = pReadAcc->GetScanline(nY); + for( tools::Long nX = 0; nX < nWidth; nX++ ) + { + const sal_uInt8 cIndex = pReadAcc->GetIndexFromData( pScanlineRead, nX ); + pWriteAcc->SetPixelOnData( pScanline, nX, + BitmapColor(pReadAcc->GetPaletteColor( cIndex ).GetLuminance() >> nShift) ); + } + } + } + else if( pReadAcc->GetScanlineFormat() == ScanlineFormat::N24BitTcBgr && + pWriteAcc->GetScanlineFormat() == ScanlineFormat::N8BitPal ) + { + nShift += 8; - for( tools::Long nX = 0; nX < nWidth; nX++ ) - { - const sal_uLong nR = *pReadScan++; - const sal_uLong nG = *pReadScan++; - const sal_uLong nB = *pReadScan++; + for( tools::Long nY = 0; nY < nHeight; nY++ ) + { + Scanline pReadScan = pReadAcc->GetScanline( nY ); + Scanline pWriteScan = pWriteAcc->GetScanline( nY ); - *pWriteScan++ = static_cast<sal_uInt8>( ( nB * 28UL + nG * 151UL + nR * 77UL ) >> nShift ); - } - } - } - else - { - for( tools::Long nY = 0; nY < nHeight; nY++ ) - { - Scanline pScanline = pWriteAcc->GetScanline(nY); - Scanline pScanlineRead = pReadAcc->GetScanline(nY); - for( tools::Long nX = 0; nX < nWidth; nX++ ) - pWriteAcc->SetPixelOnData( pScanline, nX, BitmapColor(pReadAcc->GetPixelFromData( pScanlineRead, nX ).GetLuminance() >> nShift) ); - } - } + for( tools::Long nX = 0; nX < nWidth; nX++ ) + { + const sal_uLong nB = *pReadScan++; + const sal_uLong nG = *pReadScan++; + const sal_uLong nR = *pReadScan++; - pWriteAcc.reset(); - bRet = true; + *pWriteScan++ = static_cast<sal_uInt8>( ( nB * 28UL + nG * 151UL + nR * 77UL ) >> nShift ); } + } + } + else if( pReadAcc->GetScanlineFormat() == ScanlineFormat::N24BitTcRgb && + pWriteAcc->GetScanlineFormat() == ScanlineFormat::N8BitPal ) + { + nShift += 8; - pReadAcc.reset(); + for( tools::Long nY = 0; nY < nHeight; nY++ ) + { + Scanline pReadScan = pReadAcc->GetScanline( nY ); + Scanline pWriteScan = pWriteAcc->GetScanline( nY ); - if( bRet ) + for( tools::Long nX = 0; nX < nWidth; nX++ ) { - const MapMode aMap( maPrefMapMode ); - const Size aSize( maPrefSize ); - - *this = aNewBmp; + const sal_uLong nR = *pReadScan++; + const sal_uLong nG = *pReadScan++; + const sal_uLong nB = *pReadScan++; - maPrefMapMode = aMap; - maPrefSize = aSize; + *pWriteScan++ = static_cast<sal_uInt8>( ( nB * 28UL + nG * 151UL + nR * 77UL ) >> nShift ); } } - else + } + else + { + for( tools::Long nY = 0; nY < nHeight; nY++ ) { - pReadAcc.reset(); - bRet = true; + Scanline pScanline = pWriteAcc->GetScanline(nY); + Scanline pScanlineRead = pReadAcc->GetScanline(nY); + for( tools::Long nX = 0; nX < nWidth; nX++ ) + pWriteAcc->SetPixelOnData( pScanline, nX, BitmapColor(pReadAcc->GetPixelFromData( pScanlineRead, nX ).GetLuminance() >> nShift) ); } } - return bRet; + pWriteAcc.reset(); + pReadAcc.reset(); + + const MapMode aMap( maPrefMapMode ); + const Size aSize( maPrefSize ); + + *this = aNewBmp; + + maPrefMapMode = aMap; + maPrefSize = aSize; + + return true; } bool Bitmap::ImplConvertUp(vcl::PixelFormat ePixelFormat, Color const * pExtColor) @@ -1098,88 +1071,81 @@ bool Bitmap::ImplConvertUp(vcl::PixelFormat ePixelFormat, Color const * pExtColo SAL_WARN_IF(ePixelFormat <= getPixelFormat(), "vcl", "New pixel format must be greater!" ); Bitmap::ScopedReadAccess pReadAcc(*this); - bool bRet = false; + if (!pReadAcc) + return false; - if (pReadAcc) - { - BitmapPalette aPalette; - Bitmap aNewBmp(GetSizePixel(), ePixelFormat, pReadAcc->HasPalette() ? &pReadAcc->GetPalette() : &aPalette); - BitmapScopedWriteAccess pWriteAcc(aNewBmp); + BitmapPalette aPalette; + Bitmap aNewBmp(GetSizePixel(), ePixelFormat, pReadAcc->HasPalette() ? &pReadAcc->GetPalette() : &aPalette); + BitmapScopedWriteAccess pWriteAcc(aNewBmp); + if (!pWriteAcc) + return false; - if (pWriteAcc) - { - const tools::Long nWidth = pWriteAcc->Width(); - const tools::Long nHeight = pWriteAcc->Height(); + const tools::Long nWidth = pWriteAcc->Width(); + const tools::Long nHeight = pWriteAcc->Height(); - if (pWriteAcc->HasPalette()) - { - const BitmapPalette& rOldPalette = pReadAcc->GetPalette(); - const sal_uInt16 nOldCount = rOldPalette.GetEntryCount(); - assert(nOldCount <= (1 << vcl::pixelFormatBitCount(getPixelFormat()))); + if (pWriteAcc->HasPalette()) + { + const BitmapPalette& rOldPalette = pReadAcc->GetPalette(); + const sal_uInt16 nOldCount = rOldPalette.GetEntryCount(); + assert(nOldCount <= (1 << vcl::pixelFormatBitCount(getPixelFormat()))); - aPalette.SetEntryCount(1 << vcl::pixelFormatBitCount(ePixelFormat)); + aPalette.SetEntryCount(1 << vcl::pixelFormatBitCount(ePixelFormat)); - for (sal_uInt16 i = 0; i < nOldCount; i++) - aPalette[i] = rOldPalette[i]; + for (sal_uInt16 i = 0; i < nOldCount; i++) + aPalette[i] = rOldPalette[i]; - if (pExtColor) - aPalette[aPalette.GetEntryCount() - 1] = *pExtColor; + if (pExtColor) + aPalette[aPalette.GetEntryCount() - 1] = *pExtColor; - pWriteAcc->SetPalette(aPalette); + pWriteAcc->SetPalette(aPalette); - for (tools::Long nY = 0; nY < nHeight; nY++) - { - Scanline pScanline = pWriteAcc->GetScanline(nY); - Scanline pScanlineRead = pReadAcc->GetScanline(nY); - for (tools::Long nX = 0; nX < nWidth; nX++) - { - pWriteAcc->SetPixelOnData(pScanline, nX, pReadAcc->GetPixelFromData(pScanlineRead, nX)); - } - } + for (tools::Long nY = 0; nY < nHeight; nY++) + { + Scanline pScanline = pWriteAcc->GetScanline(nY); + Scanline pScanlineRead = pReadAcc->GetScanline(nY); + for (tools::Long nX = 0; nX < nWidth; nX++) + { + pWriteAcc->SetPixelOnData(pScanline, nX, pReadAcc->GetPixelFromData(pScanlineRead, nX)); } - else + } + } + else + { + if (pReadAcc->HasPalette()) + { + for (tools::Long nY = 0; nY < nHeight; nY++) { - if (pReadAcc->HasPalette()) + Scanline pScanline = pWriteAcc->GetScanline(nY); + Scanline pScanlineRead = pReadAcc->GetScanline(nY); + for (tools::Long nX = 0; nX < nWidth; nX++) { - for (tools::Long nY = 0; nY < nHeight; nY++) - { - Scanline pScanline = pWriteAcc->GetScanline(nY); - Scanline pScanlineRead = pReadAcc->GetScanline(nY); - for (tools::Long nX = 0; nX < nWidth; nX++) - { - pWriteAcc->SetPixelOnData(pScanline, nX, pReadAcc->GetPaletteColor(pReadAcc->GetIndexFromData(pScanlineRead, nX))); - } - } + pWriteAcc->SetPixelOnData(pScanline, nX, pReadAcc->GetPaletteColor(pReadAcc->GetIndexFromData(pScanlineRead, nX))); } - else + } + } + else + { + for (tools::Long nY = 0; nY < nHeight; nY++) + { + Scanline pScanline = pWriteAcc->GetScanline(nY); + Scanline pScanlineRead = pReadAcc->GetScanline(nY); + for (tools::Long nX = 0; nX < nWidth; nX++) { - for (tools::Long nY = 0; nY < nHeight; nY++) - { - Scanline pScanline = pWriteAcc->GetScanline(nY); - Scanline pScanlineRead = pReadAcc->GetScanline(nY); - for (tools::Long nX = 0; nX < nWidth; nX++) - { - pWriteAcc->SetPixelOnData(pScanline, nX, pReadAcc->GetPixelFromData(pScanlineRead, nX)); - } - } + pWriteAcc->SetPixelOnData(pScanline, nX, pReadAcc->GetPixelFromData(pScanlineRead, nX)); } } - bRet = true; } + } - if (bRet) - { - const MapMode aMap(maPrefMapMode); - const Size aSize(maPrefSize); + const MapMode aMap(maPrefMapMode); + const Size aSize(maPrefSize); - *this = aNewBmp; + *this = aNewBmp; - maPrefMapMode = aMap; - maPrefSize = aSize; - } - } + maPrefMapMode = aMap; + maPrefSize = aSize; - return bRet; + return true; } bool Bitmap::ImplConvertDown8BPP(Color const * pExtColor) @@ -1187,127 +1153,120 @@ bool Bitmap::ImplConvertDown8BPP(Color const * pExtColor) SAL_WARN_IF(vcl::PixelFormat::N8_BPP > getPixelFormat(), "vcl", "New pixelformat must be lower ( or equal when pExtColor is set )!"); Bitmap::ScopedReadAccess pReadAcc(*this); - bool bRet = false; + if (!pReadAcc) + return false; - if (pReadAcc) - { - BitmapPalette aPalette; - Bitmap aNewBmp(GetSizePixel(), vcl::PixelFormat::N8_BPP, &aPalette); - BitmapScopedWriteAccess pWriteAcc(aNewBmp); + BitmapPalette aPalette; + Bitmap aNewBmp(GetSizePixel(), vcl::PixelFormat::N8_BPP, &aPalette); + BitmapScopedWriteAccess pWriteAcc(aNewBmp); + if (!pWriteAcc) + return false; - if (pWriteAcc) - { - sal_Int16 nNewBitCount = sal_Int16(vcl::PixelFormat::N8_BPP); - const sal_uInt16 nCount = 1 << nNewBitCount; - const tools::Long nWidth = pWriteAcc->Width(); - const tools::Long nWidth1 = nWidth - 1; - const tools::Long nHeight = pWriteAcc->Height(); - Octree aOctree(*pReadAcc, pExtColor ? (nCount - 1) : nCount); - aPalette = aOctree.GetPalette(); - InverseColorMap aColorMap(aPalette); - BitmapColor aColor; - ImpErrorQuad aErrQuad; - std::vector<ImpErrorQuad> aErrQuad1(nWidth); - std::vector<ImpErrorQuad> aErrQuad2(nWidth); - ImpErrorQuad* pQLine1 = aErrQuad1.data(); - ImpErrorQuad* pQLine2 = nullptr; - tools::Long nYTmp = 0; - sal_uInt8 cIndex; - bool bQ1 = true; - - if (pExtColor) - { - aPalette.SetEntryCount(aPalette.GetEntryCount() + 1); - aPalette[aPalette.GetEntryCount() - 1] = *pExtColor; - } + sal_Int16 nNewBitCount = sal_Int16(vcl::PixelFormat::N8_BPP); + const sal_uInt16 nCount = 1 << nNewBitCount; + const tools::Long nWidth = pWriteAcc->Width(); + const tools::Long nWidth1 = nWidth - 1; + const tools::Long nHeight = pWriteAcc->Height(); + Octree aOctree(*pReadAcc, pExtColor ? (nCount - 1) : nCount); + aPalette = aOctree.GetPalette(); + InverseColorMap aColorMap(aPalette); + BitmapColor aColor; + ImpErrorQuad aErrQuad; + std::vector<ImpErrorQuad> aErrQuad1(nWidth); + std::vector<ImpErrorQuad> aErrQuad2(nWidth); + ImpErrorQuad* pQLine1 = aErrQuad1.data(); + ImpErrorQuad* pQLine2 = nullptr; + tools::Long nYTmp = 0; + sal_uInt8 cIndex; + bool bQ1 = true; + + if (pExtColor) + { + aPalette.SetEntryCount(aPalette.GetEntryCount() + 1); + aPalette[aPalette.GetEntryCount() - 1] = *pExtColor; + } - // set Black/White always, if we have enough space - if (aPalette.GetEntryCount() < (nCount - 1)) - { - aPalette.SetEntryCount(aPalette.GetEntryCount() + 2); - aPalette[aPalette.GetEntryCount() - 2] = COL_BLACK; - aPalette[aPalette.GetEntryCount() - 1] = COL_WHITE; - } + // set Black/White always, if we have enough space + if (aPalette.GetEntryCount() < (nCount - 1)) + { + aPalette.SetEntryCount(aPalette.GetEntryCount() + 2); + aPalette[aPalette.GetEntryCount() - 2] = COL_BLACK; + aPalette[aPalette.GetEntryCount() - 1] = COL_WHITE; + } - pWriteAcc->SetPalette(aPalette); + pWriteAcc->SetPalette(aPalette); - for (tools::Long nY = 0; nY < std::min(nHeight, tools::Long(2)); nY++, nYTmp++) - { - pQLine2 = !nY ? aErrQuad1.data() : aErrQuad2.data(); - Scanline pScanlineRead = pReadAcc->GetScanline(nYTmp); - for (tools::Long nX = 0; nX < nWidth; nX++) - { - if (pReadAcc->HasPalette()) - pQLine2[nX] = pReadAcc->GetPaletteColor(pReadAcc->GetIndexFromData(pScanlineRead, nX)); - else - pQLine2[nX] = pReadAcc->GetPixelFromData(pScanlineRead, nX); - } - } + for (tools::Long nY = 0; nY < std::min(nHeight, tools::Long(2)); nY++, nYTmp++) + { + pQLine2 = !nY ? aErrQuad1.data() : aErrQuad2.data(); + Scanline pScanlineRead = pReadAcc->GetScanline(nYTmp); + for (tools::Long nX = 0; nX < nWidth; nX++) + { + if (pReadAcc->HasPalette()) + pQLine2[nX] = pReadAcc->GetPaletteColor(pReadAcc->GetIndexFromData(pScanlineRead, nX)); + else + pQLine2[nX] = pReadAcc->GetPixelFromData(pScanlineRead, nX); + } + } - assert(pQLine2 || nHeight == 0); + assert(pQLine2 || nHeight == 0); - for (tools::Long nY = 0; nY < nHeight; nY++, nYTmp++) - { - // first pixel in the line - cIndex = static_cast<sal_uInt8>(aColorMap.GetBestPaletteIndex(pQLine1[0].ImplGetColor())); - Scanline pScanline = pWriteAcc->GetScanline(nY); - pWriteAcc->SetPixelOnData(pScanline, 0, BitmapColor(cIndex)); + for (tools::Long nY = 0; nY < nHeight; nY++, nYTmp++) + { + // first pixel in the line + cIndex = static_cast<sal_uInt8>(aColorMap.GetBestPaletteIndex(pQLine1[0].ImplGetColor())); + Scanline pScanline = pWriteAcc->GetScanline(nY); + pWriteAcc->SetPixelOnData(pScanline, 0, BitmapColor(cIndex)); - tools::Long nX; - for (nX = 1; nX < nWidth1; nX++) - { - aColor = pQLine1[nX].ImplGetColor(); - cIndex = static_cast<sal_uInt8>(aColorMap.GetBestPaletteIndex(aColor)); - aErrQuad = (ImpErrorQuad(aColor) -= pWriteAcc->GetPaletteColor(cIndex)); - pQLine1[++nX].ImplAddColorError7(aErrQuad); - pQLine2[nX--].ImplAddColorError1(aErrQuad); - pQLine2[nX--].ImplAddColorError5(aErrQuad); - pQLine2[nX++].ImplAddColorError3(aErrQuad); - pWriteAcc->SetPixelOnData(pScanline, nX, BitmapColor(cIndex)); - } + tools::Long nX; + for (nX = 1; nX < nWidth1; nX++) + { + aColor = pQLine1[nX].ImplGetColor(); + cIndex = static_cast<sal_uInt8>(aColorMap.GetBestPaletteIndex(aColor)); + aErrQuad = (ImpErrorQuad(aColor) -= pWriteAcc->GetPaletteColor(cIndex)); + pQLine1[++nX].ImplAddColorError7(aErrQuad); + pQLine2[nX--].ImplAddColorError1(aErrQuad); + pQLine2[nX--].ImplAddColorError5(aErrQuad); + pQLine2[nX++].ImplAddColorError3(aErrQuad); + pWriteAcc->SetPixelOnData(pScanline, nX, BitmapColor(cIndex)); + } - // Last RowPixel - if (nX < nWidth) - { - cIndex = static_cast<sal_uInt8>(aColorMap.GetBestPaletteIndex(pQLine1[nWidth1].ImplGetColor())); - pWriteAcc->SetPixelOnData(pScanline, nX, BitmapColor(cIndex)); - } + // Last RowPixel + if (nX < nWidth) + { + cIndex = static_cast<sal_uInt8>(aColorMap.GetBestPaletteIndex(pQLine1[nWidth1].ImplGetColor())); + pWriteAcc->SetPixelOnData(pScanline, nX, BitmapColor(cIndex)); + } - // Refill/copy row buffer - pQLine1 = pQLine2; - bQ1 = !bQ1; - pQLine2 = bQ1 ? aErrQuad2.data() : aErrQuad1.data(); + // Refill/copy row buffer + pQLine1 = pQLine2; + bQ1 = !bQ1; + pQLine2 = bQ1 ? aErrQuad2.data() : aErrQuad1.data(); - if (nYTmp < nHeight) - { - Scanline pScanlineRead = pReadAcc->GetScanline(nYTmp); - for (nX = 0; nX < nWidth; nX++) - { - if (pReadAcc->HasPalette()) - pQLine2[nX] = pReadAcc->GetPaletteColor(pReadAcc->GetIndexFromData(pScanlineRead, nX)); - else - pQLine2[nX] = pReadAcc->GetPixelFromData(pScanlineRead, nX); - } - } + if (nYTmp < nHeight) + { + Scanline pScanlineRead = pReadAcc->GetScanline(nYTmp); + for (nX = 0; nX < nWidth; nX++) + { + if (pReadAcc->HasPalette()) + pQLine2[nX] = pReadAcc->GetPaletteColor(pReadAcc->GetIndexFromData(pScanlineRead, nX)); + else + pQLine2[nX] = pReadAcc->GetPixelFromData(pScanlineRead, nX); } - - bRet = true; } - pWriteAcc.reset(); + } - if(bRet) - { - const MapMode aMap(maPrefMapMode); - const Size aSize(maPrefSize); + pWriteAcc.reset(); - *this = aNewBmp; + const MapMode aMap(maPrefMapMode); + const Size aSize(maPrefSize); - maPrefMapMode = aMap; - maPrefSize = aSize; - } - } + *this = aNewBmp; - return bRet; + maPrefMapMode = aMap; + maPrefSize = aSize; + + return true; } bool Bitmap::Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag ) @@ -1488,81 +1447,78 @@ bool Bitmap::Dither() const Size aSize( GetSizePixel() ); if( aSize.Width() == 1 || aSize.Height() == 1 ) return true; - if( ( aSize.Width() > 3 ) && ( aSize.Height() > 2 ) ) + if( ( aSize.Width() <= 3 ) || ( aSize.Height() <= 2 ) ) + return false; + + ScopedReadAccess pReadAcc(*this); + Bitmap aNewBmp(GetSizePixel(), vcl::PixelFormat::N8_BPP); + BitmapScopedWriteAccess pWriteAcc(aNewBmp); + if( !pReadAcc || !pWriteAcc ) + return false; + + tools::Long nWidth = pReadAcc->Width(); + tools::Long nWidth1 = nWidth - 1; + tools::Long nHeight = pReadAcc->Height(); + tools::Long nW = nWidth * 3; + tools::Long nW2 = nW - 3; + std::unique_ptr<sal_Int32[]> p1(new sal_Int32[ nW ]); + std::unique_ptr<sal_Int32[]> p2(new sal_Int32[ nW ]); + sal_Int32* p1T = p1.get(); + sal_Int32* p2T = p2.get(); + sal_Int32* pTmp = p2T; + for (tools::Long nZ = 0; nZ < nWidth; nZ++) { - ScopedReadAccess pReadAcc(*this); - Bitmap aNewBmp(GetSizePixel(), vcl::PixelFormat::N8_BPP); - BitmapScopedWriteAccess pWriteAcc(aNewBmp); - if( pReadAcc && pWriteAcc ) + pTmp = shiftColor(pTmp, getColor(pReadAcc.get(), nZ)); + } + tools::Long nRErr, nGErr, nBErr; + tools::Long nRC, nGC, nBC; + for( tools::Long nY = 1, nYAcc = 0; nY <= nHeight; nY++, nYAcc++ ) + { + pTmp = p1T; + p1T = p2T; + p2T = pTmp; + if (nY < nHeight) { - tools::Long nWidth = pReadAcc->Width(); - tools::Long nWidth1 = nWidth - 1; - tools::Long nHeight = pReadAcc->Height(); - tools::Long nW = nWidth * 3; - tools::Long nW2 = nW - 3; - std::unique_ptr<sal_Int32[]> p1(new sal_Int32[ nW ]); - std::unique_ptr<sal_Int32[]> p2(new sal_Int32[ nW ]); - sal_Int32* p1T = p1.get(); - sal_Int32* p2T = p2.get(); - sal_Int32* pTmp = p2T; for (tools::Long nZ = 0; nZ < nWidth; nZ++) { pTmp = shiftColor(pTmp, getColor(pReadAcc.get(), nZ)); } - tools::Long nRErr, nGErr, nBErr; - tools::Long nRC, nGC, nBC; - for( tools::Long nY = 1, nYAcc = 0; nY <= nHeight; nY++, nYAcc++ ) - { - pTmp = p1T; - p1T = p2T; - p2T = pTmp; - if (nY < nHeight) - { - for (tools::Long nZ = 0; nZ < nWidth; nZ++) - { - pTmp = shiftColor(pTmp, getColor(pReadAcc.get(), nZ)); - } - } - // Examine first Pixel separately - tools::Long nX = 0; - tools::Long nTemp; - CALC_ERRORS; - CALC_TABLES7; - nX -= 5; - CALC_TABLES5; - Scanline pScanline = pWriteAcc->GetScanline(nYAcc); - pWriteAcc->SetPixelOnData( pScanline, 0, BitmapColor(static_cast<sal_uInt8>(nVCLBLut[ nBC ] + nVCLGLut[nGC ] + nVCLRLut[nRC ])) ); - // Get middle Pixels using a loop - tools::Long nXAcc; - for ( nX = 3, nXAcc = 1; nX < nW2; nXAcc++ ) - { - CALC_ERRORS; - CALC_TABLES7; - nX -= 8; - CALC_TABLES3; - CALC_TABLES5; - pWriteAcc->SetPixelOnData( pScanline, nXAcc, BitmapColor(static_cast<sal_uInt8>(nVCLBLut[ nBC ] + nVCLGLut[nGC ] + nVCLRLut[nRC ])) ); - } - // Treat last Pixel separately - CALC_ERRORS; - nX -= 5; - CALC_TABLES3; - CALC_TABLES5; - pWriteAcc->SetPixelOnData( pScanline, nWidth1, BitmapColor(static_cast<sal_uInt8>(nVCLBLut[ nBC ] + nVCLGLut[nGC ] + nVCLRLut[nRC ])) ); - } - pReadAcc.reset(); - pWriteAcc.reset(); - const MapMode aMap( maPrefMapMode ); - const Size aPrefSize( maPrefSize ); - *this = aNewBmp; - maPrefMapMode = aMap; - maPrefSize = aPrefSize; - return true; } - pReadAcc.reset(); - pWriteAcc.reset(); + // Examine first Pixel separately + tools::Long nX = 0; + tools::Long nTemp; + CALC_ERRORS; + CALC_TABLES7; + nX -= 5; + CALC_TABLES5; + Scanline pScanline = pWriteAcc->GetScanline(nYAcc); + pWriteAcc->SetPixelOnData( pScanline, 0, BitmapColor(static_cast<sal_uInt8>(nVCLBLut[ nBC ] + nVCLGLut[nGC ] + nVCLRLut[nRC ])) ); + // Get middle Pixels using a loop + tools::Long nXAcc; + for ( nX = 3, nXAcc = 1; nX < nW2; nXAcc++ ) + { + CALC_ERRORS; + CALC_TABLES7; + nX -= 8; + CALC_TABLES3; + CALC_TABLES5; + pWriteAcc->SetPixelOnData( pScanline, nXAcc, BitmapColor(static_cast<sal_uInt8>(nVCLBLut[ nBC ] + nVCLGLut[nGC ] + nVCLRLut[nRC ])) ); + } + // Treat last Pixel separately + CALC_ERRORS; + nX -= 5; + CALC_TABLES3; + CALC_TABLES5; + pWriteAcc->SetPixelOnData( pScanline, nWidth1, BitmapColor(static_cast<sal_uInt8>(nVCLBLut[ nBC ] + nVCLGLut[nGC ] + nVCLRLut[nRC ])) ); } - return false; + pReadAcc.reset(); + pWriteAcc.reset(); + const MapMode aMap( maPrefMapMode ); + const Size aPrefSize( maPrefSize ); + *this = aNewBmp; + maPrefMapMode = aMap; + maPrefSize = aPrefSize; + return true; } void Bitmap::Vectorize( GDIMetaFile& rMtf, sal_uInt8 cReduce, const Link<tools::Long,void>* pProgress ) diff --git a/vcl/source/bitmap/bitmappaint.cxx b/vcl/source/bitmap/bitmappaint.cxx index cdece0f438ed..e13e222699a5 100644 --- a/vcl/source/bitmap/bitmappaint.cxx +++ b/vcl/source/bitmap/bitmappaint.cxx @@ -284,152 +284,147 @@ bool Bitmap::Mirror(BmpMirrorFlags nMirrorFlags) bool Bitmap::Rotate(Degree10 nAngle10, const Color& rFillColor) { - bool bRet = false; - nAngle10 %= 3600_deg10; nAngle10 = (nAngle10 < 0_deg10) ? (Degree10(3599) + nAngle10) : nAngle10; if (!nAngle10) - bRet = true; - else if (nAngle10 == 1800_deg10) - bRet = Mirror(BmpMirrorFlags::Horizontal | BmpMirrorFlags::Vertical); - else + return true; + if (nAngle10 == 1800_deg10) + return Mirror(BmpMirrorFlags::Horizontal | BmpMirrorFlags::Vertical); + + ScopedReadAccess pReadAcc(*this); + Bitmap aRotatedBmp; + bool bRet = false; + + if (pReadAcc) { - ScopedReadAccess pReadAcc(*this); - Bitmap aRotatedBmp; + const Size aSizePix(GetSizePixel()); - if (pReadAcc) + if (nAngle10 == 900_deg10 || nAngle10 == 2700_deg10) { - const Size aSizePix(GetSizePixel()); + const Size aNewSizePix(aSizePix.Height(), aSizePix.Width()); + Bitmap aNewBmp(aNewSizePix, getPixelFormat(), &pReadAcc->GetPalette()); + BitmapScopedWriteAccess pWriteAcc(aNewBmp); - if (nAngle10 == 900_deg10 || nAngle10 == 2700_deg10) + if (pWriteAcc) { - const Size aNewSizePix(aSizePix.Height(), aSizePix.Width()); - Bitmap aNewBmp(aNewSizePix, getPixelFormat(), &pReadAcc->GetPalette()); - BitmapScopedWriteAccess pWriteAcc(aNewBmp); - - if (pWriteAcc) + const tools::Long nWidth = aSizePix.Width(); + const tools::Long nWidth1 = nWidth - 1; + const tools::Long nHeight = aSizePix.Height(); + const tools::Long nHeight1 = nHeight - 1; + const tools::Long nNewWidth = aNewSizePix.Width(); + const tools::Long nNewHeight = aNewSizePix.Height(); + + if (nAngle10 == 900_deg10) { - const tools::Long nWidth = aSizePix.Width(); - const tools::Long nWidth1 = nWidth - 1; - const tools::Long nHeight = aSizePix.Height(); - const tools::Long nHeight1 = nHeight - 1; - const tools::Long nNewWidth = aNewSizePix.Width(); - const tools::Long nNewHeight = aNewSizePix.Height(); - - if (nAngle10 == 900_deg10) + for (tools::Long nY = 0, nOtherX = nWidth1; nY < nNewHeight; nY++, nOtherX--) { - for (tools::Long nY = 0, nOtherX = nWidth1; nY < nNewHeight; - nY++, nOtherX--) + Scanline pScanline = pWriteAcc->GetScanline(nY); + for (tools::Long nX = 0, nOtherY = 0; nX < nNewWidth; nX++) { - Scanline pScanline = pWriteAcc->GetScanline(nY); - for (tools::Long nX = 0, nOtherY = 0; nX < nNewWidth; nX++) - { - pWriteAcc->SetPixelOnData(pScanline, nX, - pReadAcc->GetPixel(nOtherY++, nOtherX)); - } + pWriteAcc->SetPixelOnData(pScanline, nX, + pReadAcc->GetPixel(nOtherY++, nOtherX)); } } - else if (nAngle10 == 2700_deg10) + } + else if (nAngle10 == 2700_deg10) + { + for (tools::Long nY = 0, nOtherX = 0; nY < nNewHeight; nY++, nOtherX++) { - for (tools::Long nY = 0, nOtherX = 0; nY < nNewHeight; nY++, nOtherX++) + Scanline pScanline = pWriteAcc->GetScanline(nY); + for (tools::Long nX = 0, nOtherY = nHeight1; nX < nNewWidth; nX++) { - Scanline pScanline = pWriteAcc->GetScanline(nY); - for (tools::Long nX = 0, nOtherY = nHeight1; nX < nNewWidth; nX++) - { - pWriteAcc->SetPixelOnData(pScanline, nX, - pReadAcc->GetPixel(nOtherY--, nOtherX)); - } + pWriteAcc->SetPixelOnData(pScanline, nX, + pReadAcc->GetPixel(nOtherY--, nOtherX)); } } - - pWriteAcc.reset(); } - aRotatedBmp = aNewBmp; + pWriteAcc.reset(); } - else - { - Point aTmpPoint; - tools::Rectangle aTmpRectangle(aTmpPoint, aSizePix); - tools::Polygon aPoly(aTmpRectangle); - aPoly.Rotate(aTmpPoint, nAngle10); - tools::Rectangle aNewBound(aPoly.GetBoundRect()); - const Size aNewSizePix(aNewBound.GetSize()); - Bitmap aNewBmp(aNewSizePix, getPixelFormat(), &pReadAcc->GetPalette()); - BitmapScopedWriteAccess pWriteAcc(aNewBmp); + aRotatedBmp = aNewBmp; + } + else + { + Point aTmpPoint; + tools::Rectangle aTmpRectangle(aTmpPoint, aSizePix); + tools::Polygon aPoly(aTmpRectangle); + aPoly.Rotate(aTmpPoint, nAngle10); + + tools::Rectangle aNewBound(aPoly.GetBoundRect()); + const Size aNewSizePix(aNewBound.GetSize()); + Bitmap aNewBmp(aNewSizePix, getPixelFormat(), &pReadAcc->GetPalette()); + BitmapScopedWriteAccess pWriteAcc(aNewBmp); - if (pWriteAcc) + if (pWriteAcc) + { + const BitmapColor aFillColor(pWriteAcc->GetBestMatchingColor(rFillColor)); + const double fCosAngle = cos(toRadians(nAngle10)); + const double fSinAngle = sin(toRadians(nAngle10)); + const double fXMin = aNewBound.Left(); + const double fYMin = aNewBound.Top(); + const sal_Int32 nWidth = aSizePix.Width(); + const sal_Int32 nHeight = aSizePix.Height(); + const sal_Int32 nNewWidth = aNewSizePix.Width(); + const sal_Int32 nNewHeight = aNewSizePix.Height(); + // we store alternating values of cos/sin. We do this instead of + // separate arrays to improve cache hit. + std::unique_ptr<sal_Int32[]> pCosSinX(new sal_Int32[nNewWidth * 2]); + std::unique_ptr<sal_Int32[]> pCosSinY(new sal_Int32[nNewHeight * 2]); + + for (sal_Int32 nIdx = 0, nX = 0; nX < nNewWidth; nX++) { - const BitmapColor aFillColor(pWriteAcc->GetBestMatchingColor(rFillColor)); - const double fCosAngle = cos(toRadians(nAngle10)); - const double fSinAngle = sin(toRadians(nAngle10)); - const double fXMin = aNewBound.Left(); - const double fYMin = aNewBound.Top(); - const sal_Int32 nWidth = aSizePix.Width(); - const sal_Int32 nHeight = aSizePix.Height(); - const sal_Int32 nNewWidth = aNewSizePix.Width(); - const sal_Int32 nNewHeight = aNewSizePix.Height(); - // we store alternating values of cos/sin. We do this instead of - // separate arrays to improve cache hit. - std::unique_ptr<sal_Int32[]> pCosSinX(new sal_Int32[nNewWidth * 2]); - std::unique_ptr<sal_Int32[]> pCosSinY(new sal_Int32[nNewHeight * 2]); - - for (sal_Int32 nIdx = 0, nX = 0; nX < nNewWidth; nX++) - { - const double fTmp = (fXMin + nX) * 64; + const double fTmp = (fXMin + nX) * 64; - pCosSinX[nIdx++] = std::round(fCosAngle * fTmp); - pCosSinX[nIdx++] = std::round(fSinAngle * fTmp); - } + pCosSinX[nIdx++] = std::round(fCosAngle * fTmp); + pCosSinX[nIdx++] = std::round(fSinAngle * fTmp); + } - for (sal_Int32 nIdx = 0, nY = 0; nY < nNewHeight; nY++) - { - const double fTmp = (fYMin + nY) * 64; + for (sal_Int32 nIdx = 0, nY = 0; nY < nNewHeight; nY++) + { + const double fTmp = (fYMin + nY) * 64; - pCosSinY[nIdx++] = std::round(fCosAngle * fTmp); - pCosSinY[nIdx++] = std::round(fSinAngle * fTmp); - } + pCosSinY[nIdx++] = std::round(fCosAngle * fTmp); + pCosSinY[nIdx++] = std::round(fSinAngle * fTmp); + } - for (sal_Int32 nCosSinYIdx = 0, nY = 0; nY < nNewHeight; nY++) + for (sal_Int32 nCosSinYIdx = 0, nY = 0; nY < nNewHeight; nY++) + { + sal_Int32 nCosY = pCosSinY[nCosSinYIdx++]; + sal_Int32 nSinY = pCosSinY[nCosSinYIdx++]; + Scanline pScanline = pWriteAcc->GetScanline(nY); + + for (sal_Int32 nCosSinXIdx = 0, nX = 0; nX < nNewWidth; nX++) { - sal_Int32 nCosY = pCosSinY[nCosSinYIdx++]; - sal_Int32 nSinY = pCosSinY[nCosSinYIdx++]; - Scanline pScanline = pWriteAcc->GetScanline(nY); + sal_Int32 nRotX = (pCosSinX[nCosSinXIdx++] - nSinY) >> 6; + sal_Int32 nRotY = (pCosSinX[nCosSinXIdx++] + nCosY) >> 6; - for (sal_Int32 nCosSinXIdx = 0, nX = 0; nX < nNewWidth; nX++) + if ((nRotX > -1) && (nRotX < nWidth) && (nRotY > -1) && (nRotY < nHeight)) + { + pWriteAcc->SetPixelOnData(pScanline, nX, + pReadAcc->GetPixel(nRotY, nRotX)); + } + else { - sal_Int32 nRotX = (pCosSinX[nCosSinXIdx++] - nSinY) >> 6; - sal_Int32 nRotY = (pCosSinX[nCosSinXIdx++] + nCosY) >> 6; - - if ((nRotX > -1) && (nRotX < nWidth) && (nRotY > -1) - && (nRotY < nHeight)) - { - pWriteAcc->SetPixelOnData(pScanline, nX, - pReadAcc->GetPixel(nRotY, nRotX)); - } - else - { - pWriteAcc->SetPixelOnData(pScanline, nX, aFillColor); - } + pWriteAcc->SetPixelOnData(pScanline, nX, aFillColor); } } - - pWriteAcc.reset(); } - aRotatedBmp = aNewBmp; + pWriteAcc.reset(); } - pReadAcc.reset(); + aRotatedBmp = aNewBmp; } - bRet = !aRotatedBmp.IsEmpty(); - if (bRet) - ReassignWithSize(aRotatedBmp); + pReadAcc.reset(); } + bRet = !aRotatedBmp.IsEmpty(); + if (bRet) + ReassignWithSize(aRotatedBmp); + return bRet; }; @@ -620,99 +615,94 @@ Bitmap Bitmap::CreateMask(const Color& rTransColor, sal_uInt8 nTol) const vcl::Region Bitmap::CreateRegion(const Color& rColor, const tools::Rectangle& rRect) const { - vcl::Region aRegion; tools::Rectangle aRect(rRect); ScopedReadAccess pReadAcc(const_cast<Bitmap&>(*this)); aRect.Intersection(tools::Rectangle(Point(), GetSizePixel())); aRect.Normalize(); - if (pReadAcc) - { - const tools::Long nLeft = aRect.Left(); - const tools::Long nTop = aRect.Top(); - const tools::Long nRight = aRect.Right(); - const tools::Long nBottom = aRect.Bottom(); - const BitmapColor aMatch(pReadAcc->GetBestMatchingColor(rColor)); + if (!pReadAcc) + return vcl::Region(aRect); + + vcl::Region aRegion; + const tools::Long nLeft = aRect.Left(); + const tools::Long nTop = aRect.Top(); + const tools::Long nRight = aRect.Right(); + const tools::Long nBottom = aRect.Bottom(); + const BitmapColor aMatch(pReadAcc->GetBestMatchingColor(rColor)); + + std::vector<tools::Long> aLine; + tools::Long nYStart(nTop); + tools::Long nY(nTop); - std::vector<tools::Long> aLine; - tools::Long nYStart(nTop); - tools::Long nY(nTop); + for (; nY <= nBottom; nY++) + { + std::vector<tools::Long> aNewLine; + tools::Long nX(nLeft); + Scanline pScanlineRead = pReadAcc->GetScanline(nY); - for (; nY <= nBottom; nY++) + for (; nX <= nRight;) { - std::vector<tools::Long> aNewLine; - tools::Long nX(nLeft); - Scanline pScanlineRead = pReadAcc->GetScanline(nY); + while ((nX <= nRight) && (aMatch != pReadAcc->GetPixelFromData(pScanlineRead, nX))) + nX++; - for (; nX <= nRight;) + if (nX <= nRight) { - while ((nX <= nRight) && (aMatch != pReadAcc->GetPixelFromData(pScanlineRead, nX))) - nX++; + aNewLine.push_back(nX); - if (nX <= nRight) + while ((nX <= nRight) && (aMatch == pReadAcc->GetPixelFromData(pScanlineRead, nX))) { - aNewLine.push_back(nX); - - while ((nX <= nRight) - && (aMatch == pReadAcc->GetPixelFromData(pScanlineRead, nX))) - { - nX++; - } - - aNewLine.push_back(nX - 1); + nX++; } + + aNewLine.push_back(nX - 1); } + } - if (aNewLine != aLine) + if (aNewLine != aLine) + { + // need to write aLine, it's different from the next line + if (!aLine.empty()) { - // need to write aLine, it's different from the next line - if (!aLine.empty()) - { - tools::Rectangle aSubRect; + tools::Rectangle aSubRect; - // enter y values and proceed ystart - aSubRect.SetTop(nYStart); - aSubRect.SetBottom(nY ? nY - 1 : 0); + // enter y values and proceed ystart + aSubRect.SetTop(nYStart); + aSubRect.SetBottom(nY ? nY - 1 : 0); - for (size_t a(0); a < aLine.size();) - { - aSubRect.SetLeft(aLine[a++]); - aSubRect.SetRight(aLine[a++]); - aRegion.Union(aSubRect); - } + for (size_t a(0); a < aLine.size();) + { + aSubRect.SetLeft(aLine[a++]); + aSubRect.SetRight(aLine[a++]); + aRegion.Union(aSubRect); } - - // copy line as new line - aLine = aNewLine; - nYStart = nY; } + + // copy line as new line + aLine = aNewLine; + nYStart = nY; } + } - // write last line if used - if (!aLine.empty()) - { - tools::Rectangle aSubRect; + // write last line if used + if (!aLine.empty()) + { + tools::Rectangle aSubRect; - // enter y values - aSubRect.SetTop(nYStart); - aSubRect.SetBottom(nY ? nY - 1 : 0); + // enter y values + aSubRect.SetTop(nYStart); + aSubRect.SetBottom(nY ? nY - 1 : 0); - for (size_t a(0); a < aLine.size();) - { - aSubRect.SetLeft(aLine[a++]); - aSubRect.SetRight(aLine[a++]); - aRegion.Union(aSubRect); - } + for (size_t a(0); a < aLine.size();) + { + aSubRect.SetLeft(aLine[a++]); + aSubRect.SetRight(aLine[a++]); + aRegion.Union(aSubRect); } - - pReadAcc.reset(); - } - else - { - aRegion = aRect; } + pReadAcc.reset(); + return aRegion; } @@ -720,78 +710,75 @@ bool Bitmap::Replace(const Bitmap& rMask, const Color& rReplaceColor) { ScopedReadAccess pMaskAcc(const_cast<Bitmap&>(rMask)); BitmapScopedWriteAccess pAcc(*this); - bool bRet = false; - if (pMaskAcc && pAcc) + if (!pMaskAcc || !pAcc) + return false; + + const tools::Long nWidth = std::min(pMaskAcc->Width(), pAcc->Width()); + const tools::Long nHeight = std::min(pMaskAcc->Height(), pAcc->Height()); + const BitmapColor aMaskWhite(pMaskAcc->GetBestMatchingColor(COL_WHITE)); + BitmapColor aReplace; + + if (pAcc->HasPalette()) { - const tools::Long nWidth = std::min(pMaskAcc->Width(), pAcc->Width()); - const tools::Long nHeight = std::min(pMaskAcc->Height(), pAcc->Height()); - const BitmapColor aMaskWhite(pMaskAcc->GetBestMatchingColor(COL_WHITE)); - BitmapColor aReplace; + const sal_uInt16 nActColors = pAcc->GetPaletteEntryCount(); + const sal_uInt16 nMaxColors = 1 << pAcc->GetBitCount(); - if (pAcc->HasPalette()) + // default to the nearest color + aReplace = pAcc->GetBestMatchingColor(rReplaceColor); + + // for paletted images without a matching palette entry + // look for an unused palette entry (NOTE: expensive!) + if (pAcc->GetPaletteColor(aReplace.GetIndex()) != BitmapColor(rReplaceColor)) { - const sal_uInt16 nActColors = pAcc->GetPaletteEntryCount(); - const sal_uInt16 nMaxColors = 1 << pAcc->GetBitCount(); + // if the palette has empty entries use the last one + if (nActColors < nMaxColors) + { + pAcc->SetPaletteEntryCount(nActColors + 1); + pAcc->SetPaletteColor(nActColors, rReplaceColor); + aReplace = BitmapColor(static_cast<sal_uInt8>(nActColors)); + } + else + { + std::unique_ptr<bool[]> pFlags(new bool[nMaxColors]); - // default to the nearest color - aReplace = pAcc->GetBestMatchingColor(rReplaceColor); + // Set all entries to false + std::fill(pFlags.get(), pFlags.get() + nMaxColors, false); - // for paletted images without a matching palette entry - // look for an unused palette entry (NOTE: expensive!) - if (pAcc->GetPaletteColor(aReplace.GetIndex()) != BitmapColor(rReplaceColor)) - { - // if the palette has empty entries use the last one - if (nActColors < nMaxColors) + for (tools::Long nY = 0; nY < nHeight; nY++) { - pAcc->SetPaletteEntryCount(nActColors + 1); - pAcc->SetPaletteColor(nActColors, rReplaceColor); - aReplace = BitmapColor(static_cast<sal_uInt8>(nActColors)); + Scanline pScanline = pAcc->GetScanline(nY); + for (tools::Long nX = 0; nX < nWidth; nX++) + pFlags[pAcc->GetIndexFromData(pScanline, nX)] = true; } - else - { - std::unique_ptr<bool[]> pFlags(new bool[nMaxColors]); - - // Set all entries to false - std::fill(pFlags.get(), pFlags.get() + nMaxColors, false); - for (tools::Long nY = 0; nY < nHeight; nY++) - { - Scanline pScanline = pAcc->GetScanline(nY); - for (tools::Long nX = 0; nX < nWidth; nX++) - pFlags[pAcc->GetIndexFromData(pScanline, nX)] = true; - } - - for (sal_uInt16 i = 0; i < nMaxColors; i++) + for (sal_uInt16 i = 0; i < nMaxColors; i++) + { + // Hurray, we do have an unused entry + if (!pFlags[i]) { - // Hurray, we do have an unused entry - if (!pFlags[i]) - { - pAcc->SetPaletteColor(i, rReplaceColor); - aReplace = BitmapColor(static_cast<sal_uInt8>(i)); - } + pAcc->SetPaletteColor(i, rReplaceColor); + aReplace = BitmapColor(static_cast<sal_uInt8>(i)); } } } } - else - aReplace = rReplaceColor; + } + else + aReplace = rReplaceColor; - for (tools::Long nY = 0; nY < nHeight; nY++) + for (tools::Long nY = 0; nY < nHeight; nY++) + { + Scanline pScanline = pAcc->GetScanline(nY); + Scanline pScanlineMask = pMaskAcc->GetScanline(nY); + for (tools::Long nX = 0; nX < nWidth; nX++) { - Scanline pScanline = pAcc->GetScanline(nY); - Scanline pScanlineMask = pMaskAcc->GetScanline(nY); - for (tools::Long nX = 0; nX < nWidth; nX++) - { - if (pMaskAcc->GetPixelFromData(pScanlineMask, nX) == aMaskWhite) - pAcc->SetPixelOnData(pScanline, nX, aReplace); - } + if (pMaskAcc->GetPixelFromData(pScanlineMask, nX) == aMaskWhite) + pAcc->SetPixelOnData(pScanline, nX, aReplace); } - - bRet = true; } - return bRet; + return true; } bool Bitmap::Replace(const AlphaMask& rAlpha, const Color& rMergeColor) @@ -800,45 +787,39 @@ bool Bitmap::Replace(const AlphaMask& rAlpha, const Color& rMergeColor) ScopedReadAccess pAcc(*this); AlphaMask::ScopedReadAccess pAlphaAcc(const_cast<AlphaMask&>(rAlpha)); BitmapScopedWriteAccess pNewAcc(aNewBmp); - bool bRet = false; - if (pAcc && pAlphaAcc && pNewAcc) - { - BitmapColor aCol; - const tools::Long nWidth = std::min(pAlphaAcc->Width(), pAcc->Width()); - const tools::Long nHeight = std::min(pAlphaAcc->Height(), pAcc->Height()); + if (!pAcc || !pAlphaAcc || !pNewAcc) + return false; - for (tools::Long nY = 0; nY < nHeight; nY++) + BitmapColor aCol; + const tools::Long nWidth = std::min(pAlphaAcc->Width(), pAcc->Width()); + const tools::Long nHeight = std::min(pAlphaAcc->Height(), pAcc->Height()); + + for (tools::Long nY = 0; nY < nHeight; nY++) + { + Scanline pScanline = pNewAcc->GetScanline(nY); + Scanline pScanlineAlpha = pAlphaAcc->GetScanline(nY); + for (tools::Long nX = 0; nX < nWidth; nX++) { - Scanline pScanline = pNewAcc->GetScanline(nY); - Scanline pScanlineAlpha = pAlphaAcc->GetScanline(nY); - for (tools::Long nX = 0; nX < nWidth; nX++) - { - aCol = pAcc->GetColor(nY, nX); - aCol.Merge(rMergeColor, 255 - pAlphaAcc->GetIndexFromData(pScanlineAlpha, nX)); - pNewAcc->SetPixelOnData(pScanline, nX, aCol); - } + aCol = pAcc->GetColor(nY, nX); + aCol.Merge(rMergeColor, 255 - pAlphaAcc->GetIndexFromData(pScanlineAlpha, nX)); + pNewAcc->SetPixelOnData(pScanline, nX, aCol); } - - bRet = true; } pAcc.reset(); pAlphaAcc.reset(); pNewAcc.reset(); - if (bRet) - { - const MapMode aMap(maPrefMapMode); - const Size aSize(maPrefSize); + const MapMode aMap(maPrefMapMode); + const Size aSize(maPrefSize); - *this = aNewBmp; + *this = aNewBmp; - maPrefMapMode = aMap; - maPrefSize = aSize; - } + maPrefMapMode = aMap; + maPrefSize = aSize; - return bRet; + return true; } bool Bitmap::Replace(const Color& rSearchColor, const Color& rReplaceColor, sal_uInt8 nTol) @@ -1024,39 +1005,36 @@ bool Bitmap::CombineOr(const Bitmap& rMask) { ScopedReadAccess pMaskAcc(const_cast<Bitmap&>(rMask)); BitmapScopedWriteAccess pAcc(*this); - bool bRet = false; - if (pMaskAcc && pAcc) - { - const tools::Long nWidth = std::min(pMaskAcc->Width(), pAcc->Width()); - const tools::Long nHeight = std::min(pMaskAcc->Height(), pAcc->Height()); - const Color aColBlack(COL_BLACK); - const BitmapColor aWhite(pAcc->GetBestMatchingColor(COL_WHITE)); - const BitmapColor aBlack(pAcc->GetBestMatchingColor(aColBlack)); - const BitmapColor aMaskBlack(pMaskAcc->GetBestMatchingColor(aColBlack)); + if (!pMaskAcc || !pAcc) + return false; - for (tools::Long nY = 0; nY < nHeight; nY++) + const tools::Long nWidth = std::min(pMaskAcc->Width(), pAcc->Width()); + const tools::Long nHeight = std::min(pMaskAcc->Height(), pAcc->Height()); + const Color aColBlack(COL_BLACK); + const BitmapColor aWhite(pAcc->GetBestMatchingColor(COL_WHITE)); + const BitmapColor aBlack(pAcc->GetBestMatchingColor(aColBlack)); + const BitmapColor aMaskBlack(pMaskAcc->GetBestMatchingColor(aColBlack)); + + for (tools::Long nY = 0; nY < nHeight; nY++) + { + Scanline pScanline = pAcc->GetScanline(nY); + Scanline pScanlineMask = pMaskAcc->GetScanline(nY); + for (tools::Long nX = 0; nX < nWidth; nX++) { - Scanline pScanline = pAcc->GetScanline(nY); - Scanline pScanlineMask = pMaskAcc->GetScanline(nY); - for (tools::Long nX = 0; nX < nWidth; nX++) + if (pMaskAcc->GetPixelFromData(pScanlineMask, nX) != aMaskBlack + || pAcc->GetPixelFromData(pScanline, nX) != aBlack) { - if (pMaskAcc->GetPixelFromData(pScanlineMask, nX) != aMaskBlack - || pAcc->GetPixelFromData(pScanline, nX) != aBlack) - { - pAcc->SetPixelOnData(pScanline, nX, aWhite); - } - else - { - pAcc->SetPixelOnData(pScanline, nX, aBlack); - } + pAcc->SetPixelOnData(pScanline, nX, aWhite); + } + else + { + pAcc->SetPixelOnData(pScanline, nX, aBlack); } } - - bRet = true; } - return bRet; + return true; } // TODO: Have a look at OutputDevice::ImplDrawAlpha() for some @@ -1071,30 +1049,27 @@ bool Bitmap::Blend(const AlphaMask& rAlpha, const Color& rBackgroundColor) AlphaMask::ScopedReadAccess pAlphaAcc(const_cast<AlphaMask&>(rAlpha)); BitmapScopedWriteAccess pAcc(*this); - bool bRet = false; - if (pAlphaAcc && pAcc) - { - const tools::Long nWidth = std::min(pAlphaAcc->Width(), pAcc->Width()); - const tools::Long nHeight = std::min(pAlphaAcc->Height(), pAcc->Height()); + if (!pAlphaAcc || !pAcc) + return false; - for (tools::Long nY = 0; nY < nHeight; ++nY) + const tools::Long nWidth = std::min(pAlphaAcc->Width(), pAcc->Width()); + const tools::Long nHeight = std::min(pAlphaAcc->Height(), pAcc->Height()); + + for (tools::Long nY = 0; nY < nHeight; ++nY) + { + Scanline pScanline = pAcc->GetScanline(nY); + Scanline pScanlineAlpha = pAlphaAcc->GetScanline(nY); + for (tools::Long nX = 0; nX < nWidth; ++nX) { - Scanline pScanline = pAcc->GetScanline(nY); - Scanline pScanlineAlpha = pAlphaAcc->GetScanline(nY); - for (tools::Long nX = 0; nX < nWidth; ++nX) - { - BitmapColor aBmpColor = pAcc->GetPixelFromData(pScanline, nX); - aBmpColor.Merge(rBackgroundColor, - 255 - pAlphaAcc->GetIndexFromData(pScanlineAlpha, nX)); - pAcc->SetPixelOnData(pScanline, nX, aBmpColor); - } + BitmapColor aBmpColor = pAcc->GetPixelFromData(pScanline, nX); + aBmpColor.Merge(rBackgroundColor, + 255 - pAlphaAcc->GetIndexFromData(pScanlineAlpha, nX)); + pAcc->SetPixelOnData(pScanline, nX, aBmpColor); } - - bRet = true; } - return bRet; + return true; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/bitmap/dibtools.cxx b/vcl/source/bitmap/dibtools.cxx index 96b82b9a7b86..e2e9076c5ddb 100644 --- a/vcl/source/bitmap/dibtools.cxx +++ b/vcl/source/bitmap/dibtools.cxx @@ -1664,43 +1664,43 @@ bool ImplWriteDIB( const Size aSizePix(rSource.GetSizePixel()); bool bRet(false); - if(aSizePix.Width() && aSizePix.Height()) - { - Bitmap::ScopedReadAccess pAcc(const_cast< Bitmap& >(rSource)); - Bitmap::ScopedReadAccess pAccAlpha; - const SvStreamEndian nOldFormat(rOStm.GetEndian()); - const sal_uInt64 nOldPos(rOStm.Tell()); + if(!aSizePix.Width() || !aSizePix.Height()) + return false; + + Bitmap::ScopedReadAccess pAcc(const_cast< Bitmap& >(rSource)); + Bitmap::ScopedReadAccess pAccAlpha; + const SvStreamEndian nOldFormat(rOStm.GetEndian()); + const sal_uInt64 nOldPos(rOStm.Tell()); - rOStm.SetEndian(SvStreamEndian::LITTLE); + rOStm.SetEndian(SvStreamEndian::LITTLE); - if (pAcc) + if (pAcc) + { + if(bFileHeader) { - if(bFileHeader) - { - if(ImplWriteDIBFileHeader(rOStm, *pAcc)) - { - bRet = ImplWriteDIBBody(rSource, rOStm, *pAcc, pAccAlpha.get(), bCompressed); - } - } - else + if(ImplWriteDIBFileHeader(rOStm, *pAcc)) { bRet = ImplWriteDIBBody(rSource, rOStm, *pAcc, pAccAlpha.get(), bCompressed); } - - pAcc.reset(); } - - pAccAlpha.reset(); - - if(!bRet) + else { - rOStm.SetError(SVSTREAM_GENERALERROR); - rOStm.Seek(nOldPos); + bRet = ImplWriteDIBBody(rSource, rOStm, *pAcc, pAccAlpha.get(), bCompressed); } - rOStm.SetEndian(nOldFormat); + pAcc.reset(); + } + + pAccAlpha.reset(); + + if(!bRet) + { + rOStm.SetError(SVSTREAM_GENERALERROR); + rOStm.Seek(nOldPos); } + rOStm.SetEndian(nOldFormat); + return bRet; } |