summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2018-04-20 20:27:41 +1000
committerTomaž Vajngerl <quikee@gmail.com>2018-04-22 05:33:11 +0200
commitc38485279cd36da96ac81107d567ea4e779b2b96 (patch)
treead9843a17f87271f9e0cf89643e2e6c3ee8a8de1 /vcl
parentbcbf767bcfc024e2be839e0c0886f942dd068e4f (diff)
vcl: ImplSolarize() to BitmapSolarizeFilter
Change-Id: I3d615bcce851cb0f0140e2a1542a4073727a51be Reviewed-on: https://gerrit.libreoffice.org/53201 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/Library_vcl.mk1
-rw-r--r--vcl/source/bitmap/BitmapSolarizeFilter.cxx68
-rw-r--r--vcl/source/gdi/bitmap4.cxx56
3 files changed, 75 insertions, 50 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index c39ea5f6b28d..940bd8b35974 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -313,6 +313,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/bitmap/bitmap \
vcl/source/bitmap/bitmapfilter \
vcl/source/bitmap/BitmapSobelGreyFilter \
+ vcl/source/bitmap/BitmapSolarizeFilter \
vcl/source/bitmap/BitmapPopArtFilter \
vcl/source/bitmap/BitmapConvolutionMatrixFilter \
vcl/source/bitmap/BitmapMedianFilter \
diff --git a/vcl/source/bitmap/BitmapSolarizeFilter.cxx b/vcl/source/bitmap/BitmapSolarizeFilter.cxx
new file mode 100644
index 000000000000..88808ff97426
--- /dev/null
+++ b/vcl/source/bitmap/BitmapSolarizeFilter.cxx
@@ -0,0 +1,68 @@
+/* -*- 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/bitmapaccess.hxx>
+#include <vcl/BitmapSolarizeFilter.hxx>
+
+#include <bitmapwriteaccess.hxx>
+
+BitmapEx BitmapSolarizeFilter::execute(BitmapEx const& rBitmapEx)
+{
+ Bitmap aBitmap(rBitmapEx.GetBitmap());
+ bool bRet = false;
+ BitmapScopedWriteAccess pWriteAcc(aBitmap);
+
+ if (pWriteAcc)
+ {
+ if (pWriteAcc->HasPalette())
+ {
+ const BitmapPalette& rPal = pWriteAcc->GetPalette();
+
+ for (sal_uInt16 i = 0, nCount = rPal.GetEntryCount(); i < nCount; i++)
+ {
+ if (rPal[i].GetLuminance() >= mcSolarGreyThreshold)
+ {
+ BitmapColor aCol(rPal[i]);
+ pWriteAcc->SetPaletteColor(i, aCol.Invert());
+ }
+ }
+ }
+ else
+ {
+ BitmapColor aCol;
+ 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++)
+ {
+ aCol = pWriteAcc->GetPixelFromData(pScanline, nX);
+
+ if (aCol.GetLuminance() >= mcSolarGreyThreshold)
+ pWriteAcc->SetPixelOnData(pScanline, nX, aCol.Invert());
+ }
+ }
+ }
+
+ pWriteAcc.reset();
+ bRet = true;
+ }
+
+ if (bRet)
+ return BitmapEx(rBitmapEx);
+
+ return BitmapEx();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/bitmap4.cxx b/vcl/source/gdi/bitmap4.cxx
index 656ab4317f99..adaa3f846f7f 100644
--- a/vcl/source/gdi/bitmap4.cxx
+++ b/vcl/source/gdi/bitmap4.cxx
@@ -24,6 +24,7 @@
#include <vcl/BitmapSharpenFilter.hxx>
#include <vcl/BitmapMedianFilter.hxx>
#include <vcl/BitmapSobelGreyFilter.hxx>
+#include <vcl/BitmapSolarizeFilter.hxx>
#include <vcl/BitmapPopArtFilter.hxx>
#include <bitmapwriteaccess.hxx>
@@ -78,7 +79,11 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
break;
case BmpFilter::Solarize:
- bRet = ImplSolarize( pFilterParam );
+ {
+ BitmapEx aBmpEx(*this);
+ bRet = BitmapFilter::Filter(aBmpEx, BitmapSolarizeFilter(pFilterParam->mcSolarGreyThreshold));
+ *this = aBmpEx.GetBitmap();
+ }
break;
case BmpFilter::Sepia:
@@ -226,55 +231,6 @@ bool Bitmap::ImplEmbossGrey( const BmpFilterParam* pFilterParam )
return bRet;
}
-bool Bitmap::ImplSolarize( const BmpFilterParam* pFilterParam )
-{
- bool bRet = false;
- BitmapScopedWriteAccess pWriteAcc(*this);
-
- if( pWriteAcc )
- {
- const sal_uInt8 cThreshold = ( pFilterParam && pFilterParam->meFilter == BmpFilter::Solarize ) ?
- pFilterParam->mcSolarGreyThreshold : 128;
-
- if( pWriteAcc->HasPalette() )
- {
- const BitmapPalette& rPal = pWriteAcc->GetPalette();
-
- for( sal_uInt16 i = 0, nCount = rPal.GetEntryCount(); i < nCount; i++ )
- {
- if( rPal[ i ].GetLuminance() >= cThreshold )
- {
- BitmapColor aCol( rPal[ i ] );
- pWriteAcc->SetPaletteColor( i, aCol.Invert() );
- }
- }
- }
- else
- {
- BitmapColor aCol;
- 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++ )
- {
- aCol = pWriteAcc->GetPixelFromData( pScanline, nX );
-
- if( aCol.GetLuminance() >= cThreshold )
- pWriteAcc->SetPixelOnData( pScanline, nX, aCol.Invert() );
- }
- }
- }
-
- pWriteAcc.reset();
- bRet = true;
- }
-
- return bRet;
-}
-
bool Bitmap::ImplSepia( const BmpFilterParam* pFilterParam )
{
ScopedReadAccess pReadAcc(*this);