• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3                   2004, 2005, 2006 Rob Buis <buis@kde.org>
4 
5     This file is part of the KDE project
6 
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.
11 
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.
16 
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.
21 */
22 
23 #include "config.h"
24 
25 #if ENABLE(SVG) && ENABLE(FILTERS)
26 #include "SVGFEColorMatrixElement.h"
27 
28 #include "MappedAttribute.h"
29 #include "SVGNames.h"
30 #include "SVGNumberList.h"
31 #include "SVGResourceFilter.h"
32 
33 namespace WebCore {
34 
SVGFEColorMatrixElement(const QualifiedName & tagName,Document * doc)35 SVGFEColorMatrixElement::SVGFEColorMatrixElement(const QualifiedName& tagName, Document* doc)
36     : SVGFilterPrimitiveStandardAttributes(tagName, doc)
37     , m_in1(this, SVGNames::inAttr)
38     , m_type(this, SVGNames::typeAttr, FECOLORMATRIX_TYPE_UNKNOWN)
39     , m_values(this, SVGNames::valuesAttr, SVGNumberList::create(SVGNames::valuesAttr))
40 {
41 }
42 
~SVGFEColorMatrixElement()43 SVGFEColorMatrixElement::~SVGFEColorMatrixElement()
44 {
45 }
46 
parseMappedAttribute(MappedAttribute * attr)47 void SVGFEColorMatrixElement::parseMappedAttribute(MappedAttribute* attr)
48 {
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);
59     }
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);
66 }
67 
build(SVGResourceFilter * filterResource)68 bool SVGFEColorMatrixElement::build(SVGResourceFilter* filterResource)
69 {
70     FilterEffect* input1 = filterResource->builder()->getEffectById(in1());
71 
72     if (!input1)
73         return false;
74 
75     Vector<float> _values;
76     SVGNumberList* numbers = values();
77 
78     ExceptionCode ec = 0;
79     unsigned int nr = numbers->numberOfItems();
80     for (unsigned int i = 0;i < nr;i++)
81         _values.append(numbers->getItem(i, ec));
82 
83     RefPtr<FilterEffect> effect = FEColorMatrix::create(input1, static_cast<ColorMatrixType>(type()), _values);
84     filterResource->addFilterEffect(this, effect.release());
85 
86     return true;
87 }
88 
89 } //namespace WebCore
90 
91 #endif // ENABLE(SVG)
92