sc/source/core/tool/scmatrix.cxx                          |   34 
 vcl/source/bitmap/BitmapMedianFilter.cxx                  |  274 +--
 vcl/source/bitmap/BitmapMonochromeFilter.cxx              |  108 -
 vcl/source/bitmap/BitmapScaleConvolutionFilter.cxx        |  116 -
 vcl/source/bitmap/BitmapSepiaFilter.cxx                   |  119 -
 vcl/source/bitmap/BitmapSimpleColorQuantizationFilter.cxx |  127 -
 vcl/source/bitmap/BitmapSobelGreyFilter.cxx               |  243 +-
 vcl/source/bitmap/bitmap.cxx                              | 1222 ++++++--------
 vcl/source/bitmap/bitmappaint.cxx                         |  559 +++---
 vcl/source/bitmap/dibtools.cxx                            |   50 
 10 files changed, 1357 insertions(+), 1495 deletions(-)

New commits:
commit 5de1d0472b319e9d48972eb067fd8189507fa640
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Tue Jan 3 20:19:56 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Jan 4 15:36:08 2023 +0000

    use sal_uInt8 for maMatFlag
    
    which is way more cache-dense than double
    
    Change-Id: I04503eb3a4054cce5312a7a0048c9b6679a8fd16
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145018
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index f5d04bdb3fb9..8afeb796b35e 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -64,10 +64,18 @@ struct matrix_trait
 
     typedef mdds::mtv::custom_block_func1<sc::string_block> element_block_func;
 };
+struct matrix_flag_trait
+{
+    typedef sc::string_block string_element_block;
+    typedef mdds::mtv::uint8_element_block integer_element_block;
+
+    typedef mdds::mtv::custom_block_func1<sc::string_block> element_block_func;
+};
 
 }
 
 typedef mdds::multi_type_matrix<matrix_trait> MatrixImplType;
+typedef mdds::multi_type_matrix<matrix_flag_trait> MatrixFlagImplType;
 
 namespace {
 
@@ -218,16 +226,14 @@ Comp CompareMatrixElemFunc<Comp>::maComp;
 
 }
 
-/* TODO: it would be good if mdds had get/set<sal_uInt8> additionally to
- * get/set<bool>, we're abusing double here. */
-typedef double TMatFlag;
-const TMatFlag SC_MATFLAG_EMPTYRESULT = 1.0;
-const TMatFlag SC_MATFLAG_EMPTYPATH   = 2.0;
+typedef uint8_t TMatFlag;
+const TMatFlag SC_MATFLAG_EMPTYRESULT = 1;
+const TMatFlag SC_MATFLAG_EMPTYPATH   = 2;
 
 class ScMatrixImpl
 {
     MatrixImplType maMat;
-    MatrixImplType maMatFlag;
+    MatrixFlagImplType maMatFlag;
     ScInterpreter* pErrorInterpreter;
 
 public:
@@ -706,7 +712,7 @@ svl::SharedString ScMatrixImpl::GetString( 
SvNumberFormatter& rFormatter, SCSIZE
             return maMat.get_string(aPos);
         case mdds::mtm::element_empty:
         {
-            if (maMatFlag.get_numeric(nR, nC) != SC_MATFLAG_EMPTYPATH)
+            if (maMatFlag.get<uint8_t>(nR, nC) != SC_MATFLAG_EMPTYPATH)
                 // not an empty path.
                 return svl::SharedString::getEmptyString();
 
@@ -769,8 +775,8 @@ ScMatrixValue ScMatrixImpl::Get(SCSIZE nC, SCSIZE nR) const
                     case mdds::mtm::element_empty:
                         aVal.nType = ScMatValType::Empty;
                     break;
-                    case mdds::mtm::element_numeric:
-                        aVal.nType = maMatFlag.get<TMatFlag>(nR, nC)
+                    case mdds::mtm::element_integer:
+                        aVal.nType = maMatFlag.get<uint8_t>(nR, nC)
                             == SC_MATFLAG_EMPTYPATH ? ScMatValType::EmptyPath 
: ScMatValType::Empty;
                     break;
                     default:
@@ -816,7 +822,7 @@ bool ScMatrixImpl::IsEmpty( SCSIZE nC, SCSIZE nR ) const
     // but not an 'empty path' element.
     ValidColRowReplicated( nC, nR );
     return maMat.get_type(nR, nC) == mdds::mtm::element_empty &&
-        maMatFlag.get_numeric(nR, nC) != SC_MATFLAG_EMPTYPATH;
+        maMatFlag.get_integer(nR, nC) != SC_MATFLAG_EMPTYPATH;
 }
 
 bool ScMatrixImpl::IsEmptyCell( SCSIZE nC, SCSIZE nR ) const
@@ -834,7 +840,7 @@ bool ScMatrixImpl::IsEmptyResult( SCSIZE nC, SCSIZE nR ) 
const
     // 'empty' or 'empty cell' or 'empty path' element.
     ValidColRowReplicated( nC, nR );
     return maMat.get_type(nR, nC) == mdds::mtm::element_empty &&
-        maMatFlag.get_numeric(nR, nC) == SC_MATFLAG_EMPTYRESULT;
+        maMatFlag.get_integer(nR, nC) == SC_MATFLAG_EMPTYRESULT;
 }
 
 bool ScMatrixImpl::IsEmptyPath( SCSIZE nC, SCSIZE nR ) const
@@ -842,7 +848,7 @@ bool ScMatrixImpl::IsEmptyPath( SCSIZE nC, SCSIZE nR ) const
     // Flag must indicate an 'empty path' element.
     if (ValidColRowOrReplicated( nC, nR ))
         return maMat.get_type(nR, nC) == mdds::mtm::element_empty &&
-            maMatFlag.get_numeric(nR, nC) == SC_MATFLAG_EMPTYPATH;
+            maMatFlag.get_integer(nR, nC) == SC_MATFLAG_EMPTYPATH;
     else
         return true;
 }
@@ -973,7 +979,7 @@ void ScMatrixImpl::PutEmptyResultVector( SCSIZE nCount, 
SCSIZE nC, SCSIZE nR )
     {
         maMat.set_empty(nR, nC, nCount);
         // Flag to indicate that this is 'empty result', not 'empty' or 'empty 
path'.
-        std::vector<TMatFlag> aVals(nCount, SC_MATFLAG_EMPTYRESULT);
+        std::vector<uint8_t> aVals(nCount, SC_MATFLAG_EMPTYRESULT);
         maMatFlag.set(nR, nC, aVals.begin(), aVals.end());
     }
     else
@@ -988,7 +994,7 @@ void ScMatrixImpl::PutEmptyPathVector( SCSIZE nCount, 
SCSIZE nC, SCSIZE nR )
     {
         maMat.set_empty(nR, nC, nCount);
         // Flag to indicate 'empty path'.
-        std::vector<TMatFlag> aVals(nCount, SC_MATFLAG_EMPTYPATH);
+        std::vector<uint8_t> aVals(nCount, SC_MATFLAG_EMPTYPATH);
         maMatFlag.set(nR, nC, aVals.begin(), aVals.end());
     }
     else
commit a76a135c9e9bdecd38970e293e72eeeeca000d27
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Tue Jan 3 20:14:21 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Jan 4 15:35:56 2023 +0000

    flatten some vcl code
    
    Change-Id: I3747c9ccc97ac59a2e41c1fe4427d1a2f458352a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145017
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

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;
 

... etc. - the rest is truncated

Reply via email to