KHTML
SVGFEDisplacementMapElement.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "config.h"
00022
00023 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
00024 #include "SVGFEDisplacementMapElement.h"
00025
00026 #include "SVGResourceFilter.h"
00027
00028 namespace WebCore {
00029
00030 SVGFEDisplacementMapElement::SVGFEDisplacementMapElement(const QualifiedName& tagName, Document* doc)
00031 : SVGFilterPrimitiveStandardAttributes(tagName, doc)
00032 , m_xChannelSelector(SVG_CHANNEL_A)
00033 , m_yChannelSelector(SVG_CHANNEL_A)
00034 , m_scale(0.0f)
00035 , m_filterEffect(0)
00036 {
00037 }
00038
00039 SVGFEDisplacementMapElement::~SVGFEDisplacementMapElement()
00040 {
00041 delete m_filterEffect;
00042 }
00043
00044 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDisplacementMapElement, String, String, string, In1, in1, SVGNames::inAttr, m_in1)
00045 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDisplacementMapElement, String, String, string, In2, in2, SVGNames::in2Attr, m_in2)
00046 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDisplacementMapElement, int, Enumeration, enumeration, XChannelSelector, xChannelSelector, SVGNames::xChannelSelectorAttr, m_xChannelSelector)
00047 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDisplacementMapElement, int, Enumeration, enumeration, YChannelSelector, yChannelSelector, SVGNames::yChannelSelectorAttr, m_yChannelSelector)
00048 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDisplacementMapElement, float, Number, number, Scale, scale, SVGNames::scaleAttr, m_scale)
00049
00050 SVGChannelSelectorType SVGFEDisplacementMapElement::stringToChannel(const String& key)
00051 {
00052 if (key == "R")
00053 return SVG_CHANNEL_R;
00054 else if (key == "G")
00055 return SVG_CHANNEL_G;
00056 else if (key == "B")
00057 return SVG_CHANNEL_B;
00058 else if (key == "A")
00059 return SVG_CHANNEL_A;
00060
00061 return SVG_CHANNEL_UNKNOWN;
00062 }
00063
00064 void SVGFEDisplacementMapElement::parseMappedAttribute(MappedAttribute* attr)
00065 {
00066 const String& value = attr->value();
00067 if (attr->name() == SVGNames::xChannelSelectorAttr)
00068 setXChannelSelectorBaseValue(stringToChannel(value));
00069 else if (attr->name() == SVGNames::yChannelSelectorAttr)
00070 setYChannelSelectorBaseValue(stringToChannel(value));
00071 else if (attr->name() == SVGNames::inAttr)
00072 setIn1BaseValue(value);
00073 else if (attr->name() == SVGNames::in2Attr)
00074 setIn2BaseValue(value);
00075 else if (attr->name() == SVGNames::scaleAttr)
00076 setScaleBaseValue(value.toFloat());
00077 else
00078 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
00079 }
00080
00081 SVGFEDisplacementMap* SVGFEDisplacementMapElement::filterEffect(SVGResourceFilter* filter) const
00082 {
00083 if (!m_filterEffect)
00084 m_filterEffect = new SVGFEDisplacementMap(filter);
00085
00086 m_filterEffect->setXChannelSelector((SVGChannelSelectorType) xChannelSelector());
00087 m_filterEffect->setYChannelSelector((SVGChannelSelectorType) yChannelSelector());
00088 m_filterEffect->setIn(in1());
00089 m_filterEffect->setIn2(in2());
00090 m_filterEffect->setScale(scale());
00091
00092 setStandardAttributes(m_filterEffect);
00093 return m_filterEffect;
00094 }
00095
00096 }
00097
00098 #endif // ENABLE(SVG)
00099
00100