summaryrefslogtreecommitdiff
path: root/vcl/source/gdi
diff options
context:
space:
mode:
Diffstat (limited to 'vcl/source/gdi')
-rw-r--r--vcl/source/gdi/bitmap4.cxx43
1 files changed, 43 insertions, 0 deletions
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: */