summaryrefslogtreecommitdiff
path: root/vcl/source
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2018-04-22 22:33:40 +1000
committerTomaž Vajngerl <quikee@gmail.com>2018-05-13 08:28:43 +0200
commit1f6af5c409105562edf2a034f4841c1aeb5a38b5 (patch)
tree28b62c6b4807bf135c0a066d8ee85412548366e4 /vcl/source
parent48cf194a1bdd7625c58edd201a7d5191fcd0f934 (diff)
vcl: move Bitmap::MakeMonochrome() to BitmapMonochromeFilter
Change-Id: Iefe5be4349475a4aa0138534cf6bfe87ff7df245 Reviewed-on: https://gerrit.libreoffice.org/53280 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/source')
-rw-r--r--vcl/source/bitmap/BitmapMonochromeFilter.cxx101
-rw-r--r--vcl/source/bitmap/bitmap.cxx76
-rw-r--r--vcl/source/gdi/bitmap3.cxx7
-rw-r--r--vcl/source/gdi/bitmapex.cxx14
-rw-r--r--vcl/source/outdev/bitmap.cxx7
5 files changed, 122 insertions, 83 deletions
diff --git a/vcl/source/bitmap/BitmapMonochromeFilter.cxx b/vcl/source/bitmap/BitmapMonochromeFilter.cxx
new file mode 100644
index 000000000000..0bdb2cd09226
--- /dev/null
+++ b/vcl/source/bitmap/BitmapMonochromeFilter.cxx
@@ -0,0 +1,101 @@
+/* -*- 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/BitmapMonochromeFilter.hxx>
+#include <vcl/bitmapaccess.hxx>
+
+#include <bitmapwriteaccess.hxx>
+
+BitmapEx BitmapMonochromeFilter::execute(BitmapEx const& aBitmapEx)
+{
+ Bitmap aBitmap = aBitmapEx.GetBitmap();
+ Bitmap::ScopedReadAccess pReadAcc(aBitmap);
+ bool bRet = false;
+
+ if (pReadAcc)
+ {
+ Bitmap aNewBmp(aBitmap.GetSizePixel(), 1);
+ BitmapScopedWriteAccess pWriteAcc(aNewBmp);
+
+ if (pWriteAcc)
+ {
+ const BitmapColor aBlack(pWriteAcc->GetBestMatchingColor(COL_BLACK));
+ const BitmapColor aWhite(pWriteAcc->GetBestMatchingColor(COL_WHITE));
+ const long nWidth = pWriteAcc->Width();
+ const long nHeight = pWriteAcc->Height();
+
+ if (pReadAcc->HasPalette())
+ {
+ for (long nY = 0; nY < nHeight; nY++)
+ {
+ Scanline pScanline = pWriteAcc->GetScanline(nY);
+ Scanline pScanlineRead = pReadAcc->GetScanline(nY);
+ for (long nX = 0; nX < nWidth; nX++)
+ {
+ const sal_uInt8 cIndex = pReadAcc->GetIndexFromData(pScanlineRead, nX);
+ if (pReadAcc->GetPaletteColor(cIndex).GetLuminance() >= mcThreshold)
+ {
+ pWriteAcc->SetPixelOnData(pScanline, nX, aWhite);
+ }
+ else
+ {
+ pWriteAcc->SetPixelOnData(pScanline, nX, aBlack);
+ }
+ }
+ }
+ }
+ 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++)
+ {
+ if (pReadAcc->GetPixelFromData(pScanlineRead, nX).GetLuminance()
+ >= mcThreshold)
+ {
+ pWriteAcc->SetPixelOnData(pScanline, nX, aWhite);
+ }
+ else
+ {
+ pWriteAcc->SetPixelOnData(pScanline, nX, aBlack);
+ }
+ }
+ }
+ }
+
+ pWriteAcc.reset();
+ bRet = true;
+ }
+
+ pReadAcc.reset();
+
+ if (bRet)
+ {
+ const MapMode aMap(aBitmap.GetPrefMapMode());
+ const Size aSize(aBitmap.GetPrefSize());
+
+ aBitmap = aNewBmp;
+
+ aBitmap.SetPrefMapMode(aMap);
+ aBitmap.SetPrefSize(aSize);
+ }
+ }
+
+ if (bRet)
+ return BitmapEx(aBitmap);
+
+ return BitmapEx();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/bitmap/bitmap.cxx b/vcl/source/bitmap/bitmap.cxx
index b273bbfca983..23477b6e60ab 100644
--- a/vcl/source/bitmap/bitmap.cxx
+++ b/vcl/source/bitmap/bitmap.cxx
@@ -850,82 +850,6 @@ Bitmap Bitmap::CreateDisplayBitmap( OutputDevice* pDisplay )
return aDispBmp;
}
-bool Bitmap::MakeMonochrome(sal_uInt8 cThreshold)
-{
- ScopedReadAccess pReadAcc(*this);
- bool bRet = false;
-
- if( pReadAcc )
- {
- Bitmap aNewBmp( GetSizePixel(), 1 );
- BitmapScopedWriteAccess pWriteAcc(aNewBmp);
-
- if( pWriteAcc )
- {
- const BitmapColor aBlack( pWriteAcc->GetBestMatchingColor( COL_BLACK ) );
- const BitmapColor aWhite( pWriteAcc->GetBestMatchingColor( COL_WHITE ) );
- const long nWidth = pWriteAcc->Width();
- const long nHeight = pWriteAcc->Height();
-
- if( pReadAcc->HasPalette() )
- {
- for( long nY = 0; nY < nHeight; nY++ )
- {
- Scanline pScanline = pWriteAcc->GetScanline(nY);
- Scanline pScanlineRead = pReadAcc->GetScanline(nY);
- for( long nX = 0; nX < nWidth; nX++ )
- {
- const sal_uInt8 cIndex = pReadAcc->GetIndexFromData( pScanlineRead, nX );
- if( pReadAcc->GetPaletteColor( cIndex ).GetLuminance() >=
- cThreshold )
- {
- pWriteAcc->SetPixelOnData( pScanline, nX, aWhite );
- }
- else
- pWriteAcc->SetPixelOnData( pScanline, nX, aBlack );
- }
- }
- }
- 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++ )
- {
- if( pReadAcc->GetPixelFromData( pScanlineRead, nX ).GetLuminance() >=
- cThreshold )
- {
- pWriteAcc->SetPixelOnData( pScanline, nX, aWhite );
- }
- else
- pWriteAcc->SetPixelOnData( pScanline, nX, aBlack );
- }
- }
- }
-
- 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::GetSystemData( BitmapSystemData& rData ) const
{
bool bRet = false;
diff --git a/vcl/source/gdi/bitmap3.cxx b/vcl/source/gdi/bitmap3.cxx
index 8503db8fc2ca..e178a0c845b3 100644
--- a/vcl/source/gdi/bitmap3.cxx
+++ b/vcl/source/gdi/bitmap3.cxx
@@ -27,6 +27,7 @@
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLHelper.hxx>
#endif
+#include <vcl/BitmapMonochromeFilter.hxx>
#include <impoctree.hxx>
#include <BitmapScaleSuperFilter.hxx>
@@ -245,7 +246,11 @@ bool Bitmap::Convert( BmpConversion eConversion )
switch( eConversion )
{
case BmpConversion::N1BitThreshold:
- bRet = MakeMonochrome(128);
+ {
+ BitmapEx aBmpEx(*this);
+ bRet = BitmapFilter::Filter(aBmpEx, BitmapMonochromeFilter(128));
+ *this = aBmpEx.GetBitmap();
+ }
break;
case BmpConversion::N4BitGreys:
diff --git a/vcl/source/gdi/bitmapex.cxx b/vcl/source/gdi/bitmapex.cxx
index 4d31dbb1fa0a..c81b8b0fd446 100644
--- a/vcl/source/gdi/bitmapex.cxx
+++ b/vcl/source/gdi/bitmapex.cxx
@@ -34,6 +34,7 @@
#include <vcl/bitmapaccess.hxx>
#include <vcl/virdev.hxx>
#include <vcl/settings.hxx>
+#include <vcl/BitmapMonochromeFilter.hxx>
// BitmapEx::Create
#include <salbmp.hxx>
@@ -125,7 +126,9 @@ BitmapEx::BitmapEx( const Bitmap& rBmp, const Bitmap& rMask ) :
if( !!maMask && maMask.GetBitCount() != 1 )
{
SAL_WARN( "vcl", "BitmapEx: forced mask to monochrome");
- maMask.MakeMonochrome(255);
+ BitmapEx aMaskEx(maMask);
+ BitmapFilter::Filter(aMaskEx, BitmapMonochromeFilter(255));
+ maMask = aMaskEx.GetBitmap();
}
if (!!maBitmap && !!maMask && maBitmap.GetSizePixel() != maMask.GetSizePixel())
@@ -249,8 +252,13 @@ Bitmap BitmapEx::GetMask() const
{
Bitmap aRet( maMask );
- if( IsAlpha() )
- aRet.MakeMonochrome(255);
+ if (IsAlpha())
+ {
+
+ BitmapEx aMaskEx(aRet);
+ BitmapFilter::Filter(aMaskEx, BitmapMonochromeFilter(255));
+ aRet = aMaskEx.GetBitmap();
+ }
return aRet;
}
diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index e924a1f35f58..4108bc6f2cf8 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -32,6 +32,7 @@
#include <vcl/virdev.hxx>
#include <vcl/image.hxx>
#include <vcl/window.hxx>
+#include <vcl/BitmapMonochromeFilter.hxx>
#include <bmpfast.hxx>
#include <salgdi.hxx>
@@ -327,9 +328,9 @@ void OutputDevice::DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
// DRAWMODE_BLACK/WHITEBITMAP requires monochrome
// output, having alpha-induced grey levels is not
// acceptable.
- Bitmap aMask( aBmpEx.GetAlpha().GetBitmap() );
- aMask.MakeMonochrome(129);
- aBmpEx = BitmapEx( aColorBmp, aMask );
+ BitmapEx aMaskEx(aBmpEx.GetAlpha().GetBitmap());
+ BitmapFilter::Filter(aMaskEx, BitmapMonochromeFilter(129));
+ aBmpEx = BitmapEx(aColorBmp, aMaskEx.GetBitmap());
}
else
{