initial import
[vuplus_webkit] / Source / WebCore / svg / SVGFEComponentTransferElement.cpp
1 /*
2  * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #include "config.h"
22
23 #if ENABLE(SVG) && ENABLE(FILTERS)
24 #include "SVGFEComponentTransferElement.h"
25
26 #include "Attr.h"
27 #include "FilterEffect.h"
28 #include "SVGFEFuncAElement.h"
29 #include "SVGFEFuncBElement.h"
30 #include "SVGFEFuncGElement.h"
31 #include "SVGFEFuncRElement.h"
32 #include "SVGFilterBuilder.h"
33 #include "SVGNames.h"
34
35 namespace WebCore {
36
37 // Animated property definitions
38 DEFINE_ANIMATED_STRING(SVGFEComponentTransferElement, SVGNames::inAttr, In1, in1)
39
40 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGFEComponentTransferElement)
41     REGISTER_LOCAL_ANIMATED_PROPERTY(in1)
42     REGISTER_PARENT_ANIMATED_PROPERTIES(SVGFilterPrimitiveStandardAttributes)
43 END_REGISTER_ANIMATED_PROPERTIES
44
45 inline SVGFEComponentTransferElement::SVGFEComponentTransferElement(const QualifiedName& tagName, Document* document)
46     : SVGFilterPrimitiveStandardAttributes(tagName, document)
47 {
48     ASSERT(hasTagName(SVGNames::feComponentTransferTag));
49     registerAnimatedPropertiesForSVGFEComponentTransferElement();
50 }
51
52 PassRefPtr<SVGFEComponentTransferElement> SVGFEComponentTransferElement::create(const QualifiedName& tagName, Document* document)
53 {
54     return adoptRef(new SVGFEComponentTransferElement(tagName, document));
55 }
56
57 bool SVGFEComponentTransferElement::isSupportedAttribute(const QualifiedName& attrName)
58 {
59     DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
60     if (supportedAttributes.isEmpty())
61         supportedAttributes.add(SVGNames::inAttr);
62     return supportedAttributes.contains(attrName);
63 }
64
65 void SVGFEComponentTransferElement::parseMappedAttribute(Attribute* attr)
66 {
67     if (!isSupportedAttribute(attr->name())) {
68         SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
69         return;
70     }
71
72     const AtomicString& value = attr->value();
73     if (attr->name() == SVGNames::inAttr) {
74         setIn1BaseValue(value);
75         return;
76     }
77
78     ASSERT_NOT_REACHED();
79 }
80
81 PassRefPtr<FilterEffect> SVGFEComponentTransferElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
82 {
83     FilterEffect* input1 = filterBuilder->getEffectById(in1());
84     
85     if (!input1)
86         return 0;
87
88     ComponentTransferFunction red;
89     ComponentTransferFunction green;
90     ComponentTransferFunction blue;
91     ComponentTransferFunction alpha;
92     
93     for (Node* node = firstChild(); node; node = node->nextSibling()) {
94         if (node->hasTagName(SVGNames::feFuncRTag))
95             red = static_cast<SVGFEFuncRElement*>(node)->transferFunction();
96         else if (node->hasTagName(SVGNames::feFuncGTag))
97             green = static_cast<SVGFEFuncGElement*>(node)->transferFunction();
98         else if (node->hasTagName(SVGNames::feFuncBTag))
99            blue = static_cast<SVGFEFuncBElement*>(node)->transferFunction();
100         else if (node->hasTagName(SVGNames::feFuncATag))
101             alpha = static_cast<SVGFEFuncAElement*>(node)->transferFunction();
102     }
103     
104     RefPtr<FilterEffect> effect = FEComponentTransfer::create(filter, red, green, blue, alpha);
105     effect->inputEffects().append(input1);
106     return effect.release();
107 }
108
109 }
110
111 #endif