| 1 | /* |
| 2 | * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 | * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> |
| 4 | * Copyright (C) 2018-2019 Apple Inc. All rights reserved. |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Library General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Library General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Library General Public License |
| 17 | * along with this library; see the file COPYING.LIB. If not, write to |
| 18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | * Boston, MA 02110-1301, USA. |
| 20 | */ |
| 21 | |
| 22 | #include "config.h" |
| 23 | #include "SVGFEComponentTransferElement.h" |
| 24 | |
| 25 | #include "ElementIterator.h" |
| 26 | #include "FilterEffect.h" |
| 27 | #include "SVGFEFuncAElement.h" |
| 28 | #include "SVGFEFuncBElement.h" |
| 29 | #include "SVGFEFuncGElement.h" |
| 30 | #include "SVGFEFuncRElement.h" |
| 31 | #include "SVGFilterBuilder.h" |
| 32 | #include "SVGNames.h" |
| 33 | #include <wtf/IsoMallocInlines.h> |
| 34 | |
| 35 | namespace WebCore { |
| 36 | |
| 37 | WTF_MAKE_ISO_ALLOCATED_IMPL(SVGFEComponentTransferElement); |
| 38 | |
| 39 | inline SVGFEComponentTransferElement::SVGFEComponentTransferElement(const QualifiedName& tagName, Document& document) |
| 40 | : SVGFilterPrimitiveStandardAttributes(tagName, document) |
| 41 | { |
| 42 | ASSERT(hasTagName(SVGNames::feComponentTransferTag)); |
| 43 | |
| 44 | static std::once_flag onceFlag; |
| 45 | std::call_once(onceFlag, [] { |
| 46 | PropertyRegistry::registerProperty<SVGNames::inAttr, &SVGFEComponentTransferElement::m_in1>(); |
| 47 | }); |
| 48 | } |
| 49 | |
| 50 | Ref<SVGFEComponentTransferElement> SVGFEComponentTransferElement::create(const QualifiedName& tagName, Document& document) |
| 51 | { |
| 52 | return adoptRef(*new SVGFEComponentTransferElement(tagName, document)); |
| 53 | } |
| 54 | |
| 55 | void SVGFEComponentTransferElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
| 56 | { |
| 57 | if (name == SVGNames::inAttr) { |
| 58 | m_in1->setBaseValInternal(value); |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value); |
| 63 | } |
| 64 | |
| 65 | RefPtr<FilterEffect> SVGFEComponentTransferElement::build(SVGFilterBuilder* filterBuilder, Filter& filter) const |
| 66 | { |
| 67 | auto input1 = filterBuilder->getEffectById(in1()); |
| 68 | |
| 69 | if (!input1) |
| 70 | return nullptr; |
| 71 | |
| 72 | ComponentTransferFunction red; |
| 73 | ComponentTransferFunction green; |
| 74 | ComponentTransferFunction blue; |
| 75 | ComponentTransferFunction alpha; |
| 76 | |
| 77 | for (auto& child : childrenOfType<SVGElement>(*this)) { |
| 78 | if (is<SVGFEFuncRElement>(child)) |
| 79 | red = downcast<SVGFEFuncRElement>(child).transferFunction(); |
| 80 | else if (is<SVGFEFuncGElement>(child)) |
| 81 | green = downcast<SVGFEFuncGElement>(child).transferFunction(); |
| 82 | else if (is<SVGFEFuncBElement>(child)) |
| 83 | blue = downcast<SVGFEFuncBElement>(child).transferFunction(); |
| 84 | else if (is<SVGFEFuncAElement>(child)) |
| 85 | alpha = downcast<SVGFEFuncAElement>(child).transferFunction(); |
| 86 | } |
| 87 | |
| 88 | auto effect = FEComponentTransfer::create(filter, red, green, blue, alpha); |
| 89 | effect->inputEffects().append(input1); |
| 90 | return effect; |
| 91 | } |
| 92 | |
| 93 | } |
| 94 | |