1/*
2    Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3                  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 "MappedAttribute.h"
28#include "SVGFEFuncAElement.h"
29#include "SVGFEFuncBElement.h"
30#include "SVGFEFuncGElement.h"
31#include "SVGFEFuncRElement.h"
32#include "SVGNames.h"
33#include "SVGRenderStyle.h"
34#include "SVGResourceFilter.h"
35
36namespace WebCore {
37
38SVGFEComponentTransferElement::SVGFEComponentTransferElement(const QualifiedName& tagName, Document* doc)
39    : SVGFilterPrimitiveStandardAttributes(tagName, doc)
40{
41}
42
43SVGFEComponentTransferElement::~SVGFEComponentTransferElement()
44{
45}
46
47void SVGFEComponentTransferElement::parseMappedAttribute(MappedAttribute* attr)
48{
49    const String& value = attr->value();
50    if (attr->name() == SVGNames::inAttr)
51        setIn1BaseValue(value);
52    else
53        SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
54}
55
56void SVGFEComponentTransferElement::synchronizeProperty(const QualifiedName& attrName)
57{
58    SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName);
59
60    if (attrName == anyQName() || attrName == SVGNames::inAttr)
61        synchronizeIn1();
62}
63
64bool SVGFEComponentTransferElement::build(SVGResourceFilter* filterResource)
65{
66    FilterEffect* input1 = filterResource->builder()->getEffectById(in1());
67
68    if (!input1)
69        return false;
70
71    ComponentTransferFunction red;
72    ComponentTransferFunction green;
73    ComponentTransferFunction blue;
74    ComponentTransferFunction alpha;
75
76    for (Node* n = firstChild(); n != 0; n = n->nextSibling()) {
77        if (n->hasTagName(SVGNames::feFuncRTag))
78            red = static_cast<SVGFEFuncRElement*>(n)->transferFunction();
79        else if (n->hasTagName(SVGNames::feFuncGTag))
80            green = static_cast<SVGFEFuncGElement*>(n)->transferFunction();
81        else if (n->hasTagName(SVGNames::feFuncBTag))
82           blue = static_cast<SVGFEFuncBElement*>(n)->transferFunction();
83        else if (n->hasTagName(SVGNames::feFuncATag))
84            alpha = static_cast<SVGFEFuncAElement*>(n)->transferFunction();
85    }
86
87    RefPtr<FilterEffect> effect = FEComponentTransfer::create(input1, red, green, blue, alpha);
88    filterResource->addFilterEffect(this, effect.release());
89
90    return true;
91}
92
93}
94
95#endif // ENABLE(SVG)
96
97// vim:ts=4:noet
98