2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / WebCore / svg / SVGFEColorMatrixElement.cpp
blobc3a8f014a0ae9a4da639298ba32f2f75dc82fe0b
1 /*
2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006 Rob Buis <buis@kde.org>
5 This file is part of the KDE project
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.
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.
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.
23 #include "config.h"
25 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
26 #include "SVGFEColorMatrixElement.h"
28 #include "SVGNames.h"
29 #include "SVGNumberList.h"
30 #include "SVGResourceFilter.h"
32 namespace WebCore {
34 SVGFEColorMatrixElement::SVGFEColorMatrixElement(const QualifiedName& tagName, Document* doc)
35 : SVGFilterPrimitiveStandardAttributes(tagName, doc)
36 , m_in1(this, SVGNames::inAttr)
37 , m_type(this, SVGNames::typeAttr, FECOLORMATRIX_TYPE_UNKNOWN)
38 , m_values(this, SVGNames::valuesAttr, SVGNumberList::create(SVGNames::valuesAttr))
39 , m_filterEffect(0)
43 SVGFEColorMatrixElement::~SVGFEColorMatrixElement()
47 void SVGFEColorMatrixElement::parseMappedAttribute(MappedAttribute* attr)
49 const String& value = attr->value();
50 if (attr->name() == SVGNames::typeAttr) {
51 if (value == "matrix")
52 setTypeBaseValue(FECOLORMATRIX_TYPE_MATRIX);
53 else if (value == "saturate")
54 setTypeBaseValue(FECOLORMATRIX_TYPE_SATURATE);
55 else if (value == "hueRotate")
56 setTypeBaseValue(FECOLORMATRIX_TYPE_HUEROTATE);
57 else if (value == "luminanceToAlpha")
58 setTypeBaseValue(FECOLORMATRIX_TYPE_LUMINANCETOALPHA);
60 else if (attr->name() == SVGNames::inAttr)
61 setIn1BaseValue(value);
62 else if (attr->name() == SVGNames::valuesAttr)
63 valuesBaseValue()->parse(value);
64 else
65 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
68 SVGFilterEffect* SVGFEColorMatrixElement::filterEffect(SVGResourceFilter* filter) const
70 ASSERT_NOT_REACHED();
71 return 0;
74 bool SVGFEColorMatrixElement::build(FilterBuilder* builder)
76 FilterEffect* input1 = builder->getEffectById(in1());
78 if(!input1)
79 return false;
81 Vector<float> _values;
82 SVGNumberList* numbers = values();
84 ExceptionCode ec = 0;
85 unsigned int nr = numbers->numberOfItems();
86 for (unsigned int i = 0;i < nr;i++)
87 _values.append(numbers->getItem(i, ec));
89 builder->add(result(), FEColorMatrix::create(input1, static_cast<ColorMatrixType> (type()), _values));
91 return true;
94 } //namespace WebCore
96 #endif // ENABLE(SVG)