[Libreoffice-commits] core.git: 2 commits - offapi/com oox/source svtools/source writerfilter/source
LuboÅ¡ LuÅák
l.lunak at collabora.com
Wed Apr 30 14:40:57 PDT 2014
offapi/com/sun/star/graphic/XGraphicTransformer.idl | 10 +++++++
oox/source/drawingml/fillproperties.cxx | 27 +++++++++++++++++---
svtools/source/graphic/transformer.cxx | 17 ++++++++++++
svtools/source/graphic/transformer.hxx | 5 +++
writerfilter/source/dmapper/GraphicImport.cxx | 4 ++
5 files changed, 60 insertions(+), 3 deletions(-)
New commits:
commit 893fe88469dec5b727d96f8ea1b4edb9e88288a7
Author: LuboÅ¡ LuÅák <l.lunak at collabora.com>
Date: Wed Apr 30 22:19:08 2014 +0200
handle brightness+contrast from msoffice (bnc#875713)
This is the same like 1139d618b8bc6ab823a96184bd0f0257980aad24, for docx.
Change-Id: I1ef4e18444e8c60e9ae8f67249bcef1053f0d62d
diff --git a/offapi/com/sun/star/graphic/XGraphicTransformer.idl b/offapi/com/sun/star/graphic/XGraphicTransformer.idl
index d1a6ddf..dbd9c8d 100644
--- a/offapi/com/sun/star/graphic/XGraphicTransformer.idl
+++ b/offapi/com/sun/star/graphic/XGraphicTransformer.idl
@@ -51,6 +51,16 @@ interface XGraphicTransformer : ::com::sun::star::uno::XInterface
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 );
+
+ /** changes brightness/contrast
+
+ @param mso whether to use MSOffice brightness/contrast formula
+ @returns
+ The modified graphic
+ */
+ com::sun::star::graphic::XGraphic applyBrightnessContrast( [ in ] com::sun::star::graphic::XGraphic In,
+ [ in ] long brightness, [ in ] long contrast, [ in ] boolean mso )
+ raises( ::com::sun::star::lang::IllegalArgumentException );
};
} ; } ; } ; } ;
diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx
index 4eedd35..6ae078a 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 )
@@ -519,12 +531,23 @@ 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.setProperty(PROP_Graphic, xGraphic);
// do we still need to set GraphicURL as well? (TODO)
@@ -563,10 +586,8 @@ void GraphicProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelpe
rPropMap.setProperty(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.setProperty(PROP_AdjustLuminance, nBrightness);
- sal_Int16 nContrast = getLimitedValue< sal_Int16, sal_Int32 >( maBlipProps.moContrast.get( 0 ) / PER_PERCENT, -100, 100 );
if( nContrast != 0 )
rPropMap.setProperty(PROP_AdjustContrast, nContrast);
diff --git a/svtools/source/graphic/transformer.cxx b/svtools/source/graphic/transformer.cxx
index f7012ac..945d78b 100644
--- a/svtools/source/graphic/transformer.cxx
+++ b/svtools/source/graphic/transformer.cxx
@@ -159,6 +159,23 @@ uno::Reference< graphic::XGraphic > SAL_CALL GraphicTransformer::applyDuotone(
return xRet;
}
+uno::Reference< graphic::XGraphic > SAL_CALL GraphicTransformer::applyBrightnessContrast(
+ const uno::Reference< graphic::XGraphic >& rxGraphic, sal_Int32 nBrightness, sal_Int32 nContrast, sal_Bool mso )
+ throw ( lang::IllegalArgumentException, uno::RuntimeException, std::exception)
+{
+ const uno::Reference< uno::XInterface > xIFace( rxGraphic, uno::UNO_QUERY );
+ ::Graphic aGraphic( *::unographic::Graphic::getImplementation( xIFace ) );
+
+ BitmapEx aBitmapEx( aGraphic.GetBitmapEx() );
+ aBitmapEx.Adjust( nBrightness, nContrast, 0, 0, 0, 0, false, mso );
+ aGraphic = ::Graphic( aBitmapEx );
+
+ ::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 802164f..2dd137a 100644
--- a/svtools/source/graphic/transformer.hxx
+++ b/svtools/source/graphic/transformer.hxx
@@ -51,6 +51,11 @@ class GraphicTransformer : public GraphicTransformer_UnoImplHelper1
sal_Int32 nColorOne, sal_Int32 nColorTwo )
throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+ virtual ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > SAL_CALL applyBrightnessContrast(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >& rxGraphic,
+ sal_Int32 nBrightness, sal_Int32 nContrast, sal_Bool mso )
+ throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
+
};
}
commit 804da2a977989ba1f046847b9e00f00c83749e30
Author: LuboÅ¡ LuÅák <l.lunak at collabora.com>
Date: Wed Apr 30 21:52:28 2014 +0200
actually read brightness/contrast when reading docx (bnc#875713)
It's read for the shape in oox/ , but it didn't make it any further apparently.
Change-Id: I0885a675f72d63b3d262f1ef7e42f5d2e03588b6
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index 5b06b8c..a145905 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -656,6 +656,10 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
xShapeProps->getPropertyValue("ShadowTransparence") >>= m_pImpl->nShadowTransparence;
}
+ xShapeProps->getPropertyValue("GraphicColorMode") >>= m_pImpl->eColorMode;
+ xShapeProps->getPropertyValue("AdjustLuminance") >>= m_pImpl->nBrightness;
+ xShapeProps->getPropertyValue("AdjustContrast") >>= m_pImpl->nContrast;
+
// fdo#70457: transform XShape into a SwXTextGraphicObject only if there's no rotation
if ( nRotation == 0 )
m_xGraphicObject = createGraphicObject( aMediaProperties );
More information about the Libreoffice-commits
mailing list