[Libreoffice-commits] core.git: include/vcl vcl/Library_vcl.mk vcl/source
Chris Sherlock
chris.sherlock79 at gmail.com
Sun Apr 22 03:33:50 UTC 2018
include/vcl/BitmapSobelGreyFilter.hxx | 26 ++++
include/vcl/bitmap.hxx | 1
vcl/Library_vcl.mk | 1
vcl/source/bitmap/BitmapSobelGreyFilter.cxx | 166 ++++++++++++++++++++++++++++
vcl/source/gdi/bitmap4.cxx | 135 +---------------------
5 files changed, 199 insertions(+), 130 deletions(-)
New commits:
commit 0474be6d5527baab609b16846d6cb38ed89d47fc
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date: Thu Apr 19 20:36:10 2018 +1000
vcl: ImplSobelGrey() -> BitmapSobelGreyFilter
Change-Id: I2082d7e3b90172b4517ad0f4be75f85006eb5891
Reviewed-on: https://gerrit.libreoffice.org/53150
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/include/vcl/BitmapSobelGreyFilter.hxx b/include/vcl/BitmapSobelGreyFilter.hxx
new file mode 100644
index 000000000000..ac4cd9498d65
--- /dev/null
+++ b/include/vcl/BitmapSobelGreyFilter.hxx
@@ -0,0 +1,26 @@
+/* -*- 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_BITMAPSOBELGREYILTER_HXX
+#define INCLUDED_VCL_BITMAPSOBELGREYILTER_HXX
+
+#include <vcl/BitmapFilter.hxx>
+
+class VCL_DLLPUBLIC BitmapSobelGreyFilter : public BitmapFilter
+{
+public:
+ BitmapSobelGreyFilter() {}
+
+ virtual BitmapEx execute(BitmapEx const& rBitmapEx) override;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx
index b89b2004fed6..7f560e517ab0 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 ImplSobelGrey();
SAL_DLLPRIVATE bool ImplEmbossGrey( const BmpFilterParam* pFilterParam );
SAL_DLLPRIVATE bool ImplSolarize( const BmpFilterParam* pFilterParam );
SAL_DLLPRIVATE bool ImplSepia( const BmpFilterParam* pFilterParam );
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index ba26fb7fa91e..72aa7e122217 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -312,6 +312,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/graphic/UnoGraphicTransformer \
vcl/source/bitmap/bitmap \
vcl/source/bitmap/bitmapfilter \
+ vcl/source/bitmap/BitmapSobelGreyFilter \
vcl/source/bitmap/BitmapConvolutionMatrixFilter \
vcl/source/bitmap/BitmapMedianFilter \
vcl/source/bitmap/BitmapInterpolateScaleFilter \
diff --git a/vcl/source/bitmap/BitmapSobelGreyFilter.cxx b/vcl/source/bitmap/BitmapSobelGreyFilter.cxx
new file mode 100644
index 000000000000..450772dd2abe
--- /dev/null
+++ b/vcl/source/bitmap/BitmapSobelGreyFilter.cxx
@@ -0,0 +1,166 @@
+/* -*- 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/BitmapSobelGreyFilter.hxx>
+
+#include <bitmapwriteaccess.hxx>
+
+BitmapEx BitmapSobelGreyFilter::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();
+ const long nMask111 = -1, nMask121 = 0, nMask131 = 1;
+ const long nMask211 = -2, nMask221 = 0, nMask231 = 2;
+ const long nMask311 = -1, nMask321 = 0, nMask331 = 1;
+ const long nMask112 = 1, nMask122 = 2, nMask132 = 1;
+ const long nMask212 = 0, nMask222 = 0, nMask232 = 0;
+ const long nMask312 = -1, nMask322 = -2, nMask332 = -1;
+ long nGrey11, nGrey12, nGrey13;
+ long nGrey21, nGrey22, nGrey23;
+ long nGrey31, nGrey32, nGrey33;
+ long* pHMap = new long[nWidth + 2];
+ long* pVMap = new long[nHeight + 2];
+ long nX, nY, nSum1, nSum2;
+
+ // 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++)
+ {
+ nSum1 = nSum2 = 0;
+
+ nSum1 += nMask111 * nGrey11;
+ nSum2 += nMask112 * nGrey11;
+
+ nSum1 += nMask121 * nGrey12;
+ nSum2 += nMask122 * nGrey12;
+
+ nSum1 += nMask131 * nGrey13;
+ nSum2 += nMask132 * nGrey13;
+
+ nSum1 += nMask211 * nGrey21;
+ nSum2 += nMask212 * nGrey21;
+
+ nSum1 += nMask221 * nGrey22;
+ nSum2 += nMask222 * nGrey22;
+
+ nSum1 += nMask231 * nGrey23;
+ nSum2 += nMask232 * nGrey23;
+
+ nSum1 += nMask311 * nGrey31;
+ nSum2 += nMask312 * nGrey31;
+
+ nSum1 += nMask321 * nGrey32;
+ nSum2 += nMask322 * nGrey32;
+
+ nSum1 += nMask331 * nGrey33;
+ nSum2 += nMask332 * nGrey33;
+
+ nSum1 = static_cast<long>(
+ sqrt(static_cast<double>(nSum1 * nSum1 + nSum2 * nSum2)));
+
+ aGrey.SetIndex(~static_cast<sal_uInt8>(SAL_BOUND(nSum1, 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(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 a82498ed633a..edd420b1ea70 100644
--- a/vcl/source/gdi/bitmap4.cxx
+++ b/vcl/source/gdi/bitmap4.cxx
@@ -23,6 +23,7 @@
#include <vcl/BitmapSmoothenFilter.hxx>
#include <vcl/BitmapSharpenFilter.hxx>
#include <vcl/BitmapMedianFilter.hxx>
+#include <vcl/BitmapSobelGreyFilter.hxx>
#include <bitmapwriteaccess.hxx>
@@ -68,7 +69,11 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
break;
case BmpFilter::SobelGrey:
- bRet = ImplSobelGrey();
+ {
+ BitmapEx aBmpEx(*this);
+ bRet = BitmapFilter::Filter(aBmpEx, BitmapSobelGreyFilter());
+ *this = aBmpEx.GetBitmap();
+ }
break;
case BmpFilter::Solarize:
@@ -103,134 +108,6 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
return bRet;
}
-
-bool Bitmap::ImplSobelGrey()
-{
- 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();
- const long nMask111 = -1, nMask121 = 0, nMask131 = 1;
- const long nMask211 = -2, nMask221 = 0, nMask231 = 2;
- const long nMask311 = -1, nMask321 = 0, nMask331 = 1;
- const long nMask112 = 1, nMask122 = 2, nMask132 = 1;
- const long nMask212 = 0, nMask222 = 0, nMask232 = 0;
- const long nMask312 = -1, nMask322 = -2, nMask332 = -1;
- long nGrey11, nGrey12, nGrey13;
- long nGrey21, nGrey22, nGrey23;
- long nGrey31, nGrey32, nGrey33;
- long* pHMap = new long[ nWidth + 2 ];
- long* pVMap = new long[ nHeight + 2 ];
- long nX, nY, nSum1, nSum2;
-
- // 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++ )
- {
- nSum1 = nSum2 = 0;
-
- nSum1 += nMask111 * nGrey11;
- nSum2 += nMask112 * nGrey11;
-
- nSum1 += nMask121 * nGrey12;
- nSum2 += nMask122 * nGrey12;
-
- nSum1 += nMask131 * nGrey13;
- nSum2 += nMask132 * nGrey13;
-
- nSum1 += nMask211 * nGrey21;
- nSum2 += nMask212 * nGrey21;
-
- nSum1 += nMask221 * nGrey22;
- nSum2 += nMask222 * nGrey22;
-
- nSum1 += nMask231 * nGrey23;
- nSum2 += nMask232 * nGrey23;
-
- nSum1 += nMask311 * nGrey31;
- nSum2 += nMask312 * nGrey31;
-
- nSum1 += nMask321 * nGrey32;
- nSum2 += nMask322 * nGrey32;
-
- nSum1 += nMask331 * nGrey33;
- nSum2 += nMask332 * nGrey33;
-
- nSum1 = static_cast<long>(sqrt( static_cast<double>( nSum1 * nSum1 + nSum2 * nSum2 ) ));
- aGrey.SetIndex( ~static_cast<sal_uInt8>(SAL_BOUND( nSum1, 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::ImplEmbossGrey( const BmpFilterParam* pFilterParam )
{
bool bRet = ImplMakeGreyscales( 256 );
More information about the Libreoffice-commits
mailing list