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

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Thu May 7 19:57:52 UTC 2020


 include/vcl/BitmapColorReplaceFilter.hxx       |   44 ++++++++++++++++++++++++
 vcl/Library_vcl.mk                             |    1 
 vcl/source/bitmap/BitmapColorReplaceFilter.cxx |   45 +++++++++++++++++++++++++
 3 files changed, 90 insertions(+)

New commits:
commit a98bdbae459ad7341bf7f484c402e77e4062cd16
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Wed May 6 11:23:26 2020 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Thu May 7 21:57:18 2020 +0200

    Add color replacement bitmap filter
    
    It replaces colors in bitmap by modifying pixels, without shortcuts
    like replacing entries in bitmap palette.
    Needed for glow effect (tdf#101181)
    
    Change-Id: I9af734ce8ebbc57f723ab75c5b8406eb6fd6e31b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93553
    Tested-by: Jenkins
    Tested-by: Mike Kaganski <mike.kaganski at collabora.com>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/vcl/BitmapColorReplaceFilter.hxx b/include/vcl/BitmapColorReplaceFilter.hxx
new file mode 100644
index 000000000000..caeac83d0fda
--- /dev/null
+++ b/include/vcl/BitmapColorReplaceFilter.hxx
@@ -0,0 +1,44 @@
+/* -*- 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_BITMAPCOLORREPLACEFILTER_HXX
+#define INCLUDED_INCLUDE_VCL_BITMAPCOLORREPLACEFILTER_HXX
+
+#include <vcl/BitmapFilter.hxx>
+
+class VCL_DLLPUBLIC BitmapColorReplaceFilter final : public BitmapFilter
+{
+public:
+    /** Replaces a color with another by changing pixels, without shortcuts like modifying palette
+        (that is how it's different from using Bitmap::Replace).
+
+        @param cReplaceWhat
+        Color that will be replaced.
+
+        @param cReplaceTo
+        New color that will replace cReplaceWhat.
+
+     */
+    BitmapColorReplaceFilter(const Color& cReplaceWhat, const Color& cReplaceTo)
+        : m_aReplaceWhat(cReplaceWhat)
+        , m_aReplaceTo(cReplaceTo)
+    {
+    }
+
+    virtual BitmapEx execute(BitmapEx const& rBitmapEx) const override;
+
+private:
+    Color m_aReplaceWhat;
+    Color m_aReplaceTo;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index ffe065b24fff..def727918433 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -332,6 +332,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/bitmap/bitmapfilter \
     vcl/source/bitmap/BitmapAlphaClampFilter \
     vcl/source/bitmap/BitmapBasicMorphologyFilter \
+    vcl/source/bitmap/BitmapColorReplaceFilter \
     vcl/source/bitmap/BitmapMonochromeFilter \
     vcl/source/bitmap/BitmapSmoothenFilter \
     vcl/source/bitmap/BitmapLightenFilter \
diff --git a/vcl/source/bitmap/BitmapColorReplaceFilter.cxx b/vcl/source/bitmap/BitmapColorReplaceFilter.cxx
new file mode 100644
index 000000000000..151cfbfbb48b
--- /dev/null
+++ b/vcl/source/bitmap/BitmapColorReplaceFilter.cxx
@@ -0,0 +1,45 @@
+/* -*- 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/bitmapaccess.hxx>
+#include <vcl/BitmapColorReplaceFilter.hxx>
+#include <vcl/bitmapex.hxx>
+
+#include <bitmapwriteaccess.hxx>
+
+BitmapEx BitmapColorReplaceFilter::execute(BitmapEx const& aBitmapEx) const
+{
+    Bitmap aBitmap = aBitmapEx.GetBitmap();
+
+    if (BitmapScopedWriteAccess pWriteAcc{ aBitmap })
+    {
+        const BitmapColor aReplaceWhat(pWriteAcc->GetBestMatchingColor(m_aReplaceWhat));
+        const BitmapColor aReplaceTo(pWriteAcc->GetBestMatchingColor(m_aReplaceTo));
+        const long nWidth = pWriteAcc->Width();
+        const long nHeight = pWriteAcc->Height();
+
+        for (long nY = 0; nY < nHeight; nY++)
+        {
+            Scanline pScanline = pWriteAcc->GetScanline(nY);
+            for (long nX = 0; nX < nWidth; nX++)
+            {
+                if (pWriteAcc->GetPixelFromData(pScanline, nX) == aReplaceWhat)
+                {
+                    pWriteAcc->SetPixelOnData(pScanline, nX, aReplaceTo);
+                }
+            }
+        }
+    }
+
+    return BitmapEx(aBitmap);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list