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

Noel Grandin noel.grandin at collabora.co.uk
Thu Feb 8 08:02:21 UTC 2018


 include/vcl/bitmapex.hxx               |   20 +++++++++++++++
 svtools/source/graphic/transformer.cxx |   43 ++++++---------------------------
 vcl/source/gdi/bitmapex.cxx            |   28 +++++++++++++++++++++
 3 files changed, 57 insertions(+), 34 deletions(-)

New commits:
commit 5531e6338bc9d7d5676a5c52059d5ccb2fcccb0c
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Feb 7 15:09:12 2018 +0200

    move setAlphaFrom from GraphicTransformer to BitmapEx
    
    Change-Id: I69329c61e81791db3806fabe3256571fa937deb6
    Reviewed-on: https://gerrit.libreoffice.org/49360
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/vcl/bitmapex.hxx b/include/vcl/bitmapex.hxx
index 31b008a081b2..9faf3c8eb41c 100644
--- a/include/vcl/bitmapex.hxx
+++ b/include/vcl/bitmapex.hxx
@@ -265,6 +265,24 @@ public:
                             const Color& rSearchColor,
                             const Color& rReplaceColor );
 
+    /** Replace all pixel having the search color with the specified color
+
+        @param rSearchColor
+        Color specifying which pixel should be replaced
+
+        @param rReplaceColor
+        Color to be placed in all changed pixel
+
+        @param nTolerance
+        Tolerance value. Specifies the maximal difference between
+        rSearchColor and the individual pixel values, such that the
+        corresponding pixel is still regarded a match.
+     */
+    void                Replace(
+                            const Color& rSearchColor,
+                            const Color& rReplaceColor,
+                            sal_uInt8 nTolerance );
+
     /** Replace all pixel having one the search colors with the corresponding replace color
 
         @param pSearchColors
@@ -421,6 +439,8 @@ public:
     bool                Create(
                             const css::uno::Reference< css::rendering::XBitmapCanvas > &xBitmapCanvas,
                             const Size &rSize );
+
+    void                setAlphaFrom( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo );
 public:
 
     SAL_DLLPRIVATE std::shared_ptr<ImpBitmap> const & ImplGetBitmapImpBitmap() const { return aBitmap.ImplGetImpBitmap(); }
diff --git a/svtools/source/graphic/transformer.cxx b/svtools/source/graphic/transformer.cxx
index 17fb3a3f87c6..12bc40f3babc 100644
--- a/svtools/source/graphic/transformer.cxx
+++ b/svtools/source/graphic/transformer.cxx
@@ -46,28 +46,6 @@ GraphicTransformer::~GraphicTransformer()
 }
 
 
-void setAlpha( Bitmap& rBitmap, AlphaMask& rAlpha, sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo )
-{
-    BitmapWriteAccess* pWriteAccess = rAlpha.AcquireWriteAccess();
-    BitmapReadAccess* pReadAccess = rBitmap.AcquireReadAccess();
-    if ( pReadAccess && pWriteAccess )
-    {
-        for ( long nY = 0; nY < pReadAccess->Height(); nY++ )
-        {
-            Scanline pScanline = pWriteAccess->GetScanline( nY );
-            Scanline pScanlineRead = pReadAccess->GetScanline( nY );
-            for ( long nX = 0; nX < pReadAccess->Width(); nX++ )
-            {
-                const sal_uInt8 cIndex = pReadAccess->GetIndexFromData( pScanlineRead, nX );
-                if ( cIndex == cIndexFrom )
-                    pWriteAccess->SetPixelOnData( pScanline, nX, BitmapColor(nAlphaTo) );
-            }
-        }
-    }
-    Bitmap::ReleaseAccess( pReadAccess );
-    rAlpha.ReleaseAccess( pWriteAccess );
-}
-
 // XGraphicTransformer
 uno::Reference< graphic::XGraphic > SAL_CALL GraphicTransformer::colorChange(
     const uno::Reference< graphic::XGraphic >& rxGraphic, sal_Int32 nColorFrom, sal_Int8 nTolerance, sal_Int32 nColorTo, sal_Int8 nAlphaTo )
@@ -90,10 +68,9 @@ uno::Reference< graphic::XGraphic > SAL_CALL GraphicTransformer::colorChange(
 
         if (aBitmapEx.IsAlpha())
         {
-            AlphaMask aAlphaMask(aBitmapEx.GetAlpha());
-            setAlpha(aBitmap, aAlphaMask, cIndexFrom, nAlphaTo);
-            aBitmap.Replace(aColorFrom, aColorTo, nTolerance);
-            aGraphic = ::Graphic(BitmapEx(aBitmap, aAlphaMask));
+            aBitmapEx.setAlphaFrom( cIndexFrom, nAlphaTo );
+            aBitmapEx.Replace(aColorFrom, aColorTo, nTolerance);
+            aGraphic = ::Graphic(aBitmapEx);
         }
         else if (aBitmapEx.IsTransparent())
         {
@@ -107,10 +84,9 @@ uno::Reference< graphic::XGraphic > SAL_CALL GraphicTransformer::colorChange(
             }
             else
             {
-                AlphaMask aAlphaMask(aBitmapEx.GetMask());
-                setAlpha(aBitmap, aAlphaMask, cIndexFrom, 0xff - nAlphaTo);
-                aBitmap.Replace(aColorFrom, aColorTo, nTolerance);
-                aGraphic = ::Graphic(BitmapEx(aBitmap, aAlphaMask));
+                aBitmapEx.setAlphaFrom(cIndexFrom, 0xff - nAlphaTo);
+                aBitmapEx.Replace(aColorFrom, aColorTo, nTolerance);
+                aGraphic = ::Graphic(aBitmapEx);
             }
         }
         else
@@ -123,10 +99,9 @@ uno::Reference< graphic::XGraphic > SAL_CALL GraphicTransformer::colorChange(
             }
             else
             {
-                AlphaMask aAlphaMask(aBitmapEx.GetSizePixel());
-                setAlpha(aBitmap, aAlphaMask, cIndexFrom, nAlphaTo);
-                aBitmap.Replace(aColorFrom, aColorTo, nTolerance);
-                aGraphic = ::Graphic(BitmapEx(aBitmap, aAlphaMask));
+                aBitmapEx.setAlphaFrom(cIndexFrom, nAlphaTo);
+                aBitmapEx.Replace(aColorFrom, aColorTo, nTolerance);
+                aGraphic = ::Graphic(aBitmapEx);
             }
         }
     }
diff --git a/vcl/source/gdi/bitmapex.cxx b/vcl/source/gdi/bitmapex.cxx
index bf3a57b2ad75..3acb0a36f26a 100644
--- a/vcl/source/gdi/bitmapex.cxx
+++ b/vcl/source/gdi/bitmapex.cxx
@@ -1294,4 +1294,32 @@ BitmapEx createBlendFrame(
     return pBlendFrameCache->m_aLastResult;
 }
 
+void BitmapEx::Replace(const Color& rSearchColor,
+                           const Color& rReplaceColor,
+                           sal_uInt8 nTolerance)
+{
+    aBitmap.Replace(rSearchColor, rReplaceColor, nTolerance);
+}
+
+void BitmapEx::setAlphaFrom( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo )
+{
+    AlphaMask aAlphaMask(GetAlpha());
+    Bitmap::ScopedWriteAccess pWriteAccess(aAlphaMask);
+    Bitmap::ScopedReadAccess pReadAccess(aBitmap);
+    assert( pReadAccess.get() && pWriteAccess.get() );
+    if ( pReadAccess.get() && pWriteAccess.get() )
+    {
+        for ( long nY = 0; nY < pReadAccess->Height(); nY++ )
+        {
+            Scanline pScanline = pWriteAccess->GetScanline( nY );
+            Scanline pScanlineRead = pReadAccess->GetScanline( nY );
+            for ( long nX = 0; nX < pReadAccess->Width(); nX++ )
+            {
+                const sal_uInt8 cIndex = pReadAccess->GetIndexFromData( pScanlineRead, nX );
+                if ( cIndex == cIndexFrom )
+                    pWriteAccess->SetPixelOnData( pScanline, nX, BitmapColor(nAlphaTo) );
+            }
+        }
+    }
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list