File indexing completed on 2024-04-21 14:58:22
0001 /* 0002 Copyright (C) 2006 Oliver Hunt <oliver@nerget.com> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #if ENABLE(SVG) && ENABLE(SVG_FILTERS) 0021 #include "SVGFEDisplacementMapElement.h" 0022 0023 #include "SVGResourceFilter.h" 0024 0025 namespace WebCore 0026 { 0027 0028 SVGFEDisplacementMapElement::SVGFEDisplacementMapElement(const QualifiedName &tagName, Document *doc) 0029 : SVGFilterPrimitiveStandardAttributes(tagName, doc) 0030 , m_xChannelSelector(SVG_CHANNEL_A) 0031 , m_yChannelSelector(SVG_CHANNEL_A) 0032 , m_scale(0.0f) 0033 , m_filterEffect(0) 0034 { 0035 } 0036 0037 SVGFEDisplacementMapElement::~SVGFEDisplacementMapElement() 0038 { 0039 delete m_filterEffect; 0040 } 0041 0042 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDisplacementMapElement, String, String, string, In1, in1, SVGNames::inAttr, m_in1) 0043 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDisplacementMapElement, String, String, string, In2, in2, SVGNames::in2Attr, m_in2) 0044 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDisplacementMapElement, int, Enumeration, enumeration, XChannelSelector, xChannelSelector, SVGNames::xChannelSelectorAttr, m_xChannelSelector) 0045 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDisplacementMapElement, int, Enumeration, enumeration, YChannelSelector, yChannelSelector, SVGNames::yChannelSelectorAttr, m_yChannelSelector) 0046 ANIMATED_PROPERTY_DEFINITIONS(SVGFEDisplacementMapElement, float, Number, number, Scale, scale, SVGNames::scaleAttr, m_scale) 0047 0048 SVGChannelSelectorType SVGFEDisplacementMapElement::stringToChannel(const String &key) 0049 { 0050 if (key == "R") { 0051 return SVG_CHANNEL_R; 0052 } else if (key == "G") { 0053 return SVG_CHANNEL_G; 0054 } else if (key == "B") { 0055 return SVG_CHANNEL_B; 0056 } else if (key == "A") { 0057 return SVG_CHANNEL_A; 0058 } 0059 0060 return SVG_CHANNEL_UNKNOWN; 0061 } 0062 0063 void SVGFEDisplacementMapElement::parseMappedAttribute(MappedAttribute *attr) 0064 { 0065 const String &value = attr->value(); 0066 if (attr->name() == SVGNames::xChannelSelectorAttr) { 0067 setXChannelSelectorBaseValue(stringToChannel(value)); 0068 } else if (attr->name() == SVGNames::yChannelSelectorAttr) { 0069 setYChannelSelectorBaseValue(stringToChannel(value)); 0070 } else if (attr->name() == SVGNames::inAttr) { 0071 setIn1BaseValue(value); 0072 } else if (attr->name() == SVGNames::in2Attr) { 0073 setIn2BaseValue(value); 0074 } else if (attr->name() == SVGNames::scaleAttr) { 0075 setScaleBaseValue(value.toFloat()); 0076 } else { 0077 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); 0078 } 0079 } 0080 0081 SVGFEDisplacementMap *SVGFEDisplacementMapElement::filterEffect(SVGResourceFilter *filter) const 0082 { 0083 if (!m_filterEffect) { 0084 m_filterEffect = new SVGFEDisplacementMap(filter); 0085 } 0086 0087 m_filterEffect->setXChannelSelector((SVGChannelSelectorType) xChannelSelector()); 0088 m_filterEffect->setYChannelSelector((SVGChannelSelectorType) yChannelSelector()); 0089 m_filterEffect->setIn(in1()); 0090 m_filterEffect->setIn2(in2()); 0091 m_filterEffect->setScale(scale()); 0092 0093 setStandardAttributes(m_filterEffect); 0094 return m_filterEffect; 0095 } 0096 0097 } 0098 0099 #endif // ENABLE(SVG) 0100