[Libreoffice-commits] core.git: include/vcl vcl/source

Stephan Bergmann sbergman at redhat.com
Thu Jul 10 01:38:01 PDT 2014


 include/vcl/alpha.hxx       |    3 -
 include/vcl/bitmap.hxx      |    3 +
 vcl/source/gdi/alpha.cxx    |  108 --------------------------------------------
 vcl/source/gdi/bitmap.cxx   |  108 ++++++++++++++++++++++++++++++++++++++++++++
 vcl/source/gdi/bitmapex.cxx |    2 
 5 files changed, 112 insertions(+), 112 deletions(-)

New commits:
commit f136890dc01260bde611b4c121ddf119281cf5b4
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Thu Jul 10 10:37:08 2014 +0200

    Clean up AlphaMask::CopyPixel "override" hack
    
    ...that required undefined downcasts of Bitmap objects that are not actually AlphaMasks.
    
    Change-Id: I629f4a81d40a2a85cd877ffec13445786ef58187

diff --git a/include/vcl/alpha.hxx b/include/vcl/alpha.hxx
index 483f749..de3b451 100644
--- a/include/vcl/alpha.hxx
+++ b/include/vcl/alpha.hxx
@@ -105,9 +105,6 @@ public:
 
     Bitmap  GetBitmap() const;
 
-    bool    CopyPixel( const Rectangle& rRectDst, const Rectangle& rRectSrc,
-                           const AlphaMask* pAlphaSrc = NULL);
-
     bool    Erase( sal_uInt8 cTransparency );
     bool    Replace( const Bitmap& rMask, sal_uInt8 rReplaceTransparency );
     bool    Replace( sal_uInt8 cSearchTransparency, sal_uInt8 cReplaceTransparency,
diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx
index 8dd7125..d2f0cac 100644
--- a/include/vcl/bitmap.hxx
+++ b/include/vcl/bitmap.hxx
@@ -512,6 +512,9 @@ public:
                                        const Rectangle& rRectSrc,
                                        const Bitmap* pBmpSrc = NULL );
 
+    bool    CopyPixel_AlphaOptimized( const Rectangle& rRectDst, const Rectangle& rRectSrc,
+                           const Bitmap* pBmpSrc = NULL);
+
     /** Perform boolean operations with another bitmap
 
         @param rMask
diff --git a/vcl/source/gdi/alpha.cxx b/vcl/source/gdi/alpha.cxx
index 32c42d0..1a26072 100644
--- a/vcl/source/gdi/alpha.cxx
+++ b/vcl/source/gdi/alpha.cxx
@@ -76,114 +76,6 @@ Bitmap AlphaMask::GetBitmap() const
     return ImplGetBitmap();
 }
 
-bool AlphaMask::CopyPixel( const Rectangle& rRectDst, const Rectangle& rRectSrc,
-                           const AlphaMask* pAlphaSrc )
-{
-    // 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() );
-    Rectangle   aRectDst( rRectDst );
-    bool        bRet = false;
-
-    aRectDst.Intersection( Rectangle( Point(), aSizePix ) );
-
-    if( !aRectDst.IsEmpty() )
-    {
-        if( pAlphaSrc && ( *pAlphaSrc != *this ) )
-        {
-            Bitmap*         pSrc = (Bitmap*) pAlphaSrc;
-            const Size      aCopySizePix( pSrc->GetSizePixel() );
-            Rectangle       aRectSrc( rRectSrc );
-
-            aRectSrc.Intersection( Rectangle( Point(), aCopySizePix ) );
-
-            if( !aRectSrc.IsEmpty() )
-            {
-                BitmapReadAccess* pReadAcc = pSrc->AcquireReadAccess();
-
-                if( pReadAcc )
-                {
-                    BitmapWriteAccess* pWriteAcc = AcquireWriteAccess();
-
-                    if( pWriteAcc )
-                    {
-                        const long  nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() );
-                        const long  nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() );
-                        const long  nSrcEndX = aRectSrc.Left() + nWidth;
-                        const long  nSrcEndY = aRectSrc.Top() + nHeight;
-                        long        nDstY = aRectDst.Top();
-
-                        for( long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++ )
-                            for( long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ )
-                                pWriteAcc->SetPixel( nDstY, nDstX, pReadAcc->GetPixel( nSrcY, nSrcX ) );
-
-                        ReleaseAccess( pWriteAcc );
-                        bRet = ( nWidth > 0L ) && ( nHeight > 0L );
-                    }
-
-                    pSrc->ReleaseAccess( pReadAcc );
-                }
-            }
-        }
-        else
-        {
-            Rectangle aRectSrc( rRectSrc );
-
-            aRectSrc.Intersection( Rectangle( Point(), aSizePix ) );
-
-            if( !aRectSrc.IsEmpty() && ( aRectSrc != aRectDst ) )
-            {
-                BitmapWriteAccess*  pWriteAcc = AcquireWriteAccess();
-
-                if( pWriteAcc )
-                {
-                    const long  nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() );
-                    const long  nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() );
-                    const long  nSrcX = aRectSrc.Left();
-                    const long  nSrcY = aRectSrc.Top();
-                    const long  nSrcEndX1 = nSrcX + nWidth - 1L;
-                    const long  nSrcEndY1 = nSrcY + nHeight - 1L;
-                    const long  nDstX = aRectDst.Left();
-                    const long  nDstY = aRectDst.Top();
-                    const long  nDstEndX1 = nDstX + nWidth - 1L;
-                    const long  nDstEndY1 = nDstY + nHeight - 1L;
-
-                    if( ( nDstX <= nSrcX ) && ( nDstY <= nSrcY ) )
-                    {
-                        for( long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ )
-                            for( long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ )
-                                pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
-                    }
-                    else if( ( nDstX <= nSrcX ) && ( nDstY >= nSrcY ) )
-                    {
-                        for( long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- )
-                            for( long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ )
-                                pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
-                    }
-                    else if( ( nDstX >= nSrcX ) && ( nDstY <= nSrcY ) )
-                    {
-                        for( long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ )
-                            for( long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- )
-                                pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
-                    }
-                    else
-                    {
-                        for( long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- )
-                            for( long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- )
-                                pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
-                    }
-
-                    ReleaseAccess( pWriteAcc );
-                    bRet = true;
-                }
-            }
-        }
-    }
-
-    return bRet;
-
-}
-
 bool AlphaMask::Erase( sal_uInt8 cTransparency )
 {
     return Bitmap::Erase( Color( cTransparency, cTransparency, cTransparency ) );
diff --git a/vcl/source/gdi/bitmap.cxx b/vcl/source/gdi/bitmap.cxx
index 3612767..24fd842 100644
--- a/vcl/source/gdi/bitmap.cxx
+++ b/vcl/source/gdi/bitmap.cxx
@@ -1004,6 +1004,114 @@ bool Bitmap::CopyPixel( const Rectangle& rRectDst,
     return bRet;
 }
 
+bool Bitmap::CopyPixel_AlphaOptimized( const Rectangle& rRectDst, const Rectangle& rRectSrc,
+                           const Bitmap* pBmpSrc )
+{
+    // 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() );
+    Rectangle   aRectDst( rRectDst );
+    bool        bRet = false;
+
+    aRectDst.Intersection( Rectangle( Point(), aSizePix ) );
+
+    if( !aRectDst.IsEmpty() )
+    {
+        if( pBmpSrc && ( *pBmpSrc != *this ) )
+        {
+            Bitmap*         pSrc = (Bitmap*) pBmpSrc;
+            const Size      aCopySizePix( pSrc->GetSizePixel() );
+            Rectangle       aRectSrc( rRectSrc );
+
+            aRectSrc.Intersection( Rectangle( Point(), aCopySizePix ) );
+
+            if( !aRectSrc.IsEmpty() )
+            {
+                BitmapReadAccess* pReadAcc = pSrc->AcquireReadAccess();
+
+                if( pReadAcc )
+                {
+                    BitmapWriteAccess* pWriteAcc = AcquireWriteAccess();
+
+                    if( pWriteAcc )
+                    {
+                        const long  nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() );
+                        const long  nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() );
+                        const long  nSrcEndX = aRectSrc.Left() + nWidth;
+                        const long  nSrcEndY = aRectSrc.Top() + nHeight;
+                        long        nDstY = aRectDst.Top();
+
+                        for( long nSrcY = aRectSrc.Top(); nSrcY < nSrcEndY; nSrcY++, nDstY++ )
+                            for( long nSrcX = aRectSrc.Left(), nDstX = aRectDst.Left(); nSrcX < nSrcEndX; nSrcX++, nDstX++ )
+                                pWriteAcc->SetPixel( nDstY, nDstX, pReadAcc->GetPixel( nSrcY, nSrcX ) );
+
+                        ReleaseAccess( pWriteAcc );
+                        bRet = ( nWidth > 0L ) && ( nHeight > 0L );
+                    }
+
+                    pSrc->ReleaseAccess( pReadAcc );
+                }
+            }
+        }
+        else
+        {
+            Rectangle aRectSrc( rRectSrc );
+
+            aRectSrc.Intersection( Rectangle( Point(), aSizePix ) );
+
+            if( !aRectSrc.IsEmpty() && ( aRectSrc != aRectDst ) )
+            {
+                BitmapWriteAccess*  pWriteAcc = AcquireWriteAccess();
+
+                if( pWriteAcc )
+                {
+                    const long  nWidth = std::min( aRectSrc.GetWidth(), aRectDst.GetWidth() );
+                    const long  nHeight = std::min( aRectSrc.GetHeight(), aRectDst.GetHeight() );
+                    const long  nSrcX = aRectSrc.Left();
+                    const long  nSrcY = aRectSrc.Top();
+                    const long  nSrcEndX1 = nSrcX + nWidth - 1L;
+                    const long  nSrcEndY1 = nSrcY + nHeight - 1L;
+                    const long  nDstX = aRectDst.Left();
+                    const long  nDstY = aRectDst.Top();
+                    const long  nDstEndX1 = nDstX + nWidth - 1L;
+                    const long  nDstEndY1 = nDstY + nHeight - 1L;
+
+                    if( ( nDstX <= nSrcX ) && ( nDstY <= nSrcY ) )
+                    {
+                        for( long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ )
+                            for( long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ )
+                                pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
+                    }
+                    else if( ( nDstX <= nSrcX ) && ( nDstY >= nSrcY ) )
+                    {
+                        for( long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- )
+                            for( long nX = nSrcX, nXN = nDstX; nX <= nSrcEndX1; nX++, nXN++ )
+                                pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
+                    }
+                    else if( ( nDstX >= nSrcX ) && ( nDstY <= nSrcY ) )
+                    {
+                        for( long nY = nSrcY, nYN = nDstY; nY <= nSrcEndY1; nY++, nYN++ )
+                            for( long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- )
+                                pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
+                    }
+                    else
+                    {
+                        for( long nY = nSrcEndY1, nYN = nDstEndY1; nY >= nSrcY; nY--, nYN-- )
+                            for( long nX = nSrcEndX1, nXN = nDstEndX1; nX >= nSrcX; nX--, nXN-- )
+                                pWriteAcc->SetPixel( nYN, nXN, pWriteAcc->GetPixel( nY, nX ) );
+                    }
+
+                    ReleaseAccess( pWriteAcc );
+                    bRet = true;
+                }
+            }
+        }
+    }
+
+    return bRet;
+
+}
+
 bool Bitmap::Expand( sal_uLong nDX, sal_uLong nDY, const Color* pInitColor )
 {
     bool bRet = false;
diff --git a/vcl/source/gdi/bitmapex.cxx b/vcl/source/gdi/bitmapex.cxx
index bc25f04..7673f0b 100644
--- a/vcl/source/gdi/bitmapex.cxx
+++ b/vcl/source/gdi/bitmapex.cxx
@@ -525,7 +525,7 @@ bool BitmapEx::CopyPixel( const Rectangle& rRectDst, const Rectangle& rRectSrc,
                 {
                     if( IsAlpha() )
                         // cast to use the optimized AlphaMask::CopyPixel
-                        ((AlphaMask*) &aMask)->CopyPixel( rRectDst, rRectSrc, (AlphaMask*)&pBmpExSrc->aMask );
+                        aMask.CopyPixel_AlphaOptimized( rRectDst, rRectSrc, &pBmpExSrc->aMask );
                     else if( IsTransparent() )
                     {
                         AlphaMask* pAlpha = new AlphaMask( aMask );


More information about the Libreoffice-commits mailing list