1/* 2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> 4 * 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. 9 * 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. 14 * 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. 19 */ 20 21#include "config.h" 22 23#if ENABLE(SVG) && ENABLE(FILTERS) 24#include "SVGFEComponentTransferElement.h" 25 26#include "Attr.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" 33#include "SVGNames.h" 34 35namespace WebCore { 36 37// Animated property declarations 38DEFINE_ANIMATED_STRING(SVGFEComponentTransferElement, SVGNames::inAttr, In1, in1) 39 40inline SVGFEComponentTransferElement::SVGFEComponentTransferElement(const QualifiedName& tagName, Document* document) 41 : SVGFilterPrimitiveStandardAttributes(tagName, document) 42{ 43} 44 45PassRefPtr<SVGFEComponentTransferElement> SVGFEComponentTransferElement::create(const QualifiedName& tagName, Document* document) 46{ 47 return adoptRef(new SVGFEComponentTransferElement(tagName, document)); 48} 49 50void SVGFEComponentTransferElement::parseMappedAttribute(Attribute* attr) 51{ 52 const String& value = attr->value(); 53 if (attr->name() == SVGNames::inAttr) 54 setIn1BaseValue(value); 55 else 56 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); 57} 58 59void SVGFEComponentTransferElement::synchronizeProperty(const QualifiedName& attrName) 60{ 61 SVGFilterPrimitiveStandardAttributes::synchronizeProperty(attrName); 62 63 if (attrName == anyQName() || attrName == SVGNames::inAttr) 64 synchronizeIn1(); 65} 66 67AttributeToPropertyTypeMap& SVGFEComponentTransferElement::attributeToPropertyTypeMap() 68{ 69 DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ()); 70 return s_attributeToPropertyTypeMap; 71} 72 73void SVGFEComponentTransferElement::fillAttributeToPropertyTypeMap() 74{ 75 AttributeToPropertyTypeMap& attributeToPropertyTypeMap = this->attributeToPropertyTypeMap(); 76 77 SVGFilterPrimitiveStandardAttributes::fillPassedAttributeToPropertyTypeMap(attributeToPropertyTypeMap); 78 attributeToPropertyTypeMap.set(SVGNames::inAttr, AnimatedString); 79} 80 81PassRefPtr<FilterEffect> SVGFEComponentTransferElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) 82{ 83 FilterEffect* input1 = filterBuilder->getEffectById(in1()); 84 85 if (!input1) 86 return 0; 87 88 ComponentTransferFunction red; 89 ComponentTransferFunction green; 90 ComponentTransferFunction blue; 91 ComponentTransferFunction alpha; 92 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(); 102 } 103 104 RefPtr<FilterEffect> effect = FEComponentTransfer::create(filter, red, green, blue, alpha); 105 effect->inputEffects().append(input1); 106 return effect.release(); 107} 108 109} 110 111#endif 112