| Flutter Impeller |

image_filter.cc
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 #include "impeller/aiks/image_filter.h"
6 #include "impeller/entity/contents/filters/color_filter_contents.h"
7 #include "impeller/entity/contents/filters/filter_contents.h"
8 #include "impeller/entity/contents/filters/inputs/filter_input.h"
9
10 namespace impeller {
11
12 /*******************************************************************************
13 ******* ImageFilter
14 ******************************************************************************/
15
16 ImageFilter::ImageFilter() = default;
17
18 ImageFilter::~ImageFilter() = default;
19
20 std::shared_ptr<ImageFilter> ImageFilter::MakeBlur(
21 Sigma sigma_x,
22 Sigma sigma_y,
23 FilterContents::BlurStyle blur_style,
24 Entity::TileMode tile_mode) {
25 return std::make_shared<BlurImageFilter>(sigma_x, sigma_y, blur_style,
26 tile_mode);
27 }
28
29 std::shared_ptr<ImageFilter> ImageFilter::MakeDilate(Radius radius_x,
30 Radius radius_y) {
31 return std::make_shared<DilateImageFilter>(radius_x, radius_y);
32 }
33
34 std::shared_ptr<ImageFilter> ImageFilter::MakeErode(Radius radius_x,
35 Radius radius_y) {
36 return std::make_shared<ErodeImageFilter>(radius_x, radius_y);
37 }
38
39 std::shared_ptr<ImageFilter> ImageFilter::MakeMatrix(
40 const Matrix& matrix,
41 SamplerDescriptor sampler_descriptor) {
42 return std::make_shared<MatrixImageFilter>(matrix,
43 std::move(sampler_descriptor));
44 }
45
46 std::shared_ptr<ImageFilter> ImageFilter::MakeCompose(
47 const ImageFilter& inner,
48 const ImageFilter& outer) {
49 return std::make_shared<ComposeImageFilter>(inner, outer);
50 }
51
52 std::shared_ptr<ImageFilter> ImageFilter::MakeFromColorFilter(
53 const ColorFilter& color_filter) {
54 return std::make_shared<ColorImageFilter>(color_filter);
55 }
56
57 std::shared_ptr<ImageFilter> ImageFilter::MakeLocalMatrix(
58 const Matrix& matrix,
59 const ImageFilter& internal_filter) {
60 return std::make_shared<LocalMatrixImageFilter>(matrix, internal_filter);
61 }
62
63 std::shared_ptr<FilterContents> ImageFilter::GetFilterContents() const {
64 return WrapInput(FilterInput::Make(Rect()));
65 }
66
67 /*******************************************************************************
68 ******* BlurImageFilter
69 ******************************************************************************/
70
71 BlurImageFilter::BlurImageFilter(Sigma sigma_x,
72 Sigma sigma_y,
73 FilterContents::BlurStyle blur_style,
74 Entity::TileMode tile_mode)
75 : sigma_x_(sigma_x),
76 sigma_y_(sigma_y),
77 blur_style_(blur_style),
78 tile_mode_(tile_mode) {}
79
80 BlurImageFilter::~BlurImageFilter() = default;
81
82 std::shared_ptr<FilterContents> BlurImageFilter::WrapInput(
83 const FilterInput::Ref& input) const {
84 return FilterContents::MakeGaussianBlur(input, sigma_x_, sigma_y_,
85 blur_style_, tile_mode_);
86 }
87
88 std::shared_ptr<ImageFilter> BlurImageFilter::Clone() const {
89 return std::make_shared<BlurImageFilter>(*this);
90 }
91
92 /*******************************************************************************
93 ******* DilateImageFilter
94 ******************************************************************************/
95
96 DilateImageFilter::DilateImageFilter(Radius radius_x, Radius radius_y)
97 : radius_x_(radius_x), radius_y_(radius_y) {}
98
99 DilateImageFilter::~DilateImageFilter() = default;
100
101 std::shared_ptr<FilterContents> DilateImageFilter::WrapInput(
102 const FilterInput::Ref& input) const {
103 return FilterContents::MakeMorphology(input, radius_x_, radius_y_,
104 FilterContents::MorphType::kDilate);
105 }
106
107 std::shared_ptr<ImageFilter> DilateImageFilter::Clone() const {
108 return std::make_shared<DilateImageFilter>(*this);
109 }
110
111 /*******************************************************************************
112 ******* ErodeImageFilter
113 ******************************************************************************/
114
115 ErodeImageFilter::ErodeImageFilter(Radius radius_x, Radius radius_y)
116 : radius_x_(radius_x), radius_y_(radius_y) {}
117
118 ErodeImageFilter::~ErodeImageFilter() = default;
119
120 std::shared_ptr<FilterContents> ErodeImageFilter::WrapInput(
121 const FilterInput::Ref& input) const {
122 return FilterContents::MakeMorphology(input, radius_x_, radius_y_,
123 FilterContents::MorphType::kErode);
124 }
125
126 std::shared_ptr<ImageFilter> ErodeImageFilter::Clone() const {
127 return std::make_shared<ErodeImageFilter>(*this);
128 }
129
130 /*******************************************************************************
131 ******* MatrixImageFilter
132 ******************************************************************************/
133
134 MatrixImageFilter::MatrixImageFilter(const Matrix& matrix,
135 SamplerDescriptor sampler_descriptor)
136 : matrix_(matrix), sampler_descriptor_(std::move(sampler_descriptor)) {}
137
138 MatrixImageFilter::~MatrixImageFilter() = default;
139
140 std::shared_ptr<FilterContents> MatrixImageFilter::WrapInput(
141 const FilterInput::Ref& input) const {
142 return FilterContents::MakeMatrixFilter(input, matrix_, sampler_descriptor_);
143 }
144
145 std::shared_ptr<ImageFilter> MatrixImageFilter::Clone() const {
146 return std::make_shared<MatrixImageFilter>(*this);
147 }
148
149 /*******************************************************************************
150 ******* ComposeImageFilter
151 ******************************************************************************/
152
153 ComposeImageFilter::ComposeImageFilter(const ImageFilter& inner,
154 const ImageFilter& outer)
155 : inner_(inner.Clone()), outer_(outer.Clone()) {}
156
157 ComposeImageFilter::~ComposeImageFilter() = default;
158
159 std::shared_ptr<FilterContents> ComposeImageFilter::WrapInput(
160 const FilterInput::Ref& input) const {
161 return outer_->WrapInput(FilterInput::Make(inner_->WrapInput(input)));
162 }
163
164 std::shared_ptr<ImageFilter> ComposeImageFilter::Clone() const {
165 return std::make_shared<ComposeImageFilter>(*this);
166 }
167
168 /*******************************************************************************
169 ******* ColorImageFilter
170 ******************************************************************************/
171
172 ColorImageFilter::ColorImageFilter(const ColorFilter& color_filter)
173 : color_filter_(color_filter.Clone()) {}
174
175 ColorImageFilter::~ColorImageFilter() = default;
176
177 std::shared_ptr<FilterContents> ColorImageFilter::WrapInput(
178 const FilterInput::Ref& input) const {
179 return color_filter_->WrapWithGPUColorFilter(
180 input, ColorFilterContents::AbsorbOpacity::kNo);
181 }
182
183 std::shared_ptr<ImageFilter> ColorImageFilter::Clone() const {
184 return std::make_shared<ColorImageFilter>(*this);
185 }
186
187 /*******************************************************************************
188 ******* LocalMatrixImageFilter
189 ******************************************************************************/
190
191 LocalMatrixImageFilter::LocalMatrixImageFilter(
192 const Matrix& matrix,
193 const ImageFilter& internal_filter)
194 : matrix_(matrix), internal_filter_(internal_filter.Clone()) {}
195
196 LocalMatrixImageFilter::~LocalMatrixImageFilter() = default;
197
198 std::shared_ptr<FilterContents> LocalMatrixImageFilter::WrapInput(
199 const FilterInput::Ref& input) const {
200 return FilterContents::MakeLocalMatrixFilter(
201 FilterInput::Make(internal_filter_->WrapInput(input)), matrix_);
202 }
203
204 std::shared_ptr<ImageFilter> LocalMatrixImageFilter::Clone() const {
205 return std::make_shared<LocalMatrixImageFilter>(*this);
206 }
207
208 } // namespace impeller
impeller::ColorFilter
Definition: color_filter.h:18
impeller::DilateImageFilter::WrapInput
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:101
impeller::MatrixImageFilter::MatrixImageFilter
MatrixImageFilter(const Matrix &matrix, SamplerDescriptor sampler_descriptor)
Definition: image_filter.cc:134
impeller::FilterContents::MorphType::kErode
@ kErode
impeller::ImageFilter::MakeDilate
static std::shared_ptr< ImageFilter > MakeDilate(Radius radius_x, Radius radius_y)
Definition: image_filter.cc:29
impeller::ImageFilter::WrapInput
virtual std::shared_ptr< FilterContents > WrapInput(const FilterInput::Ref &input) const =0
Wraps the given filter input with a GPU-based image filter.
image_filter.h
impeller::ErodeImageFilter::Clone
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:126
impeller::BlurImageFilter::~BlurImageFilter
~BlurImageFilter() override
impeller::DilateImageFilter::DilateImageFilter
DilateImageFilter(Radius radius_x, Radius radius_y)
Definition: image_filter.cc:96
impeller::FilterContents::BlurStyle
BlurStyle
Definition: filter_contents.h:21
impeller::ComposeImageFilter::~ComposeImageFilter
~ComposeImageFilter() override
impeller::FilterInput::Make
static FilterInput::Ref Make(Variant input, bool msaa_enabled=true)
Definition: filter_input.cc:19
impeller::ColorImageFilter::ColorImageFilter
ColorImageFilter(const ColorFilter &color_filter)
Definition: image_filter.cc:172
impeller::FilterInput::Ref
std::shared_ptr< FilterInput > Ref
Definition: filter_input.h:31
impeller::ImageFilter::ImageFilter
ImageFilter()
impeller::ColorFilterContents::AbsorbOpacity::kNo
@ kNo
impeller::ImageFilter::MakeBlur
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
impeller::MatrixImageFilter::WrapInput
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:140
impeller::LocalMatrixImageFilter::~LocalMatrixImageFilter
~LocalMatrixImageFilter() override
impeller::ImageFilter::MakeFromColorFilter
static std::shared_ptr< ImageFilter > MakeFromColorFilter(const ColorFilter &color_filter)
Definition: image_filter.cc:52
impeller::MatrixImageFilter::~MatrixImageFilter
~MatrixImageFilter() override
impeller::ImageFilter::GetFilterContents
std::shared_ptr< FilterContents > GetFilterContents() const
Generate a new FilterContents using this filter's configuration.
Definition: image_filter.cc:63
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:18
impeller::ImageFilter::~ImageFilter
virtual ~ImageFilter()
impeller::FilterContents::MakeGaussianBlur
static std::shared_ptr< FilterContents > MakeGaussianBlur(const FilterInput::Ref &input, Sigma sigma_x, Sigma sigma_y, BlurStyle blur_style=BlurStyle::kNormal, Entity::TileMode tile_mode=Entity::TileMode::kDecal)
Definition: filter_contents.cc:52
filter_contents.h
impeller::ComposeImageFilter::ComposeImageFilter
ComposeImageFilter(const ImageFilter &inner, const ImageFilter &outer)
Definition: image_filter.cc:153
impeller::Radius
For convolution filters, the "radius" is the size of the convolution kernel to use on the local space...
Definition: sigma.h:47
impeller::ImageFilter::MakeLocalMatrix
static std::shared_ptr< ImageFilter > MakeLocalMatrix(const Matrix &matrix, const ImageFilter &internal_filter)
Definition: image_filter.cc:57
impeller::Sigma
In filters that use Gaussian distributions, "sigma" is a size of one standard deviation in terms of t...
Definition: sigma.h:31
impeller::LocalMatrixImageFilter::LocalMatrixImageFilter
LocalMatrixImageFilter(const Matrix &matrix, const ImageFilter &internal_filter)
Definition: image_filter.cc:191
impeller::ImageFilter::MakeErode
static std::shared_ptr< ImageFilter > MakeErode(Radius radius_x, Radius radius_y)
Definition: image_filter.cc:34
filter_input.h
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:306
impeller::ColorImageFilter::WrapInput
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:177
impeller::ImageFilter
Definition: image_filter.h:22
color_filter_contents.h
impeller::Entity::TileMode
TileMode
Definition: entity.h:40
impeller::ImageFilter::MakeMatrix
static std::shared_ptr< ImageFilter > MakeMatrix(const Matrix &matrix, SamplerDescriptor sampler_descriptor)
Definition: image_filter.cc:39
impeller::ErodeImageFilter::WrapInput
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:120
impeller::ImageFilter::MakeCompose
static std::shared_ptr< ImageFilter > MakeCompose(const ImageFilter &inner, const ImageFilter &outer)
Definition: image_filter.cc:46
impeller::FilterContents::MakeMorphology
static std::shared_ptr< FilterContents > MakeMorphology(FilterInput::Ref input, Radius radius_x, Radius radius_y, MorphType morph_type)
Definition: filter_contents.cc:91
impeller::ColorImageFilter::Clone
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:183
impeller::BlurImageFilter::BlurImageFilter
BlurImageFilter(Sigma sigma_x, Sigma sigma_y, FilterContents::BlurStyle blur_style, Entity::TileMode tile_mode)
Definition: image_filter.cc:71
std
Definition: comparable.h:98
impeller::FilterContents::MorphType::kDilate
@ kDilate
impeller::ColorImageFilter::~ColorImageFilter
~ColorImageFilter() override
impeller::ComposeImageFilter::WrapInput
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:159
impeller::ComposeImageFilter::Clone
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:164
impeller::BlurImageFilter::Clone
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:88
impeller::FilterContents::MakeMatrixFilter
static std::shared_ptr< FilterContents > MakeMatrixFilter(FilterInput::Ref input, const Matrix &matrix, const SamplerDescriptor &desc)
Definition: filter_contents.cc:103
impeller::MatrixImageFilter::Clone
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:145
impeller::LocalMatrixImageFilter::WrapInput
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:198
impeller::ErodeImageFilter::ErodeImageFilter
ErodeImageFilter(Radius radius_x, Radius radius_y)
Definition: image_filter.cc:115
impeller::FilterContents::MakeLocalMatrixFilter
static std::shared_ptr< FilterContents > MakeLocalMatrixFilter(FilterInput::Ref input, const Matrix &matrix)
Definition: filter_contents.cc:114
impeller::ErodeImageFilter::~ErodeImageFilter
~ErodeImageFilter() override
impeller::BlurImageFilter::WrapInput
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
impeller
Definition: aiks_context.cc:10
impeller::LocalMatrixImageFilter::Clone
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:204
impeller::DilateImageFilter::~DilateImageFilter
~DilateImageFilter() override
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:36
impeller::DilateImageFilter::Clone
std::shared_ptr< ImageFilter > Clone() const override
Definition: image_filter.cc:107