Kaydet (Commit) fefca920 authored tarafından Chris Sherlock's avatar Chris Sherlock Kaydeden (comit) Tomaž Vajngerl

vcl: ImplDuoTone() -> BitmapDuoToneFilter

Change-Id: If779cf4033948601997a932839eaa10a874de1b3
Reviewed-on: https://gerrit.libreoffice.org/53205Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst a9903c13
/* -*- 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_BITMAPDUOTONEFILTER_HXX
#define INCLUDED_VCL_BITMAPDUOTONEFILTER_HXX
#include <vcl/BitmapFilter.hxx>
class BitmapEx;
class VCL_DLLPUBLIC BitmapDuoToneFilter : public BitmapFilter
{
public:
BitmapDuoToneFilter(sal_uLong nColorOne, sal_uLong nColorTwo)
: mnColorOne(nColorOne)
, mnColorTwo(nColorTwo)
{
}
virtual BitmapEx execute(BitmapEx const& rBitmapEx) override;
private:
sal_uLong mnColorOne;
sal_uLong mnColorTwo;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -658,8 +658,6 @@ public: ...@@ -658,8 +658,6 @@ public:
SAL_DLLPRIVATE bool ImplDitherFloyd(); SAL_DLLPRIVATE bool ImplDitherFloyd();
SAL_DLLPRIVATE bool ImplDitherFloyd16(); SAL_DLLPRIVATE bool ImplDitherFloyd16();
SAL_DLLPRIVATE bool ImplDuotoneFilter( const sal_uLong nColorOne, sal_uLong nColorTwo );
public: public:
BitmapInfoAccess* AcquireInfoAccess(); BitmapInfoAccess* AcquireInfoAccess();
......
...@@ -318,6 +318,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ ...@@ -318,6 +318,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/bitmap/BitmapMosaicFilter \ vcl/source/bitmap/BitmapMosaicFilter \
vcl/source/bitmap/BitmapEmbossGreyFilter \ vcl/source/bitmap/BitmapEmbossGreyFilter \
vcl/source/bitmap/BitmapPopArtFilter \ vcl/source/bitmap/BitmapPopArtFilter \
vcl/source/bitmap/BitmapDuoToneFilter \
vcl/source/bitmap/BitmapConvolutionMatrixFilter \ vcl/source/bitmap/BitmapConvolutionMatrixFilter \
vcl/source/bitmap/BitmapMedianFilter \ vcl/source/bitmap/BitmapMedianFilter \
vcl/source/bitmap/BitmapInterpolateScaleFilter \ vcl/source/bitmap/BitmapInterpolateScaleFilter \
......
/* -*- 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: */
...@@ -30,20 +30,13 @@ ...@@ -30,20 +30,13 @@
#include <vcl/BitmapEmbossGreyFilter.hxx> #include <vcl/BitmapEmbossGreyFilter.hxx>
#include <vcl/BitmapSepiaFilter.hxx> #include <vcl/BitmapSepiaFilter.hxx>
#include <vcl/BitmapPopArtFilter.hxx> #include <vcl/BitmapPopArtFilter.hxx>
#include <vcl/BitmapDuoToneFilter.hxx>
#include <bitmapwriteaccess.hxx> #include <bitmapwriteaccess.hxx>
#include <memory> #include <memory>
#include <stdlib.h> #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 Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
{ {
bool bRet = false; bool bRet = false;
...@@ -126,7 +119,12 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam ) ...@@ -126,7 +119,12 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
break; break;
case BmpFilter::DuoTone: 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; break;
default: default:
...@@ -137,35 +135,4 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam ) ...@@ -137,35 +135,4 @@ bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam )
return bRet; 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment