1 /*
2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005 Rob Buis <buis@kde.org>
4
5 This file is part of the KDE project
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21 */
22
23 #include "config.h"
24
25 #if ENABLE(SVG) && ENABLE(FILTERS)
26 #include "SVGFEComponentTransferElement.h"
27
28 #include "Attr.h"
29 #include "MappedAttribute.h"
30 #include "SVGFEFuncAElement.h"
31 #include "SVGFEFuncBElement.h"
32 #include "SVGFEFuncGElement.h"
33 #include "SVGFEFuncRElement.h"
34 #include "SVGNames.h"
35 #include "SVGRenderStyle.h"
36 #include "SVGResourceFilter.h"
37
38 namespace WebCore {
39
SVGFEComponentTransferElement(const QualifiedName & tagName,Document * doc)40 SVGFEComponentTransferElement::SVGFEComponentTransferElement(const QualifiedName& tagName, Document* doc)
41 : SVGFilterPrimitiveStandardAttributes(tagName, doc)
42 , m_in1(this, SVGNames::inAttr)
43 {
44 }
45
~SVGFEComponentTransferElement()46 SVGFEComponentTransferElement::~SVGFEComponentTransferElement()
47 {
48 }
49
parseMappedAttribute(MappedAttribute * attr)50 void SVGFEComponentTransferElement::parseMappedAttribute(MappedAttribute* attr)
51 {
52 const String& value = attr->value();
53 if (attr->name() == SVGNames::inAttr)
54 setIn1BaseValue(value);
55 else
56 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
57 }
58
build(SVGResourceFilter * filterResource)59 bool SVGFEComponentTransferElement::build(SVGResourceFilter* filterResource)
60 {
61 FilterEffect* input1 = filterResource->builder()->getEffectById(in1());
62
63 if (!input1)
64 return false;
65
66 ComponentTransferFunction red;
67 ComponentTransferFunction green;
68 ComponentTransferFunction blue;
69 ComponentTransferFunction alpha;
70
71 for (Node* n = firstChild(); n != 0; n = n->nextSibling()) {
72 if (n->hasTagName(SVGNames::feFuncRTag))
73 red = static_cast<SVGFEFuncRElement*>(n)->transferFunction();
74 else if (n->hasTagName(SVGNames::feFuncGTag))
75 green = static_cast<SVGFEFuncGElement*>(n)->transferFunction();
76 else if (n->hasTagName(SVGNames::feFuncBTag))
77 blue = static_cast<SVGFEFuncBElement*>(n)->transferFunction();
78 else if (n->hasTagName(SVGNames::feFuncATag))
79 alpha = static_cast<SVGFEFuncAElement*>(n)->transferFunction();
80 }
81
82 RefPtr<FilterEffect> effect = FEComponentTransfer::create(input1, red, green, blue, alpha);
83 filterResource->addFilterEffect(this, effect.release());
84
85 return true;
86 }
87
88 }
89
90 #endif // ENABLE(SVG)
91
92 // vim:ts=4:noet
93