[Libreoffice-commits] core.git: 3 commits - include/vcl vcl/Library_vcl.mk vcl/source
Chris Sherlock
chris.sherlock79 at gmail.com
Sun Apr 22 03:34:52 UTC 2018
include/vcl/BitmapPopArtFilter.hxx | 33 ++++
include/vcl/BitmapSepiaFilter.hxx | 34 ++++
include/vcl/BitmapSolarizeFilter.hxx | 34 ++++
include/vcl/bitmap.hxx | 3
vcl/Library_vcl.mk | 3
vcl/source/bitmap/BitmapPopArtFilter.cxx | 118 ++++++++++++++
vcl/source/bitmap/BitmapSepiaFilter.cxx | 106 ++++++++++++
vcl/source/bitmap/BitmapSolarizeFilter.cxx | 68 ++++++++
vcl/source/gdi/bitmap4.cxx | 239 ++---------------------------
9 files changed, 414 insertions(+), 224 deletions(-)
New commits:
commit 1ab12471f3a69c4d502e6271e84ddf8a981f507f
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date: Fri Apr 20 20:32:23 2018 +1000
vcl: ImplSepia -> BitmapSepiaFilter
Change-Id: I96a4072bf919bd37b30c01ab16d98779c76717ab
Reviewed-on: https://gerrit.libreoffice.org/53202
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/include/vcl/BitmapSepiaFilter.hxx b/include/vcl/BitmapSepiaFilter.hxx
new file mode 100644
index 000000000000..717f10d1466b
--- /dev/null
+++ b/include/vcl/BitmapSepiaFilter.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_BITMAPSEPIAFILTER_HXX
+#define INCLUDED_VCL_BITMAPSEPIAFILTER_HXX
+
+#include <vcl/BitmapFilter.hxx>
+
+class BitmapEx;
+
+class VCL_DLLPUBLIC BitmapSepiaFilter : public BitmapFilter
+{
+public:
+ BitmapSepiaFilter(double nSepiaPercent)
+ : mnSepiaPercent(nSepiaPercent)
+ {
+ }
+
+ virtual BitmapEx execute(BitmapEx const& rBitmapEx) override;
+
+private:
+ sal_uInt16 mnSepiaPercent;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx
index bffeca808ea2..b71f8a4224ba 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 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 940bd8b35974..82f67dd845b9 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -314,6 +314,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/bitmap/bitmapfilter \
vcl/source/bitmap/BitmapSobelGreyFilter \
vcl/source/bitmap/BitmapSolarizeFilter \
+ vcl/source/bitmap/BitmapSepiaFilter \
vcl/source/bitmap/BitmapPopArtFilter \
vcl/source/bitmap/BitmapConvolutionMatrixFilter \
vcl/source/bitmap/BitmapMedianFilter \
diff --git a/vcl/source/bitmap/BitmapSepiaFilter.cxx b/vcl/source/bitmap/BitmapSepiaFilter.cxx
new file mode 100644
index 000000000000..a953fcbee2a8
--- /dev/null
+++ b/vcl/source/bitmap/BitmapSepiaFilter.cxx
@@ -0,0 +1,106 @@
+/* -*- 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/BitmapSepiaFilter.hxx>
+
+#include <bitmapwriteaccess.hxx>
+
+BitmapEx BitmapSepiaFilter::execute(BitmapEx const& rBitmapEx)
+{
+ Bitmap aBitmap(rBitmapEx.GetBitmap());
+ Bitmap::ScopedReadAccess pReadAcc(aBitmap);
+ bool bRet = false;
+
+ if (pReadAcc)
+ {
+ const long nSepia = 10000 - 100 * SAL_BOUND(mnSepiaPercent, 0, 100);
+ BitmapPalette aSepiaPal(256);
+
+ for (sal_uInt16 i = 0; i < 256; i++)
+ {
+ BitmapColor& rCol = aSepiaPal[i];
+ const sal_uInt8 cSepiaValue = static_cast<sal_uInt8>(nSepia * i / 10000);
+
+ rCol.SetRed(static_cast<sal_uInt8>(i));
+ rCol.SetGreen(cSepiaValue);
+ rCol.SetBlue(cSepiaValue);
+ }
+
+ Bitmap aNewBmp(aBitmap.GetSizePixel(), 8, &aSepiaPal);
+ BitmapScopedWriteAccess pWriteAcc(aNewBmp);
+
+ if (pWriteAcc)
+ {
+ BitmapColor aCol(sal_uInt8(0));
+ const long nWidth = pWriteAcc->Width();
+ const long nHeight = pWriteAcc->Height();
+
+ if (pReadAcc->HasPalette())
+ {
+ const sal_uInt16 nPalCount = pReadAcc->GetPaletteEntryCount();
+ std::unique_ptr<sal_uInt8[]> pIndexMap(new sal_uInt8[nPalCount]);
+ for (sal_uInt16 i = 0; i < nPalCount; i++)
+ {
+ pIndexMap[i] = pReadAcc->GetPaletteColor(i).GetLuminance();
+ }
+
+ for (long nY = 0; nY < nHeight; nY++)
+ {
+ Scanline pScanline = pWriteAcc->GetScanline(nY);
+ Scanline pScanlineRead = pReadAcc->GetScanline(nY);
+ for (long nX = 0; nX < nWidth; nX++)
+ {
+ aCol.SetIndex(pIndexMap[pReadAcc->GetIndexFromData(pScanlineRead, nX)]);
+ pWriteAcc->SetPixelOnData(pScanline, nX, aCol);
+ }
+ }
+ }
+ else
+ {
+ for (long nY = 0; nY < nHeight; nY++)
+ {
+ Scanline pScanline = pWriteAcc->GetScanline(nY);
+ Scanline pScanlineRead = pReadAcc->GetScanline(nY);
+ for (long nX = 0; nX < nWidth; nX++)
+ {
+ aCol.SetIndex(pReadAcc->GetPixelFromData(pScanlineRead, nX).GetLuminance());
+ pWriteAcc->SetPixelOnData(pScanline, nX, aCol);
+ }
+ }
+ }
+
+ pWriteAcc.reset();
+ bRet = true;
+ }
+
+ pReadAcc.reset();
+
+ if (bRet)
+ {
+ const MapMode aMap(aBitmap.GetPrefMapMode());
+ const Size aPrefSize(aBitmap.GetPrefSize());
+
+ aBitmap = aNewBmp;
+
+ aBitmap.SetPrefMapMode(aMap);
+ aBitmap.SetPrefSize(aPrefSize);
+ }
+ }
+
+ 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 adaa3f846f7f..ea8fec2d4d49 100644
--- a/vcl/source/gdi/bitmap4.cxx
+++ b/vcl/source/gdi/bitmap4.cxx
@@ -25,6 +25,7 @@
#include <vcl/BitmapMedianFilter.hxx>
#include <vcl/BitmapSobelGreyFilter.hxx>
#include <vcl/BitmapSolarizeFilter.hxx>
+#include <vcl/BitmapSepiaFilter.hxx>
#include <vcl/BitmapPopArtFilter.hxx>
#include <bitmapwriteaccess.hxx>
@@ -87,7 +88,11 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
break;
case BmpFilter::Sepia:
- bRet = ImplSepia( pFilterParam );
+ {
+ BitmapEx aBmpEx(*this);
+ bRet = BitmapFilter::Filter(aBmpEx, BitmapSepiaFilter(pFilterParam->mnSepiaPercent));
+ *this = aBmpEx.GetBitmap();
+ }
break;
case BmpFilter::Mosaic:
@@ -231,90 +236,6 @@ bool Bitmap::ImplEmbossGrey( const BmpFilterParam* pFilterParam )
return bRet;
}
-bool Bitmap::ImplSepia( const BmpFilterParam* pFilterParam )
-{
- ScopedReadAccess pReadAcc(*this);
- bool bRet = false;
-
- if( pReadAcc )
- {
- long nSepiaPercent = ( pFilterParam && pFilterParam->meFilter == BmpFilter::Sepia ) ?
- pFilterParam->mnSepiaPercent : 10;
- const long nSepia = 10000 - 100 * SAL_BOUND( nSepiaPercent, 0, 100 );
- BitmapPalette aSepiaPal( 256 );
-
- for( sal_uInt16 i = 0; i < 256; i++ )
- {
- BitmapColor& rCol = aSepiaPal[ i ];
- const sal_uInt8 cSepiaValue = static_cast<sal_uInt8>( nSepia * i / 10000 );
-
- rCol.SetRed( static_cast<sal_uInt8>(i) );
- rCol.SetGreen( cSepiaValue );
- rCol.SetBlue( cSepiaValue );
- }
-
- Bitmap aNewBmp( GetSizePixel(), 8, &aSepiaPal );
- BitmapScopedWriteAccess pWriteAcc(aNewBmp);
-
- if( pWriteAcc )
- {
- BitmapColor aCol( sal_uInt8(0) );
- const long nWidth = pWriteAcc->Width();
- const long nHeight = pWriteAcc->Height();
-
- if( pReadAcc->HasPalette() )
- {
- const sal_uInt16 nPalCount = pReadAcc->GetPaletteEntryCount();
- std::unique_ptr<sal_uInt8[]> pIndexMap( new sal_uInt8[ nPalCount ] );
- for( sal_uInt16 i = 0; i < nPalCount; i++ )
- pIndexMap[ i ] = pReadAcc->GetPaletteColor( i ).GetLuminance();
-
- for( long nY = 0; nY < nHeight ; nY++ )
- {
- Scanline pScanline = pWriteAcc->GetScanline(nY);
- Scanline pScanlineRead = pReadAcc->GetScanline(nY);
- for( long nX = 0; nX < nWidth; nX++ )
- {
- aCol.SetIndex( pIndexMap[ pReadAcc->GetIndexFromData( pScanlineRead, nX ) ] );
- pWriteAcc->SetPixelOnData( pScanline, nX, aCol );
- }
- }
- }
- else
- {
- for( long nY = 0; nY < nHeight ; nY++ )
- {
- Scanline pScanline = pWriteAcc->GetScanline(nY);
- Scanline pScanlineRead = pReadAcc->GetScanline(nY);
- for( long nX = 0; nX < nWidth; nX++ )
- {
- aCol.SetIndex( pReadAcc->GetPixelFromData( pScanlineRead, nX ).GetLuminance() );
- pWriteAcc->SetPixelOnData( pScanline, nX, aCol );
- }
- }
- }
-
- pWriteAcc.reset();
- bRet = true;
- }
-
- pReadAcc.reset();
-
- if( bRet )
- {
- const MapMode aMap( maPrefMapMode );
- const Size aSize( maPrefSize );
-
- *this = aNewBmp;
-
- maPrefMapMode = aMap;
- maPrefSize = aSize;
- }
- }
-
- return bRet;
-}
-
bool Bitmap::ImplMosaic( const BmpFilterParam* pFilterParam )
{
sal_uLong nTileWidth = ( pFilterParam && pFilterParam->meFilter == BmpFilter::Mosaic ) ?
commit c38485279cd36da96ac81107d567ea4e779b2b96
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date: Fri Apr 20 20:27:41 2018 +1000
vcl: ImplSolarize() to BitmapSolarizeFilter
Change-Id: I3d615bcce851cb0f0140e2a1542a4073727a51be
Reviewed-on: https://gerrit.libreoffice.org/53201
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
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);
commit bcbf767bcfc024e2be839e0c0886f942dd068e4f
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date: Thu Apr 19 20:48:29 2018 +1000
vcl: ImplPopArt() -> BitmapPopArtFilter
Change-Id: I7b81d0441b5ffdc322a19ca1fea7c7ca63e9e499
Reviewed-on: https://gerrit.libreoffice.org/53151
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/include/vcl/BitmapPopArtFilter.hxx b/include/vcl/BitmapPopArtFilter.hxx
new file mode 100644
index 000000000000..5c926940d3cf
--- /dev/null
+++ b/include/vcl/BitmapPopArtFilter.hxx
@@ -0,0 +1,33 @@
+/* -*- 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_BITMAPPOPARTILTER_HXX
+#define INCLUDED_VCL_BITMAPPOPARTILTER_HXX
+
+#include <vcl/BitmapFilter.hxx>
+
+class VCL_DLLPUBLIC BitmapPopArtFilter : public BitmapFilter
+{
+public:
+ BitmapPopArtFilter() {}
+
+ virtual BitmapEx execute(BitmapEx const& rBitmapEx) override;
+
+private:
+ struct PopArtEntry
+ {
+ sal_uInt32 mnIndex;
+ sal_uInt32 mnCount;
+ };
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx
index 7f560e517ab0..eaa985d74b54 100644
--- a/include/vcl/bitmap.hxx
+++ b/include/vcl/bitmap.hxx
@@ -662,7 +662,6 @@ public:
SAL_DLLPRIVATE bool ImplSolarize( const BmpFilterParam* pFilterParam );
SAL_DLLPRIVATE bool ImplSepia( const BmpFilterParam* pFilterParam );
SAL_DLLPRIVATE bool ImplMosaic( const BmpFilterParam* pFilterParam );
- SAL_DLLPRIVATE bool ImplPopArt();
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 72aa7e122217..c39ea5f6b28d 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/BitmapPopArtFilter \
vcl/source/bitmap/BitmapConvolutionMatrixFilter \
vcl/source/bitmap/BitmapMedianFilter \
vcl/source/bitmap/BitmapInterpolateScaleFilter \
diff --git a/vcl/source/bitmap/BitmapPopArtFilter.cxx b/vcl/source/bitmap/BitmapPopArtFilter.cxx
new file mode 100644
index 000000000000..15b1b9ea09dd
--- /dev/null
+++ b/vcl/source/bitmap/BitmapPopArtFilter.cxx
@@ -0,0 +1,118 @@
+/* -*- 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/BitmapPopArtFilter.hxx>
+
+#include <bitmapwriteaccess.hxx>
+
+#include <cstdlib>
+
+BitmapEx BitmapPopArtFilter::execute(BitmapEx const& rBitmapEx)
+{
+ Bitmap aBitmap(rBitmapEx.GetBitmap());
+
+ bool bRet = (aBitmap.GetBitCount() <= 8) || aBitmap.Convert(BmpConversion::N8BitColors);
+
+ if (bRet)
+ {
+ bRet = false;
+
+ BitmapScopedWriteAccess pWriteAcc(aBitmap);
+
+ if (pWriteAcc)
+ {
+ const long nWidth = pWriteAcc->Width();
+ const long nHeight = pWriteAcc->Height();
+ const int nEntryCount = 1 << pWriteAcc->GetBitCount();
+ int n = 0;
+ PopArtEntry* pPopArtTable = new PopArtEntry[nEntryCount];
+
+ for (n = 0; n < nEntryCount; n++)
+ {
+ PopArtEntry& rEntry = pPopArtTable[n];
+ rEntry.mnIndex = static_cast<sal_uInt16>(n);
+ rEntry.mnCount = 0;
+ }
+
+ // get pixel count for each palette entry
+ for (long nY = 0; nY < nHeight; nY++)
+ {
+ Scanline pScanline = pWriteAcc->GetScanline(nY);
+ for (long nX = 0; nX < nWidth; nX++)
+ {
+ pPopArtTable[pWriteAcc->GetIndexFromData(pScanline, nX)].mnCount++;
+ }
+ }
+
+ // sort table
+ std::qsort(pPopArtTable, nEntryCount, sizeof(PopArtEntry),
+ [](const void* p1, const void* p2) {
+ int nRet;
+
+ if (static_cast<PopArtEntry const*>(p1)->mnCount
+ < static_cast<PopArtEntry const*>(p2)->mnCount)
+ {
+ nRet = 1;
+ }
+ else if (static_cast<PopArtEntry const*>(p1)->mnCount
+ == static_cast<PopArtEntry const*>(p2)->mnCount)
+ {
+ nRet = 0;
+ }
+ else
+ {
+ nRet = -1;
+ }
+
+ return nRet;
+ });
+
+ // get last used entry
+ sal_uLong nFirstEntry;
+ sal_uLong nLastEntry = 0;
+
+ for (n = 0; n < nEntryCount; n++)
+ {
+ if (pPopArtTable[n].mnCount)
+ nLastEntry = n;
+ }
+
+ // rotate palette (one entry)
+ const BitmapColor aFirstCol(pWriteAcc->GetPaletteColor(
+ sal::static_int_cast<sal_uInt16>(pPopArtTable[0].mnIndex)));
+
+ for (nFirstEntry = 0; nFirstEntry < nLastEntry; nFirstEntry++)
+ {
+ pWriteAcc->SetPaletteColor(
+ sal::static_int_cast<sal_uInt16>(pPopArtTable[nFirstEntry].mnIndex),
+ pWriteAcc->GetPaletteColor(
+ sal::static_int_cast<sal_uInt16>(pPopArtTable[nFirstEntry + 1].mnIndex)));
+ }
+
+ pWriteAcc->SetPaletteColor(
+ sal::static_int_cast<sal_uInt16>(pPopArtTable[nLastEntry].mnIndex), aFirstCol);
+
+ // cleanup
+ delete[] pPopArtTable;
+ pWriteAcc.reset();
+ bRet = true;
+ }
+ }
+
+ if (bRet)
+ return BitmapEx(aBitmap);
+
+ return BitmapEx();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/bitmap4.cxx b/vcl/source/gdi/bitmap4.cxx
index edd420b1ea70..656ab4317f99 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/BitmapPopArtFilter.hxx>
#include <bitmapwriteaccess.hxx>
@@ -93,7 +94,11 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
break;
case BmpFilter::PopArt:
- bRet = ImplPopArt();
+ {
+ BitmapEx aBmpEx(*this);
+ bRet = BitmapFilter::Filter(aBmpEx, BitmapPopArtFilter());
+ *this = aBmpEx.GetBitmap();
+ }
break;
case BmpFilter::DuoTone:
@@ -527,91 +532,6 @@ bool Bitmap::ImplMosaic( const BmpFilterParam* pFilterParam )
return bRet;
}
-
-struct PopArtEntry
-{
- sal_uInt32 mnIndex;
- sal_uInt32 mnCount;
-};
-
-extern "C" int ImplPopArtCmpFnc( const void* p1, const void* p2 )
-{
- int nRet;
-
- if( static_cast<PopArtEntry const *>(p1)->mnCount < static_cast<PopArtEntry const *>(p2)->mnCount )
- nRet = 1;
- else if( static_cast<PopArtEntry const *>(p1)->mnCount == static_cast<PopArtEntry const *>(p2)->mnCount )
- nRet = 0;
- else
- nRet = -1;
-
- return nRet;
-}
-
-bool Bitmap::ImplPopArt()
-{
- /* note: GetBitCount() after that is no more than 8 */
- bool bRet = ( GetBitCount() <= 8 ) || Convert( BmpConversion::N8BitColors );
-
- if( bRet )
- {
- bRet = false;
-
- BitmapScopedWriteAccess pWriteAcc(*this);
-
- if( pWriteAcc )
- {
- const long nWidth = pWriteAcc->Width();
- const long nHeight = pWriteAcc->Height();
- const int nEntryCount = 1 << pWriteAcc->GetBitCount();
- int n;
- PopArtEntry* pPopArtTable = new PopArtEntry[ nEntryCount ];
-
- for( n = 0; n < nEntryCount; n++ )
- {
- PopArtEntry& rEntry = pPopArtTable[ n ];
- rEntry.mnIndex = static_cast<sal_uInt16>(n);
- rEntry.mnCount = 0;
- }
-
- // get pixel count for each palette entry
- for( long nY = 0; nY < nHeight ; nY++ )
- {
- Scanline pScanline = pWriteAcc->GetScanline(nY);
- for( long nX = 0; nX < nWidth; nX++ )
- pPopArtTable[ pWriteAcc->GetIndexFromData( pScanline, nX ) ].mnCount++;
- }
-
- // sort table
- qsort( pPopArtTable, nEntryCount, sizeof( PopArtEntry ), ImplPopArtCmpFnc );
-
- // get last used entry
- sal_uLong nFirstEntry;
- sal_uLong nLastEntry = 0;
-
- for( n = 0; n < nEntryCount; n++ )
- if( pPopArtTable[ n ].mnCount )
- nLastEntry = n;
-
- // rotate palette (one entry)
- const BitmapColor aFirstCol( pWriteAcc->GetPaletteColor( sal::static_int_cast<sal_uInt16>(pPopArtTable[ 0 ].mnIndex) ) );
- for( nFirstEntry = 0; nFirstEntry < nLastEntry; nFirstEntry++ )
- {
- pWriteAcc->SetPaletteColor( sal::static_int_cast<sal_uInt16>(pPopArtTable[ nFirstEntry ].mnIndex),
- pWriteAcc->GetPaletteColor( sal::static_int_cast<sal_uInt16>(pPopArtTable[ nFirstEntry + 1 ].mnIndex) ) );
- }
- pWriteAcc->SetPaletteColor( sal::static_int_cast<sal_uInt16>(pPopArtTable[ nLastEntry ].mnIndex), aFirstCol );
-
- // cleanup
- delete[] pPopArtTable;
- pWriteAcc.reset();
- bRet = true;
- }
- }
-
- return bRet;
-}
-
bool Bitmap::ImplDuotoneFilter( const sal_uLong nColorOne, const sal_uLong nColorTwo )
{
const long nWidth = GetSizePixel().Width();
More information about the Libreoffice-commits
mailing list