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_TRACE(SVGFEComponentTransferElement
)
45 visitor
->trace(m_in1
);
46 SVGFilterPrimitiveStandardAttributes::trace(visitor
);
49 DEFINE_NODE_FACTORY(SVGFEComponentTransferElement
)
51 void SVGFEComponentTransferElement::svgAttributeChanged(const QualifiedName
& attrName
)
53 if (attrName
== SVGNames::inAttr
) {
54 SVGElement::InvalidationGuard
invalidationGuard(this);
59 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName
);
62 PassRefPtrWillBeRawPtr
<FilterEffect
> SVGFEComponentTransferElement::build(SVGFilterBuilder
* filterBuilder
, Filter
* filter
)
64 FilterEffect
* input1
= filterBuilder
->getEffectById(AtomicString(m_in1
->currentValue()->value()));
69 ComponentTransferFunction red
;
70 ComponentTransferFunction green
;
71 ComponentTransferFunction blue
;
72 ComponentTransferFunction alpha
;
74 for (SVGElement
* element
= Traversal
<SVGElement
>::firstChild(*this); element
; element
= Traversal
<SVGElement
>::nextSibling(*element
)) {
75 if (isSVGFEFuncRElement(*element
))
76 red
= toSVGFEFuncRElement(*element
).transferFunction();
77 else if (isSVGFEFuncGElement(*element
))
78 green
= toSVGFEFuncGElement(*element
).transferFunction();
79 else if (isSVGFEFuncBElement(*element
))
80 blue
= toSVGFEFuncBElement(*element
).transferFunction();
81 else if (isSVGFEFuncAElement(*element
))
82 alpha
= toSVGFEFuncAElement(*element
).transferFunction();
85 RefPtrWillBeRawPtr
<FilterEffect
> effect
= FEComponentTransfer::create(filter
, red
, green
, blue
, alpha
);
86 effect
->inputEffects().append(input1
);
87 return effect
.release();