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

Noel Grandin noel.grandin at collabora.co.uk
Thu May 31 06:31:05 UTC 2018


 canvas/source/vcl/canvashelper.cxx           |   12 +-----
 include/vcl/BitmapAlphaClampFilter.hxx       |   36 ++++++++++++++++++++
 vcl/Library_vcl.mk                           |    1 
 vcl/source/bitmap/BitmapAlphaClampFilter.cxx |   47 +++++++++++++++++++++++++++
 4 files changed, 86 insertions(+), 10 deletions(-)

New commits:
commit 8b0ded99e5f8d71c9b763db264ac445b5f665234
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed May 30 15:06:39 2018 +0200

    move some CanvasHelper::implDrawBitmap inside vcl
    
    part of making mask and alpha internal details of Bitmap/BitmapEx
    
    Change-Id: I87ca24af18a29f5eb8a5761c5d95ae2806d97e77
    Reviewed-on: https://gerrit.libreoffice.org/55078
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/canvas/source/vcl/canvashelper.cxx b/canvas/source/vcl/canvashelper.cxx
index d7005261558c..a6661c5d5609 100644
--- a/canvas/source/vcl/canvashelper.cxx
+++ b/canvas/source/vcl/canvashelper.cxx
@@ -46,7 +46,7 @@
 #include <vcl/bitmapaccess.hxx>
 #include <vcl/canvastools.hxx>
 #include <vcl/window.hxx>
-#include <vcl/BitmapMonochromeFilter.hxx>
+#include <vcl/BitmapAlphaClampFilter.hxx>
 
 #include <canvas/canvastools.hxx>
 
@@ -720,15 +720,7 @@ namespace vclcanvas
                     // transparency is fully transparent
                     if( aBmpEx.IsAlpha() )
                     {
-                        Bitmap aMask( aBmpEx.GetAlpha().GetBitmap() );
-                        BitmapEx aMaskEx(aMask);
-                        BitmapFilter::Filter(aMaskEx, BitmapMonochromeFilter(253));
-                        aMask = aMaskEx.GetBitmap();
-                        aBmpEx = BitmapEx( aBmpEx.GetBitmap(), aMask );
-                    }
-                    else if( aBmpEx.IsTransparent() )
-                    {
-                        aBmpEx = BitmapEx( aBmpEx.GetBitmap(), aBmpEx.GetMask() );
+                        BitmapFilter::Filter(aBmpEx, BitmapAlphaClampFilter(253));
                     }
 
                     mp2ndOutDevProvider->getOutDev().DrawBitmapEx( vcl::unotools::pointFromB2DPoint( aOutputPos ),
diff --git a/include/vcl/BitmapAlphaClampFilter.hxx b/include/vcl/BitmapAlphaClampFilter.hxx
new file mode 100644
index 000000000000..0fc6274b6d4e
--- /dev/null
+++ b/include/vcl/BitmapAlphaClampFilter.hxx
@@ -0,0 +1,36 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_INCLUDE_VCL_BITMAPMONOCHROMEFILTER_HXX
+#define INCLUDED_INCLUDE_VCL_BITMAPMONOCHROMEFILTER_HXX
+
+#include <tools/color.hxx>
+
+#include <vcl/BitmapFilter.hxx>
+
+/** If the alpha is beyond a certain threshold, make it fully transparent
+ */
+class VCL_DLLPUBLIC BitmapAlphaClampFilter : public BitmapFilter
+{
+public:
+    BitmapAlphaClampFilter(sal_uInt8 cThreshold)
+        : mcThreshold(cThreshold)
+    {
+    }
+
+    virtual BitmapEx execute(BitmapEx const& rBitmapEx) override;
+
+private:
+    sal_uInt8 mcThreshold;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 38a2460cf81f..fd99be295c98 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -311,6 +311,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/graphic/UnoGraphicTransformer \
     vcl/source/bitmap/bitmap \
     vcl/source/bitmap/bitmapfilter \
+    vcl/source/bitmap/BitmapAlphaClampFilter \
     vcl/source/bitmap/BitmapMonochromeFilter \
     vcl/source/bitmap/BitmapSmoothenFilter \
     vcl/source/bitmap/BitmapLightenFilter \
diff --git a/vcl/source/bitmap/BitmapAlphaClampFilter.cxx b/vcl/source/bitmap/BitmapAlphaClampFilter.cxx
new file mode 100644
index 000000000000..5fd19235b6d1
--- /dev/null
+++ b/vcl/source/bitmap/BitmapAlphaClampFilter.cxx
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <vcl/bitmap.hxx>
+#include <vcl/bitmapex.hxx>
+#include <vcl/BitmapAlphaClampFilter.hxx>
+#include <vcl/bitmapaccess.hxx>
+
+#include <bitmapwriteaccess.hxx>
+
+BitmapEx BitmapAlphaClampFilter::execute(BitmapEx const& rBitmapEx)
+{
+    if (!rBitmapEx.IsTransparent())
+        return rBitmapEx;
+
+    AlphaMask aBitmapAlpha(rBitmapEx.GetAlpha());
+    {
+        AlphaScopedWriteAccess pWriteAlpha(aBitmapAlpha);
+        const Size aSize(rBitmapEx.GetSizePixel());
+
+        for (long nY = 0; nY < aSize.Height(); ++nY)
+        {
+            Scanline pScanAlpha = pWriteAlpha->GetScanline(nY);
+
+            for (long nX = 0; nX < aSize.Width(); ++nX)
+            {
+                BitmapColor aBitmapAlphaValue(pWriteAlpha->GetPixelFromData(pScanAlpha, nX));
+                if (aBitmapAlphaValue.GetIndex() > mcThreshold)
+                {
+                    aBitmapAlphaValue.SetIndex(255);
+                    pWriteAlpha->SetPixelOnData(pScanAlpha, nX, aBitmapAlphaValue);
+                }
+            }
+        }
+    }
+
+    return BitmapEx(rBitmapEx.GetBitmap(), aBitmapAlpha);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list