2 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4 * Copyright (C) 2005 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * Copyright (C) 2013 Google Inc. All rights reserved.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
26 #include "platform/graphics/filters/FEMorphology.h"
28 #include "SkMorphologyImageFilter.h"
29 #include "platform/graphics/filters/Filter.h"
30 #include "platform/graphics/filters/SkiaImageFilterBuilder.h"
31 #include "platform/text/TextStream.h"
35 FEMorphology::FEMorphology(Filter* filter, MorphologyOperatorType type, float radiusX, float radiusY)
36 : FilterEffect(filter)
43 PassRefPtr<FEMorphology> FEMorphology::create(Filter* filter, MorphologyOperatorType type, float radiusX, float radiusY)
45 return adoptRef(new FEMorphology(filter, type, radiusX, radiusY));
48 MorphologyOperatorType FEMorphology::morphologyOperator() const
53 bool FEMorphology::setMorphologyOperator(MorphologyOperatorType type)
61 float FEMorphology::radiusX() const
66 bool FEMorphology::setRadiusX(float radiusX)
68 if (m_radiusX == radiusX)
74 float FEMorphology::radiusY() const
79 FloatRect FEMorphology::mapRect(const FloatRect& rect, bool)
81 FloatRect result = rect;
82 result.inflateX(filter()->applyHorizontalScale(m_radiusX));
83 result.inflateY(filter()->applyVerticalScale(m_radiusY));
87 bool FEMorphology::setRadiusY(float radiusY)
89 if (m_radiusY == radiusY)
95 PassRefPtr<SkImageFilter> FEMorphology::createImageFilter(SkiaImageFilterBuilder* builder)
97 RefPtr<SkImageFilter> input(builder->build(inputEffect(0), operatingColorSpace()));
98 SkScalar radiusX = SkFloatToScalar(filter()->applyHorizontalScale(m_radiusX));
99 SkScalar radiusY = SkFloatToScalar(filter()->applyVerticalScale(m_radiusY));
100 SkImageFilter::CropRect rect = getCropRect(builder->cropOffset());
101 if (m_type == FEMORPHOLOGY_OPERATOR_DILATE)
102 return adoptRef(SkDilateImageFilter::Create(radiusX, radiusY, input.get(), &rect));
103 return adoptRef(SkErodeImageFilter::Create(radiusX, radiusY, input.get(), &rect));
106 static TextStream& operator<<(TextStream& ts, const MorphologyOperatorType& type)
109 case FEMORPHOLOGY_OPERATOR_UNKNOWN:
112 case FEMORPHOLOGY_OPERATOR_ERODE:
115 case FEMORPHOLOGY_OPERATOR_DILATE:
122 TextStream& FEMorphology::externalRepresentation(TextStream& ts, int indent) const
124 writeIndent(ts, indent);
125 ts << "[feMorphology";
126 FilterEffect::externalRepresentation(ts);
127 ts << " operator=\"" << morphologyOperator() << "\" "
128 << "radius=\"" << radiusX() << ", " << radiusY() << "\"]\n";
129 inputEffect(0)->externalRepresentation(ts, indent + 1);