summaryrefslogtreecommitdiff
path: root/vcl/source/gdi/bitmap4.cxx
diff options
context:
space:
mode:
authorMuthu Subramanian <sumuthu@suse.com>2013-07-17 13:13:30 +0530
committerMuthu Subramanian <sumuthu@suse.com>2013-07-17 13:13:30 +0530
commitad4604428dc98686d00637b06fe09078873c9acf (patch)
treea0a7ff54f6c18fb13fd556644266e413925e06a1 /vcl/source/gdi/bitmap4.cxx
parentb8bcfade5731297dc64c02afd64ba0ea3b4f5132 (diff)
n#820077: Import images with duotone filter.suse-4.0-8
Also, contains implementation for a simple duotone filter. (Port from commit: 8b716072410bcfd252739fb953d5ac198e27a895)
Diffstat (limited to 'vcl/source/gdi/bitmap4.cxx')
-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: */