diff options
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/vcl/bitmap.hxx | 2 | ||||
-rw-r--r-- | vcl/source/gdi/bitmap4.cxx | 43 |
2 files changed, 45 insertions, 0 deletions
diff --git a/vcl/inc/vcl/bitmap.hxx b/vcl/inc/vcl/bitmap.hxx index ea52068160c9..46448b32732c 100644 --- a/vcl/inc/vcl/bitmap.hxx +++ b/vcl/inc/vcl/bitmap.hxx @@ -139,6 +139,7 @@ enum BmpFilter BMP_FILTER_SEPIA = 6, BMP_FILTER_MOSAIC = 7, BMP_FILTER_POPART = 8, + BMP_FILTER_DUOTONE = 9, BMP_FILTER_UNKNOWN = 65535 }; @@ -402,6 +403,7 @@ public: SAL_DLLPRIVATE bool ImplSeparableBlurFilter( const double aRadius = 0.7 ); SAL_DLLPRIVATE bool ImplSeparableUnsharpenFilter( const double aRadius = 0.7 ); + SAL_DLLPRIVATE bool ImplDuotoneFilter( const sal_uLong nColorOne, sal_uLong nColorTwo ); SAL_DLLPRIVATE void ImplBlurContributions( const int aSize, const int aNumberOfContributions, double* pBlurVector, double*& pWeights, int*& pPixels, int*& pCount ); public: diff --git a/vcl/source/gdi/bitmap4.cxx b/vcl/source/gdi/bitmap4.cxx index be50269b9fd3..b5eb7d39ac59 100644 --- a/vcl/source/gdi/bitmap4.cxx +++ b/vcl/source/gdi/bitmap4.cxx @@ -38,6 +38,14 @@ // - Bitmap - // ---------- +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 (sal_uInt8) (color1+color2); +} + sal_Bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam, const Link* pProgress ) { sal_Bool bRet = sal_False; @@ -98,6 +106,10 @@ sal_Bool Bitmap::Filter( BmpFilter eFilter, const BmpFilterParam* pFilterParam, bRet = ImplPopArt( pFilterParam, pProgress ); break; + case( BMP_FILTER_DUOTONE ): + bRet = ImplDuotoneFilter( pFilterParam->mnProgressStart, pFilterParam->mnProgressEnd ); + break; + default: OSL_FAIL( "Bitmap::Convert(): Unsupported filter" ); break; @@ -1199,4 +1211,35 @@ bool Bitmap::ImplSeparableUnsharpenFilter(const double radius) { } + +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); + BitmapReadAccess* pReadAcc = AcquireReadAccess(); + BitmapWriteAccess* pWriteAcc = aResultBitmap.AcquireWriteAccess(); + 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( int x = 0; x < nWidth; x++ ) + { + for( int y = 0; y < nHeight; y++ ) + { + BitmapColor aColor = pReadAcc->GetColor( y, x ); + BitmapColor aResultColor( + lcl_getDuotoneColorComponent( aColor.GetRed(), aColorOne.GetRed(), aColorTwo.GetRed() ) , + lcl_getDuotoneColorComponent( aColor.GetGreen(), aColorOne.GetGreen(), aColorTwo.GetGreen() ) , + lcl_getDuotoneColorComponent( aColor.GetBlue(), aColorOne.GetBlue(), aColorTwo.GetBlue() ) ); + pWriteAcc->SetPixel( y, x, aResultColor ); + } + } + + ReleaseAccess( pWriteAcc ); + ReleaseAccess( pReadAcc ); + ImplAssignWithSize ( aResultBitmap ); + return true; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |