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#include "core/svg/SVGFEComponentTransferElement.h" 24 25#include "SVGNames.h" 26#include "platform/graphics/filters/FilterEffect.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 33namespace WebCore { 34 35// Animated property definitions 36DEFINE_ANIMATED_STRING(SVGFEComponentTransferElement, SVGNames::inAttr, In1, in1) 37 38BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGFEComponentTransferElement) 39 REGISTER_LOCAL_ANIMATED_PROPERTY(in1) 40 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGFilterPrimitiveStandardAttributes) 41END_REGISTER_ANIMATED_PROPERTIES 42 43inline SVGFEComponentTransferElement::SVGFEComponentTransferElement(Document& document) 44 : SVGFilterPrimitiveStandardAttributes(SVGNames::feComponentTransferTag, document) 45{ 46 ScriptWrappable::init(this); 47 registerAnimatedPropertiesForSVGFEComponentTransferElement(); 48} 49 50PassRefPtr<SVGFEComponentTransferElement> SVGFEComponentTransferElement::create(Document& document) 51{ 52 return adoptRef(new SVGFEComponentTransferElement(document)); 53} 54 55bool SVGFEComponentTransferElement::isSupportedAttribute(const QualifiedName& attrName) 56{ 57 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); 58 if (supportedAttributes.isEmpty()) 59 supportedAttributes.add(SVGNames::inAttr); 60 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); 61} 62 63void SVGFEComponentTransferElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 64{ 65 if (!isSupportedAttribute(name)) { 66 SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value); 67 return; 68 } 69 70 if (name == SVGNames::inAttr) { 71 setIn1BaseValue(value); 72 return; 73 } 74 75 ASSERT_NOT_REACHED(); 76} 77 78PassRefPtr<FilterEffect> SVGFEComponentTransferElement::build(SVGFilterBuilder* filterBuilder, Filter* filter) 79{ 80 FilterEffect* input1 = filterBuilder->getEffectById(in1CurrentValue()); 81 82 if (!input1) 83 return 0; 84 85 ComponentTransferFunction red; 86 ComponentTransferFunction green; 87 ComponentTransferFunction blue; 88 ComponentTransferFunction alpha; 89 90 for (Node* node = firstChild(); node; node = node->nextSibling()) { 91 if (node->hasTagName(SVGNames::feFuncRTag)) 92 red = toSVGFEFuncRElement(node)->transferFunction(); 93 else if (node->hasTagName(SVGNames::feFuncGTag)) 94 green = toSVGFEFuncGElement(node)->transferFunction(); 95 else if (node->hasTagName(SVGNames::feFuncBTag)) 96 blue = toSVGFEFuncBElement(node)->transferFunction(); 97 else if (node->hasTagName(SVGNames::feFuncATag)) 98 alpha = toSVGFEFuncAElement(node)->transferFunction(); 99 } 100 101 RefPtr<FilterEffect> effect = FEComponentTransfer::create(filter, red, green, blue, alpha); 102 effect->inputEffects().append(input1); 103 return effect.release(); 104} 105 106} 107