drawinglayer/source/processor2d/SDPRProcessor2dTools.cxx |   12 
 filter/source/graphicfilter/icgm/bitmap.cxx              |    2 
 framework/source/uiconfiguration/ImageList.cxx           |    2 
 include/vcl/bitmap.hxx                                   |   29 
 include/vcl/bitmapex.hxx                                 |   29 
 oox/source/export/drawingml.cxx                          |    2 
 sd/source/ui/view/viewoverlaymanager.cxx                 |   12 
 sfx2/source/control/recentdocsviewitem.cxx               |    2 
 vcl/source/bitmap/BitmapEx.cxx                           |   70 --
 vcl/source/bitmap/bitmap.cxx                             |  518 +++++++--------
 vcl/source/graphic/GraphicObject2.cxx                    |    2 
 vcl/source/window/menubarwindow.cxx                      |    2 
 12 files changed, 363 insertions(+), 319 deletions(-)

New commits:
commit 29fc0ec9930fc1c09c0e79d41c56f93ae853c054
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Sat Dec 2 22:27:34 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sun Dec 3 17:39:43 2023 +0100

    Split the *Bitmap::CopyPixel functions
    
    into the two entire separate cases they want to handle, there is
    no reason to mix the two different cases like this.
    
    Change-Id: I38e99e7ad6168a84e7a744f61407887825158902
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160248
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/drawinglayer/source/processor2d/SDPRProcessor2dTools.cxx 
b/drawinglayer/source/processor2d/SDPRProcessor2dTools.cxx
index 4789cc30cfdd..3d738cd09c99 100644
--- a/drawinglayer/source/processor2d/SDPRProcessor2dTools.cxx
+++ b/drawinglayer/source/processor2d/SDPRProcessor2dTools.cxx
@@ -68,15 +68,15 @@ void takeCareOfOffsetXY(
                 const tools::Rectangle aSrcDst(Point(), rSize);
                 aTarget.CopyPixel(aSrcDst, // Dst
                                   aSrcDst, // Src
-                                  &rTarget);
+                                  rTarget);
                 const Size aSizeA(b, h);
                 aTarget.CopyPixel(tools::Rectangle(Point(0, h), aSizeA), // Dst
                                   tools::Rectangle(Point(a, 0), aSizeA), // Src
-                                  &rTarget);
+                                  rTarget);
                 const Size aSizeB(a, h);
                 aTarget.CopyPixel(tools::Rectangle(Point(b, h), aSizeB), // Dst
                                   tools::Rectangle(Point(), aSizeB), // Src
-                                  &rTarget);
+                                  rTarget);
 
                 setOffsetXYCreatedBitmap(
                     
const_cast<drawinglayer::primitive2d::FillGraphicPrimitive2D&>(
@@ -111,15 +111,15 @@ void takeCareOfOffsetXY(
                 const tools::Rectangle aSrcDst(Point(), rSize);
                 aTarget.CopyPixel(aSrcDst, // Dst
                                   aSrcDst, // Src
-                                  &rTarget);
+                                  rTarget);
                 const Size aSizeA(w, b);
                 aTarget.CopyPixel(tools::Rectangle(Point(w, 0), aSizeA), // Dst
                                   tools::Rectangle(Point(0, a), aSizeA), // Src
-                                  &rTarget);
+                                  rTarget);
                 const Size aSizeB(w, a);
                 aTarget.CopyPixel(tools::Rectangle(Point(w, b), aSizeB), // Dst
                                   tools::Rectangle(Point(), aSizeB), // Src
-                                  &rTarget);
+                                  rTarget);
 
                 setOffsetXYCreatedBitmap(
                     
const_cast<drawinglayer::primitive2d::FillGraphicPrimitive2D&>(
diff --git a/filter/source/graphicfilter/icgm/bitmap.cxx 
b/filter/source/graphicfilter/icgm/bitmap.cxx
index f747c0af651d..f7fea35f3583 100644
--- a/filter/source/graphicfilter/icgm/bitmap.cxx
+++ b/filter/source/graphicfilter/icgm/bitmap.cxx
@@ -393,7 +393,7 @@ void CGMBitmap::ImplInsert( CGMBitmapDescriptor const & 
rSource, CGMBitmapDescri
     }
     rDest.mxBitmap.Expand( 0, rSource.mnY );
     rDest.mxBitmap.CopyPixel( tools::Rectangle( Point( 0, rDest.mnY ), Size( 
rSource.mnX, rSource.mnY ) ),
-        tools::Rectangle( Point( 0, 0 ), Size( rSource.mnX, rSource.mnY ) ), 
&rSource.mxBitmap );
+        tools::Rectangle( Point( 0, 0 ), Size( rSource.mnX, rSource.mnY ) ), 
rSource.mxBitmap );
 
     if ( ( rSource.mnR.Y == rDest.mnQ.Y ) && ( rSource.mnR.X == rDest.mnQ.X ) )
     {   // Insert on Bottom
diff --git a/framework/source/uiconfiguration/ImageList.cxx 
b/framework/source/uiconfiguration/ImageList.cxx
index 0e64d219c166..5fb0f44f65b6 100644
--- a/framework/source/uiconfiguration/ImageList.cxx
+++ b/framework/source/uiconfiguration/ImageList.cxx
@@ -56,7 +56,7 @@ BitmapEx ImageList::GetAsHorizontalStrip() const
         tools::Rectangle aDestRect( Point( nIdx * aImageSize.Width(), 0 ), 
aImageSize );
         ImageAryData *pData = maImages[ nIdx ].get();
         BitmapEx aTmp = pData->maImage.GetBitmapEx();
-        aResult.CopyPixel( aDestRect, aSrcRect, &aTmp);
+        aResult.CopyPixel( aDestRect, aSrcRect, aTmp);
     }
 
     return aResult;
diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx
index f8123b177932..b7059654e016 100644
--- a/include/vcl/bitmap.hxx
+++ b/include/vcl/bitmap.hxx
@@ -233,12 +233,37 @@ public:
     bool                    CopyPixel(
                                 const tools::Rectangle& rRectDst,
                                 const tools::Rectangle& rRectSrc,
-                                const Bitmap* pBmpSrc = nullptr );
+                                const Bitmap& rBmpSrc );
+
+    /** Copy a rectangular area inside this bitmap.
+
+        @param rRectDst
+        Destination rectangle in this bitmap. This is clipped to the
+        bitmap dimensions.
+
+        @param rRectSrc
+        Source rectangl. This is clipped to the
+        bitmap dimensions. Note further that no scaling takes place
+        during this copy operation, i.e. only the minimum of source
+        and destination rectangle's width and height are used.
+
+        @return true, if the operation completed successfully. false
+        is not only returned when the operation failed, but also if
+        nothing had to be done, e.g. because one of the rectangles are
+        empty.
+     */
+    bool                    CopyPixel(
+                                const tools::Rectangle& rRectDst,
+                                const tools::Rectangle& rRectSrc );
 
     bool                    CopyPixel_AlphaOptimized(
                                 const tools::Rectangle& rRectDst,
                                 const tools::Rectangle& rRectSrc,
-                                const Bitmap* pBmpSrc );
+                                const Bitmap& rBmpSrc );
+
+    bool                    CopyPixel_AlphaOptimized(
+                                const tools::Rectangle& rRectDst,
+                                const tools::Rectangle& rRectSrc );
 
     /** Alpha-blend the given bitmap against a specified uniform
           background color.
diff --git a/include/vcl/bitmapex.hxx b/include/vcl/bitmapex.hxx
index 9d7a104264ef..c159e7d4910c 100644
--- a/include/vcl/bitmapex.hxx
+++ b/include/vcl/bitmapex.hxx
@@ -139,10 +139,8 @@ public:
         during this copy operation, i.e. only the minimum of source
         and destination rectangle's width and height are used.
 
-        @param pBmpExSrc
-        The source bitmap to copy from. If this argument is NULL, or
-        equal to the object this method is called on, copying takes
-        place within the same bitmap.
+        @param rBmpExSrc
+        The source bitmap to copy from.
 
         @return true, if the operation completed successfully. false
         is not only returned when the operation failed, but also if
@@ -152,7 +150,28 @@ public:
     bool                CopyPixel(
                             const tools::Rectangle& rRectDst,
                             const tools::Rectangle& rRectSrc,
-                            const BitmapEx* pBmpExSrc );
+                            const BitmapEx& rBmpExSrc );
+
+    /** Copy a rectangular area from one part of the bitmap to another.
+
+        @param rRectDst
+        Destination rectangle in this bitmap. This is clipped to the
+        bitmap dimensions.
+
+        @param rRectSrc
+        Source rectangle in this bitmap. This is clipped to the
+        bitmap dimensions. Note further that no scaling takes place
+        during this copy operation, i.e. only the minimum of source
+        and destination rectangle's width and height are used.
+
+        @return true, if the operation completed successfully. false
+        is not only returned when the operation failed, but also if
+        nothing had to be done, e.g. because one of the rectangles are
+        empty.
+     */
+    bool                CopyPixel(
+                            const tools::Rectangle& rRectDst,
+                            const tools::Rectangle& rRectSrc );
 
     /** Fill the entire bitmap with the given color
 
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 87c693a9cd75..228aa2326cc0 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -3164,7 +3164,7 @@ void DrawingML::WriteParagraphNumbering(const Reference< 
XPropertySet >& rXPropS
             aSourceBitmap.Scale(aDestRect.GetSize());
             tools::Rectangle aSourceRect(Point(0, 0), aDestRect.GetSize());
             BitmapEx aDestBitmap(Bitmap(aDestSize, vcl::PixelFormat::N24_BPP), 
aMask);
-            aDestBitmap.CopyPixel(aDestRect, aSourceRect, &aSourceBitmap);
+            aDestBitmap.CopyPixel(aDestRect, aSourceRect, aSourceBitmap);
             Graphic aDestGraphic(aDestBitmap);
             sRelationId = writeGraphicToStorage(aDestGraphic);
             fBulletSizeRel = 1.0f;
diff --git a/sd/source/ui/view/viewoverlaymanager.cxx 
b/sd/source/ui/view/viewoverlaymanager.cxx
index 6cc93b71c781..bd2e6be970f8 100644
--- a/sd/source/ui/view/viewoverlaymanager.cxx
+++ b/sd/source/ui/view/viewoverlaymanager.cxx
@@ -86,7 +86,7 @@ constexpr OUString aBigPlaceHolders[] =
     BMP_PLACEHOLDER_MOVIE_LARGE_HOVER
 };
 
-static BitmapEx* getButtonImage( int index, bool large )
+static BitmapEx& getButtonImage( int index, bool large )
 {
     static vcl::DeleteOnDeinit< BitmapEx > 
gSmallButtonImages[SAL_N_ELEMENTS(aSmallPlaceHolders)] = { 
vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, 
vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, 
vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, 
vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty };
     static vcl::DeleteOnDeinit< BitmapEx > 
gLargeButtonImages[SAL_N_ELEMENTS(aBigPlaceHolders)] = { 
vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, 
vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, 
vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty, 
vcl::DeleteOnDeinitFlag::Empty, vcl::DeleteOnDeinitFlag::Empty };
@@ -104,11 +104,11 @@ static BitmapEx* getButtonImage( int index, bool large )
 
     if( large )
     {
-        return gLargeButtonImages[index].get();
+        return *gLargeButtonImages[index].get();
     }
     else
     {
-        return gSmallButtonImages[index].get();
+        return *gSmallButtonImages[index].get();
     }
 }
 
@@ -368,13 +368,13 @@ BitmapEx ChangePlaceholderTag::createOverlayImage( int 
nHighlight )
 
         bool bLarge = nShapeSizePix > 250;
 
-        Size aSize( getButtonImage( 0, bLarge )->GetSizePixel() );
+        Size aSize( getButtonImage( 0, bLarge ).GetSizePixel() );
 
         aRet.Scale(Size(aSize.Width() << 1, aSize.Height() << 1));
 
         const ::tools::Rectangle aRectSrc( Point( 0, 0 ), aSize );
 
-        aRet = *(getButtonImage((nHighlight == 0) ? 4 : 0, bLarge));
+        aRet = getButtonImage((nHighlight == 0) ? 4 : 0, bLarge);
         aRet.Expand( aSize.Width(), aSize.Height(), true );
 
         aRet.CopyPixel( ::tools::Rectangle( Point( aSize.Width(), 0            
  ), aSize ), aRectSrc, getButtonImage((nHighlight == 1) ? 5 : 1, bLarge) );
@@ -406,7 +406,7 @@ void ChangePlaceholderTag::addCustomHandles( SdrHdlList& 
rHandlerList )
 
     bool bLarge = nShapeSizePix > 250;
 
-    Size aButtonSize( pDev->PixelToLogic( getButtonImage(0, bLarge 
)->GetSizePixel()) );
+    Size aButtonSize( pDev->PixelToLogic( getButtonImage(0, bLarge 
).GetSizePixel()) );
 
     const int nColumns = 2;
     const int nRows = 2;
diff --git a/sfx2/source/control/recentdocsviewitem.cxx 
b/sfx2/source/control/recentdocsviewitem.cxx
index 2070a4efe46e..369e219e98c5 100644
--- a/sfx2/source/control/recentdocsviewitem.cxx
+++ b/sfx2/source/control/recentdocsviewitem.cxx
@@ -208,7 +208,7 @@ RecentDocsViewItem::RecentDocsViewItem(sfx2::RecentDocsView 
&rView, const OUStri
         aThumbnail.CopyPixel(
                 ::tools::Rectangle(Point((aThumbnailSize.Width() - 
aExtSize.Width()) / 2, (aThumbnailSize.Height() - aExtSize.Height()) / 2), 
aExtSize),
                 ::tools::Rectangle(Point(0, 0), aExtSize),
-                &aExt);
+                aExt);
     }
     else
     {
diff --git a/vcl/source/bitmap/BitmapEx.cxx b/vcl/source/bitmap/BitmapEx.cxx
index 84c14cae4b7c..11f35c219ddb 100644
--- a/vcl/source/bitmap/BitmapEx.cxx
+++ b/vcl/source/bitmap/BitmapEx.cxx
@@ -69,7 +69,7 @@ BitmapEx::BitmapEx( const BitmapEx& rBitmapEx, Point aSrc, 
Size aSize )
 
     tools::Rectangle aDestRect( Point( 0, 0 ), aSize );
     tools::Rectangle aSrcRect( aSrc, aSize );
-    CopyPixel( aDestRect, aSrcRect, &rBitmapEx );
+    CopyPixel( aDestRect, aSrcRect, rBitmapEx );
 }
 
 BitmapEx::BitmapEx(Size aSize, vcl::PixelFormat ePixelFormat)
@@ -407,53 +407,49 @@ void BitmapEx::Expand( sal_Int32 nDX, sal_Int32 nDY, bool 
bExpandTransparent )
                 "BitmapEx::Expand(): size mismatch for bitmap and alpha 
mask.");
 }
 
+bool BitmapEx::CopyPixel( const tools::Rectangle& rRectDst, const 
tools::Rectangle& rRectSrc )
+{
+    if( maBitmap.IsEmpty() )
+        return false;
+
+    bool bRet = maBitmap.CopyPixel( rRectDst, rRectSrc );
+
+    if( bRet && !maAlphaMask.IsEmpty() )
+        maAlphaMask.CopyPixel( rRectDst, rRectSrc );
+
+    return bRet;
+}
+
 bool BitmapEx::CopyPixel( const tools::Rectangle& rRectDst, const 
tools::Rectangle& rRectSrc,
-                          const BitmapEx* pBmpExSrc )
+                          const BitmapEx& rBmpExSrc )
 {
-    bool bRet = false;
+    if( maBitmap.IsEmpty() )
+        return false;
+
+    if (!maBitmap.CopyPixel( rRectDst, rRectSrc, rBmpExSrc.maBitmap ))
+        return false;
 
-    if( !pBmpExSrc || pBmpExSrc->IsEmpty() )
+    if( rBmpExSrc.IsAlpha() )
     {
-        if( !maBitmap.IsEmpty() )
+        if( IsAlpha() )
+            // cast to use the optimized AlphaMask::CopyPixel
+            maAlphaMask.CopyPixel_AlphaOptimized( rRectDst, rRectSrc, 
rBmpExSrc.maAlphaMask );
+        else
         {
-            bRet = maBitmap.CopyPixel( rRectDst, rRectSrc );
-
-            if( bRet && !maAlphaMask.IsEmpty() )
-                maAlphaMask.CopyPixel( rRectDst, rRectSrc );
+            sal_uInt8 nTransparencyOpaque = 0;
+            maAlphaMask = AlphaMask(GetSizePixel(), &nTransparencyOpaque);
+            maAlphaMask.CopyPixel( rRectDst, rRectSrc, rBmpExSrc.maAlphaMask );
         }
     }
-    else
+    else if (IsAlpha())
     {
-        if( !maBitmap.IsEmpty() )
-        {
-            bRet = maBitmap.CopyPixel( rRectDst, rRectSrc, 
&pBmpExSrc->maBitmap );
+        sal_uInt8 nTransparencyOpaque = 0;
+        const AlphaMask aAlphaSrc(rBmpExSrc.GetSizePixel(), 
&nTransparencyOpaque);
 
-            if( bRet )
-            {
-                if( pBmpExSrc->IsAlpha() )
-                {
-                    if( IsAlpha() )
-                        // cast to use the optimized AlphaMask::CopyPixel
-                        maAlphaMask.CopyPixel_AlphaOptimized( rRectDst, 
rRectSrc, &pBmpExSrc->maAlphaMask );
-                    else
-                    {
-                        sal_uInt8 nTransparencyOpaque = 0;
-                        maAlphaMask = AlphaMask(GetSizePixel(), 
&nTransparencyOpaque);
-                        maAlphaMask.CopyPixel( rRectDst, rRectSrc, 
&pBmpExSrc->maAlphaMask );
-                    }
-                }
-                else if (IsAlpha())
-                {
-                    sal_uInt8 nTransparencyOpaque = 0;
-                    const AlphaMask aAlphaSrc(pBmpExSrc->GetSizePixel(), 
&nTransparencyOpaque);
-
-                    maAlphaMask.CopyPixel( rRectDst, rRectSrc, &aAlphaSrc );
-                }
-            }
-        }
+        maAlphaMask.CopyPixel( rRectDst, rRectSrc, aAlphaSrc );
     }
 
-    return bRet;
+    return true;
 }
 
 bool BitmapEx::Erase( const Color& rFillColor )
diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx
index 917c59e7e3b7..1167789b7986 100644
--- a/vcl/source/bitmap/bitmap.cxx
+++ b/vcl/source/bitmap/bitmap.cxx
@@ -443,335 +443,339 @@ bool Bitmap::Crop( const tools::Rectangle& rRectPixel )
 };
 
 bool Bitmap::CopyPixel( const tools::Rectangle& rRectDst,
-                        const tools::Rectangle& rRectSrc, const Bitmap* 
pBmpSrc )
+                        const tools::Rectangle& rRectSrc )
 {
     const Size  aSizePix( GetSizePixel() );
     tools::Rectangle   aRectDst( rRectDst );
-    bool        bRet = false;
 
     aRectDst.Intersection( tools::Rectangle( Point(), aSizePix ) );
 
     if( aRectDst.IsEmpty() )
         return false;
 
-    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());
+    tools::Rectangle aRectSrc( rRectSrc );
+
+    aRectSrc.Intersection( tools::Rectangle( Point(), aSizePix ) );
+
+    if( aRectSrc.IsEmpty() || ( aRectSrc == aRectDst ) )
+        return false;
 
-        if( nSrcBitCount > nDstBitCount )
+    BitmapScopedWriteAccess   pWriteAcc(*this);
+    if( !pWriteAcc )
+        return false;
+
+    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++ 
)
+        {
+            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 ) )
+    {
+        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 ) );
+        }
+    }
+    else if( ( nDstX >= nSrcX ) && ( nDstY <= nSrcY ) )
+    {
+        for( tools::Long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ 
)
         {
-            int nNextIndex = 0;
+            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
+    {
+        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 ) );
+        }
+    }
 
-            if (nSrcBitCount == 24)
-                Convert( BmpConversion::N24Bit );
-            else if (nSrcBitCount == 8)
-            {
-                Convert( BmpConversion::N8BitColors );
-                nNextIndex = 16;
-            }
-            else if (nSrcBitCount == 4)
-            {
-                assert(false);
-            }
+    return true;
+}
 
-            if( nNextIndex )
-            {
-                ScopedReadAccess    pSrcAcc(*pSrc);
-                BitmapScopedWriteAccess pDstAcc(*this);
+bool Bitmap::CopyPixel( const tools::Rectangle& rRectDst,
+                        const tools::Rectangle& rRectSrc, const Bitmap& 
rBmpSrc )
+{
+    const Size  aSizePix( GetSizePixel() );
+    tools::Rectangle   aRectDst( rRectDst );
 
-                if( pSrcAcc && pDstAcc )
-                {
-                    const int nSrcCount = pSrcAcc->GetPaletteEntryCount();
-                    const int nDstCount = 1 << nDstBitCount;
+    aRectDst.Intersection( tools::Rectangle( Point(), aSizePix ) );
 
-                    for (int i = 0; ( i < nSrcCount ) && ( nNextIndex < 
nDstCount ); ++i)
-                    {
-                        const BitmapColor& rSrcCol = pSrcAcc->GetPaletteColor( 
static_cast<sal_uInt16>(i) );
+    if( aRectDst.IsEmpty() )
+        return false;
 
-                        bool bFound = false;
+    if( rBmpSrc.mxSalBmp == mxSalBmp ) // if self-copy
+        return CopyPixel(rRectDst, rRectSrc);
 
-                        for (int j = 0; j < nDstCount; ++j)
-                        {
-                            if( rSrcCol == pDstAcc->GetPaletteColor( 
static_cast<sal_uInt16>(j) ) )
-                            {
-                                bFound = true;
-                                break;
-                            }
-                        }
+    Bitmap*         pSrc = &const_cast<Bitmap&>(rBmpSrc);
+    const Size      aCopySizePix( pSrc->GetSizePixel() );
+    tools::Rectangle       aRectSrc( rRectSrc );
+    const sal_uInt16 nSrcBitCount = 
vcl::pixelFormatBitCount(rBmpSrc.getPixelFormat());
+    const sal_uInt16 nDstBitCount = vcl::pixelFormatBitCount(getPixelFormat());
 
-                        if( !bFound )
-                            pDstAcc->SetPaletteColor( 
static_cast<sal_uInt16>(nNextIndex++), rSrcCol );
-                    }
-                }
-            }
-        }
+    if( nSrcBitCount > nDstBitCount )
+    {
+        int nNextIndex = 0;
 
-        aRectSrc.Intersection( tools::Rectangle( Point(), aCopySizePix ) );
+        if (nSrcBitCount == 24)
+            Convert( BmpConversion::N24Bit );
+        else if (nSrcBitCount == 8)
+        {
+            Convert( BmpConversion::N8BitColors );
+            nNextIndex = 16;
+        }
+        else if (nSrcBitCount == 4)
+        {
+            assert(false);
+        }
 
-        if( !aRectSrc.IsEmpty() )
+        if( nNextIndex )
         {
-            ScopedReadAccess pReadAcc(*pSrc);
+            ScopedReadAccess    pSrcAcc(*pSrc);
+            BitmapScopedWriteAccess pDstAcc(*this);
 
-            if( pReadAcc )
+            if( pSrcAcc && pDstAcc )
             {
-                BitmapScopedWriteAccess pWriteAcc(*this);
+                const int nSrcCount = pSrcAcc->GetPaletteEntryCount();
+                const int nDstCount = 1 << nDstBitCount;
 
-                if( pWriteAcc )
+                for (int i = 0; ( i < nSrcCount ) && ( nNextIndex < nDstCount 
); ++i)
                 {
-                    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 BitmapColor& rSrcCol = pSrcAcc->GetPaletteColor( 
static_cast<sal_uInt16>(i) );
 
-                    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 ) ));
+                    bool bFound = false;
 
-                        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() )
+                    for (int j = 0; j < nDstCount; ++j)
                     {
-                        for( tools::Long nSrcY = aRectSrc.Top(); nSrcY < 
nSrcEndY; nSrcY++, nDstY++ )
+                        if( rSrcCol == pDstAcc->GetPaletteColor( 
static_cast<sal_uInt16>(j) ) )
                         {
-                            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 ) ) 
);
+                            bFound = true;
+                            break;
                         }
                     }
-                    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 );
+                    if( !bFound )
+                        pDstAcc->SetPaletteColor( 
static_cast<sal_uInt16>(nNextIndex++), rSrcCol );
                 }
-
-                pReadAcc.reset();
             }
         }
     }
-    else
-    {
-        tools::Rectangle aRectSrc( rRectSrc );
 
-        aRectSrc.Intersection( tools::Rectangle( Point(), aSizePix ) );
+    aRectSrc.Intersection( tools::Rectangle( Point(), aCopySizePix ) );
 
-        if( !aRectSrc.IsEmpty() && ( aRectSrc != aRectDst ) )
-        {
-            BitmapScopedWriteAccess   pWriteAcc(*this);
+    if( aRectSrc.IsEmpty() )
+        return false;
 
-            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 ) )
-                {
-                    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 ) );
-                    }
-                }
-                else if( ( nDstX <= nSrcX ) && ( nDstY >= nSrcY ) )
-                {
-                    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 ) );
-                    }
-                }
-                else if( ( nDstX >= nSrcX ) && ( nDstY <= nSrcY ) )
-                {
-                    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 ) );
-                    }
-                }
-                else
-                {
-                    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 ) );
-                    }
-                }
+    ScopedReadAccess pReadAcc(*pSrc);
+    if( !pReadAcc )
+        return false;
 
-                pWriteAcc.reset();
-                bRet = true;
-            }
+    BitmapScopedWriteAccess pWriteAcc(*this);
+    if( !pWriteAcc )
+        return false;
+
+    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( 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 ) ));
+
+        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() )
+    {
+        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 ) ) 
);
+        }
+    }
+    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 ) );
+        }
+
+    bool bRet = ( nWidth > 0 ) && ( nHeight > 0 );
 
     return bRet;
 }
 
-bool Bitmap::CopyPixel_AlphaOptimized( const tools::Rectangle& rRectDst, const 
tools::Rectangle& rRectSrc,
-                           const Bitmap* pBmpSrc )
+bool Bitmap::CopyPixel_AlphaOptimized( const tools::Rectangle& rRectDst, const 
tools::Rectangle& rRectSrc )
 {
+    assert(HasGreyPalette8Bit());
     // Note: this code is copied from Bitmap::CopyPixel but avoids any palette 
lookups
     // This optimization is possible because the palettes of AlphaMasks are 
always identical (8bit GreyPalette, see ctor)
     const Size  aSizePix( GetSizePixel() );
     tools::Rectangle   aRectDst( rRectDst );
-    bool        bRet = false;
 
     aRectDst.Intersection( tools::Rectangle( Point(), aSizePix ) );
 
     if( aRectDst.IsEmpty() )
         return false;
 
-    if( pBmpSrc && ( pBmpSrc->mxSalBmp != mxSalBmp ) )
-    {
-        Bitmap*         pSrc = const_cast<Bitmap*>(pBmpSrc);
-        const Size      aCopySizePix( pSrc->GetSizePixel() );
-        tools::Rectangle       aRectSrc( rRectSrc );
+    tools::Rectangle aRectSrc( rRectSrc );
+    aRectSrc.Intersection( tools::Rectangle( Point(), aSizePix ) );
+    if( aRectSrc.IsEmpty() || ( aRectSrc == aRectDst ) )
+        return false;
 
-        aRectSrc.Intersection( tools::Rectangle( Point(), aCopySizePix ) );
+    BitmapScopedWriteAccess   pWriteAcc(*this);
+    if( !pWriteAcc )
+        return false;
 
-        if( !aRectSrc.IsEmpty() )
+    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++ 
)
+        {
+            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 ) )
+    {
+        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 ) );
+        }
+    }
+    else if( ( nDstX >= nSrcX ) && ( nDstY <= nSrcY ) )
+    {
+        for( tools::Long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ 
)
         {
-            ScopedReadAccess pReadAcc(*pSrc);
+            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
+    {
+        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 ) );
+        }
+    }
 
-            if( pReadAcc )
-            {
-                BitmapScopedWriteAccess pWriteAcc(*this);
+    return true;
+}
 
-                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  nSrcEndX = aRectSrc.Left() + nWidth;
-                    const tools::Long  nSrcEndY = aRectSrc.Top() + nHeight;
-                    tools::Long        nDstY = aRectDst.Top();
+bool Bitmap::CopyPixel_AlphaOptimized( const tools::Rectangle& rRectDst, const 
tools::Rectangle& rRectSrc,
+                           const Bitmap& rBmpSrc )
+{
+    assert(HasGreyPalette8Bit());
+    assert(rBmpSrc.HasGreyPalette8Bit());
+    // Note: this code is copied from Bitmap::CopyPixel but avoids any palette 
lookups
+    // This optimization is possible because the palettes of AlphaMasks are 
always identical (8bit GreyPalette, see ctor)
+    const Size  aSizePix( GetSizePixel() );
+    tools::Rectangle   aRectDst( rRectDst );
 
-                    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 ) );
-                    }
+    aRectDst.Intersection( tools::Rectangle( Point(), aSizePix ) );
 
-                    pWriteAcc.reset();
-                    bRet = ( nWidth > 0 ) && ( nHeight > 0 );
-                }
+    if( aRectDst.IsEmpty() )
+        return false;
 
-                pReadAcc.reset();
-            }
-        }
-    }
-    else
-    {
-        tools::Rectangle aRectSrc( rRectSrc );
+    if( rBmpSrc.mxSalBmp == mxSalBmp ) // self-copy
+        return CopyPixel_AlphaOptimized(rRectDst, rRectSrc);
 
-        aRectSrc.Intersection( tools::Rectangle( Point(), aSizePix ) );
+    Bitmap*         pSrc = &const_cast<Bitmap&>(rBmpSrc);
+    const Size      aCopySizePix( pSrc->GetSizePixel() );
+    tools::Rectangle       aRectSrc( rRectSrc );
 
-        if( !aRectSrc.IsEmpty() && ( aRectSrc != aRectDst ) )
-        {
-            BitmapScopedWriteAccess   pWriteAcc(*this);
+    aRectSrc.Intersection( tools::Rectangle( Point(), aCopySizePix ) );
+    if( aRectSrc.IsEmpty() )
+        return false;
 
-            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 ) )
-                {
-                    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 ) );
-                    }
-                }
-                else if( ( nDstX <= nSrcX ) && ( nDstY >= nSrcY ) )
-                {
-                    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 ) );
-                    }
-                }
-                else if( ( nDstX >= nSrcX ) && ( nDstY <= nSrcY ) )
-                {
-                    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 ) );
-                    }
-                }
-                else
-                {
-                    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 ) );
-                    }
-                }
+    ScopedReadAccess pReadAcc(*pSrc);
+    if( !pReadAcc )
+        return false;
 
-                pWriteAcc.reset();
-                bRet = true;
-            }
-        }
+    BitmapScopedWriteAccess pWriteAcc(*this);
+    if( !pWriteAcc )
+        return false;
+
+    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 ) );
     }
 
-    return bRet;
+    bool bRet = ( nWidth > 0 ) && ( nHeight > 0 );
 
+    return bRet;
 }
 
 bool Bitmap::Expand( sal_Int32 nDX, sal_Int32 nDY, const Color* pInitColor )
diff --git a/vcl/source/graphic/GraphicObject2.cxx 
b/vcl/source/graphic/GraphicObject2.cxx
index 2f60e315d5ef..a8dd186a3d93 100644
--- a/vcl/source/graphic/GraphicObject2.cxx
+++ b/vcl/source/graphic/GraphicObject2.cxx
@@ -474,7 +474,7 @@ void GraphicObject::ImplTransformBitmap( BitmapEx&          
rBmpEx,
 
             aBmpEx2.Scale(Size(nPadTotalWidth, nPadTotalHeight));
             aBmpEx2.Erase( Color(ColorAlpha,0,0,0,0) );
-            aBmpEx2.CopyPixel( tools::Rectangle( Point(nPadLeft, nPadTop), 
aBmpSize ), tools::Rectangle( Point(0, 0), aBmpSize ), &rBmpEx );
+            aBmpEx2.CopyPixel( tools::Rectangle( Point(nPadLeft, nPadTop), 
aBmpSize ), tools::Rectangle( Point(0, 0), aBmpSize ), rBmpEx );
             rBmpEx = aBmpEx2;
         }
     }
diff --git a/vcl/source/window/menubarwindow.cxx 
b/vcl/source/window/menubarwindow.cxx
index c52b0cf6787a..8e2bc8d7ebe2 100644
--- a/vcl/source/window/menubarwindow.cxx
+++ b/vcl/source/window/menubarwindow.cxx
@@ -106,7 +106,7 @@ void DecoToolBox::SetImages( tools::Long nMaxHeight, bool 
bForce )
                             (lastSize - maImage.GetSizePixel().Height())/2 ),
                         maImage.GetSizePixel() );
 
-    aBmpExDst.CopyPixel( aDestRect, aSrcRect, &aBmpExSrc );
+    aBmpExDst.CopyPixel( aDestRect, aSrcRect, aBmpExSrc );
     SetItemImage( ToolBoxItemId(IID_DOCUMENTCLOSE), Image( aBmpExDst ) );
 
 }

Reply via email to