summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2018-04-20 21:13:55 +1000
committerTomaž Vajngerl <quikee@gmail.com>2018-04-23 07:01:42 +0200
commitfefca920f474b2eaff93db18169a208a74262f2b (patch)
treefb7abad7d15d24c16c5999eb72a8aa012a3b53a3 /vcl
parenta9903c130de4656b2624e0f2a94df42a0041d851 (diff)
vcl: ImplDuoTone() -> BitmapDuoToneFilter
Change-Id: If779cf4033948601997a932839eaa10a874de1b3 Reviewed-on: https://gerrit.libreoffice.org/53205 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/Library_vcl.mk1
-rw-r--r--vcl/source/bitmap/BitmapDuoToneFilter.cxx66
-rw-r--r--vcl/source/gdi/bitmap4.cxx47
3 files changed, 74 insertions, 40 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 42416b3a3008..6d21dc36302f 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -318,6 +318,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/bitmap/BitmapMosaicFilter \
vcl/source/bitmap/BitmapEmbossGreyFilter \
vcl/source/bitmap/BitmapPopArtFilter \
+ vcl/source/bitmap/BitmapDuoToneFilter \
vcl/source/bitmap/BitmapConvolutionMatrixFilter \
vcl/source/bitmap/BitmapMedianFilter \
vcl/source/bitmap/BitmapInterpolateScaleFilter \
diff --git a/vcl/source/bitmap/BitmapDuoToneFilter.cxx b/vcl/source/bitmap/BitmapDuoToneFilter.cxx
new file mode 100644
index 000000000000..1769081b9ccd
--- /dev/null
+++ b/vcl/source/bitmap/BitmapDuoToneFilter.cxx
@@ -0,0 +1,66 @@
+/* -*- 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/BitmapDuoToneFilter.hxx>
+#include <vcl/bitmapaccess.hxx>
+
+#include <bitmapwriteaccess.hxx>
+
+static inline sal_uInt8 lcl_getDuotoneColorComponent(sal_uInt8 base, sal_uInt16 color1,
+ sal_uInt16 color2)
+{
+ color2 = color2 * base / 0xFF;
+ color1 = color1 * (0xFF - base) / 0xFF;
+
+ return static_cast<sal_uInt8>(color1 + color2);
+}
+
+BitmapEx BitmapDuoToneFilter::execute(BitmapEx const& rBitmapEx)
+{
+ Bitmap aBitmap(rBitmapEx.GetBitmap());
+
+ const long nWidth = aBitmap.GetSizePixel().Width();
+ const long nHeight = aBitmap.GetSizePixel().Height();
+
+ Bitmap aResultBitmap(aBitmap.GetSizePixel(), 24);
+ Bitmap::ScopedReadAccess pReadAcc(aBitmap);
+ BitmapScopedWriteAccess pWriteAcc(aResultBitmap);
+ const BitmapColor aColorOne(static_cast<sal_uInt8>(mnColorOne >> 16),
+ static_cast<sal_uInt8>(mnColorOne >> 8),
+ static_cast<sal_uInt8>(mnColorOne));
+ const BitmapColor aColorTwo(static_cast<sal_uInt8>(mnColorTwo >> 16),
+ static_cast<sal_uInt8>(mnColorTwo >> 8),
+ static_cast<sal_uInt8>(mnColorTwo));
+
+ for (long x = 0; x < nWidth; x++)
+ {
+ for (long y = 0; y < nHeight; y++)
+ {
+ BitmapColor aColor = pReadAcc->GetColor(y, x);
+ sal_uInt8 nLuminance = aColor.GetLuminance();
+ BitmapColor aResultColor(
+ lcl_getDuotoneColorComponent(nLuminance, aColorOne.GetRed(), aColorTwo.GetRed()),
+ lcl_getDuotoneColorComponent(nLuminance, aColorOne.GetGreen(),
+ aColorTwo.GetGreen()),
+ lcl_getDuotoneColorComponent(nLuminance, aColorOne.GetBlue(), aColorTwo.GetBlue()));
+ pWriteAcc->SetPixel(y, x, aResultColor);
+ }
+ }
+
+ pWriteAcc.reset();
+ pReadAcc.reset();
+ aBitmap.ReassignWithSize(aResultBitmap);
+
+ return BitmapEx(aBitmap);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/gdi/bitmap4.cxx b/vcl/source/gdi/bitmap4.cxx
index 0f8c7501d9b0..3cf4475087b2 100644
--- a/vcl/source/gdi/bitmap4.cxx
+++ b/vcl/source/gdi/bitmap4.cxx
@@ -30,20 +30,13 @@
#include <vcl/BitmapEmbossGreyFilter.hxx>
#include <vcl/BitmapSepiaFilter.hxx>
#include <vcl/BitmapPopArtFilter.hxx>
+#include <vcl/BitmapDuoToneFilter.hxx>
#include <bitmapwriteaccess.hxx>
#include <memory>
#include <stdlib.h>
-static inline sal_uInt8 lcl_getDuotoneColorComponent( sal_uInt8 base, sal_uInt16 color1, sal_uInt16 color2 )
-{
- color2 = color2*base/0xFF;
- color1 = color1*(0xFF-base)/0xFF;
-
- return static_cast<sal_uInt8>(color1+color2);
-}
-
bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
{
bool bRet = false;
@@ -126,7 +119,12 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
break;
case BmpFilter::DuoTone:
- bRet = ImplDuotoneFilter( pFilterParam->mnProgressStart, pFilterParam->mnProgressEnd );
+ {
+ BitmapEx aBmpEx(*this);
+ bRet = BitmapFilter::Filter(aBmpEx, BitmapDuoToneFilter(pFilterParam->mnProgressStart,
+ pFilterParam->mnProgressEnd));
+ *this = aBmpEx.GetBitmap();
+ }
break;
default:
@@ -137,35 +135,4 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
return bRet;
}
-bool Bitmap::ImplDuotoneFilter( const sal_uLong nColorOne, const sal_uLong nColorTwo )
-{
- const long nWidth = GetSizePixel().Width();
- const long nHeight = GetSizePixel().Height();
-
- Bitmap aResultBitmap( GetSizePixel(), 24);
- ScopedReadAccess pReadAcc(*this);
- BitmapScopedWriteAccess pWriteAcc(aResultBitmap);
- const BitmapColor aColorOne( static_cast< sal_uInt8 >( nColorOne >> 16 ), static_cast< sal_uInt8 >( nColorOne >> 8 ), static_cast< sal_uInt8 >( nColorOne ) );
- const BitmapColor aColorTwo( static_cast< sal_uInt8 >( nColorTwo >> 16 ), static_cast< sal_uInt8 >( nColorTwo >> 8 ), static_cast< sal_uInt8 >( nColorTwo ) );
-
- for( long x = 0; x < nWidth; x++ )
- {
- for( long y = 0; y < nHeight; y++ )
- {
- BitmapColor aColor = pReadAcc->GetColor( y, x );
- sal_uInt8 luminance = aColor.GetLuminance();
- BitmapColor aResultColor(
- lcl_getDuotoneColorComponent( luminance, aColorOne.GetRed(), aColorTwo.GetRed() ) ,
- lcl_getDuotoneColorComponent( luminance, aColorOne.GetGreen(), aColorTwo.GetGreen() ) ,
- lcl_getDuotoneColorComponent( luminance, aColorOne.GetBlue(), aColorTwo.GetBlue() ) );
- pWriteAcc->SetPixel( y, x, aResultColor );
- }
- }
-
- pWriteAcc.reset();
- pReadAcc.reset();
- ReassignWithSize(aResultBitmap);
- return true;
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */