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

Chris Sherlock chris.sherlock79 at gmail.com
Mon Apr 23 05:02:30 UTC 2018


 include/vcl/BitmapDuoToneFilter.hxx       |   36 ++++++++++++++++
 include/vcl/bitmap.hxx                    |    2 
 vcl/Library_vcl.mk                        |    1 
 vcl/source/bitmap/BitmapDuoToneFilter.cxx |   66 ++++++++++++++++++++++++++++++
 vcl/source/gdi/bitmap4.cxx                |   47 +++------------------
 5 files changed, 110 insertions(+), 42 deletions(-)

New commits:
commit fefca920f474b2eaff93db18169a208a74262f2b
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date:   Fri Apr 20 21:13:55 2018 +1000

    vcl: ImplDuoTone() -> BitmapDuoToneFilter
    
    Change-Id: If779cf4033948601997a932839eaa10a874de1b3
    Reviewed-on: https://gerrit.libreoffice.org/53205
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/vcl/BitmapDuoToneFilter.hxx b/include/vcl/BitmapDuoToneFilter.hxx
new file mode 100644
index 000000000000..72c02e7afcfa
--- /dev/null
+++ b/include/vcl/BitmapDuoToneFilter.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_VCL_BITMAPDUOTONEFILTER_HXX
+#define INCLUDED_VCL_BITMAPDUOTONEFILTER_HXX
+
+#include <vcl/BitmapFilter.hxx>
+
+class BitmapEx;
+
+class VCL_DLLPUBLIC BitmapDuoToneFilter : public BitmapFilter
+{
+public:
+    BitmapDuoToneFilter(sal_uLong nColorOne, sal_uLong nColorTwo)
+        : mnColorOne(nColorOne)
+        , mnColorTwo(nColorTwo)
+    {
+    }
+
+    virtual BitmapEx execute(BitmapEx const& rBitmapEx) override;
+
+private:
+    sal_uLong mnColorOne;
+    sal_uLong mnColorTwo;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx
index 1da50be8aaac..78aeb2292533 100644
--- a/include/vcl/bitmap.hxx
+++ b/include/vcl/bitmap.hxx
@@ -658,8 +658,6 @@ public:
     SAL_DLLPRIVATE bool     ImplDitherFloyd();
     SAL_DLLPRIVATE bool     ImplDitherFloyd16();
 
-    SAL_DLLPRIVATE bool     ImplDuotoneFilter( const sal_uLong nColorOne,  sal_uLong nColorTwo );
-
 public:
 
     BitmapInfoAccess*       AcquireInfoAccess();
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 42416b3a3008..6d21dc36302f 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -318,6 +318,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/bitmap/BitmapMosaicFilter \
     vcl/source/bitmap/BitmapEmbossGreyFilter \
     vcl/source/bitmap/BitmapPopArtFilter \
+    vcl/source/bitmap/BitmapDuoToneFilter \
     vcl/source/bitmap/BitmapConvolutionMatrixFilter \
     vcl/source/bitmap/BitmapMedianFilter \
     vcl/source/bitmap/BitmapInterpolateScaleFilter \
diff --git a/vcl/source/bitmap/BitmapDuoToneFilter.cxx b/vcl/source/bitmap/BitmapDuoToneFilter.cxx
new file mode 100644
index 000000000000..1769081b9ccd
--- /dev/null
+++ b/vcl/source/bitmap/BitmapDuoToneFilter.cxx
@@ -0,0 +1,66 @@
+/* -*- 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/BitmapDuoToneFilter.hxx>
+#include <vcl/bitmapaccess.hxx>
+
+#include <bitmapwriteaccess.hxx>
+
+static inline sal_uInt8 lcl_getDuotoneColorComponent(sal_uInt8 base, sal_uInt16 color1,
+                                                     sal_uInt16 color2)
+{
+    color2 = color2 * base / 0xFF;
+    color1 = color1 * (0xFF - base) / 0xFF;
+
+    return static_cast<sal_uInt8>(color1 + color2);
+}
+
+BitmapEx BitmapDuoToneFilter::execute(BitmapEx const& rBitmapEx)
+{
+    Bitmap aBitmap(rBitmapEx.GetBitmap());
+
+    const long nWidth = aBitmap.GetSizePixel().Width();
+    const long nHeight = aBitmap.GetSizePixel().Height();
+
+    Bitmap aResultBitmap(aBitmap.GetSizePixel(), 24);
+    Bitmap::ScopedReadAccess pReadAcc(aBitmap);
+    BitmapScopedWriteAccess pWriteAcc(aResultBitmap);
+    const BitmapColor aColorOne(static_cast<sal_uInt8>(mnColorOne >> 16),
+                                static_cast<sal_uInt8>(mnColorOne >> 8),
+                                static_cast<sal_uInt8>(mnColorOne));
+    const BitmapColor aColorTwo(static_cast<sal_uInt8>(mnColorTwo >> 16),
+                                static_cast<sal_uInt8>(mnColorTwo >> 8),
+                                static_cast<sal_uInt8>(mnColorTwo));
+
+    for (long x = 0; x < nWidth; x++)
+    {
+        for (long y = 0; y < nHeight; y++)
+        {
+            BitmapColor aColor = pReadAcc->GetColor(y, x);
+            sal_uInt8 nLuminance = aColor.GetLuminance();
+            BitmapColor aResultColor(
+                lcl_getDuotoneColorComponent(nLuminance, aColorOne.GetRed(), aColorTwo.GetRed()),
+                lcl_getDuotoneColorComponent(nLuminance, aColorOne.GetGreen(),
+                                             aColorTwo.GetGreen()),
+                lcl_getDuotoneColorComponent(nLuminance, aColorOne.GetBlue(), aColorTwo.GetBlue()));
+            pWriteAcc->SetPixel(y, x, aResultColor);
+        }
+    }
+
+    pWriteAcc.reset();
+    pReadAcc.reset();
+    aBitmap.ReassignWithSize(aResultBitmap);
+
+    return BitmapEx(aBitmap);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/bitmap4.cxx b/vcl/source/gdi/bitmap4.cxx
index 0f8c7501d9b0..3cf4475087b2 100644
--- a/vcl/source/gdi/bitmap4.cxx
+++ b/vcl/source/gdi/bitmap4.cxx
@@ -30,20 +30,13 @@
 #include <vcl/BitmapEmbossGreyFilter.hxx>
 #include <vcl/BitmapSepiaFilter.hxx>
 #include <vcl/BitmapPopArtFilter.hxx>
+#include <vcl/BitmapDuoToneFilter.hxx>
 
 #include <bitmapwriteaccess.hxx>
 
 #include <memory>
 #include <stdlib.h>
 
-static inline sal_uInt8 lcl_getDuotoneColorComponent( sal_uInt8 base, sal_uInt16 color1, sal_uInt16 color2 )
-{
-    color2 = color2*base/0xFF;
-    color1 = color1*(0xFF-base)/0xFF;
-
-    return static_cast<sal_uInt8>(color1+color2);
-}
-
 bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
 {
     bool bRet = false;
@@ -126,7 +119,12 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
         break;
 
         case BmpFilter::DuoTone:
-            bRet = ImplDuotoneFilter( pFilterParam->mnProgressStart, pFilterParam->mnProgressEnd );
+        {
+            BitmapEx aBmpEx(*this);
+            bRet = BitmapFilter::Filter(aBmpEx, BitmapDuoToneFilter(pFilterParam->mnProgressStart,
+                                                                    pFilterParam->mnProgressEnd));
+            *this = aBmpEx.GetBitmap();
+        }
         break;
 
         default:
@@ -137,35 +135,4 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
     return bRet;
 }
 
-bool Bitmap::ImplDuotoneFilter( const sal_uLong nColorOne, const sal_uLong nColorTwo )
-{
-    const long  nWidth = GetSizePixel().Width();
-    const long  nHeight = GetSizePixel().Height();
-
-    Bitmap aResultBitmap( GetSizePixel(), 24);
-    ScopedReadAccess pReadAcc(*this);
-    BitmapScopedWriteAccess pWriteAcc(aResultBitmap);
-    const BitmapColor aColorOne( static_cast< sal_uInt8 >( nColorOne >> 16 ), static_cast< sal_uInt8 >( nColorOne >> 8 ), static_cast< sal_uInt8 >( nColorOne ) );
-    const BitmapColor aColorTwo( static_cast< sal_uInt8 >( nColorTwo >> 16 ), static_cast< sal_uInt8 >( nColorTwo >> 8 ), static_cast< sal_uInt8 >( nColorTwo ) );
-
-    for( long x = 0; x < nWidth; x++ )
-    {
-        for( long y = 0; y < nHeight; y++ )
-        {
-            BitmapColor aColor = pReadAcc->GetColor( y, x );
-            sal_uInt8 luminance = aColor.GetLuminance();
-            BitmapColor aResultColor(
-                    lcl_getDuotoneColorComponent( luminance, aColorOne.GetRed(), aColorTwo.GetRed() ) ,
-                    lcl_getDuotoneColorComponent( luminance, aColorOne.GetGreen(), aColorTwo.GetGreen() ) ,
-                    lcl_getDuotoneColorComponent( luminance, aColorOne.GetBlue(), aColorTwo.GetBlue() ) );
-            pWriteAcc->SetPixel( y, x, aResultColor );
-        }
-    }
-
-    pWriteAcc.reset();
-    pReadAcc.reset();
-    ReassignWithSize(aResultBitmap);
-    return true;
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list