Flutter Engine
The Flutter Engine
image_filter.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_IMPELLER_AIKS_IMAGE_FILTER_H_
6#define FLUTTER_IMPELLER_AIKS_IMAGE_FILTER_H_
7
14
15namespace impeller {
16
17struct Paint;
18
19class LocalMatrixImageFilter;
20class BlurImageFilter;
21class DilateImageFilter;
22class ErodeImageFilter;
23class MatrixImageFilter;
24class ComposeImageFilter;
25class ColorImageFilter;
26
28 public:
29 virtual void Visit(const BlurImageFilter& filter) = 0;
30 virtual void Visit(const LocalMatrixImageFilter& filter) = 0;
31 virtual void Visit(const DilateImageFilter& filter) = 0;
32 virtual void Visit(const ErodeImageFilter& filter) = 0;
33 virtual void Visit(const MatrixImageFilter& filter) = 0;
34 virtual void Visit(const ComposeImageFilter& filter) = 0;
35 virtual void Visit(const ColorImageFilter& filter) = 0;
36};
37
38/*******************************************************************************
39 ******* ImageFilter
40 ******************************************************************************/
41
43 public:
45
46 virtual ~ImageFilter();
47
48 static std::shared_ptr<ImageFilter> MakeBlur(
49 Sigma sigma_x,
50 Sigma sigma_y,
52 Entity::TileMode tile_mode);
53
54 static std::shared_ptr<ImageFilter> MakeDilate(Radius radius_x,
55 Radius radius_y);
56
57 static std::shared_ptr<ImageFilter> MakeErode(Radius radius_x,
58 Radius radius_y);
59
60 static std::shared_ptr<ImageFilter> MakeMatrix(
61 const Matrix& matrix,
62 SamplerDescriptor sampler_descriptor);
63
64 static std::shared_ptr<ImageFilter> MakeCompose(const ImageFilter& inner,
65 const ImageFilter& outer);
66
67 static std::shared_ptr<ImageFilter> MakeFromColorFilter(
69
70 static std::shared_ptr<ImageFilter> MakeLocalMatrix(
71 const Matrix& matrix,
72 const ImageFilter& internal_filter);
73
74 /// @brief Generate a new FilterContents using this filter's configuration.
75 ///
76 /// This is the same as WrapInput, except no input is set. The input
77 /// for the filter chain can be set later using.
78 /// FilterContents::SetLeafInputs().
79 ///
80 /// @see `FilterContents::SetLeafInputs`
81 std::shared_ptr<FilterContents> GetFilterContents() const;
82
83 /// @brief Wraps the given filter input with a GPU-based image filter.
84 virtual std::shared_ptr<FilterContents> WrapInput(
85 const FilterInput::Ref& input) const = 0;
86
87 virtual std::shared_ptr<ImageFilter> Clone() const = 0;
88
89 virtual void Visit(ImageFilterVisitor& visitor) = 0;
90};
91
92/*******************************************************************************
93 ******* BlurImageFilter
94 ******************************************************************************/
95
97 public:
98 BlurImageFilter(Sigma sigma_x,
99 Sigma sigma_y,
100 FilterContents::BlurStyle blur_style,
101 Entity::TileMode tile_mode);
102
104
105 // |ImageFilter|
106 std::shared_ptr<FilterContents> WrapInput(
107 const FilterInput::Ref& input) const override;
108
109 // |ImageFilter|
110 std::shared_ptr<ImageFilter> Clone() const override;
111
112 // |ImageFilter|
113 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
114
115 private:
116 Sigma sigma_x_;
117 Sigma sigma_y_;
118 FilterContents::BlurStyle blur_style_;
119 Entity::TileMode tile_mode_;
120};
121
122/*******************************************************************************
123 ******* DilateImageFilter
124 ******************************************************************************/
125
127 public:
128 DilateImageFilter(Radius radius_x, Radius radius_y);
129
131
132 // |ImageFilter|
133 std::shared_ptr<FilterContents> WrapInput(
134 const FilterInput::Ref& input) const override;
135
136 // |ImageFilter|
137 std::shared_ptr<ImageFilter> Clone() const override;
138
139 // |ImageFilter|
140 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
141
142 private:
143 Radius radius_x_;
144 Radius radius_y_;
145};
146
147/*******************************************************************************
148 ******* ErodeImageFilter
149 ******************************************************************************/
150
152 public:
153 ErodeImageFilter(Radius radius_x, Radius radius_y);
154
156
157 // |ImageFilter|
158 std::shared_ptr<FilterContents> WrapInput(
159 const FilterInput::Ref& input) const override;
160
161 // |ImageFilter|
162 std::shared_ptr<ImageFilter> Clone() const override;
163
164 // |ImageFilter|
165 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
166
167 private:
168 Radius radius_x_;
169 Radius radius_y_;
170};
171
172/*******************************************************************************
173 ******* MatrixImageFilter
174 ******************************************************************************/
175
177 public:
178 MatrixImageFilter(const Matrix& matrix, SamplerDescriptor sampler_descriptor);
179
181
182 // |ImageFilter|
183 std::shared_ptr<FilterContents> WrapInput(
184 const FilterInput::Ref& input) const override;
185
186 // |ImageFilter|
187 std::shared_ptr<ImageFilter> Clone() const override;
188
189 // |ImageFilter|
190 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
191
192 const Matrix& GetMatrix() const { return matrix_; }
193
194 private:
195 Matrix matrix_;
196 SamplerDescriptor sampler_descriptor_;
197};
198
199/*******************************************************************************
200 ******* ComposeImageFilter
201 ******************************************************************************/
202
204 public:
205 ComposeImageFilter(const ImageFilter& inner, const ImageFilter& outer);
206
208
209 // |ImageFilter|
210 std::shared_ptr<FilterContents> WrapInput(
211 const FilterInput::Ref& input) const override;
212
213 // |ImageFilter|
214 std::shared_ptr<ImageFilter> Clone() const override;
215
216 // |ImageFilter|
217 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
218
219 private:
220 std::shared_ptr<ImageFilter> inner_;
221 std::shared_ptr<ImageFilter> outer_;
222};
223
224/*******************************************************************************
225 ******* ColorImageFilter
226 ******************************************************************************/
227
229 public:
231
233
234 // |ImageFilter|
235 std::shared_ptr<FilterContents> WrapInput(
236 const FilterInput::Ref& input) const override;
237
238 // |ImageFilter|
239 std::shared_ptr<ImageFilter> Clone() const override;
240
241 // |ImageFilter|
242 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
243
244 private:
245 std::shared_ptr<ColorFilter> color_filter_;
246};
247
248/*******************************************************************************
249 ******* LocalMatrixImageFilter
250 ******************************************************************************/
251
253 public:
255 const ImageFilter& internal_filter);
256
258
259 // |ImageFilter|
260 std::shared_ptr<FilterContents> WrapInput(
261 const FilterInput::Ref& input) const override;
262
263 // |ImageFilter|
264 std::shared_ptr<ImageFilter> Clone() const override;
265
266 // |ImageFilter|
267 void Visit(ImageFilterVisitor& visitor) override { visitor.Visit(*this); }
268
269 private:
270 Matrix matrix_;
271 std::shared_ptr<ImageFilter> internal_filter_;
272};
273
274} // namespace impeller
275
276#endif // FLUTTER_IMPELLER_AIKS_IMAGE_FILTER_H_
static sk_sp< SkImage > color_filter(const SkImage *image, SkColorFilter *colorFilter)
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:88
void Visit(ImageFilterVisitor &visitor) override
Definition: image_filter.h:113
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
Definition: image_filter.cc:82
BlurImageFilter(Sigma sigma_x, Sigma sigma_y, FilterContents::BlurStyle blur_style, Entity::TileMode tile_mode)
Definition: image_filter.cc:71
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
void Visit(ImageFilterVisitor &visitor) override
Definition: image_filter.h:242
std::shared_ptr< ImageFilter > Clone() const override
ColorImageFilter(const ColorFilter &color_filter)
ComposeImageFilter(const ImageFilter &inner, const ImageFilter &outer)
std::shared_ptr< ImageFilter > Clone() const override
void Visit(ImageFilterVisitor &visitor) override
Definition: image_filter.h:217
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
void Visit(ImageFilterVisitor &visitor) override
Definition: image_filter.h:140
std::shared_ptr< ImageFilter > Clone() const override
DilateImageFilter(Radius radius_x, Radius radius_y)
Definition: image_filter.cc:96
std::shared_ptr< ImageFilter > Clone() const override
ErodeImageFilter(Radius radius_x, Radius radius_y)
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
void Visit(ImageFilterVisitor &visitor) override
Definition: image_filter.h:165
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:32
virtual void Visit(const DilateImageFilter &filter)=0
virtual void Visit(const BlurImageFilter &filter)=0
virtual void Visit(const MatrixImageFilter &filter)=0
virtual void Visit(const ErodeImageFilter &filter)=0
virtual void Visit(const LocalMatrixImageFilter &filter)=0
virtual void Visit(const ComposeImageFilter &filter)=0
virtual void Visit(const ColorImageFilter &filter)=0
static std::shared_ptr< ImageFilter > MakeMatrix(const Matrix &matrix, SamplerDescriptor sampler_descriptor)
Definition: image_filter.cc:39
static std::shared_ptr< ImageFilter > MakeLocalMatrix(const Matrix &matrix, const ImageFilter &internal_filter)
Definition: image_filter.cc:57
virtual void Visit(ImageFilterVisitor &visitor)=0
static std::shared_ptr< ImageFilter > MakeErode(Radius radius_x, Radius radius_y)
Definition: image_filter.cc:34
virtual std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const =0
Wraps the given filter input with a GPU-based image filter.
static std::shared_ptr< ImageFilter > MakeBlur(Sigma sigma_x, Sigma sigma_y, FilterContents::BlurStyle blur_style, Entity::TileMode tile_mode)
Definition: image_filter.cc:20
static std::shared_ptr< ImageFilter > MakeDilate(Radius radius_x, Radius radius_y)
Definition: image_filter.cc:29
static std::shared_ptr< ImageFilter > MakeFromColorFilter(const ColorFilter &color_filter)
Definition: image_filter.cc:52
virtual std::shared_ptr< ImageFilter > Clone() const =0
std::shared_ptr< FilterContents > GetFilterContents() const
Generate a new FilterContents using this filter's configuration.
Definition: image_filter.cc:63
static std::shared_ptr< ImageFilter > MakeCompose(const ImageFilter &inner, const ImageFilter &outer)
Definition: image_filter.cc:46
void Visit(ImageFilterVisitor &visitor) override
Definition: image_filter.h:267
LocalMatrixImageFilter(const Matrix &matrix, const ImageFilter &internal_filter)
std::shared_ptr< ImageFilter > Clone() const override
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
std::shared_ptr< ImageFilter > Clone() const override
MatrixImageFilter(const Matrix &matrix, SamplerDescriptor sampler_descriptor)
std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const override
Wraps the given filter input with a GPU-based image filter.
void Visit(ImageFilterVisitor &visitor) override
Definition: image_filter.h:190
const Matrix & GetMatrix() const
Definition: image_filter.h:192
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
For convolution filters, the "radius" is the size of the convolution kernel to use on the local space...
Definition: sigma.h:48
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
Definition: sigma.h:32