summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2014-04-30 22:19:08 +0200
committerCaolán McNamara <caolanm@redhat.com>2014-05-01 09:24:21 +0000
commit75a839188d1cac5f0ac602e59462b32879d2242a (patch)
treefe2209e9768f7fa2dde575fafad113441ccb7f9c /oox
parentf295a442e18db2f3bb647bf502dd60d87823c19f (diff)
handle brightness+contrast from msoffice (bnc#875713)
This is the same like 1139d618b8bc6ab823a96184bd0f0257980aad24, for docx. (cherry picked from commit 893fe88469dec5b727d96f8ea1b4edb9e88288a7) Conflicts: oox/source/drawingml/fillproperties.cxx Change-Id: I1ef4e18444e8c60e9ae8f67249bcef1053f0d62d Reviewed-on: https://gerrit.libreoffice.org/9217 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'oox')
-rw-r--r--oox/source/drawingml/fillproperties.cxx26
1 files changed, 24 insertions, 2 deletions
diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx
index c96c77ad4f0b..99026a96869b 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -92,6 +92,18 @@ Reference< XGraphic > lclCheckAndApplyChangeColorTransform( const BlipFillProper
return xGraphic;
}
+Reference< XGraphic > applyBrightnessContrast( Reference< XGraphic > xGraphic, sal_Int32 brightness, sal_Int32 contrast )
+{
+ try
+ {
+ Reference< XGraphicTransformer > xTransformer( xGraphic, UNO_QUERY_THROW );
+ xGraphic = xTransformer->applyBrightnessContrast( xGraphic, brightness, contrast, true );
+ }
+ catch( Exception& )
+ {
+ }
+ return xGraphic;
+}
BitmapMode lclGetBitmapMode( sal_Int32 nToken )
@@ -501,12 +513,24 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap,
void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelper& rGraphicHelper, sal_Int32 nPhClr ) const
{
+ sal_Int16 nBrightness = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moBrightness.get( 0 ) / PER_PERCENT, -100, 100 );
+ sal_Int16 nContrast = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moContrast.get( 0 ) / PER_PERCENT, -100, 100 );
if( maBlipProps.mxGraphic.is() )
{
// created transformed graphic
Reference< XGraphic > xGraphic = lclCheckAndApplyDuotoneTransform( maBlipProps, maBlipProps.mxGraphic, rGraphicHelper, nPhClr );
xGraphic = lclCheckAndApplyChangeColorTransform( maBlipProps, xGraphic, rGraphicHelper, nPhClr );
+ // MSO uses a different algorithm for contrast+brightness, LO applies contrast before brightness,
+ // while MSO apparently applies half of brightness before contrast and half after. So if only
+ // contrast or brightness need to be altered, the result is the same, but if both are involved,
+ // there's no way to map that, so just force a conversion of the image.
+ if( nBrightness != 0 && nContrast != 0 )
+ {
+ xGraphic = applyBrightnessContrast( xGraphic, nBrightness, nContrast );
+ nBrightness = 0;
+ nContrast = 0;
+ }
rPropMap[ PROP_Graphic ] <<= xGraphic;
// do we still need to set GraphicURL as well? (TODO)
@@ -545,10 +569,8 @@ void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelpe
rPropMap[ PROP_GraphicColorMode ] <<= eColorMode;
// brightness and contrast
- sal_Int16 nBrightness = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moBrightness.get( 0 ) / PER_PERCENT, -100, 100 );
if( nBrightness != 0 )
rPropMap[ PROP_AdjustLuminance ] <<= nBrightness;
- sal_Int16 nContrast = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moContrast.get( 0 ) / PER_PERCENT, -100, 100 );
if( nContrast != 0 )
rPropMap[ PROP_AdjustContrast ] <<= nContrast;