2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
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.
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.
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.
23 #if ENABLE(SVG) && ENABLE(FILTERS)
24 #include "SVGFEComponentTransferElement.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"
37 // Animated property definitions
38 DEFINE_ANIMATED_STRING(SVGFEComponentTransferElement, SVGNames::inAttr, In1, in1)
40 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGFEComponentTransferElement)
41 REGISTER_LOCAL_ANIMATED_PROPERTY(in1)
42 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGFilterPrimitiveStandardAttributes)
43 END_REGISTER_ANIMATED_PROPERTIES
45 inline SVGFEComponentTransferElement::SVGFEComponentTransferElement(const QualifiedName& tagName, Document* document)
46 : SVGFilterPrimitiveStandardAttributes(tagName, document)
48 ASSERT(hasTagName(SVGNames::feComponentTransferTag));
49 registerAnimatedPropertiesForSVGFEComponentTransferElement();
52 PassRefPtr<SVGFEComponentTransferElement> SVGFEComponentTransferElement::create(const QualifiedName& tagName, Document* document)
54 return adoptRef(new SVGFEComponentTransferElement(tagName, document));
57 bool SVGFEComponentTransferElement::isSupportedAttribute(const QualifiedName& attrName)
59 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
60 if (supportedAttributes.isEmpty())
61 supportedAttributes.add(SVGNames::inAttr);
62 return supportedAttributes.contains(attrName);
65 void SVGFEComponentTransferElement::parseMappedAttribute(Attribute* attr)
67 if (!isSupportedAttribute(attr->name())) {
68 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
72 const AtomicString& value = attr->value();
73 if (attr->name() == SVGNames::inAttr) {
74 setIn1BaseValue(value);
81 PassRefPtr<FilterEffect> SVGFEComponentTransferElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
83 FilterEffect* input1 = filterBuilder->getEffectById(in1());
88 ComponentTransferFunction red;
89 ComponentTransferFunction green;
90 ComponentTransferFunction blue;
91 ComponentTransferFunction alpha;
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();
104 RefPtr<FilterEffect> effect = FEComponentTransfer::create(filter, red, green, blue, alpha);
105 effect->inputEffects().append(input1);
106 return effect.release();