diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2014-04-18 20:46:34 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2014-04-18 20:53:01 +0200 |
commit | 1139d618b8bc6ab823a96184bd0f0257980aad24 (patch) | |
tree | 763931577dbadbc3e6853950a3df099b1f69a4f4 /filter/source/msfilter/msdffimp.cxx | |
parent | 8afabd394214bb7c772c88b08ec3cadb56771cce (diff) |
handle strange brightness+contrast adjustment from msoffice (fdo#38410)
LO uses basically the formula "newpixel=(oldpixel-128)*contrast+128+brightness",
i.e. contrast is applied first. It looks like there's no "oficial" formula for this,
so a formula that applies brightness first would be ok too. MSO for some weird reason
apparently uses a formula that applies half of brightness before contrast and
half afterwards (insert funny political correctness or compromise joke here).
While the result is the same like with the LO formula if only either brightness
or contrast is adjusted, the result is different if both are involved. Just modify
the image using the MSO algorithm if this is the case.
Change-Id: I55fe8f395832685b90f024cf2f58b0797c1ba588
Diffstat (limited to 'filter/source/msfilter/msdffimp.cxx')
-rw-r--r-- | filter/source/msfilter/msdffimp.cxx | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx index eb2e91de3053..30d0ec669edd 100644 --- a/filter/source/msfilter/msdffimp.cxx +++ b/filter/source/msfilter/msdffimp.cxx @@ -3818,7 +3818,12 @@ SdrObject* SvxMSDffManager::ImportGraphic( SvStream& rSt, SfxItemSet& rSet, cons if ( nContrast || nBrightness || ( nGamma != 0x10000 ) || ( eDrawMode != GRAPHICDRAWMODE_STANDARD ) ) { - if ( ( rObjData.nSpFlags & SP_FOLESHAPE ) == 0 ) + // 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. + bool needsConversion = nContrast != 0 && nBrightness != 0; + if ( ( rObjData.nSpFlags & SP_FOLESHAPE ) == 0 && !needsConversion ) { if ( nBrightness ) rSet.Put( SdrGrafLuminanceItem( nBrightness ) ); @@ -3843,7 +3848,7 @@ SdrObject* SvxMSDffManager::ImportGraphic( SvStream& rSt, SfxItemSet& rSet, cons { BitmapEx aBitmapEx( aGraf.GetBitmapEx() ); if ( nBrightness || nContrast || ( nGamma != 0x10000 ) ) - aBitmapEx.Adjust( nBrightness, (sal_Int16)nContrast, 0, 0, 0, (double)nGamma / 0x10000, false ); + aBitmapEx.Adjust( nBrightness, (sal_Int16)nContrast, 0, 0, 0, (double)nGamma / 0x10000, false, true ); if ( eDrawMode == GRAPHICDRAWMODE_GREYS ) aBitmapEx.Convert( BMP_CONVERSION_8BIT_GREYS ); else if ( eDrawMode == GRAPHICDRAWMODE_MONO ) @@ -3857,7 +3862,7 @@ SdrObject* SvxMSDffManager::ImportGraphic( SvStream& rSt, SfxItemSet& rSet, cons { GDIMetaFile aGdiMetaFile( aGraf.GetGDIMetaFile() ); if ( nBrightness || nContrast || ( nGamma != 0x10000 ) ) - aGdiMetaFile.Adjust( nBrightness, (sal_Int16)nContrast, 0, 0, 0, (double)nGamma / 0x10000, false ); + aGdiMetaFile.Adjust( nBrightness, (sal_Int16)nContrast, 0, 0, 0, (double)nGamma / 0x10000, false, true ); if ( eDrawMode == GRAPHICDRAWMODE_GREYS ) aGdiMetaFile.Convert( MTF_CONVERSION_8BIT_GREYS ); else if ( eDrawMode == GRAPHICDRAWMODE_MONO ) |