diff options
author | Muthu Subramanian <sumuthu@suse.com> | 2013-07-17 13:13:30 +0530 |
---|---|---|
committer | Muthu Subramanian <sumuthu@suse.com> | 2013-07-17 13:13:30 +0530 |
commit | ad4604428dc98686d00637b06fe09078873c9acf (patch) | |
tree | a0a7ff54f6c18fb13fd556644266e413925e06a1 | |
parent | b8bcfade5731297dc64c02afd64ba0ea3b4f5132 (diff) |
n#820077: Import images with duotone filter.suse-4.0-8
Also, contains implementation for a simple duotone filter.
(Port from commit: 8b716072410bcfd252739fb953d5ac198e27a895)
-rw-r--r-- | offapi/com/sun/star/graphic/XGraphicTransformer.idl | 9 | ||||
-rw-r--r-- | oox/inc/oox/drawingml/fillproperties.hxx | 1 | ||||
-rw-r--r-- | oox/inc/oox/drawingml/fillpropertiesgroupcontext.hxx | 24 | ||||
-rw-r--r-- | oox/source/drawingml/fillproperties.cxx | 18 | ||||
-rw-r--r-- | oox/source/drawingml/fillpropertiesgroupcontext.cxx | 26 | ||||
-rw-r--r-- | svtools/source/graphic/transformer.cxx | 19 | ||||
-rw-r--r-- | svtools/source/graphic/transformer.hxx | 5 | ||||
-rw-r--r-- | vcl/inc/vcl/bitmap.hxx | 2 | ||||
-rw-r--r-- | vcl/source/gdi/bitmap4.cxx | 43 |
9 files changed, 146 insertions, 1 deletions
diff --git a/offapi/com/sun/star/graphic/XGraphicTransformer.idl b/offapi/com/sun/star/graphic/XGraphicTransformer.idl index 51a88e47aec1..df0b81ba76ec 100644 --- a/offapi/com/sun/star/graphic/XGraphicTransformer.idl +++ b/offapi/com/sun/star/graphic/XGraphicTransformer.idl @@ -42,6 +42,15 @@ interface XGraphicTransformer : ::com::sun::star::uno::XInterface com::sun::star::graphic::XGraphic colorChange( [ in ] com::sun::star::graphic::XGraphic In, [ in ] long ColorFrom, [ in ] byte tolerance, [ in ] long ColorTo, [ in ] byte AlphaTo ) raises( ::com::sun::star::lang::IllegalArgumentException ); + + /** applies Duotone effect + + @returns + The modified graphic + */ + com::sun::star::graphic::XGraphic applyDuotone( [ in ] com::sun::star::graphic::XGraphic In, + [ in ] long ColorOne, [ in ] long ColorTwo ) + raises( ::com::sun::star::lang::IllegalArgumentException ); }; } ; } ; } ; } ; diff --git a/oox/inc/oox/drawingml/fillproperties.hxx b/oox/inc/oox/drawingml/fillproperties.hxx index fb9aa849e92e..4a54fa327546 100644 --- a/oox/inc/oox/drawingml/fillproperties.hxx +++ b/oox/inc/oox/drawingml/fillproperties.hxx @@ -93,6 +93,7 @@ struct BlipFillProperties OptValue< sal_Int32 > moContrast; /// Contrast in the range [-100000,100000]. Color maColorChangeFrom; /// Start color of color transformation. Color maColorChangeTo; /// Destination color of color transformation. + Color maDuotoneColors[2]; /// Duotone Colors /** Overwrites all members that are explicitly set in rSourceProps. */ void assignUsed( const BlipFillProperties& rSourceProps ); diff --git a/oox/inc/oox/drawingml/fillpropertiesgroupcontext.hxx b/oox/inc/oox/drawingml/fillpropertiesgroupcontext.hxx index 81d8a6e0db20..2b6ab859a6cf 100644 --- a/oox/inc/oox/drawingml/fillpropertiesgroupcontext.hxx +++ b/oox/inc/oox/drawingml/fillpropertiesgroupcontext.hxx @@ -81,6 +81,30 @@ private: }; // ============================================================================ + +/** Context handler that imports the a:duotone element containing the colors + of a bitmap duotone transformation. */ +class DuotoneContext : public ::oox::core::ContextHandler +{ +public: + explicit DuotoneContext( + ::oox::core::ContextHandler& rParent, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& rxAttribs, + BlipFillProperties& rBlipProps ); + virtual ~DuotoneContext(); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL + createFastChildContext( + sal_Int32 nElement, + const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& rxAttribs ) + throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException ); + +private: + BlipFillProperties& mrBlipProps; + int mnColorIndex; +}; + + // ============================================================================ /** Context handler that imports the a:clrChange element containing the colors diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx index 78184aa0f1a0..c4f58a884acc 100644 --- a/oox/source/drawingml/fillproperties.cxx +++ b/oox/source/drawingml/fillproperties.cxx @@ -150,6 +150,8 @@ void BlipFillProperties::assignUsed( const BlipFillProperties& rSourceProps ) moContrast.assignIfUsed( rSourceProps.moContrast ); maColorChangeFrom.assignIfUsed( rSourceProps.maColorChangeFrom ); maColorChangeTo.assignIfUsed( rSourceProps.maColorChangeTo ); + maDuotoneColors[0].assignIfUsed( rSourceProps.maDuotoneColors[0] ); + maDuotoneColors[1].assignIfUsed( rSourceProps.maDuotoneColors[1] ); } // ============================================================================ @@ -373,9 +375,23 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap, // do not start complex graphic transformation if property is not supported... if( maBlipProps.mxGraphic.is() && rPropMap.supportsProperty( SHAPEPROP_FillBitmapUrl ) ) { + Reference< XGraphic > xGraphic = maBlipProps.mxGraphic; + if( maBlipProps.maDuotoneColors[0].isUsed() && maBlipProps.maDuotoneColors[1].isUsed() ) + { + sal_Int32 nColor1 = maBlipProps.maDuotoneColors[0].getColor( rGraphicHelper, nPhClr ); + sal_Int32 nColor2 = maBlipProps.maDuotoneColors[1].getColor( rGraphicHelper, nPhClr ); + try + { + Reference< XGraphicTransformer > xTransformer( maBlipProps.mxGraphic, UNO_QUERY_THROW ); + xGraphic = xTransformer->applyDuotone( maBlipProps.mxGraphic, nColor1, nColor2 ); + } + catch( Exception& ) + { + } + } // TODO: "rotate with shape" is not possible with our current core - OUString aGraphicUrl = rGraphicHelper.createGraphicObject( maBlipProps.mxGraphic ); + OUString aGraphicUrl = rGraphicHelper.createGraphicObject( xGraphic ); // push bitmap or named bitmap to property map if( !aGraphicUrl.isEmpty() && rPropMap.setProperty( SHAPEPROP_FillBitmapUrl, aGraphicUrl ) ) eFillStyle = FillStyle_BITMAP; diff --git a/oox/source/drawingml/fillpropertiesgroupcontext.cxx b/oox/source/drawingml/fillpropertiesgroupcontext.cxx index ad928cd5980f..b73fb2fc91b8 100644 --- a/oox/source/drawingml/fillpropertiesgroupcontext.cxx +++ b/oox/source/drawingml/fillpropertiesgroupcontext.cxx @@ -187,6 +187,9 @@ Reference< XFastContextHandler > BlipContext::createFastChildContext( case A_TOKEN( clrChange ): return new ColorChangeContext( *this, rxAttribs, mrBlipProps ); + case A_TOKEN( duotone ): + return new DuotoneContext( *this, rxAttribs, mrBlipProps ); + case A_TOKEN( lum ): mrBlipProps.moBrightness = aAttribs.getInteger( XML_bright ); mrBlipProps.moContrast = aAttribs.getInteger( XML_contrast ); @@ -197,6 +200,29 @@ Reference< XFastContextHandler > BlipContext::createFastChildContext( // ============================================================================ +DuotoneContext::DuotoneContext( ContextHandler& rParent, + const Reference< XFastAttributeList >& rxAttribs, BlipFillProperties& rBlipProps ) : + ContextHandler( rParent ), + mrBlipProps( rBlipProps ), + mnColorIndex( 0 ) +{ + AttributeList aAttribs( rxAttribs ); + mrBlipProps.maDuotoneColors[0].setUnused(); + mrBlipProps.maDuotoneColors[1].setUnused(); +} + +DuotoneContext::~DuotoneContext() +{ +} + +Reference< XFastContextHandler > DuotoneContext::createFastChildContext( + sal_Int32 /*nElement*/, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException) +{ + if( mnColorIndex < 2 ) + return new ColorValueContext( *this, mrBlipProps.maDuotoneColors[mnColorIndex++] ); + return 0; +} + BlipFillContext::BlipFillContext( ContextHandler& rParent, const Reference< XFastAttributeList >& rxAttribs, BlipFillProperties& rBlipProps ) : ContextHandler( rParent ), diff --git a/svtools/source/graphic/transformer.cxx b/svtools/source/graphic/transformer.cxx index 874bb346e59d..684c75c80451 100644 --- a/svtools/source/graphic/transformer.cxx +++ b/svtools/source/graphic/transformer.cxx @@ -141,6 +141,25 @@ uno::Reference< graphic::XGraphic > SAL_CALL GraphicTransformer::colorChange( return xRet; } +uno::Reference< graphic::XGraphic > SAL_CALL GraphicTransformer::applyDuotone( + const uno::Reference< graphic::XGraphic >& rxGraphic, sal_Int32 nColorOne, sal_Int32 nColorTwo ) + throw ( lang::IllegalArgumentException, uno::RuntimeException) +{ + const uno::Reference< uno::XInterface > xIFace( rxGraphic, uno::UNO_QUERY ); + ::Graphic aGraphic( *::unographic::Graphic::getImplementation( xIFace ) ); + + BitmapEx aBitmapEx( aGraphic.GetBitmapEx() ); + Bitmap aBitmap( aBitmapEx.GetBitmap() ); + BmpFilterParam aFilter( (sal_uLong) nColorOne, (sal_uLong) nColorTwo ); + aBitmap.Filter( BMP_FILTER_DUOTONE, &aFilter ); + aGraphic = ::Graphic( BitmapEx( aBitmap ) ); + + ::unographic::Graphic* pUnoGraphic = new ::unographic::Graphic(); + pUnoGraphic->init( aGraphic ); + uno::Reference< graphic::XGraphic > xRet( pUnoGraphic ); + return xRet; +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svtools/source/graphic/transformer.hxx b/svtools/source/graphic/transformer.hxx index 9ae4cffdda47..f6a24d161c92 100644 --- a/svtools/source/graphic/transformer.hxx +++ b/svtools/source/graphic/transformer.hxx @@ -48,6 +48,11 @@ class GraphicTransformer : public GraphicTransformer_UnoImplHelper1 sal_Int32 nColorFrom, sal_Int8 nTolerance, sal_Int32 nColorTo, sal_Int8 nAlphaTo ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > SAL_CALL applyDuotone( + const ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >& rGraphic, + sal_Int32 nColorOne, sal_Int32 nColorTwo ) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); + }; } 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: */ |