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

Noel Grandin noel.grandin at collabora.co.uk
Thu Mar 15 06:31:15 UTC 2018


 include/vcl/BitmapTools.hxx       |    2 
 svx/source/svdraw/svdfmtf.cxx     |   83 --------------------------------------
 vcl/source/bitmap/BitmapTools.cxx |   70 ++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+), 81 deletions(-)

New commits:
commit 14d49662d32fa2fcf2916682dbf1f974a8eecb08
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Mar 14 17:13:42 2018 +0200

    move some GDI import code from svx to vcl
    
    part of making ScopedWriteAccess an internal detail of vcl
    
    Change-Id: I916f2ca05c9d7c17b62c91e113df6d8454bb4351
    Reviewed-on: https://gerrit.libreoffice.org/51283
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/include/vcl/BitmapTools.hxx b/include/vcl/BitmapTools.hxx
index d7525869320f..7dde62788a53 100644
--- a/include/vcl/BitmapTools.hxx
+++ b/include/vcl/BitmapTools.hxx
@@ -92,6 +92,8 @@ VCL_DLLPUBLIC BitmapEx CanvasTransformBitmap( const BitmapEx& rBitmap,
                                   ::basegfx::B2DRectangle const & rDestRect,
                                   ::basegfx::B2DHomMatrix const & rLocalTransform );
 
+VCL_DLLPUBLIC void DrawAlphaBitmapAndAlphaGradient(BitmapEx & rBitmapEx, bool bFixedTransparence, float fTransparence, AlphaMask & rNewMask);
+
 }} // end vcl::bitmap
 
 #endif // INCLUDED_VCL_BITMAP_TOOLS_HXX
diff --git a/svx/source/svdraw/svdfmtf.cxx b/svx/source/svdraw/svdfmtf.cxx
index 457095f6adc0..f3806362aba6 100644
--- a/svx/source/svdraw/svdfmtf.cxx
+++ b/svx/source/svdraw/svdfmtf.cxx
@@ -71,6 +71,7 @@
 #include <basegfx/polygon/b2dpolypolygontools.hxx>
 #include <svx/svditer.hxx>
 #include <svx/svdogrp.hxx>
+#include <vcl/BitmapTools.hxx>
 
 using namespace com::sun::star;
 
@@ -1557,87 +1558,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaFloatTransparentAction const & rAct)
             }
             else
             {
-                // mix existing and new alpha mask
-                AlphaMask aOldMask;
-
-                if(aBitmapEx.IsAlpha())
-                {
-                    aOldMask = aBitmapEx.GetAlpha();
-                }
-                else if(TransparentType::Bitmap == aBitmapEx.GetTransparentType())
-                {
-                    aOldMask = aBitmapEx.GetMask();
-                }
-                else if(TransparentType::Color == aBitmapEx.GetTransparentType())
-                {
-                    aOldMask = aBitmapEx.GetBitmap().CreateMask(aBitmapEx.GetTransparentColor());
-                }
-
-                AlphaMask::ScopedWriteAccess pOld(aOldMask);
-
-                if(pOld)
-                {
-                    const double fFactor(1.0 / 255.0);
-
-                    if(bFixedTransparence)
-                    {
-                        const double fOpNew(1.0 - fTransparence);
-
-                        for(long y(0); y < pOld->Height(); y++)
-                        {
-                            Scanline pScanline = pOld->GetScanline( y );
-                            for(long x(0); x < pOld->Width(); x++)
-                            {
-                                const double fOpOld(1.0 - (pOld->GetIndexFromData(pScanline, x) * fFactor));
-                                const sal_uInt8 aCol(basegfx::fround((1.0 - (fOpOld * fOpNew)) * 255.0));
-
-                                pOld->SetPixelOnData(pScanline, x, BitmapColor(aCol));
-                            }
-                        }
-                    }
-                    else
-                    {
-                        AlphaMask::ScopedReadAccess pNew(aNewMask);
-
-                        if(pNew)
-                        {
-                            if(pOld->Width() == pNew->Width() && pOld->Height() == pNew->Height())
-                            {
-                                for(long y(0); y < pOld->Height(); y++)
-                                {
-                                    Scanline pScanline = pOld->GetScanline( y );
-                                    for(long x(0); x < pOld->Width(); x++)
-                                    {
-                                        const double fOpOld(1.0 - (pOld->GetIndexFromData(pScanline, x) * fFactor));
-                                        const double fOpNew(1.0 - (pNew->GetIndexFromData(pScanline, x) * fFactor));
-                                        const sal_uInt8 aCol(basegfx::fround((1.0 - (fOpOld * fOpNew)) * 255.0));
-
-                                        pOld->SetPixelOnData(pScanline, x, BitmapColor(aCol));
-                                    }
-                                }
-                            }
-                            else
-                            {
-                                OSL_ENSURE(false, "Alpha masks have different sizes (!)");
-                            }
-
-                            pNew.reset();
-                        }
-                        else
-                        {
-                            OSL_ENSURE(false, "Got no access to new alpha mask (!)");
-                        }
-                    }
-
-                    pOld.reset();
-                }
-                else
-                {
-                    OSL_ENSURE(false, "Got no access to old alpha mask (!)");
-                }
-
-                // apply combined bitmap as mask
-                aBitmapEx = BitmapEx(aBitmapEx.GetBitmap(), aOldMask);
+                vcl::bitmap::DrawAlphaBitmapAndAlphaGradient(aBitmapEx, bFixedTransparence, fTransparence, aNewMask);
             }
         }
 
diff --git a/vcl/source/bitmap/BitmapTools.cxx b/vcl/source/bitmap/BitmapTools.cxx
index 6e1ed624a049..f29989b9cab2 100644
--- a/vcl/source/bitmap/BitmapTools.cxx
+++ b/vcl/source/bitmap/BitmapTools.cxx
@@ -467,6 +467,76 @@ BitmapEx CanvasTransformBitmap( const BitmapEx&                 rBitmap,
 }
 
 
+void DrawAlphaBitmapAndAlphaGradient(BitmapEx & rBitmapEx, bool bFixedTransparence, float fTransparence, AlphaMask & rNewMask)
+{
+    // mix existing and new alpha mask
+    AlphaMask aOldMask;
+
+    if(rBitmapEx.IsAlpha())
+    {
+        aOldMask = rBitmapEx.GetAlpha();
+    }
+    else if(TransparentType::Bitmap == rBitmapEx.GetTransparentType())
+    {
+        aOldMask = rBitmapEx.GetMask();
+    }
+    else if(TransparentType::Color == rBitmapEx.GetTransparentType())
+    {
+        aOldMask = rBitmapEx.GetBitmap().CreateMask(rBitmapEx.GetTransparentColor());
+    }
+
+    {
+        AlphaMask::ScopedWriteAccess pOld(aOldMask);
+
+        assert(pOld && "Got no access to old alpha mask (!)");
+
+        const double fFactor(1.0 / 255.0);
+
+        if(bFixedTransparence)
+        {
+            const double fOpNew(1.0 - fTransparence);
+
+            for(long y(0); y < pOld->Height(); y++)
+            {
+                Scanline pScanline = pOld->GetScanline( y );
+                for(long x(0); x < pOld->Width(); x++)
+                {
+                    const double fOpOld(1.0 - (pOld->GetIndexFromData(pScanline, x) * fFactor));
+                    const sal_uInt8 aCol(basegfx::fround((1.0 - (fOpOld * fOpNew)) * 255.0));
+
+                    pOld->SetPixelOnData(pScanline, x, BitmapColor(aCol));
+                }
+            }
+        }
+        else
+        {
+            AlphaMask::ScopedReadAccess pNew(rNewMask);
+
+            assert(pNew && "Got no access to new alpha mask (!)");
+
+            assert(pOld->Width() == pNew->Width() && pOld->Height() == pNew->Height() &&
+                    "Alpha masks have different sizes (!)");
+
+            for(long y(0); y < pOld->Height(); y++)
+            {
+                Scanline pScanline = pOld->GetScanline( y );
+                for(long x(0); x < pOld->Width(); x++)
+                {
+                    const double fOpOld(1.0 - (pOld->GetIndexFromData(pScanline, x) * fFactor));
+                    const double fOpNew(1.0 - (pNew->GetIndexFromData(pScanline, x) * fFactor));
+                    const sal_uInt8 aCol(basegfx::fround((1.0 - (fOpOld * fOpNew)) * 255.0));
+
+                    pOld->SetPixelOnData(pScanline, x, BitmapColor(aCol));
+                }
+            }
+        }
+
+    }
+
+    // apply combined bitmap as mask
+    rBitmapEx = BitmapEx(rBitmapEx.GetBitmap(), aOldMask);
+}
+
 }} // end vcl::bitmap
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list