• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  Copyright (C) 2006 Oliver Hunt <oliver@nerget.com>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB.  If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18  */
19 
20 #include "config.h"
21 
22 #if ENABLE(SVG) && ENABLE(FILTERS)
23 #include "SVGFEDisplacementMapElement.h"
24 
25 #include "MappedAttribute.h"
26 #include "SVGResourceFilter.h"
27 
28 namespace WebCore {
29 
SVGFEDisplacementMapElement(const QualifiedName & tagName,Document * doc)30 SVGFEDisplacementMapElement::SVGFEDisplacementMapElement(const QualifiedName& tagName, Document* doc)
31     : SVGFilterPrimitiveStandardAttributes(tagName, doc)
32     , m_xChannelSelector(CHANNEL_A)
33     , m_yChannelSelector(CHANNEL_A)
34 {
35 }
36 
~SVGFEDisplacementMapElement()37 SVGFEDisplacementMapElement::~SVGFEDisplacementMapElement()
38 {
39 }
40 
stringToChannel(const String & key)41 ChannelSelectorType SVGFEDisplacementMapElement::stringToChannel(const String& key)
42 {
43     if (key == "R")
44         return CHANNEL_R;
45     else if (key == "G")
46         return CHANNEL_G;
47     else if (key == "B")
48         return CHANNEL_B;
49     else if (key == "A")
50         return CHANNEL_A;
51 
52     return CHANNEL_UNKNOWN;
53 }
54 
parseMappedAttribute(MappedAttribute * attr)55 void SVGFEDisplacementMapElement::parseMappedAttribute(MappedAttribute* attr)
56 {
57     const String& value = attr->value();
58     if (attr->name() == SVGNames::xChannelSelectorAttr)
59         setXChannelSelectorBaseValue(stringToChannel(value));
60     else if (attr->name() == SVGNames::yChannelSelectorAttr)
61         setYChannelSelectorBaseValue(stringToChannel(value));
62     else if (attr->name() == SVGNames::inAttr)
63         setIn1BaseValue(value);
64     else if (attr->name() == SVGNames::in2Attr)
65         setIn2BaseValue(value);
66     else if (attr->name() == SVGNames::scaleAttr)
67         setScaleBaseValue(value.toFloat());
68     else
69         SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
70 }
71 
synchronizeProperty(const QualifiedName & attrName)72 void SVGFEDisplacementMapElement::synchronizeProperty(const QualifiedName& attrName)
73 {
74     SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName);
75 
76     if (attrName == anyQName()) {
77         synchronizeXChannelSelector();
78         synchronizeYChannelSelector();
79         synchronizeIn1();
80         synchronizeIn2();
81         synchronizeScale();
82         return;
83     }
84 
85     if (attrName == SVGNames::xChannelSelectorAttr)
86         synchronizeXChannelSelector();
87     else if (attrName == SVGNames::yChannelSelectorAttr)
88         synchronizeYChannelSelector();
89     else if (attrName == SVGNames::inAttr)
90         synchronizeIn1();
91     else if (attrName == SVGNames::in2Attr)
92         synchronizeIn2();
93     else if (attrName == SVGNames::scaleAttr)
94         synchronizeScale();
95 }
96 
build(SVGResourceFilter * filterResource)97 bool SVGFEDisplacementMapElement::build(SVGResourceFilter* filterResource)
98 {
99     FilterEffect* input1 = filterResource->builder()->getEffectById(in1());
100     FilterEffect* input2 = filterResource->builder()->getEffectById(in2());
101 
102     if (!input1 || !input2)
103         return false;
104 
105 
106     RefPtr<FilterEffect> effect = FEDisplacementMap::create(input1, input2, static_cast<ChannelSelectorType>(xChannelSelector()),
107                                         static_cast<ChannelSelectorType>(yChannelSelector()), scale());
108     filterResource->addFilterEffect(this, effect.release());
109 
110     return true;
111 }
112 
113 }
114 
115 #endif // ENABLE(SVG)
116 
117 // vim:ts=4:noet
118