diff options
author | Chris Sherlock <chris.sherlock79@gmail.com> | 2018-04-20 20:27:41 +1000 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2018-04-22 05:33:11 +0200 |
commit | c38485279cd36da96ac81107d567ea4e779b2b96 (patch) | |
tree | ad9843a17f87271f9e0cf89643e2e6c3ee8a8de1 | |
parent | bcbf767bcfc024e2be839e0c0886f942dd068e4f (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>
-rw-r--r-- | include/vcl/BitmapSolarizeFilter.hxx | 34 | ||||
-rw-r--r-- | include/vcl/bitmap.hxx | 1 | ||||
-rw-r--r-- | vcl/Library_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapSolarizeFilter.cxx | 68 | ||||
-rw-r--r-- | vcl/source/gdi/bitmap4.cxx | 56 |
5 files changed, 109 insertions, 51 deletions
diff --git a/include/vcl/BitmapSolarizeFilter.hxx b/include/vcl/BitmapSolarizeFilter.hxx new file mode 100644 index 000000000000..219bc881874f --- /dev/null +++ b/include/vcl/BitmapSolarizeFilter.hxx @@ -0,0 +1,34 @@ +/* -*- 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_BITMAPSOLARIZEFILTER_HXX +#define INCLUDED_VCL_BITMAPSOLARIZEFILTER_HXX + +#include <vcl/BitmapFilter.hxx> + +class BitmapEx; + +class VCL_DLLPUBLIC BitmapSolarizeFilter : public BitmapFilter +{ +public: + BitmapSolarizeFilter(double cSolarGreyThreshold) + : mcSolarGreyThreshold(cSolarGreyThreshold) + { + } + + virtual BitmapEx execute(BitmapEx const& rBitmapEx) override; + +private: + sal_uInt8 mcSolarGreyThreshold; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx index eaa985d74b54..bffeca808ea2 100644 --- a/include/vcl/bitmap.hxx +++ b/include/vcl/bitmap.hxx @@ -659,7 +659,6 @@ public: SAL_DLLPRIVATE bool ImplDitherFloyd16(); SAL_DLLPRIVATE bool ImplEmbossGrey( const BmpFilterParam* pFilterParam ); - SAL_DLLPRIVATE bool ImplSolarize( const BmpFilterParam* pFilterParam ); SAL_DLLPRIVATE bool ImplSepia( const BmpFilterParam* pFilterParam ); SAL_DLLPRIVATE bool ImplMosaic( const BmpFilterParam* pFilterParam ); SAL_DLLPRIVATE bool ImplDuotoneFilter( const sal_uLong nColorOne, sal_uLong nColorTwo ); 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); |