[Libreoffice-commits] core.git: include/vcl vcl/Library_vcl.mk vcl/source
Chris Sherlock
chris.sherlock79 at gmail.com
Sat Apr 21 15:13:11 UTC 2018
include/vcl/BitmapSeparableUnsharpenFilter.hxx | 37 +++++++++
include/vcl/bitmap.hxx | 2
vcl/Library_vcl.mk | 1
vcl/source/bitmap/BitmapSeparableUnsharpenFilter.cxx | 76 +++++++++++++++++++
vcl/source/gdi/bitmap4.cxx | 53 +------------
5 files changed, 118 insertions(+), 51 deletions(-)
New commits:
commit 6a3d2dea1da847f5bd6674b344162f087cceda8b
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date: Wed Apr 18 20:18:47 2018 +1000
vcl: Bitmap::ImplSeparableUnsharpenFilter() -> BitmapSeparableUnsharpenFilter
Change-Id: I62d95cc8bbf7b9349b1abc3e58bf0a202e3afec5
Reviewed-on: https://gerrit.libreoffice.org/53091
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/include/vcl/BitmapSeparableUnsharpenFilter.hxx b/include/vcl/BitmapSeparableUnsharpenFilter.hxx
new file mode 100644
index 000000000000..1812b9013fe8
--- /dev/null
+++ b/include/vcl/BitmapSeparableUnsharpenFilter.hxx
@@ -0,0 +1,37 @@
+/* -*- 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_BITMAPSEPARABLEUNSHARPENFILTER_HXX
+#define INCLUDED_VCL_BITMAPSEPARABLEUNSHARPENFILTER_HXX
+
+#include <vcl/BitmapFilter.hxx>
+
+class BitmapEx;
+
+/** Separable Unsharpen Mask filter is actually a subtracted blurred
+ image from the original image.
+ */
+class VCL_DLLPUBLIC BitmapSeparableUnsharpenFilter : public BitmapFilter
+{
+public:
+ BitmapSeparableUnsharpenFilter(double fRadius)
+ : mfRadius(fRadius)
+ {
+ }
+
+ virtual BitmapEx execute(BitmapEx const& rBitmapEx) override;
+
+private:
+ double mfRadius;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx
index d46dc7ddf24e..07573b1af1b0 100644
--- a/include/vcl/bitmap.hxx
+++ b/include/vcl/bitmap.hxx
@@ -667,8 +667,6 @@ public:
SAL_DLLPRIVATE bool ImplSepia( const BmpFilterParam* pFilterParam );
SAL_DLLPRIVATE bool ImplMosaic( const BmpFilterParam* pFilterParam );
SAL_DLLPRIVATE bool ImplPopArt();
-
- SAL_DLLPRIVATE bool ImplSeparableUnsharpenFilter( const double aRadius );
SAL_DLLPRIVATE bool ImplDuotoneFilter( const sal_uLong nColorOne, sal_uLong nColorTwo );
public:
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index dc3b8a3318c6..8a2edf75b2b4 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/BitmapColorizeFilter \
vcl/source/bitmap/bitmappaint \
vcl/source/bitmap/BitmapGaussianSeparableBlurFilter \
+ vcl/source/bitmap/BitmapSeparableUnsharpenFilter \
vcl/source/bitmap/BitmapFastScaleFilter \
vcl/source/bitmap/BitmapScaleSuperFilter \
vcl/source/bitmap/BitmapScaleConvolutionFilter \
diff --git a/vcl/source/bitmap/BitmapSeparableUnsharpenFilter.cxx b/vcl/source/bitmap/BitmapSeparableUnsharpenFilter.cxx
new file mode 100644
index 000000000000..f594a808cc14
--- /dev/null
+++ b/vcl/source/bitmap/BitmapSeparableUnsharpenFilter.cxx
@@ -0,0 +1,76 @@
+/* -*- 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 <basegfx/color/bcolortools.hxx>
+
+#include <vcl/bitmap.hxx>
+#include <vcl/bitmapex.hxx>
+#include <vcl/bitmapaccess.hxx>
+#include <vcl/BitmapGaussianSeparableBlurFilter.hxx>
+#include <vcl/BitmapSeparableUnsharpenFilter.hxx>
+
+#include <bitmapwriteaccess.hxx>
+
+BitmapEx BitmapSeparableUnsharpenFilter::execute(BitmapEx const& rBitmapEx)
+{
+ Bitmap aBitmap(rBitmapEx.GetBitmap());
+
+ const long nWidth = aBitmap.GetSizePixel().Width();
+ const long nHeight = aBitmap.GetSizePixel().Height();
+
+ Bitmap aBlur(aBitmap);
+ BitmapEx aBlurEx(aBlur);
+
+ BitmapFilter::Filter(aBlurEx, BitmapGaussianSeparableBlurFilter(-mfRadius));
+ aBlur = aBlurEx.GetBitmap();
+
+ // Amount of unsharpening effect on image - currently set to a fixed value
+ double aAmount = 2.0;
+
+ Bitmap aResultBitmap(Size(nWidth, nHeight), 24);
+
+ Bitmap::ScopedReadAccess pReadAccBlur(aBlur);
+ Bitmap::ScopedReadAccess pReadAcc(aBitmap);
+ BitmapScopedWriteAccess pWriteAcc(aResultBitmap);
+
+ BitmapColor aColor, aColorBlur;
+
+ // For all pixels in original image subtract pixels values from blurred image
+ for (long y = 0; y < nHeight; y++)
+ {
+ Scanline pScanline = pWriteAcc->GetScanline(y);
+ for (long x = 0; x < nWidth; x++)
+ {
+ aColorBlur = pReadAccBlur->GetColor(y, x);
+ aColor = pReadAcc->GetColor(y, x);
+
+ BitmapColor aResultColor(
+ static_cast<sal_uInt8>(MinMax(
+ aColor.GetRed() + (aColor.GetRed() - aColorBlur.GetRed()) * aAmount, 0, 255)),
+ static_cast<sal_uInt8>(MinMax(
+ aColor.GetGreen() + (aColor.GetGreen() - aColorBlur.GetGreen()) * aAmount, 0,
+ 255)),
+ static_cast<sal_uInt8>(
+ MinMax(aColor.GetBlue() + (aColor.GetBlue() - aColorBlur.GetBlue()) * aAmount,
+ 0, 255)));
+
+ pWriteAcc->SetPixelOnData(pScanline, x, aResultColor);
+ }
+ }
+
+ pWriteAcc.reset();
+ pReadAcc.reset();
+ pReadAccBlur.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 e48a2edae9b3..1c739c380bc7 100644
--- a/vcl/source/gdi/bitmap4.cxx
+++ b/vcl/source/gdi/bitmap4.cxx
@@ -21,6 +21,7 @@
#include <vcl/bitmapaccess.hxx>
#include <vcl/bitmap.hxx>
#include <vcl/BitmapGaussianSeparableBlurFilter.hxx>
+#include <vcl/BitmapSeparableUnsharpenFilter.hxx>
#include <bitmapwriteaccess.hxx>
@@ -61,7 +62,9 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
// Unsharpen Mask for negative values of mnRadius
else if (pFilterParam->mnRadius < 0.0)
{
- bRet = ImplSeparableUnsharpenFilter(pFilterParam->mnRadius);
+ BitmapEx aBmpEx(*this);
+ bRet = BitmapFilter::Filter(aBmpEx, BitmapSeparableUnsharpenFilter(pFilterParam->mnRadius));
+ *this = aBmpEx.GetBitmap();
}
else
{
@@ -1067,54 +1070,6 @@ bool Bitmap::ImplPopArt()
return bRet;
}
-// Separable Unsharpen Mask filter is actually a subtracted blurred
-// image from the original image.
-bool Bitmap::ImplSeparableUnsharpenFilter(const double radius) {
- const long nWidth = GetSizePixel().Width();
- const long nHeight = GetSizePixel().Height();
-
- Bitmap aBlur( *this );
- BitmapEx aBlurEx(aBlur);
-
- BitmapFilter::Filter(aBlurEx, BitmapGaussianSeparableBlurFilter(-radius));
- aBlur = aBlurEx.GetBitmap();
-
- // Amount of unsharpening effect on image - currently set to a fixed value
- double aAmount = 2.0;
-
- Bitmap aResultBitmap( Size( nWidth, nHeight ), 24);
-
- ScopedReadAccess pReadAccBlur(aBlur);
- ScopedReadAccess pReadAcc(*this);
- BitmapScopedWriteAccess pWriteAcc(aResultBitmap);
-
- BitmapColor aColor, aColorBlur;
-
- // For all pixels in original image subtract pixels values from blurred image
- for( long y = 0; y < nHeight; y++ )
- {
- Scanline pScanline = pWriteAcc->GetScanline(y);
- for( long x = 0; x < nWidth; x++ )
- {
- aColorBlur = pReadAccBlur->GetColor( y , x );
- aColor = pReadAcc->GetColor( y , x );
-
- BitmapColor aResultColor(
- static_cast<sal_uInt8>(MinMax( aColor.GetRed() + (aColor.GetRed() - aColorBlur.GetRed()) * aAmount, 0, 255 )),
- static_cast<sal_uInt8>(MinMax( aColor.GetGreen() + (aColor.GetGreen() - aColorBlur.GetGreen()) * aAmount, 0, 255 )),
- static_cast<sal_uInt8>(MinMax( aColor.GetBlue() + (aColor.GetBlue() - aColorBlur.GetBlue()) * aAmount, 0, 255 )) );
-
- pWriteAcc->SetPixelOnData( pScanline, x, aResultColor );
- }
- }
-
- pWriteAcc.reset();
- pReadAcc.reset();
- pReadAccBlur.reset();
- ReassignWithSize(aResultBitmap);
- return true;
-}
-
bool Bitmap::ImplDuotoneFilter( const sal_uLong nColorOne, const sal_uLong nColorTwo )
{
const long nWidth = GetSizePixel().Width();
More information about the Libreoffice-commits
mailing list