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 #include "core/svg/SVGFEComponentTransferElement.h"
25 #include "core/SVGNames.h"
26 #include "core/dom/ElementTraversal.h"
27 #include "core/svg/SVGFEFuncAElement.h"
28 #include "core/svg/SVGFEFuncBElement.h"
29 #include "core/svg/SVGFEFuncGElement.h"
30 #include "core/svg/SVGFEFuncRElement.h"
31 #include "core/svg/graphics/filters/SVGFilterBuilder.h"
32 #include "platform/graphics/filters/FilterEffect.h"
36 inline SVGFEComponentTransferElement::SVGFEComponentTransferElement(Document& document)
37 : SVGFilterPrimitiveStandardAttributes(SVGNames::feComponentTransferTag, document)
38 , m_in1(SVGAnimatedString::create(this, SVGNames::inAttr, SVGString::create()))
40 addToPropertyMap(m_in1);
43 DEFINE_NODE_FACTORY(SVGFEComponentTransferElement)
45 bool SVGFEComponentTransferElement::isSupportedAttribute(const QualifiedName& attrName)
47 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
48 if (supportedAttributes.isEmpty())
49 supportedAttributes.add(SVGNames::inAttr);
50 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
53 void SVGFEComponentTransferElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
55 parseAttributeNew(name, value);
58 PassRefPtr<FilterEffect> SVGFEComponentTransferElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
60 FilterEffect* input1 = filterBuilder->getEffectById(AtomicString(m_in1->currentValue()->value()));
65 ComponentTransferFunction red;
66 ComponentTransferFunction green;
67 ComponentTransferFunction blue;
68 ComponentTransferFunction alpha;
70 for (SVGElement* element = Traversal<SVGElement>::firstChild(*this); element; element = Traversal<SVGElement>::nextSibling(*element)) {
71 if (isSVGFEFuncRElement(*element))
72 red = toSVGFEFuncRElement(*element).transferFunction();
73 else if (isSVGFEFuncGElement(*element))
74 green = toSVGFEFuncGElement(*element).transferFunction();
75 else if (isSVGFEFuncBElement(*element))
76 blue = toSVGFEFuncBElement(*element).transferFunction();
77 else if (isSVGFEFuncAElement(*element))
78 alpha = toSVGFEFuncAElement(*element).transferFunction();
81 RefPtr<FilterEffect> effect = FEComponentTransfer::create(filter, red, green, blue, alpha);
82 effect->inputEffects().append(input1);
83 return effect.release();