diff options
author | Armin Le Grand <alg@apache.org> | 2013-11-05 16:13:12 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-11-06 11:46:04 +0000 |
commit | f120005ea41d59caf4b7d7f6017f3549d25b4287 (patch) | |
tree | 10fffb159ac615a2c3e8cdcd2c356c60cb0d61d3 | |
parent | 3476768dc52dac9ed10a204ffcf000cd042d8993 (diff) |
Resolves: #i123500# redefined ColorModifiers and ColorModifierStack...
redefined GraphicAttr to be expressed as primitives if needed, enhanced render
and export quality if graphic is modified using graphic attributes
(cherry picked from commit 1e79e8da3f8042f7d7bd94b2c9f03cff7545b05c)
Conflicts:
basegfx/inc/basegfx/color/bcolor.hxx
basegfx/inc/basegfx/color/bcolormodifier.hxx
basegfx/source/color/bcolormodifier.cxx
drawinglayer/inc/drawinglayer/primitive2d/graphicprimitivehelper2d.hxx
drawinglayer/inc/drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx
drawinglayer/inc/drawinglayer/primitive3d/modifiedcolorprimitive3d.hxx
drawinglayer/source/primitive2d/graphicprimitive2d.cxx
drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx
drawinglayer/source/primitive2d/modifiedcolorprimitive2d.cxx
drawinglayer/source/primitive3d/modifiedcolorprimitive3d.cxx
Change-Id: Ief2172efc9cc1b9838de48ec7f536c05573c7dc3
23 files changed, 1157 insertions, 240 deletions
diff --git a/basegfx/source/color/bcolormodifier.cxx b/basegfx/source/color/bcolormodifier.cxx index a53715b62304..c1f70267769c 100644 --- a/basegfx/source/color/bcolormodifier.cxx +++ b/basegfx/source/color/bcolormodifier.cxx @@ -23,47 +23,315 @@ namespace basegfx { - ::basegfx::BColor BColorModifier::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + BColorModifier::~BColorModifier() { - switch(meMode) + } +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + BColorModifier_gray::~BColorModifier_gray() + { + } + + bool BColorModifier_gray::operator==(const BColorModifier& rCompare) const + { + return 0 != dynamic_cast< const BColorModifier_gray* >(&rCompare); + } + + ::basegfx::BColor BColorModifier_gray::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + const double fLuminance(aSourceColor.luminance()); + + return ::basegfx::BColor(fLuminance, fLuminance, fLuminance); + } +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + BColorModifier_invert::~BColorModifier_invert() + { + } + + bool BColorModifier_invert::operator==(const BColorModifier& rCompare) const + { + return 0 != dynamic_cast< const BColorModifier_invert* >(&rCompare); + } + + ::basegfx::BColor BColorModifier_invert::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + return ::basegfx::BColor(1.0 - aSourceColor.getRed(), 1.0 - aSourceColor.getGreen(), 1.0 - aSourceColor.getBlue()); + } +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + BColorModifier_luminance_to_alpha::~BColorModifier_luminance_to_alpha() + { + } + + bool BColorModifier_luminance_to_alpha::operator==(const BColorModifier& rCompare) const + { + return 0 != dynamic_cast< const BColorModifier_luminance_to_alpha* >(&rCompare); + } + + ::basegfx::BColor BColorModifier_luminance_to_alpha::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + const double fAlpha(1.0 - ((aSourceColor.getRed() * 0.2125) + (aSourceColor.getGreen() * 0.7154) + (aSourceColor.getBlue() * 0.0721))); + + return ::basegfx::BColor(fAlpha, fAlpha, fAlpha); + } +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + BColorModifier_replace::~BColorModifier_replace() + { + } + + bool BColorModifier_replace::operator==(const BColorModifier& rCompare) const + { + const BColorModifier_replace* pCompare = dynamic_cast< const BColorModifier_replace* >(&rCompare); + + if(!pCompare) { - case BCOLORMODIFYMODE_INTERPOLATE : - { - return interpolate(maBColor, aSourceColor, mfValue); - } - case BCOLORMODIFYMODE_GRAY : - { - const double fLuminance(aSourceColor.luminance()); - return ::basegfx::BColor(fLuminance, fLuminance, fLuminance); - } - case BCOLORMODIFYMODE_BLACKANDWHITE : - { - const double fLuminance(aSourceColor.luminance()); - - if(fLuminance < mfValue) - { - return ::basegfx::BColor::getEmptyBColor(); - } - else - { - return ::basegfx::BColor(1.0, 1.0, 1.0); - } - } - case BCOLORMODIFYMODE_INVERT : - { - return ::basegfx::BColor(1.0 - aSourceColor.getRed(), 1.0 - aSourceColor.getGreen(), 1.0 - aSourceColor.getBlue()); - } - case BCOLORMODIFYMODE_LUMINANCE_TO_ALPHA: + return false; + } + + return getBColor() == pCompare->getBColor(); + } + + ::basegfx::BColor BColorModifier_replace::getModifiedColor(const ::basegfx::BColor& /*aSourceColor*/) const + { + return maBColor; + } +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + BColorModifier_interpolate::~BColorModifier_interpolate() + { + } + + bool BColorModifier_interpolate::operator==(const BColorModifier& rCompare) const + { + const BColorModifier_interpolate* pCompare = dynamic_cast< const BColorModifier_interpolate* >(&rCompare); + + if(!pCompare) + { + return false; + } + + return getBColor() == pCompare->getBColor() && getValue() == pCompare->getValue(); + } + + ::basegfx::BColor BColorModifier_interpolate::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + return interpolate(maBColor, aSourceColor, mfValue); + } +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + BColorModifier_black_and_white::~BColorModifier_black_and_white() + { + } + + bool BColorModifier_black_and_white::operator==(const BColorModifier& rCompare) const + { + const BColorModifier_black_and_white* pCompare = dynamic_cast< const BColorModifier_black_and_white* >(&rCompare); + + if(!pCompare) + { + return false; + } + + return getValue() == pCompare->getValue(); + } + + ::basegfx::BColor BColorModifier_black_and_white::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + const double fLuminance(aSourceColor.luminance()); + + if(fLuminance < mfValue) + { + return ::basegfx::BColor::getEmptyBColor(); + } + else + { + return ::basegfx::BColor(1.0, 1.0, 1.0); + } + } +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + BColorModifier_gamma::BColorModifier_gamma(double fValue) + : BColorModifier(), + mfValue(fValue), + mfInvValue(fValue), + mbUseIt(!basegfx::fTools::equal(fValue, 1.0) && basegfx::fTools::more(fValue, 0.0) && basegfx::fTools::lessOrEqual(fValue, 10.0)) + { + if(mbUseIt) + { + mfInvValue = 1.0 / mfValue; + } + } + + BColorModifier_gamma::~BColorModifier_gamma() + { + } + + bool BColorModifier_gamma::operator==(const BColorModifier& rCompare) const + { + const BColorModifier_gamma* pCompare = dynamic_cast< const BColorModifier_gamma* >(&rCompare); + + if(!pCompare) + { + return false; + } + + // getValue is sufficient, mfInvValue and mbUseIt are only helper values + return getValue() == pCompare->getValue(); + } + + ::basegfx::BColor BColorModifier_gamma::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + if(mbUseIt) + { + ::basegfx::BColor aRetval( + pow(aSourceColor.getRed(), mfInvValue), + pow(aSourceColor.getGreen(), mfInvValue), + pow(aSourceColor.getBlue(), mfInvValue)); + + aRetval.clamp(); + return aRetval; + } + else + { + return aSourceColor; + } + } +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + BColorModifier_RGBLuminanceContrast::BColorModifier_RGBLuminanceContrast(double fRed, double fGreen, double fBlue, double fLuminance, double fContrast) + : BColorModifier(), + mfRed(basegfx::clamp(fRed, -1.0, 1.0)), + mfGreen(basegfx::clamp(fGreen, -1.0, 1.0)), + mfBlue(basegfx::clamp(fBlue, -1.0, 1.0)), + mfLuminance(basegfx::clamp(fLuminance, -1.0, 1.0)), + mfContrast(basegfx::clamp(fContrast, -1.0, 1.0)), + mfContrastOff(1.0), + mfRedOff(0.0), + mfGreenOff(0.0), + mfBlueOff(0.0), + mbUseIt(false) + { + if(!basegfx::fTools::equalZero(mfRed) + || !basegfx::fTools::equalZero(mfGreen) + || !basegfx::fTools::equalZero(mfBlue) + || !basegfx::fTools::equalZero(mfLuminance) + || !basegfx::fTools::equalZero(mfContrast)) + { + // calculate slope + if(mfContrast >= 0.0) { - const double fAlpha(1.0 - ((aSourceColor.getRed() * 0.2125) + (aSourceColor.getGreen() * 0.7154) + (aSourceColor.getBlue() * 0.0721))); - return ::basegfx::BColor(fAlpha, fAlpha, fAlpha); + mfContrastOff = 128.0 / (128.0 - (mfContrast * 127.0)); } - default : // BCOLORMODIFYMODE_REPLACE + else { - return maBColor; + mfContrastOff = ( 128.0 + (mfContrast * 127.0)) / 128.0; } + + // calculate unified contrast offset + const double fPreparedContrastOff((128.0 - mfContrastOff * 128.0) / 255.0); + const double fCombinedOffset(mfLuminance + fPreparedContrastOff); + + // set full offsets + mfRedOff = mfRed + fCombinedOffset; + mfGreenOff = mfGreen + fCombinedOffset; + mfBlueOff = mfBlue + fCombinedOffset; + + mbUseIt = true; } } + + BColorModifier_RGBLuminanceContrast::~BColorModifier_RGBLuminanceContrast() + { + } + + bool BColorModifier_RGBLuminanceContrast::operator==(const BColorModifier& rCompare) const + { + const BColorModifier_RGBLuminanceContrast* pCompare = dynamic_cast< const BColorModifier_RGBLuminanceContrast* >(&rCompare); + + if(!pCompare) + { + return false; + } + + // no need to compare other values, these are just helpers + return getRed() == pCompare->getRed() + && getGreen() == pCompare->getGreen() + && getBlue() == pCompare->getBlue() + && getLuminance() == pCompare->getLuminance() + && getContrast() == pCompare->getContrast(); + } + + ::basegfx::BColor BColorModifier_RGBLuminanceContrast::getModifiedColor(const ::basegfx::BColor& aSourceColor) const + { + if(mbUseIt) + { + return basegfx::BColor( + basegfx::clamp(aSourceColor.getRed() * mfContrastOff + mfRedOff, 0.0, 1.0), + basegfx::clamp(aSourceColor.getGreen() * mfContrastOff + mfGreenOff, 0.0, 1.0), + basegfx::clamp(aSourceColor.getBlue() * mfContrastOff + mfBlueOff, 0.0, 1.0)); + } + else + { + return aSourceColor; + } + } +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + ::basegfx::BColor BColorModifierStack::getModifiedColor(const ::basegfx::BColor& rSource) const + { + if(maBColorModifiers.empty()) + { + return rSource; + } + + ::basegfx::BColor aRetval(rSource); + + for(sal_uInt32 a(maBColorModifiers.size()); a;) + { + a--; + aRetval = maBColorModifiers[a]->getModifiedColor(aRetval); + } + + return aRetval; + } } // end of namespace basegfx /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/drawinglayer/source/primitive2d/graphicprimitive2d.cxx b/drawinglayer/source/primitive2d/graphicprimitive2d.cxx index df69a36cdd94..cf1fd60c4690 100644 --- a/drawinglayer/source/primitive2d/graphicprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/graphicprimitive2d.cxx @@ -22,6 +22,8 @@ #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> #include <drawinglayer/primitive2d/maskprimitive2d.hxx> #include <drawinglayer/primitive2d/graphicprimitivehelper2d.hxx> +#include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx> +#include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx> #include <basegfx/matrix/b2dhommatrixtools.hxx> #include <vcl/svapp.hxx> #include <vcl/outdev.hxx> @@ -37,79 +39,151 @@ namespace drawinglayer { Primitive2DSequence aRetval; - if(255L != getGraphicAttr().GetTransparency()) + if(255L == getGraphicAttr().GetTransparency()) { - // do not apply mirroring from GraphicAttr to the Metafile by calling - // GetTransformedGraphic, this will try to mirror the Metafile using Scale() - // at the Metafile. This again calls Scale at the single MetaFile actions, - // but this implementation never worked. I reworked that implementations, - // but for security reasons i will try not to use it. - basegfx::B2DHomMatrix aTransform(getTransform()); - - if(getGraphicAttr().IsMirrored()) - { - // content needs mirroring - const bool bHMirr(getGraphicAttr().GetMirrorFlags() & BMP_MIRROR_HORZ); - const bool bVMirr(getGraphicAttr().GetMirrorFlags() & BMP_MIRROR_VERT); - - // mirror by applying negative scale to the unit primitive and - // applying the object transformation on it. - aTransform = basegfx::tools::createScaleB2DHomMatrix( - bHMirr ? -1.0 : 1.0, - bVMirr ? -1.0 : 1.0); - aTransform.translate( - bHMirr ? 1.0 : 0.0, - bVMirr ? 1.0 : 0.0); - aTransform = getTransform() * aTransform; - } + // content is invisible, done + return aRetval; + } + + // do not apply mirroring from GraphicAttr to the Metafile by calling + // GetTransformedGraphic, this will try to mirror the Metafile using Scale() + // at the Metafile. This again calls Scale at the single MetaFile actions, + // but this implementation never worked. I reworked that implementations, + // but for security reasons i will try not to use it. + basegfx::B2DHomMatrix aTransform(getTransform()); + + if(getGraphicAttr().IsMirrored()) + { + // content needs mirroring + const bool bHMirr(getGraphicAttr().GetMirrorFlags() & BMP_MIRROR_HORZ); + const bool bVMirr(getGraphicAttr().GetMirrorFlags() & BMP_MIRROR_VERT); + + // mirror by applying negative scale to the unit primitive and + // applying the object transformation on it. + aTransform = basegfx::tools::createScaleB2DHomMatrix( + bHMirr ? -1.0 : 1.0, + bVMirr ? -1.0 : 1.0); + aTransform.translate( + bHMirr ? 1.0 : 0.0, + bVMirr ? 1.0 : 0.0); + aTransform = getTransform() * aTransform; + } + + // Get transformed graphic. Suppress rotation and cropping, only filtering is needed + // here (and may be replaced later on). Cropping is handled below as mask primitive (if set). + // Also need to suppress mirroring, it is part of the transformation now (see above). + // Also move transparency handling to embedding to a UnifiedTransparencePrimitive2D; do + // that by remembering original transparency and applying that later if needed + GraphicAttr aSuppressGraphicAttr(getGraphicAttr()); + + aSuppressGraphicAttr.SetCrop(0, 0, 0, 0); + aSuppressGraphicAttr.SetRotation(0); + aSuppressGraphicAttr.SetMirrorFlags(0); + aSuppressGraphicAttr.SetTransparency(0); + + const GraphicObject& rGraphicObject = getGraphicObject(); + Graphic aTransformedGraphic(rGraphicObject.GetGraphic()); + const bool isBitmap(GRAPHIC_BITMAP == aTransformedGraphic.GetType() && !aTransformedGraphic.getSvgData().get()); + const bool isAdjusted(getGraphicAttr().IsAdjusted()); + const bool isDrawMode(GRAPHICDRAWMODE_STANDARD != getGraphicAttr().GetDrawMode()); + + if(isBitmap && (isAdjusted || isDrawMode)) + { + // the pure primitive solution with the color modifiers works well, too, but when + // it is a bitmap graphic the old modification currently is faster; so use it here + // instead of creating all as in create2DColorModifierEmbeddingsAsNeeded (see below). + // Still, crop, rotation, mirroring and transparency is handled by primitives already + // (see above). + // This could even be done when vector graphic, but we explicitely want to have the + // pure primitive solution for this; this will allow vector graphics to stay vector + // geraphics, independent from the color filtering stuff. This will enhance e.g. + // SVG and print quality while reducing data size at the same time. + // The other way around the old modifications when only used on already bitmap objects + // will not loose any quality. + aTransformedGraphic = rGraphicObject.GetTransformedGraphic(&aSuppressGraphicAttr); + + // reset GraphicAttr after use to not apply double + aSuppressGraphicAttr = GraphicAttr(); + } + + // create sub-content; helper takes care of correct handling of + // bitmap, svg or metafile content + aRetval = create2DDecompositionOfGraphic( + aTransformedGraphic, + aTransform); - // Get transformed graphic. Suppress rotation and cropping, only filtering is needed - // here (and may be replaced later on). Cropping is handled below as mask primitive (if set). - // Also need to suppress mirroring, it is part of the transformation now (see above). - GraphicAttr aSuppressGraphicAttr(getGraphicAttr()); - aSuppressGraphicAttr.SetCrop(0, 0, 0, 0); - aSuppressGraphicAttr.SetRotation(0); - aSuppressGraphicAttr.SetMirrorFlags(0); + if(!aRetval.getLength()) + { + // content is invisible, done + return aRetval; + } - const GraphicObject& rGraphicObject = getGraphicObject(); - const Graphic aTransformedGraphic(rGraphicObject.GetTransformedGraphic(&aSuppressGraphicAttr)); + if(isAdjusted || isDrawMode) + { + // embed to needed ModifiedColorPrimitive2D's if necessary. Do this for + // adjustments and draw mode specials + aRetval = create2DColorModifierEmbeddingsAsNeeded( + aRetval, + aSuppressGraphicAttr.GetDrawMode(), + basegfx::clamp(aSuppressGraphicAttr.GetLuminance() * 0.01, -1.0, 1.0), + basegfx::clamp(aSuppressGraphicAttr.GetContrast() * 0.01, -1.0, 1.0), + basegfx::clamp(aSuppressGraphicAttr.GetChannelR() * 0.01, -1.0, 1.0), + basegfx::clamp(aSuppressGraphicAttr.GetChannelG() * 0.01, -1.0, 1.0), + basegfx::clamp(aSuppressGraphicAttr.GetChannelB() * 0.01, -1.0, 1.0), + basegfx::clamp(aSuppressGraphicAttr.GetGamma(), 0.0, 10.0), + aSuppressGraphicAttr.IsInvert()); + + if(!aRetval.getLength()) + { + // content is invisible, done + return aRetval; + } + } - aRetval = create2DDecompositionOfGraphic( - aTransformedGraphic, - aTransform); + if(getGraphicAttr().IsTransparent()) + { + // check for transparency + const double fTransparency(basegfx::clamp(getGraphicAttr().GetTransparency() * (1.0 / 255.0), 0.0, 1.0)); - if(aRetval.getLength()) + if(!basegfx::fTools::equalZero(fTransparency)) { - // check for cropping - if(getGraphicAttr().IsCropped()) - { - // calculate scalings between real image size and logic object size. This - // is necessary since the crop values are relative to original bitmap size - const basegfx::B2DVector aObjectScale(aTransform * basegfx::B2DVector(1.0, 1.0)); - const basegfx::B2DVector aCropScaleFactor( - rGraphicObject.calculateCropScaling( - aObjectScale.getX(), - aObjectScale.getY(), - getGraphicAttr().GetLeftCrop(), - getGraphicAttr().GetTopCrop(), - getGraphicAttr().GetRightCrop(), - getGraphicAttr().GetBottomCrop())); - - // embed content in cropPrimitive - Primitive2DReference xPrimitive( - new CropPrimitive2D( - aRetval, - aTransform, - getGraphicAttr().GetLeftCrop() * aCropScaleFactor.getX(), - getGraphicAttr().GetTopCrop() * aCropScaleFactor.getY(), - getGraphicAttr().GetRightCrop() * aCropScaleFactor.getX(), - getGraphicAttr().GetBottomCrop() * aCropScaleFactor.getY())); - - aRetval = Primitive2DSequence(&xPrimitive, 1); - } + const Primitive2DReference aUnifiedTransparence( + new UnifiedTransparencePrimitive2D( + aRetval, + fTransparency)); + + aRetval = Primitive2DSequence(&aUnifiedTransparence, 1); } } + if(getGraphicAttr().IsCropped()) + { + // check for cropping + // calculate scalings between real image size and logic object size. This + // is necessary since the crop values are relative to original bitmap size + const basegfx::B2DVector aObjectScale(aTransform * basegfx::B2DVector(1.0, 1.0)); + const basegfx::B2DVector aCropScaleFactor( + rGraphicObject.calculateCropScaling( + aObjectScale.getX(), + aObjectScale.getY(), + getGraphicAttr().GetLeftCrop(), + getGraphicAttr().GetTopCrop(), + getGraphicAttr().GetRightCrop(), + getGraphicAttr().GetBottomCrop())); + + // embed content in cropPrimitive + Primitive2DReference xPrimitive( + new CropPrimitive2D( + aRetval, + aTransform, + getGraphicAttr().GetLeftCrop() * aCropScaleFactor.getX(), + getGraphicAttr().GetTopCrop() * aCropScaleFactor.getY(), + getGraphicAttr().GetRightCrop() * aCropScaleFactor.getX(), + getGraphicAttr().GetBottomCrop() * aCropScaleFactor.getY())); + + aRetval = Primitive2DSequence(&xPrimitive, 1); + } + return aRetval; } diff --git a/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx b/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx index 91c5cae75a5a..ca96b233c8d4 100644 --- a/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx +++ b/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx @@ -24,8 +24,10 @@ #include <drawinglayer/primitive2d/metafileprimitive2d.hxx> #include <drawinglayer/primitive2d/transformprimitive2d.hxx> #include <drawinglayer/primitive2d/maskprimitive2d.hxx> +#include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx> #include <basegfx/polygon/b2dpolygon.hxx> #include <basegfx/polygon/b2dpolygontools.hxx> +#include <basegfx/numeric/ftools.hxx> ////////////////////////////////////////////////////////////////////////////// // helper class for animated graphics @@ -324,4 +326,137 @@ namespace drawinglayer } // end of namespace primitive2d } // end of namespace drawinglayer +////////////////////////////////////////////////////////////////////////////// + +namespace drawinglayer +{ + namespace primitive2d + { + Primitive2DSequence create2DColorModifierEmbeddingsAsNeeded( + const Primitive2DSequence& rChildren, + GraphicDrawMode aGraphicDrawMode, + double fLuminance, + double fContrast, + double fRed, + double fGreen, + double fBlue, + double fGamma, + bool bInvert) + { + Primitive2DSequence aRetval; + + if(!rChildren.getLength()) + { + // no child content, done + return aRetval; + } + + // set child content as retval; that is what will be used as child content in all + // embeddings from here + aRetval = rChildren; + + if(GRAPHICDRAWMODE_WATERMARK == aGraphicDrawMode) + { + // this is solved by applying fixed values additionally to luminance + // and contrast, do it here and reset DrawMode to GRAPHICDRAWMODE_STANDARD + // original in svtools uses: + // #define WATERMARK_LUM_OFFSET 50 + // #define WATERMARK_CON_OFFSET -70 + fLuminance = basegfx::clamp(fLuminance + 0.5, -1.0, 1.0); + fContrast = basegfx::clamp(fContrast - 0.7, -1.0, 1.0); + aGraphicDrawMode = GRAPHICDRAWMODE_STANDARD; + } + + // DrawMode (GRAPHICDRAWMODE_WATERMARK already handled) + switch(aGraphicDrawMode) + { + case GRAPHICDRAWMODE_GREYS: + { + // convert to grey + const Primitive2DReference aPrimitiveGrey( + new ModifiedColorPrimitive2D( + aRetval, + basegfx::BColorModifierSharedPtr( + new basegfx::BColorModifier_gray()))); + + aRetval = Primitive2DSequence(&aPrimitiveGrey, 1); + break; + } + case GRAPHICDRAWMODE_MONO: + { + // convert to mono (black/white with threshold 0.5) + const Primitive2DReference aPrimitiveBlackAndWhite( + new ModifiedColorPrimitive2D( + aRetval, + basegfx::BColorModifierSharedPtr( + new basegfx::BColorModifier_black_and_white(0.5)))); + + aRetval = Primitive2DSequence(&aPrimitiveBlackAndWhite, 1); + break; + } + case GRAPHICDRAWMODE_WATERMARK: + { + OSL_ENSURE(false, "OOps, GRAPHICDRAWMODE_WATERMARK should already be handled (see above)"); + // fallthrough intended + } + default: // case GRAPHICDRAWMODE_STANDARD: + { + // nothing to do + break; + } + } + + // mnContPercent, mnLumPercent, mnRPercent, mnGPercent, mnBPercent + // handled in a single call + if(!basegfx::fTools::equalZero(fLuminance) + || !basegfx::fTools::equalZero(fContrast) + || !basegfx::fTools::equalZero(fRed) + || !basegfx::fTools::equalZero(fGreen) + || !basegfx::fTools::equalZero(fBlue)) + { + const Primitive2DReference aPrimitiveRGBLuminannceContrast( + new ModifiedColorPrimitive2D( + aRetval, + basegfx::BColorModifierSharedPtr( + new basegfx::BColorModifier_RGBLuminanceContrast( + fRed, + fGreen, + fBlue, + fLuminance, + fContrast)))); + + aRetval = Primitive2DSequence(&aPrimitiveRGBLuminannceContrast, 1); + } + + // gamma (boolean) + if(!basegfx::fTools::equal(fGamma, 1.0)) + { + const Primitive2DReference aPrimitiveGamma( + new ModifiedColorPrimitive2D( + aRetval, + basegfx::BColorModifierSharedPtr( + new basegfx::BColorModifier_gamma( + fGamma)))); + + aRetval = Primitive2DSequence(&aPrimitiveGamma, 1); + } + + // invert (boolean) + if(bInvert) + { + const Primitive2DReference aPrimitiveInvert( + new ModifiedColorPrimitive2D( + aRetval, + basegfx::BColorModifierSharedPtr( + new basegfx::BColorModifier_invert()))); + + aRetval = Primitive2DSequence(&aPrimitiveInvert, 1); + } + + return aRetval; + } + + } // end of namespace primitive2d +} // end of namespace drawinglayer + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/drawinglayer/source/primitive2d/metafileprimitive2d.cxx b/drawinglayer/source/primitive2d/metafileprimitive2d.cxx index d08a8ed89ffa..40913fac1cd4 100644 --- a/drawinglayer/source/primitive2d/metafileprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/metafileprimitive2d.cxx @@ -1057,7 +1057,9 @@ namespace rTargetHolders.Current().append( new drawinglayer::primitive2d::ModifiedColorPrimitive2D( aSubContent, - basegfx::BColorModifier(basegfx::BColor(0.0, 0.0, 0.0)))); + basegfx::BColorModifierSharedPtr( + new basegfx::BColorModifier_replace( + basegfx::BColor(0.0, 0.0, 0.0))))); } else // if(rPropertyHolders.Current().isRasterOpInvert()) { diff --git a/drawinglayer/source/primitive2d/modifiedcolorprimitive2d.cxx b/drawinglayer/source/primitive2d/modifiedcolorprimitive2d.cxx index 96af83a440db..ab664f2fdc72 100644 --- a/drawinglayer/source/primitive2d/modifiedcolorprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/modifiedcolorprimitive2d.cxx @@ -32,7 +32,7 @@ namespace drawinglayer { ModifiedColorPrimitive2D::ModifiedColorPrimitive2D( const Primitive2DSequence& rChildren, - const basegfx::BColorModifier& rColorModifier) + const basegfx::BColorModifierSharedPtr& rColorModifier) : GroupPrimitive2D(rChildren), maColorModifier(rColorModifier) { @@ -44,7 +44,17 @@ namespace drawinglayer { const ModifiedColorPrimitive2D& rCompare = (ModifiedColorPrimitive2D&)rPrimitive; - return (getColorModifier() == rCompare.getColorModifier()); + if(getColorModifier().get() == rCompare.getColorModifier().get()) + { + return true; + } + + if(!getColorModifier().get() || !rCompare.getColorModifier().get()) + { + return false; + } + + return *getColorModifier().get() == *rCompare.getColorModifier().get(); } return false; diff --git a/drawinglayer/source/primitive2d/shadowprimitive2d.cxx b/drawinglayer/source/primitive2d/shadowprimitive2d.cxx index 1499faa9f807..4fe7c8ebc2d8 100644 --- a/drawinglayer/source/primitive2d/shadowprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/shadowprimitive2d.cxx @@ -73,8 +73,13 @@ namespace drawinglayer if(getChildren().hasElements()) { // create a modifiedColorPrimitive containing the shadow color and the content - const basegfx::BColorModifier aBColorModifier(getShadowColor()); - const Primitive2DReference xRefA(new ModifiedColorPrimitive2D(getChildren(), aBColorModifier)); + const basegfx::BColorModifierSharedPtr aBColorModifier( + new basegfx::BColorModifier_replace( + getShadowColor())); + const Primitive2DReference xRefA( + new ModifiedColorPrimitive2D( + getChildren(), + aBColorModifier)); const Primitive2DSequence aSequenceB(&xRefA, 1L); // build transformed primitiveVector with shadow offset and add to target diff --git a/drawinglayer/source/primitive2d/texteffectprimitive2d.cxx b/drawinglayer/source/primitive2d/texteffectprimitive2d.cxx index 5dc453fb4cf5..254ac1b8b556 100644 --- a/drawinglayer/source/primitive2d/texteffectprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/texteffectprimitive2d.cxx @@ -84,20 +84,44 @@ namespace drawinglayer if(bDefaultTextColor) { // emboss/engrave in black, original forced to white - const basegfx::BColorModifier aBColorModifierToGray(basegfx::BColor(0.0)); - const Primitive2DReference xModifiedColor(new ModifiedColorPrimitive2D(getTextContent(), aBColorModifierToGray)); - aRetval[0] = Primitive2DReference(new TransformPrimitive2D(aTransform, Primitive2DSequence(&xModifiedColor, 1))); + const basegfx::BColorModifierSharedPtr aBColorModifierToGray( + new basegfx::BColorModifier_replace( + basegfx::BColor(0.0))); + const Primitive2DReference xModifiedColor( + new ModifiedColorPrimitive2D( + getTextContent(), + aBColorModifierToGray)); + + aRetval[0] = Primitive2DReference( + new TransformPrimitive2D( + aTransform, + Primitive2DSequence(&xModifiedColor, 1))); // add original, too - const basegfx::BColorModifier aBColorModifierToWhite(basegfx::BColor(1.0)); - aRetval[1] = Primitive2DReference(new ModifiedColorPrimitive2D(getTextContent(), aBColorModifierToWhite)); + const basegfx::BColorModifierSharedPtr aBColorModifierToWhite( + new basegfx::BColorModifier_replace( + basegfx::BColor(1.0))); + + aRetval[1] = Primitive2DReference( + new ModifiedColorPrimitive2D( + getTextContent(), + aBColorModifierToWhite)); } else { // emboss/engrave in gray, keep original's color - const basegfx::BColorModifier aBColorModifierToGray(basegfx::BColor(0.75)); // 192 - const Primitive2DReference xModifiedColor(new ModifiedColorPrimitive2D(getTextContent(), aBColorModifierToGray)); - aRetval[0] = Primitive2DReference(new TransformPrimitive2D(aTransform, Primitive2DSequence(&xModifiedColor, 1))); + const basegfx::BColorModifierSharedPtr aBColorModifierToGray( + new basegfx::BColorModifier_replace( + basegfx::BColor(0.75))); // 192 + const Primitive2DReference xModifiedColor( + new ModifiedColorPrimitive2D( + getTextContent(), + aBColorModifierToGray)); + + aRetval[0] = Primitive2DReference( + new TransformPrimitive2D( + aTransform, + Primitive2DSequence(&xModifiedColor, 1))); // add original, too aRetval[1] = Primitive2DReference(new GroupPrimitive2D(getTextContent())); @@ -144,8 +168,13 @@ namespace drawinglayer aRetval[7] = Primitive2DReference(new TransformPrimitive2D(aTransform, getTextContent())); // at last, place original over it, but force to white - const basegfx::BColorModifier aBColorModifierToWhite(basegfx::BColor(1.0, 1.0, 1.0)); - aRetval[8] = Primitive2DReference(new ModifiedColorPrimitive2D(getTextContent(), aBColorModifierToWhite)); + const basegfx::BColorModifierSharedPtr aBColorModifierToWhite( + new basegfx::BColorModifier_replace( + basegfx::BColor(1.0, 1.0, 1.0))); + aRetval[8] = Primitive2DReference( + new ModifiedColorPrimitive2D( + getTextContent(), + aBColorModifierToWhite)); break; } diff --git a/drawinglayer/source/primitive3d/modifiedcolorprimitive3d.cxx b/drawinglayer/source/primitive3d/modifiedcolorprimitive3d.cxx index daff0632d322..a01007b02ad1 100644 --- a/drawinglayer/source/primitive3d/modifiedcolorprimitive3d.cxx +++ b/drawinglayer/source/primitive3d/modifiedcolorprimitive3d.cxx @@ -32,7 +32,7 @@ namespace drawinglayer { ModifiedColorPrimitive3D::ModifiedColorPrimitive3D( const Primitive3DSequence& rChildren, - const basegfx::BColorModifier& rColorModifier) + const basegfx::BColorModifierSharedPtr& rColorModifier) : GroupPrimitive3D(rChildren), maColorModifier(rColorModifier) { @@ -44,7 +44,17 @@ namespace drawinglayer { const ModifiedColorPrimitive3D& rCompare = (ModifiedColorPrimitive3D&)rPrimitive; - return (maColorModifier == rCompare.maColorModifier); + if(getColorModifier().get() == rCompare.getColorModifier().get()) + { + return true; + } + + if(!getColorModifier().get() || !rCompare.getColorModifier().get()) + { + return false; + } + + return *getColorModifier().get() == *rCompare.getColorModifier().get(); } return false; diff --git a/drawinglayer/source/primitive3d/sdrdecompositiontools3d.cxx b/drawinglayer/source/primitive3d/sdrdecompositiontools3d.cxx index 667fae1f576e..c301f3b6cf36 100644 --- a/drawinglayer/source/primitive3d/sdrdecompositiontools3d.cxx +++ b/drawinglayer/source/primitive3d/sdrdecompositiontools3d.cxx @@ -247,8 +247,13 @@ namespace drawinglayer if(::com::sun::star::drawing::TextureKind2_LUMINANCE == aSdr3DObjectAttribute.getTextureKind()) { // use modified color primitive to force textures to gray - const basegfx::BColorModifier aBColorModifier(basegfx::BColor(), 0.0, basegfx::BCOLORMODIFYMODE_GRAY); - const Primitive3DReference xRef2(new ModifiedColorPrimitive3D(aRetval, aBColorModifier)); + const basegfx::BColorModifierSharedPtr aBColorModifier( + new basegfx::BColorModifier_gray()); + const Primitive3DReference xRef2( + new ModifiedColorPrimitive3D( + aRetval, + aBColorModifier)); + aRetval = Primitive3DSequence(&xRef2, 1L); } } diff --git a/drawinglayer/source/processor2d/vclprocessor2d.cxx b/drawinglayer/source/processor2d/vclprocessor2d.cxx index 1cd768e9a31a..7f2ab70ffc6e 100644 --- a/drawinglayer/source/processor2d/vclprocessor2d.cxx +++ b/drawinglayer/source/processor2d/vclprocessor2d.cxx @@ -688,9 +688,10 @@ namespace drawinglayer if(nBColorModifierStackCount) { - const basegfx::BColorModifier& rTopmostModifier = maBColorModifierStack.getBColorModifier(nBColorModifierStackCount - 1); + const basegfx::BColorModifierSharedPtr& rTopmostModifier = maBColorModifierStack.getBColorModifier(nBColorModifierStackCount - 1); + const basegfx::BColorModifier_replace* pReplacer = dynamic_cast< const basegfx::BColorModifier_replace* >(rTopmostModifier.get()); - if(basegfx::BCOLORMODIFYMODE_REPLACE == rTopmostModifier.getMode()) + if(pReplacer) { // the bitmap fill is in unified color, so we can replace it with // a single polygon fill. The form of the fill depends on tiling @@ -701,7 +702,7 @@ namespace drawinglayer aLocalPolyPolygon.transform(maCurrentTransformation); mpOutputDevice->SetLineColor(); - mpOutputDevice->SetFillColor(Color(rTopmostModifier.getBColor())); + mpOutputDevice->SetFillColor(Color(pReplacer->getBColor())); mpOutputDevice->DrawPolyPolygon(aLocalPolyPolygon); } else @@ -733,7 +734,7 @@ namespace drawinglayer { aTarget.transform(maCurrentTransformation); mpOutputDevice->SetLineColor(); - mpOutputDevice->SetFillColor(Color(rTopmostModifier.getBColor())); + mpOutputDevice->SetFillColor(Color(pReplacer->getBColor())); mpOutputDevice->DrawPolyPolygon(aTarget); } } diff --git a/drawinglayer/source/tools/converters.cxx b/drawinglayer/source/tools/converters.cxx index 76f37d5d730c..dfd0b8f9f3f5 100644 --- a/drawinglayer/source/tools/converters.cxx +++ b/drawinglayer/source/tools/converters.cxx @@ -114,14 +114,12 @@ namespace drawinglayer maContent.Erase(); // embed primitives to paint them black - static basegfx::BColorModifyMode aMode = basegfx::BCOLORMODIFYMODE_REPLACE; const primitive2d::Primitive2DReference xRef( new primitive2d::ModifiedColorPrimitive2D( aSequence, - basegfx::BColorModifier( - basegfx::BColor(0.0, 0.0, 0.0), - 0.5, - aMode))); + basegfx::BColorModifierSharedPtr( + new basegfx::BColorModifier_replace( + basegfx::BColor(0.0, 0.0, 0.0))))); const primitive2d::Primitive2DSequence xSeq(&xRef, 1); // render diff --git a/include/basegfx/color/bcolor.hxx b/include/basegfx/color/bcolor.hxx index 152984af646d..6533c6400123 100644 --- a/include/basegfx/color/bcolor.hxx +++ b/include/basegfx/color/bcolor.hxx @@ -190,18 +190,20 @@ namespace basegfx } // clamp color to [0.0..1.0] values in all three intensity components - void clamp() + BColor& clamp() { mfX = basegfx::clamp(mfX, 0.0, 1.0); mfY = basegfx::clamp(mfY, 0.0, 1.0); mfZ = basegfx::clamp(mfZ, 0.0, 1.0); + return *this; } - void invert() + BColor& invert() { mfX = 1.0 - mfX; mfY = 1.0 - mfY; mfZ = 1.0 - mfZ; + return *this; } static const BColor& getEmptyBColor() diff --git a/include/basegfx/color/bcolormodifier.hxx b/include/basegfx/color/bcolormodifier.hxx index b8fbd9a8e4d6..b174f4853f5e 100644 --- a/include/basegfx/color/bcolormodifier.hxx +++ b/include/basegfx/color/bcolormodifier.hxx @@ -20,73 +20,370 @@ #ifndef INCLUDED_BASEGFX_COLOR_BCOLORMODIFIER_HXX #define INCLUDED_BASEGFX_COLOR_BCOLORMODIFIER_HXX +#include <basegfx/basegfxdllapi.h> #include <basegfx/color/bcolor.hxx> +#include <boost/shared_ptr.hpp> +#include <boost/utility.hpp> #include <vector> -#include <basegfx/basegfxdllapi.h> ////////////////////////////////////////////////////////////////////////////// namespace basegfx { - /** Descriptor for type of color modification + /** base class to define color modifications + + The basic idea is to have instances of color modifiers where each + of these can be asked to get a modified version of a color. This + can be as easy as to return a fixed color, but may also do any + other computation based on the given source color and the local + algorythm to apply. + + This base implementation defines the abstract base class. Every + derivation offers another color blending effect, when needed with + parameters for that blending defined as members. + + As long as aw080 is not applied, an operator== is needed to implement + the operator== of the primitive based on this instances. + + For the exact definitions of the color blending applied refer to the + implementation of the method getModifiedColor + + BColorModifier is not copyable (no copy constructor, no assigment + operator); local values cannot be changed after construction. The + instances are cheap and the idea is to create them on demand. To + be able to reuse these as much as possible, a define for a + ::boost::shared_ptr named BColorModifierSharedPtr exists below. + All usages should handle instances of BColorModifier encapsulated + into these shared pointers. */ - enum BColorModifyMode + class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier : private boost::noncopyable { - BCOLORMODIFYMODE_REPLACE, // replace all color with local color - BCOLORMODIFYMODE_INTERPOLATE, // interpolate color between given and local with local value - BCOLORMODIFYMODE_GRAY, // convert color to gray - BCOLORMODIFYMODE_BLACKANDWHITE, // convert color to B&W, local value is treshhold - BCOLORMODIFYMODE_INVERT, // invert color - BCOLORMODIFYMODE_LUMINANCE_TO_ALPHA // convert color to alpha value (used for Svg Mask) + private: + protected: + // noone is allowed to incarnate the abstract base class + // except derivations + BColorModifier() {} + + public: + // noone should directly destroy it; all incarnations should be + // handled in a boost::shared_ptr of type BColorModifierSharedPtr + virtual ~BColorModifier(); + + // compare operator + virtual bool operator==(const BColorModifier& rCompare) const = 0; + bool operator!=(const BColorModifier& rCompare) const + { + return !(operator==(rCompare)); + } + + // compute modified color + virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const = 0; }; +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// - /** Class to hold a color, value and mode for a color modification. Color modification is - done calling the getModifiedColor() method +namespace basegfx +{ + /** convert color to gray */ - class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier + class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_gray : public BColorModifier { + private: protected: - ::basegfx::BColor maBColor; - double mfValue; - BColorModifyMode meMode; + public: + BColorModifier_gray() + : BColorModifier() + { + } + + virtual ~BColorModifier_gray(); + + // compare operator + virtual bool operator==(const BColorModifier& rCompare) const; + + // compute modified color + virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const; + }; +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// +namespace basegfx +{ + /** invert color + + returns a color where red green and blue are inverted using 1.0 - n + */ + class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_invert : public BColorModifier + { + private: + protected: public: - BColorModifier( - const ::basegfx::BColor& rBColor, - double fValue = 0.5, - BColorModifyMode eMode = BCOLORMODIFYMODE_REPLACE) - : maBColor(rBColor), - mfValue(fValue), - meMode(eMode) - {} - - // compare operator(s) - bool operator==(const BColorModifier& rCompare) const + BColorModifier_invert() + : BColorModifier() { - return (maBColor == rCompare.maBColor && mfValue == rCompare.mfValue && meMode == rCompare.meMode); } - bool operator!=(const BColorModifier& rCompare) const + virtual ~BColorModifier_invert(); + + // compare operator + virtual bool operator==(const BColorModifier& rCompare) const; + + // compute modified color + virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const; + }; +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + /** convert to alpha based on luminance + + returns a color where red green and blue are first weighted and added + to build a luminance value which is then inverted and used for red, + green and blue. The weights are r * 0.2125 + g * 0.7154 + b * 0.0721. + This derivation is used for the svg importer and does exactly what SVG + defines for this needed case. + */ + class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_luminance_to_alpha : public BColorModifier + { + private: + protected: + public: + BColorModifier_luminance_to_alpha() + : BColorModifier() + { + } + + virtual ~BColorModifier_luminance_to_alpha(); + + // compare operator + virtual bool operator==(const BColorModifier& rCompare) const; + + // compute modified color + virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const; + }; +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + /** replace color + + does not use the source color at all, but always returns the + given color, replacing everything. Useful e.g. for unified shadow + creation + */ + class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_replace : public BColorModifier + { + private: + ::basegfx::BColor maBColor; + + protected: + public: + BColorModifier_replace(const ::basegfx::BColor& rBColor) + : BColorModifier(), + maBColor(rBColor) + { + } + + virtual ~BColorModifier_replace(); + + // data access + const ::basegfx::BColor& getBColor() const { return maBColor; } + + // compare operator + virtual bool operator==(const BColorModifier& rCompare) const; + + // compute modified color + virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const; + }; +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + /** interpolate color + + returns an interpolated color mixed by the given value (f) in the range + [0.0 .. 1.0] and the given color (col) as follows: + + col * (1 - f) + aSourceColor * f + */ + class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_interpolate : public BColorModifier + { + private: + ::basegfx::BColor maBColor; + double mfValue; + + protected: + public: + BColorModifier_interpolate(const ::basegfx::BColor& rBColor, double fValue) + : BColorModifier(), + maBColor(rBColor), + mfValue(fValue) { - return !(operator==(rCompare)); } + virtual ~BColorModifier_interpolate(); + // data access const ::basegfx::BColor& getBColor() const { return maBColor; } double getValue() const { return mfValue; } - BColorModifyMode getMode() const { return meMode; } + + // compare operator + virtual bool operator==(const BColorModifier& rCompare) const; + + // compute modified color + virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const; + }; +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + /** convert color to black and white + + returns black when the luminance of the given color is less than + the given treshhold value in the range [0.0 .. 1.0], else white + */ + class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_black_and_white : public BColorModifier + { + private: + double mfValue; + + protected: + public: + BColorModifier_black_and_white(double fValue) + : BColorModifier(), + mfValue(fValue) + { + } + + virtual ~BColorModifier_black_and_white(); + + // data access + double getValue() const { return mfValue; } + + // compare operator + virtual bool operator==(const BColorModifier& rCompare) const; + + // compute modified color + virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const; + }; +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + /** gamma correction + + Input is a gamma correction value in the range ]0.0 .. 10.0]; the + color values get correted using + + col(r,g,b) = clamp(pow(col(r,g,b), 1.0 / gamma), 0.0, 1.0) + */ + class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_gamma : public BColorModifier + { + private: + double mfValue; + double mfInvValue; + + /// bitfield + bool mbUseIt : 1; + + protected: + public: + BColorModifier_gamma(double fValue); + + virtual ~BColorModifier_gamma(); + + // data access + double getValue() const { return mfValue; } + + // compare operator + virtual bool operator==(const BColorModifier& rCompare) const; + + // compute modified color + virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const; + }; +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + /** Red, Green, Blue, Luminance and Contrast correction + + Input are percent values from [-1.0 .. 1-0] which correspond to -100% to 100% + correction of Red, Green, Blue, Luminance or Contrast. 0.0 means no change of + the corresponding channel. All these are combined (but can be used single) to + - be able to cover a bigger change range utilizing the cmobination + - allow execution by a small, common, precalculated table + */ + class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_RGBLuminanceContrast : public BColorModifier + { + private: + double mfRed; + double mfGreen; + double mfBlue; + double mfLuminance; + double mfContrast; + + double mfContrastOff; + double mfRedOff; + double mfGreenOff; + double mfBlueOff; + + /// bitfield + bool mbUseIt : 1; + + protected: + public: + BColorModifier_RGBLuminanceContrast(double fRed, double fGreen, double fBlue, double fLuminance, double fContrast); + + virtual ~BColorModifier_RGBLuminanceContrast(); + + // data access + double getRed() const { return mfRed; } + double getGreen() const { return mfGreen; } + double getBlue() const { return mfBlue; } + double getLuminance() const { return mfLuminance; } + double getContrast() const { return mfContrast; } + + // compare operator + virtual bool operator==(const BColorModifier& rCompare) const; // compute modified color - ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const; + virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const; }; +} // end of namespace basegfx + +////////////////////////////////////////////////////////////////////////////// + +namespace basegfx +{ + /// typedef to allow working with shared instances of BColorModifier + /// for the whole mechanism + typedef ::boost::shared_ptr< BColorModifier > BColorModifierSharedPtr; - /** Class to hold a stack of BColorModifiers and to get the modified color with - applying all existing entry changes + /** Class to hold a stack of BColorModifierSharedPtrs and to get the modified color with + applying all existing entry changes as defined in the stack. Instances of BColorModifier + can be pushed and popped to change the stack. + + All references to BColorModifier members use shared pointers, thus instances of + BColorModifierStack can be copied by the default mechanisms if needed. */ class BASEGFX_DLLPUBLIC BColorModifierStack { protected: - ::std::vector< BColorModifier > maBColorModifiers; + ::std::vector< BColorModifierSharedPtr > maBColorModifiers; public: sal_uInt32 count() const @@ -94,33 +391,17 @@ namespace basegfx return maBColorModifiers.size(); } - const BColorModifier& getBColorModifier(sal_uInt32 nIndex) const + const BColorModifierSharedPtr& getBColorModifier(sal_uInt32 nIndex) const { OSL_ENSURE(nIndex < count(), "BColorModifierStack: Access out of range (!)"); return maBColorModifiers[nIndex]; } - ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& rSource) const - { - if(count()) - { - ::basegfx::BColor aRetval(rSource); - ::std::vector< BColorModifier >::const_iterator aEnd(maBColorModifiers.end()); - - while(aEnd != maBColorModifiers.begin()) - { - aRetval = (--aEnd)->getModifiedColor(aRetval); - } - - return aRetval; - } - else - { - return rSource; - } - } + // get the color in it's modified form by applying all existing BColorModifiers, + // from back to front (the newest first) + ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& rSource) const; - void push(const BColorModifier& rNew) + void push(const BColorModifierSharedPtr& rNew) { maBColorModifiers.push_back(rNew); } @@ -132,6 +413,8 @@ namespace basegfx }; } // end of namespace basegfx +////////////////////////////////////////////////////////////////////////////// + #endif // INCLUDED_BASEGFX_COLOR_BCOLORMODIFIER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/drawinglayer/primitive2d/graphicprimitivehelper2d.hxx b/include/drawinglayer/primitive2d/graphicprimitivehelper2d.hxx index 9755a2dd21de..00e11b3c412e 100644 --- a/include/drawinglayer/primitive2d/graphicprimitivehelper2d.hxx +++ b/include/drawinglayer/primitive2d/graphicprimitivehelper2d.hxx @@ -21,6 +21,7 @@ #include <drawinglayer/drawinglayerdllapi.h> #include <drawinglayer/primitive2d/baseprimitive2d.hxx> +#include <svtools/grfmgr.hxx> ////////////////////////////////////////////////////////////////////////////// // predefines @@ -44,6 +45,22 @@ namespace drawinglayer Primitive2DSequence create2DDecompositionOfGraphic( const Graphic& rGraphic, const basegfx::B2DHomMatrix& rTransform); + + /** Helper to embed given sequence of primitives to evtl. a stack + of ModifiedColorPrimitive2D's to get all the needed modifications + applied. + */ + Primitive2DSequence create2DColorModifierEmbeddingsAsNeeded( + const Primitive2DSequence& rChildren, + GraphicDrawMode aGraphicDrawMode = GRAPHICDRAWMODE_STANDARD, + double fLuminance = 0.0, // [-1.0 .. 1.0] + double fContrast = 0.0, // [-1.0 .. 1.0] + double fRed = 0.0, // [-1.0 .. 1.0] + double fGreen = 0.0, // [-1.0 .. 1.0] + double fBlue = 0.0, // [-1.0 .. 1.0] + double fGamma = 1.0, // ]0.0 .. 10.0] + bool bInvert = false); + } // end of namespace primitive2d } // end of namespace drawinglayer diff --git a/include/drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx b/include/drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx index 4dc0371d23c8..6f68a89fcbc5 100644 --- a/include/drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx +++ b/include/drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx @@ -17,6 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ + + #ifndef INCLUDED_DRAWINGLAYER_PRIMITIVE2D_MODIFIEDCOLORPRIMITIVE2D_HXX #define INCLUDED_DRAWINGLAYER_PRIMITIVE2D_MODIFIEDCOLORPRIMITIVE2D_HXX @@ -42,7 +44,7 @@ namespace drawinglayer For the possibilities of color modifications, please refer to the basegfx::BColorModifier definitions in basegfx. For processing there is tooling in basegfx to build a stack of - BColorModifiers to always be able to proccess the correct + BColorModifierSharedPtrs to always be able to proccess the correct colors. If a renderer does not handle this primitive, the content will @@ -52,16 +54,16 @@ namespace drawinglayer { private: /// The ColorModifier to use - basegfx::BColorModifier maColorModifier; + basegfx::BColorModifierSharedPtr maColorModifier; public: /// constructor ModifiedColorPrimitive2D( const Primitive2DSequence& rChildren, - const basegfx::BColorModifier& rColorModifier); + const basegfx::BColorModifierSharedPtr& rColorModifier); /// data read access - const basegfx::BColorModifier& getColorModifier() const { return maColorModifier; } + const basegfx::BColorModifierSharedPtr& getColorModifier() const { return maColorModifier; } /// compare operator virtual bool operator==(const BasePrimitive2D& rPrimitive) const; diff --git a/include/drawinglayer/primitive3d/modifiedcolorprimitive3d.hxx b/include/drawinglayer/primitive3d/modifiedcolorprimitive3d.hxx index f791213160aa..c07aa21169cf 100644 --- a/include/drawinglayer/primitive3d/modifiedcolorprimitive3d.hxx +++ b/include/drawinglayer/primitive3d/modifiedcolorprimitive3d.hxx @@ -42,16 +42,16 @@ namespace drawinglayer { private: /// The ColorModifier to use - basegfx::BColorModifier maColorModifier; + basegfx::BColorModifierSharedPtr maColorModifier; public: /// constructor ModifiedColorPrimitive3D( const Primitive3DSequence& rChildren, - const basegfx::BColorModifier& rColorModifier); + const basegfx::BColorModifierSharedPtr& rColorModifier); /// data read access - const basegfx::BColorModifier& getColorModifier() const { return maColorModifier; } + const basegfx::BColorModifierSharedPtr& getColorModifier() const { return maColorModifier; } /// compare operator virtual bool operator==(const BasePrimitive3D& rPrimitive) const; diff --git a/svgio/source/svgreader/svgmasknode.cxx b/svgio/source/svgreader/svgmasknode.cxx index 460b7f401245..30927c5c380f 100644 --- a/svgio/source/svgreader/svgmasknode.cxx +++ b/svgio/source/svgreader/svgmasknode.cxx @@ -261,10 +261,8 @@ namespace svgio const drawinglayer::primitive2d::Primitive2DReference xInverseMask( new drawinglayer::primitive2d::ModifiedColorPrimitive2D( aMaskTarget, - basegfx::BColorModifier( - basegfx::BColor(0.0, 0.0, 0.0), - 0.5, - basegfx::BCOLORMODIFYMODE_LUMINANCE_TO_ALPHA))); + basegfx::BColorModifierSharedPtr( + new basegfx::BColorModifier_luminance_to_alpha()))); aMaskTarget = drawinglayer::primitive2d::Primitive2DSequence(&xInverseMask, 1); } diff --git a/svx/source/sdr/contact/viewobjectcontact.cxx b/svx/source/sdr/contact/viewobjectcontact.cxx index b2443d6a381e..5cc4e2daa5da 100644 --- a/svx/source/sdr/contact/viewobjectcontact.cxx +++ b/svx/source/sdr/contact/viewobjectcontact.cxx @@ -328,8 +328,15 @@ namespace sdr if(isPrimitiveGhosted(rDisplayInfo)) { const basegfx::BColor aRGBWhite(1.0, 1.0, 1.0); - const basegfx::BColorModifier aBColorModifier(aRGBWhite, 0.5, basegfx::BCOLORMODIFYMODE_INTERPOLATE); - const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::ModifiedColorPrimitive2D(xRetval, aBColorModifier)); + const basegfx::BColorModifierSharedPtr aBColorModifier( + new basegfx::BColorModifier_interpolate( + aRGBWhite, + 0.5)); + const drawinglayer::primitive2d::Primitive2DReference xReference( + new drawinglayer::primitive2d::ModifiedColorPrimitive2D( + xRetval, + aBColorModifier)); + xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1); } } diff --git a/svx/source/sdr/contact/viewobjectcontactofe3d.cxx b/svx/source/sdr/contact/viewobjectcontactofe3d.cxx index 35183bfb7343..f929aec52d06 100644 --- a/svx/source/sdr/contact/viewobjectcontactofe3d.cxx +++ b/svx/source/sdr/contact/viewobjectcontactofe3d.cxx @@ -54,8 +54,15 @@ namespace sdr if(isPrimitiveGhosted(rDisplayInfo)) { const ::basegfx::BColor aRGBWhite(1.0, 1.0, 1.0); - const ::basegfx::BColorModifier aBColorModifier(aRGBWhite, 0.5, ::basegfx::BCOLORMODIFYMODE_INTERPOLATE); - const drawinglayer::primitive3d::Primitive3DReference xReference(new drawinglayer::primitive3d::ModifiedColorPrimitive3D(xRetval, aBColorModifier)); + const ::basegfx::BColorModifierSharedPtr aBColorModifier( + new basegfx::BColorModifier_interpolate( + aRGBWhite, + 0.5)); + const drawinglayer::primitive3d::Primitive3DReference xReference( + new drawinglayer::primitive3d::ModifiedColorPrimitive3D( + xRetval, + aBColorModifier)); + xRetval = drawinglayer::primitive3d::Primitive3DSequence(&xReference, 1); } diff --git a/svx/source/sdr/contact/viewobjectcontactofe3dscene.cxx b/svx/source/sdr/contact/viewobjectcontactofe3dscene.cxx index e9515f082762..196e2d7a7fda 100644 --- a/svx/source/sdr/contact/viewobjectcontactofe3dscene.cxx +++ b/svx/source/sdr/contact/viewobjectcontactofe3dscene.cxx @@ -108,8 +108,14 @@ namespace sdr if(isPrimitiveGhosted(rDisplayInfo)) { const ::basegfx::BColor aRGBWhite(1.0, 1.0, 1.0); - const ::basegfx::BColorModifier aBColorModifier(aRGBWhite, 0.5, ::basegfx::BCOLORMODIFYMODE_INTERPOLATE); - const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::ModifiedColorPrimitive2D(xRetval, aBColorModifier)); + const ::basegfx::BColorModifierSharedPtr aBColorModifier( + new basegfx::BColorModifier_interpolate( + aRGBWhite, + 0.5)); + const drawinglayer::primitive2d::Primitive2DReference xReference( + new drawinglayer::primitive2d::ModifiedColorPrimitive2D( + xRetval, + aBColorModifier)); xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1); } diff --git a/sw/source/ui/docvw/HeaderFooterWin.cxx b/sw/source/ui/docvw/HeaderFooterWin.cxx index 19c5b5e35185..600c42c97846 100644 --- a/sw/source/ui/docvw/HeaderFooterWin.cxx +++ b/sw/source/ui/docvw/HeaderFooterWin.cxx @@ -358,8 +358,12 @@ void SwHeaderFooterWin::Paint( const Rectangle& ) // TODO Ghost it all if needed drawinglayer::primitive2d::Primitive2DSequence aGhostedSeq( 1 ); double nFadeRate = double( m_nFadeRate ) / 100.0; + const basegfx::BColorModifierSharedPtr aBColorModifier( + new basegfx::BColorModifier_interpolate( + Color( COL_WHITE ).getBColor(), + 1.0 - nFadeRate)); aGhostedSeq[0] = drawinglayer::primitive2d::Primitive2DReference( new drawinglayer::primitive2d::ModifiedColorPrimitive2D( - aSeq, BColorModifier( Color( COL_WHITE ).getBColor(), 1.0 - nFadeRate, BCOLORMODIFYMODE_INTERPOLATE ) ) ); + aSeq, aBColorModifier ) ); pProcessor->process( aGhostedSeq ); delete pProcessor; diff --git a/sw/source/ui/docvw/PageBreakWin.cxx b/sw/source/ui/docvw/PageBreakWin.cxx index 507f3f556038..a30fb0bcecc9 100644 --- a/sw/source/ui/docvw/PageBreakWin.cxx +++ b/sw/source/ui/docvw/PageBreakWin.cxx @@ -188,8 +188,12 @@ void SwPageBreakWin::Paint( const Rectangle& ) Primitive2DSequence aGhostedSeq( 1 ); double nFadeRate = double( m_nFadeRate ) / 100.0; + const basegfx::BColorModifierSharedPtr aBColorModifier( + new basegfx::BColorModifier_interpolate( + Color( COL_WHITE ).getBColor(), + 1.0 - nFadeRate)); aGhostedSeq[0] = Primitive2DReference( new drawinglayer::primitive2d::ModifiedColorPrimitive2D( - aSeq, BColorModifier( Color( COL_WHITE ).getBColor(), 1.0 - nFadeRate, BCOLORMODIFYMODE_INTERPOLATE ) ) ); + aSeq, aBColorModifier ) ); // Create the processor and process the primitives const drawinglayer::geometry::ViewInformation2D aNewViewInfos; diff --git a/vcl/source/gdi/bitmapex.cxx b/vcl/source/gdi/bitmapex.cxx index ec0f052d9b61..6deb1db79208 100644 --- a/vcl/source/gdi/bitmapex.cxx +++ b/vcl/source/gdi/bitmapex.cxx @@ -1017,58 +1017,110 @@ BitmapEx BitmapEx::ModifyBitmapEx(const basegfx::BColorModifierStack& rBColorMod for(sal_uInt32 a(rBColorModifierStack.count()); a && !bDone; ) { - const basegfx::BColorModifier& rModifier = rBColorModifierStack.getBColorModifier(--a); + const basegfx::BColorModifierSharedPtr& rModifier = rBColorModifierStack.getBColorModifier(--a); + const basegfx::BColorModifier_replace* pReplace = dynamic_cast< const basegfx::BColorModifier_replace* >(rModifier.get()); - switch(rModifier.getMode()) + if(pReplace) { - case basegfx::BCOLORMODIFYMODE_REPLACE : + // complete replace + if(IsTransparent()) { - // complete replace - if(IsTransparent()) + // clear bitmap with dest color + if(aChangedBitmap.GetBitCount() <= 8) { - // clear bitmap with dest color - if(aChangedBitmap.GetBitCount() <= 8) - { - // do NOT use erase; for e.g. 8bit Bitmaps, the nearest color to the given - // erase color is determined and used -> this may be different from what is - // wanted here. Better create a new bitmap with the needed color explicitely - BitmapReadAccess* pReadAccess = aChangedBitmap.AcquireReadAccess(); - OSL_ENSURE(pReadAccess, "Got no Bitmap ReadAccess ?!?"); + // do NOT use erase; for e.g. 8bit Bitmaps, the nearest color to the given + // erase color is determined and used -> this may be different from what is + // wanted here. Better create a new bitmap with the needed color explicitely + BitmapReadAccess* pReadAccess = aChangedBitmap.AcquireReadAccess(); + OSL_ENSURE(pReadAccess, "Got no Bitmap ReadAccess ?!?"); - if(pReadAccess) - { - BitmapPalette aNewPalette(pReadAccess->GetPalette()); - aNewPalette[0] = BitmapColor(Color(rModifier.getBColor())); - aChangedBitmap = Bitmap( - aChangedBitmap.GetSizePixel(), - aChangedBitmap.GetBitCount(), - &aNewPalette); - delete pReadAccess; - } - } - else + if(pReadAccess) { - aChangedBitmap.Erase(Color(rModifier.getBColor())); + BitmapPalette aNewPalette(pReadAccess->GetPalette()); + aNewPalette[0] = BitmapColor(Color(pReplace->getBColor())); + aChangedBitmap = Bitmap( + aChangedBitmap.GetSizePixel(), + aChangedBitmap.GetBitCount(), + &aNewPalette); + delete pReadAccess; } } else { - // erase bitmap, caller will know to paint direct - aChangedBitmap.SetEmpty(); + aChangedBitmap.Erase(Color(pReplace->getBColor())); } - - bDone = true; - break; } + else + { + // erase bitmap, caller will know to paint direct + aChangedBitmap.SetEmpty(); + } + + bDone = true; + } + else + { + BitmapWriteAccess* pContent = aChangedBitmap.AcquireWriteAccess(); - default : // BCOLORMODIFYMODE_INTERPOLATE, BCOLORMODIFYMODE_GRAY, BCOLORMODIFYMODE_BLACKANDWHITE + if(pContent) { - BitmapWriteAccess* pContent = aChangedBitmap.AcquireWriteAccess(); + const double fConvertColor(1.0 / 255.0); + + if(pContent->HasPalette()) + { + const sal_uInt16 nCount(pContent->GetPaletteEntryCount()); + + for(sal_uInt16 b(0); b < nCount; b++) + { + const BitmapColor& rCol = pContent->GetPaletteColor(b); + const basegfx::BColor aBSource( + rCol.GetRed() * fConvertColor, + rCol.GetGreen() * fConvertColor, + rCol.GetBlue() * fConvertColor); + const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource)); + pContent->SetPaletteColor(b, BitmapColor(Color(aBDest))); + } + } + else if(BMP_FORMAT_24BIT_TC_BGR == pContent->GetScanlineFormat()) + { + for(sal_uInt32 y(0L); y < (sal_uInt32)pContent->Height(); y++) + { + Scanline pScan = pContent->GetScanline(y); - if(pContent) + for(sal_uInt32 x(0L); x < (sal_uInt32)pContent->Width(); x++) + { + const basegfx::BColor aBSource( + *(pScan + 2)* fConvertColor, + *(pScan + 1) * fConvertColor, + *pScan * fConvertColor); + const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource)); + *pScan++ = static_cast< sal_uInt8 >(aBDest.getBlue() * 255.0); + *pScan++ = static_cast< sal_uInt8 >(aBDest.getGreen() * 255.0); + *pScan++ = static_cast< sal_uInt8 >(aBDest.getRed() * 255.0); + } + } + } + else if(BMP_FORMAT_24BIT_TC_RGB == pContent->GetScanlineFormat()) { - const double fConvertColor(1.0 / 255.0); + for(sal_uInt32 y(0L); y < (sal_uInt32)pContent->Height(); y++) + { + Scanline pScan = pContent->GetScanline(y); + for(sal_uInt32 x(0L); x < (sal_uInt32)pContent->Width(); x++) + { + const basegfx::BColor aBSource( + *pScan * fConvertColor, + *(pScan + 1) * fConvertColor, + *(pScan + 2) * fConvertColor); + const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource)); + *pScan++ = static_cast< sal_uInt8 >(aBDest.getRed() * 255.0); + *pScan++ = static_cast< sal_uInt8 >(aBDest.getGreen() * 255.0); + *pScan++ = static_cast< sal_uInt8 >(aBDest.getBlue() * 255.0); + } + } + } + else + { for(sal_uInt32 y(0L); y < (sal_uInt32)pContent->Height(); y++) { for(sal_uInt32 x(0L); x < (sal_uInt32)pContent->Width(); x++) @@ -1078,16 +1130,14 @@ BitmapEx BitmapEx::ModifyBitmapEx(const basegfx::BColorModifierStack& rBColorMod (double)aBMCol.GetRed() * fConvertColor, (double)aBMCol.GetGreen() * fConvertColor, (double)aBMCol.GetBlue() * fConvertColor); - const basegfx::BColor aBDest(rModifier.getModifiedColor(aBSource)); + const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource)); pContent->SetPixel(y, x, BitmapColor(Color(aBDest))); } } - - delete pContent; } - break; + delete pContent; } } } |