OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> |
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org> |
4 * Copyright (C) 2005 Eric Seidel <eric@webkit.org> | 4 * Copyright (C) 2005 Eric Seidel <eric@webkit.org> |
5 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 5 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
7 * Copyright (C) 2013 Google Inc. All rights reserved. | 7 * Copyright (C) 2013 Google Inc. All rights reserved. |
8 * | 8 * |
9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "SkMorphologyImageFilter.h" | 28 #include "SkMorphologyImageFilter.h" |
29 #include "platform/graphics/filters/Filter.h" | 29 #include "platform/graphics/filters/Filter.h" |
30 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" | 30 #include "platform/graphics/filters/SkiaImageFilterBuilder.h" |
31 #include "platform/text/TextStream.h" | 31 #include "platform/text/TextStream.h" |
32 | 32 |
33 namespace blink { | 33 namespace blink { |
34 | 34 |
35 FEMorphology::FEMorphology(Filter* filter, MorphologyOperatorType type, float ra
diusX, float radiusY) | 35 FEMorphology::FEMorphology(Filter* filter, MorphologyOperatorType type, float ra
diusX, float radiusY) |
36 : FilterEffect(filter) | 36 : FilterEffect(filter) |
37 , m_type(type) | 37 , m_type(type) |
38 , m_radiusX(radiusX) | 38 , m_radiusX(std::max(0.0f, radiusX)) |
39 , m_radiusY(radiusY) | 39 , m_radiusY(std::max(0.0f, radiusY)) |
40 { | 40 { |
41 } | 41 } |
42 | 42 |
43 PassRefPtrWillBeRawPtr<FEMorphology> FEMorphology::create(Filter* filter, Morpho
logyOperatorType type, float radiusX, float radiusY) | 43 PassRefPtrWillBeRawPtr<FEMorphology> FEMorphology::create(Filter* filter, Morpho
logyOperatorType type, float radiusX, float radiusY) |
44 { | 44 { |
45 return adoptRefWillBeNoop(new FEMorphology(filter, type, radiusX, radiusY)); | 45 return adoptRefWillBeNoop(new FEMorphology(filter, type, radiusX, radiusY)); |
46 } | 46 } |
47 | 47 |
48 MorphologyOperatorType FEMorphology::morphologyOperator() const | 48 MorphologyOperatorType FEMorphology::morphologyOperator() const |
49 { | 49 { |
50 return m_type; | 50 return m_type; |
51 } | 51 } |
52 | 52 |
53 bool FEMorphology::setMorphologyOperator(MorphologyOperatorType type) | 53 bool FEMorphology::setMorphologyOperator(MorphologyOperatorType type) |
54 { | 54 { |
55 if (m_type == type) | 55 if (m_type == type) |
56 return false; | 56 return false; |
57 m_type = type; | 57 m_type = type; |
58 return true; | 58 return true; |
59 } | 59 } |
60 | 60 |
61 float FEMorphology::radiusX() const | 61 float FEMorphology::radiusX() const |
62 { | 62 { |
63 return m_radiusX; | 63 return m_radiusX; |
64 } | 64 } |
65 | 65 |
66 bool FEMorphology::setRadiusX(float radiusX) | 66 bool FEMorphology::setRadiusX(float radiusX) |
67 { | 67 { |
| 68 radiusX = std::max(0.0f, radiusX); |
68 if (m_radiusX == radiusX) | 69 if (m_radiusX == radiusX) |
69 return false; | 70 return false; |
70 m_radiusX = radiusX; | 71 m_radiusX = radiusX; |
71 return true; | 72 return true; |
72 } | 73 } |
73 | 74 |
74 float FEMorphology::radiusY() const | 75 float FEMorphology::radiusY() const |
75 { | 76 { |
76 return m_radiusY; | 77 return m_radiusY; |
77 } | 78 } |
78 | 79 |
| 80 bool FEMorphology::setRadiusY(float radiusY) |
| 81 { |
| 82 radiusY = std::max(0.0f, radiusY); |
| 83 if (m_radiusY == radiusY) |
| 84 return false; |
| 85 m_radiusY = radiusY; |
| 86 return true; |
| 87 } |
| 88 |
79 FloatRect FEMorphology::mapRect(const FloatRect& rect, bool) | 89 FloatRect FEMorphology::mapRect(const FloatRect& rect, bool) |
80 { | 90 { |
81 FloatRect result = rect; | 91 FloatRect result = rect; |
82 result.inflateX(filter()->applyHorizontalScale(m_radiusX)); | 92 result.inflateX(filter()->applyHorizontalScale(m_radiusX)); |
83 result.inflateY(filter()->applyVerticalScale(m_radiusY)); | 93 result.inflateY(filter()->applyVerticalScale(m_radiusY)); |
84 return result; | 94 return result; |
85 } | 95 } |
86 | 96 |
87 bool FEMorphology::setRadiusY(float radiusY) | |
88 { | |
89 if (m_radiusY == radiusY) | |
90 return false; | |
91 m_radiusY = radiusY; | |
92 return true; | |
93 } | |
94 | |
95 PassRefPtr<SkImageFilter> FEMorphology::createImageFilter(SkiaImageFilterBuilder
* builder) | 97 PassRefPtr<SkImageFilter> FEMorphology::createImageFilter(SkiaImageFilterBuilder
* builder) |
96 { | 98 { |
97 RefPtr<SkImageFilter> input(builder->build(inputEffect(0), operatingColorSpa
ce())); | 99 RefPtr<SkImageFilter> input(builder->build(inputEffect(0), operatingColorSpa
ce())); |
98 SkScalar radiusX = SkFloatToScalar(filter()->applyHorizontalScale(m_radiusX)
); | 100 SkScalar radiusX = SkFloatToScalar(filter()->applyHorizontalScale(m_radiusX)
); |
99 SkScalar radiusY = SkFloatToScalar(filter()->applyVerticalScale(m_radiusY)); | 101 SkScalar radiusY = SkFloatToScalar(filter()->applyVerticalScale(m_radiusY)); |
100 SkImageFilter::CropRect rect = getCropRect(builder->cropOffset()); | 102 SkImageFilter::CropRect rect = getCropRect(builder->cropOffset()); |
101 if (m_type == FEMORPHOLOGY_OPERATOR_DILATE) | 103 if (m_type == FEMORPHOLOGY_OPERATOR_DILATE) |
102 return adoptRef(SkDilateImageFilter::Create(radiusX, radiusY, input.get(
), &rect)); | 104 return adoptRef(SkDilateImageFilter::Create(radiusX, radiusY, input.get(
), &rect)); |
103 return adoptRef(SkErodeImageFilter::Create(radiusX, radiusY, input.get(), &r
ect)); | 105 return adoptRef(SkErodeImageFilter::Create(radiusX, radiusY, input.get(), &r
ect)); |
104 } | 106 } |
(...skipping 19 matching lines...) Expand all Loading... |
124 writeIndent(ts, indent); | 126 writeIndent(ts, indent); |
125 ts << "[feMorphology"; | 127 ts << "[feMorphology"; |
126 FilterEffect::externalRepresentation(ts); | 128 FilterEffect::externalRepresentation(ts); |
127 ts << " operator=\"" << morphologyOperator() << "\" " | 129 ts << " operator=\"" << morphologyOperator() << "\" " |
128 << "radius=\"" << radiusX() << ", " << radiusY() << "\"]\n"; | 130 << "radius=\"" << radiusX() << ", " << radiusY() << "\"]\n"; |
129 inputEffect(0)->externalRepresentation(ts, indent + 1); | 131 inputEffect(0)->externalRepresentation(ts, indent + 1); |
130 return ts; | 132 return ts; |
131 } | 133 } |
132 | 134 |
133 } // namespace blink | 135 } // namespace blink |
OLD | NEW |