[Libreoffice-commits] core.git: include/vcl vcl/Library_vcl.mk vcl/source
Chris Sherlock
chris.sherlock79 at gmail.com
Sun Apr 22 12:53:14 UTC 2018
include/vcl/BitmapEmbossGreyFilter.hxx | 36 ++++++
include/vcl/bitmap.hxx | 1
vcl/Library_vcl.mk | 1
vcl/source/bitmap/BitmapEmbossGreyFilter.cxx | 153 +++++++++++++++++++++++++++
vcl/source/gdi/bitmap4.cxx | 121 +--------------------
5 files changed, 197 insertions(+), 115 deletions(-)
New commits:
commit 4b183ae94821ed6d08708b43e4d719ffb4540843
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date: Fri Apr 20 21:00:46 2018 +1000
vcl: ImplEmbossGrey() -> BitmapEmbossGreyFilter
Change-Id: I6e541e9ca9cf61dfa8df9638a4ba4b8bd1d3ad71
Reviewed-on: https://gerrit.libreoffice.org/53204
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/include/vcl/BitmapEmbossGreyFilter.hxx b/include/vcl/BitmapEmbossGreyFilter.hxx
new file mode 100644
index 000000000000..0a3227295d6e
--- /dev/null
+++ b/include/vcl/BitmapEmbossGreyFilter.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_BITMAPEMBOSSGREYFILTER_HXX
+#define INCLUDED_VCL_BITMAPEMBOSSGREYFILTER_HXX
+
+#include <vcl/BitmapFilter.hxx>
+
+class BitmapEx;
+
+class VCL_DLLPUBLIC BitmapEmbossGreyFilter : public BitmapFilter
+{
+public:
+ BitmapEmbossGreyFilter(sal_uInt16 nAzimuthAngle100, sal_uInt16 nElevationAngle100)
+ : mnAzimuthAngle100(nAzimuthAngle100)
+ , mnElevationAngle100(nElevationAngle100)
+ {
+ }
+
+ virtual BitmapEx execute(BitmapEx const& rBitmapEx) override;
+
+private:
+ sal_uInt16 mnAzimuthAngle100;
+ sal_uInt16 mnElevationAngle100;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx
index 2c1621041d7a..1da50be8aaac 100644
--- a/include/vcl/bitmap.hxx
+++ b/include/vcl/bitmap.hxx
@@ -658,7 +658,6 @@ public:
SAL_DLLPRIVATE bool ImplDitherFloyd();
SAL_DLLPRIVATE bool ImplDitherFloyd16();
- SAL_DLLPRIVATE bool ImplEmbossGrey( const BmpFilterParam* pFilterParam );
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 49044708edd3..42416b3a3008 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -316,6 +316,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/bitmap/BitmapSolarizeFilter \
vcl/source/bitmap/BitmapSepiaFilter \
vcl/source/bitmap/BitmapMosaicFilter \
+ vcl/source/bitmap/BitmapEmbossGreyFilter \
vcl/source/bitmap/BitmapPopArtFilter \
vcl/source/bitmap/BitmapConvolutionMatrixFilter \
vcl/source/bitmap/BitmapMedianFilter \
diff --git a/vcl/source/bitmap/BitmapEmbossGreyFilter.cxx b/vcl/source/bitmap/BitmapEmbossGreyFilter.cxx
new file mode 100644
index 000000000000..f6ea34527de5
--- /dev/null
+++ b/vcl/source/bitmap/BitmapEmbossGreyFilter.cxx
@@ -0,0 +1,153 @@
+/* -*- 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/BitmapEmbossGreyFilter.hxx>
+
+#include <bitmapwriteaccess.hxx>
+
+BitmapEx BitmapEmbossGreyFilter::execute(BitmapEx const& rBitmapEx)
+{
+ Bitmap aBitmap(rBitmapEx.GetBitmap());
+
+ bool bRet = aBitmap.ImplMakeGreyscales(256);
+
+ if (bRet)
+ {
+ bRet = false;
+
+ Bitmap::ScopedReadAccess pReadAcc(aBitmap);
+
+ if (pReadAcc)
+ {
+ Bitmap aNewBmp(aBitmap.GetSizePixel(), 8, &pReadAcc->GetPalette());
+ BitmapScopedWriteAccess pWriteAcc(aNewBmp);
+
+ if (pWriteAcc)
+ {
+ BitmapColor aGrey(sal_uInt8(0));
+ const long nWidth = pWriteAcc->Width();
+ const long nHeight = pWriteAcc->Height();
+ long nGrey11, nGrey12, nGrey13;
+ long nGrey21, nGrey22, nGrey23;
+ long nGrey31, nGrey32, nGrey33;
+ double fAzim = mnAzimuthAngle100 * 0.01 * F_PI180;
+ double fElev = mnElevationAngle100 * 0.01 * F_PI180;
+ long* pHMap = new long[nWidth + 2];
+ long* pVMap = new long[nHeight + 2];
+ long nX, nY, nNx, nNy, nDotL;
+ const long nLx = FRound(cos(fAzim) * cos(fElev) * 255.0);
+ const long nLy = FRound(sin(fAzim) * cos(fElev) * 255.0);
+ const long nLz = FRound(sin(fElev) * 255.0);
+ const auto nZ2 = ((6 * 255) / 4) * ((6 * 255) / 4);
+ const long nNzLz = ((6 * 255) / 4) * nLz;
+ const sal_uInt8 cLz = static_cast<sal_uInt8>(SAL_BOUND(nLz, 0, 255));
+
+ // fill mapping tables
+ pHMap[0] = 0;
+
+ for (nX = 1; nX <= nWidth; nX++)
+ {
+ pHMap[nX] = nX - 1;
+ }
+
+ pHMap[nWidth + 1] = nWidth - 1;
+
+ pVMap[0] = 0;
+
+ for (nY = 1; nY <= nHeight; nY++)
+ {
+ pVMap[nY] = nY - 1;
+ }
+
+ pVMap[nHeight + 1] = nHeight - 1;
+
+ for (nY = 0; nY < nHeight; nY++)
+ {
+ nGrey11 = pReadAcc->GetPixel(pVMap[nY], pHMap[0]).GetIndex();
+ nGrey12 = pReadAcc->GetPixel(pVMap[nY], pHMap[1]).GetIndex();
+ nGrey13 = pReadAcc->GetPixel(pVMap[nY], pHMap[2]).GetIndex();
+ nGrey21 = pReadAcc->GetPixel(pVMap[nY + 1], pHMap[0]).GetIndex();
+ nGrey22 = pReadAcc->GetPixel(pVMap[nY + 1], pHMap[1]).GetIndex();
+ nGrey23 = pReadAcc->GetPixel(pVMap[nY + 1], pHMap[2]).GetIndex();
+ nGrey31 = pReadAcc->GetPixel(pVMap[nY + 2], pHMap[0]).GetIndex();
+ nGrey32 = pReadAcc->GetPixel(pVMap[nY + 2], pHMap[1]).GetIndex();
+ nGrey33 = pReadAcc->GetPixel(pVMap[nY + 2], pHMap[2]).GetIndex();
+
+ Scanline pScanline = pWriteAcc->GetScanline(nY);
+ for (nX = 0; nX < nWidth; nX++)
+ {
+ nNx = nGrey11 + nGrey21 + nGrey31 - nGrey13 - nGrey23 - nGrey33;
+ nNy = nGrey31 + nGrey32 + nGrey33 - nGrey11 - nGrey12 - nGrey13;
+
+ if (!nNx && !nNy)
+ {
+ aGrey.SetIndex(cLz);
+ }
+ else if ((nDotL = nNx * nLx + nNy * nLy + nNzLz) < 0)
+ {
+ aGrey.SetIndex(0);
+ }
+ else
+ {
+ const double fGrey
+ = nDotL / sqrt(static_cast<double>(nNx * nNx + nNy * nNy + nZ2));
+ aGrey.SetIndex(static_cast<sal_uInt8>(SAL_BOUND(fGrey, 0, 255)));
+ }
+
+ pWriteAcc->SetPixelOnData(pScanline, nX, aGrey);
+
+ if (nX < (nWidth - 1))
+ {
+ const long nNextX = pHMap[nX + 3];
+
+ nGrey11 = nGrey12;
+ nGrey12 = nGrey13;
+ nGrey13 = pReadAcc->GetPixel(pVMap[nY], nNextX).GetIndex();
+ nGrey21 = nGrey22;
+ nGrey22 = nGrey23;
+ nGrey23 = pReadAcc->GetPixel(pVMap[nY + 1], nNextX).GetIndex();
+ nGrey31 = nGrey32;
+ nGrey32 = nGrey33;
+ nGrey33 = pReadAcc->GetPixel(pVMap[nY + 2], nNextX).GetIndex();
+ }
+ }
+ }
+
+ delete[] pHMap;
+ delete[] pVMap;
+ 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 2933ebd21a66..0f8c7501d9b0 100644
--- a/vcl/source/gdi/bitmap4.cxx
+++ b/vcl/source/gdi/bitmap4.cxx
@@ -27,6 +27,7 @@
#include <vcl/BitmapSolarizeFilter.hxx>
#include <vcl/BitmapSepiaFilter.hxx>
#include <vcl/BitmapMosaicFilter.hxx>
+#include <vcl/BitmapEmbossGreyFilter.hxx>
#include <vcl/BitmapSepiaFilter.hxx>
#include <vcl/BitmapPopArtFilter.hxx>
@@ -108,7 +109,12 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
break;
case BmpFilter::EmbossGrey:
- bRet = ImplEmbossGrey( pFilterParam );
+ {
+ BitmapEx aBmpEx(*this);
+ bRet = BitmapFilter::Filter(aBmpEx, BitmapEmbossGreyFilter(pFilterParam->maEmbossAngles.mnAzimuthAngle100,
+ pFilterParam->maEmbossAngles.mnElevationAngle100));
+ *this = aBmpEx.GetBitmap();
+ }
break;
case BmpFilter::PopArt:
@@ -131,119 +137,6 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
return bRet;
}
-bool Bitmap::ImplEmbossGrey( const BmpFilterParam* pFilterParam )
-{
- bool bRet = ImplMakeGreyscales( 256 );
-
- if( bRet )
- {
- bRet = false;
-
- ScopedReadAccess pReadAcc(*this);
-
- if( pReadAcc )
- {
- Bitmap aNewBmp( GetSizePixel(), 8, &pReadAcc->GetPalette() );
- BitmapScopedWriteAccess pWriteAcc(aNewBmp);
-
- if( pWriteAcc )
- {
- BitmapColor aGrey( sal_uInt8(0) );
- const long nWidth = pWriteAcc->Width();
- const long nHeight = pWriteAcc->Height();
- long nGrey11, nGrey12, nGrey13;
- long nGrey21, nGrey22, nGrey23;
- long nGrey31, nGrey32, nGrey33;
- double fAzim = ( ( pFilterParam && pFilterParam->meFilter == BmpFilter::EmbossGrey ) ?
- ( pFilterParam->maEmbossAngles.mnAzimuthAngle100 * 0.01 ) : 0.0 ) * F_PI180;
- double fElev = ( ( pFilterParam && pFilterParam->meFilter == BmpFilter::EmbossGrey ) ?
- ( pFilterParam->maEmbossAngles.mnElevationAngle100 * 0.01 ) : 90.0 ) * F_PI180;
- long* pHMap = new long[ nWidth + 2 ];
- long* pVMap = new long[ nHeight + 2 ];
- long nX, nY, nNx, nNy, nDotL;
- const long nLx = FRound( cos( fAzim ) * cos( fElev ) * 255.0 );
- const long nLy = FRound( sin( fAzim ) * cos( fElev ) * 255.0 );
- const long nLz = FRound( sin( fElev ) * 255.0 );
- const auto nZ2 = ( ( 6 * 255 ) / 4 ) * ( ( 6 * 255 ) / 4 );
- const long nNzLz = ( ( 6 * 255 ) / 4 ) * nLz;
- const sal_uInt8 cLz = static_cast<sal_uInt8>(SAL_BOUND( nLz, 0, 255 ));
-
- // fill mapping tables
- pHMap[ 0 ] = 0;
- for( nX = 1; nX <= nWidth; nX++ )
- pHMap[ nX ] = nX - 1;
- pHMap[ nWidth + 1 ] = nWidth - 1;
-
- pVMap[ 0 ] = 0;
- for( nY = 1; nY <= nHeight; nY++ )
- pVMap[ nY ] = nY - 1;
- pVMap[ nHeight + 1 ] = nHeight - 1;
-
- for( nY = 0; nY < nHeight ; nY++ )
- {
- nGrey11 = pReadAcc->GetPixel( pVMap[ nY ], pHMap[ 0 ] ).GetIndex();
- nGrey12 = pReadAcc->GetPixel( pVMap[ nY ], pHMap[ 1 ] ).GetIndex();
- nGrey13 = pReadAcc->GetPixel( pVMap[ nY ], pHMap[ 2 ] ).GetIndex();
- nGrey21 = pReadAcc->GetPixel( pVMap[ nY + 1 ], pHMap[ 0 ] ).GetIndex();
- nGrey22 = pReadAcc->GetPixel( pVMap[ nY + 1 ], pHMap[ 1 ] ).GetIndex();
- nGrey23 = pReadAcc->GetPixel( pVMap[ nY + 1 ], pHMap[ 2 ] ).GetIndex();
- nGrey31 = pReadAcc->GetPixel( pVMap[ nY + 2 ], pHMap[ 0 ] ).GetIndex();
- nGrey32 = pReadAcc->GetPixel( pVMap[ nY + 2 ], pHMap[ 1 ] ).GetIndex();
- nGrey33 = pReadAcc->GetPixel( pVMap[ nY + 2 ], pHMap[ 2 ] ).GetIndex();
-
- Scanline pScanline = pWriteAcc->GetScanline(nY);
- for( nX = 0; nX < nWidth; nX++ )
- {
- nNx = nGrey11 + nGrey21 + nGrey31 - nGrey13 - nGrey23 - nGrey33;
- nNy = nGrey31 + nGrey32 + nGrey33 - nGrey11 - nGrey12 - nGrey13;
-
- if( !nNx && !nNy )
- aGrey.SetIndex( cLz );
- else if( ( nDotL = nNx * nLx + nNy * nLy +nNzLz ) < 0 )
- aGrey.SetIndex( 0 );
- else
- {
- const double fGrey = nDotL / sqrt( static_cast<double>(nNx * nNx + nNy * nNy + nZ2) );
- aGrey.SetIndex( static_cast<sal_uInt8>(SAL_BOUND( fGrey, 0, 255 )) );
- }
-
- pWriteAcc->SetPixelOnData( pScanline, nX, aGrey );
-
- if( nX < ( nWidth - 1 ) )
- {
- const long nNextX = pHMap[ nX + 3 ];
-
- nGrey11 = nGrey12; nGrey12 = nGrey13; nGrey13 = pReadAcc->GetPixel( pVMap[ nY ], nNextX ).GetIndex();
- nGrey21 = nGrey22; nGrey22 = nGrey23; nGrey23 = pReadAcc->GetPixel( pVMap[ nY + 1 ], nNextX ).GetIndex();
- nGrey31 = nGrey32; nGrey32 = nGrey33; nGrey33 = pReadAcc->GetPixel( pVMap[ nY + 2 ], nNextX ).GetIndex();
- }
- }
- }
-
- delete[] pHMap;
- delete[] pVMap;
- 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::ImplDuotoneFilter( const sal_uLong nColorOne, const sal_uLong nColorTwo )
{
const long nWidth = GetSizePixel().Width();
More information about the Libreoffice-commits
mailing list