[Libreoffice-commits] core.git: oox/source svtools/source

Muthu Subramanian sumuthu at collabora.com
Thu Oct 10 05:34:02 PDT 2013


 oox/source/drawingml/colorchoicecontext.cxx |    3 ++
 oox/source/drawingml/fillproperties.cxx     |   39 +++++++++++++++++-----------
 svtools/source/graphic/transformer.cxx      |    6 ++--
 3 files changed, 30 insertions(+), 18 deletions(-)

New commits:
commit efbf0b412bc76149b410d0cd17c7040513d4c203
Author: Muthu Subramanian <sumuthu at collabora.com>
Date:   Thu Oct 10 18:03:51 2013 +0530

    n#812793: clrChange applying for EMFs
    
    Also fixed alpha clrChanges.

diff --git a/oox/source/drawingml/colorchoicecontext.cxx b/oox/source/drawingml/colorchoicecontext.cxx
index b33b6dd..bec28b0 100644
--- a/oox/source/drawingml/colorchoicecontext.cxx
+++ b/oox/source/drawingml/colorchoicecontext.cxx
@@ -17,6 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include "oox/drawingml/drawingmltypes.hxx"
 #include "oox/drawingml/colorchoicecontext.hxx"
 #include "oox/helper/attributelist.hxx"
 #include "oox/drawingml/color.hxx"
@@ -83,6 +84,8 @@ void ColorValueContext::onStartElement( const AttributeList& rAttribs )
     switch( nElement )
     {
         case A_TOKEN( alpha ):
+            mrColor.addTransformation( nElement, rAttribs.getInteger( XML_val, 0 )*PER_PERCENT );
+            break;
         case A_TOKEN( alphaMod ):
         case A_TOKEN( alphaOff ):
         case A_TOKEN( blue ):
diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx
index dcac76b..4e6d8e1 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -71,6 +71,29 @@ Reference< XGraphic > lclCheckAndApplyDuotoneTransform( const BlipFillProperties
     return xGraphic;
 }
 
+Reference< XGraphic > lclCheckAndApplyChangeColorTransform( const BlipFillProperties &aBlipProps, Reference< XGraphic > xGraphic,
+                                                            const GraphicHelper& rGraphicHelper, const sal_Int32 nPhClr )
+{
+    if( aBlipProps.maColorChangeFrom.isUsed() && aBlipProps.maColorChangeTo.isUsed() )
+    {
+        sal_Int32 nFromColor = aBlipProps.maColorChangeFrom.getColor( rGraphicHelper, nPhClr );
+        sal_Int32 nToColor = aBlipProps.maColorChangeTo.getColor( rGraphicHelper, nPhClr );
+        if ( (nFromColor != nToColor) || aBlipProps.maColorChangeTo.hasTransparency() ) try
+        {
+            sal_Int16 nToTransparence = aBlipProps.maColorChangeTo.getTransparency();
+            sal_Int8 nToAlpha = static_cast< sal_Int8 >( (100 - nToTransparence) * 2.55 );
+            Reference< XGraphicTransformer > xTransformer( aBlipProps.mxGraphic, UNO_QUERY_THROW );
+            xGraphic = xTransformer->colorChange( xGraphic, nFromColor, 9, nToColor, nToAlpha );
+        }
+        catch( Exception& )
+        {
+        }
+    }
+    return xGraphic;
+}
+
+
+
 BitmapMode lclGetBitmapMode( sal_Int32 nToken )
 {
     OSL_ASSERT((nToken & sal_Int32(0xFFFF0000))==0);
@@ -480,21 +503,7 @@ void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelpe
     {
         // created transformed graphic
         Reference< XGraphic > xGraphic = lclCheckAndApplyDuotoneTransform( maBlipProps, maBlipProps.mxGraphic, rGraphicHelper, nPhClr );
-        if( maBlipProps.maColorChangeFrom.isUsed() && maBlipProps.maColorChangeTo.isUsed() )
-        {
-            sal_Int32 nFromColor = maBlipProps.maColorChangeFrom.getColor( rGraphicHelper, nPhClr );
-            sal_Int32 nToColor = maBlipProps.maColorChangeTo.getColor( rGraphicHelper, nPhClr );
-            if ( (nFromColor != nToColor) || maBlipProps.maColorChangeTo.hasTransparency() ) try
-            {
-                sal_Int16 nToTransparence = maBlipProps.maColorChangeTo.getTransparency();
-                sal_Int8 nToAlpha = static_cast< sal_Int8 >( (100 - nToTransparence) / 39.062 );   // ?!? correct ?!?
-                Reference< XGraphicTransformer > xTransformer( maBlipProps.mxGraphic, UNO_QUERY_THROW );
-                xGraphic = xTransformer->colorChange( maBlipProps.mxGraphic, nFromColor, 9, nToColor, nToAlpha );
-            }
-            catch( Exception& )
-            {
-            }
-        }
+        xGraphic = lclCheckAndApplyChangeColorTransform( maBlipProps, xGraphic, rGraphicHelper, nPhClr );
 
         rPropMap[ PROP_Graphic ] <<= xGraphic;
 
diff --git a/svtools/source/graphic/transformer.cxx b/svtools/source/graphic/transformer.cxx
index 0b0381b..30f07c7 100644
--- a/svtools/source/graphic/transformer.cxx
+++ b/svtools/source/graphic/transformer.cxx
@@ -86,7 +86,7 @@ uno::Reference< graphic::XGraphic > SAL_CALL GraphicTransformer::colorChange(
     BitmapColor aColorTo( static_cast< sal_uInt8 >( nColorTo ), static_cast< sal_uInt8 >( nColorTo >> 8 ), static_cast< sal_uInt8 >( nColorTo  >> 16 ) );
     const sal_uInt8 cIndexFrom = aColorFrom.GetBlueOrIndex();
 
-    if ( aGraphic.GetType() == GRAPHIC_BITMAP )
+    if ( aGraphic.GetType() == GRAPHIC_BITMAP || aGraphic.GetType() == GRAPHIC_GDIMETAFILE )
     {
         BitmapEx    aBitmapEx( aGraphic.GetBitmapEx() );
         Bitmap      aBitmap( aBitmapEx.GetBitmap() );
@@ -100,7 +100,7 @@ uno::Reference< graphic::XGraphic > SAL_CALL GraphicTransformer::colorChange(
         }
         else if ( aBitmapEx.IsTransparent() )
         {
-            if ( ( nAlphaTo == 0 ) || ( nAlphaTo == sal::static_int_cast<sal_Int8>(0xff) ) )
+            if ( nAlphaTo == sal::static_int_cast<sal_Int8>(0xff) )
             {
                 Bitmap aMask( aBitmapEx.GetMask() );
                 Bitmap aMask2( aBitmap.CreateMask( aColorFrom, nTolerance ) );
@@ -111,7 +111,7 @@ uno::Reference< graphic::XGraphic > SAL_CALL GraphicTransformer::colorChange(
             else
             {
                 AlphaMask aAlphaMask( aBitmapEx.GetMask() );
-                setAlpha( aBitmap, aAlphaMask, cIndexFrom, nAlphaTo );
+                setAlpha( aBitmap, aAlphaMask, cIndexFrom, 0xff - nAlphaTo );
                 aBitmap.Replace( aColorFrom, aColorTo, nTolerance );
                 aGraphic = ::Graphic( BitmapEx( aBitmap, aAlphaMask ) );
             }


More information about the Libreoffice-commits mailing list