Flutter Impeller
color_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 
9 
10 namespace impeller {
11 
12 /*******************************************************************************
13  ******* ColorFilter
14  ******************************************************************************/
15 
16 ColorFilter::ColorFilter() = default;
17 
18 ColorFilter::~ColorFilter() = default;
19 
20 std::shared_ptr<ColorFilter> ColorFilter::MakeBlend(BlendMode blend_mode,
21  Color color) {
22  return std::make_shared<BlendColorFilter>(blend_mode, color);
23 }
24 
25 std::shared_ptr<ColorFilter> ColorFilter::MakeMatrix(ColorMatrix color_matrix) {
26  return std::make_shared<MatrixColorFilter>(color_matrix);
27 }
28 
29 std::shared_ptr<ColorFilter> ColorFilter::MakeSrgbToLinear() {
30  return std::make_shared<SrgbToLinearColorFilter>();
31 }
32 
33 std::shared_ptr<ColorFilter> ColorFilter::MakeLinearToSrgb() {
34  return std::make_shared<LinearToSrgbColorFilter>();
35 }
36 
37 /*******************************************************************************
38  ******* BlendColorFilter
39  ******************************************************************************/
40 
42  : blend_mode_(blend_mode), color_(color) {}
43 
45 
46 std::shared_ptr<ColorFilterContents> BlendColorFilter::WrapWithGPUColorFilter(
47  std::shared_ptr<FilterInput> input,
48  ColorFilterContents::AbsorbOpacity absorb_opacity) const {
49  auto filter =
50  ColorFilterContents::MakeBlend(blend_mode_, {std::move(input)}, color_);
51  filter->SetAbsorbOpacity(absorb_opacity);
52  return filter;
53 }
54 
56  return [filter_blend_mode = blend_mode_, filter_color = color_](Color color) {
57  return color.Blend(filter_color, filter_blend_mode);
58  };
59 }
60 
61 std::shared_ptr<ColorFilter> BlendColorFilter::Clone() const {
62  return std::make_shared<BlendColorFilter>(*this);
63 }
64 
65 /*******************************************************************************
66  ******* MatrixColorFilter
67  ******************************************************************************/
68 
70  : color_matrix_(color_matrix) {}
71 
73 
74 std::shared_ptr<ColorFilterContents> MatrixColorFilter::WrapWithGPUColorFilter(
75  std::shared_ptr<FilterInput> input,
76  ColorFilterContents::AbsorbOpacity absorb_opacity) const {
77  auto filter =
78  ColorFilterContents::MakeColorMatrix({std::move(input)}, color_matrix_);
79  filter->SetAbsorbOpacity(absorb_opacity);
80  return filter;
81 }
82 
84  return [color_matrix = color_matrix_](Color color) {
85  return color.ApplyColorMatrix(color_matrix);
86  };
87 }
88 
89 std::shared_ptr<ColorFilter> MatrixColorFilter::Clone() const {
90  return std::make_shared<MatrixColorFilter>(*this);
91 }
92 
93 /*******************************************************************************
94  ******* SrgbToLinearColorFilter
95  ******************************************************************************/
96 
98 
100 
101 std::shared_ptr<ColorFilterContents>
103  std::shared_ptr<FilterInput> input,
104  ColorFilterContents::AbsorbOpacity absorb_opacity) const {
105  auto filter = ColorFilterContents::MakeSrgbToLinearFilter({std::move(input)});
106  filter->SetAbsorbOpacity(absorb_opacity);
107  return filter;
108 }
109 
111  const {
112  return [](Color color) { return color.SRGBToLinear(); };
113 }
114 
115 std::shared_ptr<ColorFilter> SrgbToLinearColorFilter::Clone() const {
116  return std::make_shared<SrgbToLinearColorFilter>(*this);
117 }
118 
119 /*******************************************************************************
120  ******* LinearToSrgbColorFilter
121  ******************************************************************************/
122 
124 
126 
127 std::shared_ptr<ColorFilterContents>
129  std::shared_ptr<FilterInput> input,
130  ColorFilterContents::AbsorbOpacity absorb_opacity) const {
131  auto filter = ColorFilterContents::MakeSrgbToLinearFilter({std::move(input)});
132  filter->SetAbsorbOpacity(absorb_opacity);
133  return filter;
134 }
135 
137  const {
138  return [](Color color) { return color.LinearToSRGB(); };
139 }
140 
141 std::shared_ptr<ColorFilter> LinearToSrgbColorFilter::Clone() const {
142  return std::make_shared<LinearToSrgbColorFilter>(*this);
143 }
144 
145 } // namespace impeller
impeller::BlendMode
BlendMode
Definition: color.h:57
impeller::MatrixColorFilter::~MatrixColorFilter
~MatrixColorFilter() override
impeller::MatrixColorFilter::GetCPUColorFilterProc
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
Definition: color_filter.cc:83
impeller::BlendColorFilter::WrapWithGPUColorFilter
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const override
Wraps the given filter input with a GPU-based filter that will perform the color operation....
Definition: color_filter.cc:46
impeller::BlendColorFilter::BlendColorFilter
BlendColorFilter(BlendMode blend_mode, Color color)
Definition: color_filter.cc:41
impeller::Color
Definition: color.h:122
impeller::ColorFilter::ColorFilterProc
std::function< Color(Color)> ColorFilterProc
Definition: color_filter.h:24
impeller::MatrixColorFilter::MatrixColorFilter
MatrixColorFilter(ColorMatrix color_matrix)
Definition: color_filter.cc:69
impeller::ColorFilter::ColorFilter
ColorFilter()
impeller::MatrixColorFilter::WrapWithGPUColorFilter
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const override
Wraps the given filter input with a GPU-based filter that will perform the color operation....
Definition: color_filter.cc:74
impeller::BlendColorFilter::Clone
std::shared_ptr< ColorFilter > Clone() const override
Definition: color_filter.cc:61
impeller::SrgbToLinearColorFilter::Clone
std::shared_ptr< ColorFilter > Clone() const override
Definition: color_filter.cc:115
impeller::LinearToSrgbColorFilter::LinearToSrgbColorFilter
LinearToSrgbColorFilter()
impeller::ColorFilter::MakeBlend
static std::shared_ptr< ColorFilter > MakeBlend(BlendMode blend_mode, Color color)
Definition: color_filter.cc:20
impeller::LinearToSrgbColorFilter::Clone
std::shared_ptr< ColorFilter > Clone() const override
Definition: color_filter.cc:141
impeller::BlendColorFilter::~BlendColorFilter
~BlendColorFilter() override
impeller::SrgbToLinearColorFilter::WrapWithGPUColorFilter
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const override
Wraps the given filter input with a GPU-based filter that will perform the color operation....
Definition: color_filter.cc:102
impeller::SrgbToLinearColorFilter::~SrgbToLinearColorFilter
~SrgbToLinearColorFilter() override
impeller::ColorFilterContents::MakeSrgbToLinearFilter
static std::shared_ptr< ColorFilterContents > MakeSrgbToLinearFilter(FilterInput::Ref input)
Definition: color_filter_contents.cc:75
impeller::LinearToSrgbColorFilter::WrapWithGPUColorFilter
std::shared_ptr< ColorFilterContents > WrapWithGPUColorFilter(std::shared_ptr< FilterInput > input, ColorFilterContents::AbsorbOpacity absorb_opacity) const override
Wraps the given filter input with a GPU-based filter that will perform the color operation....
Definition: color_filter.cc:128
impeller::SrgbToLinearColorFilter::SrgbToLinearColorFilter
SrgbToLinearColorFilter()
filter_input.h
color_filter_contents.h
impeller::MatrixColorFilter::Clone
std::shared_ptr< ColorFilter > Clone() const override
Definition: color_filter.cc:89
impeller::ColorFilter::MakeMatrix
static std::shared_ptr< ColorFilter > MakeMatrix(ColorMatrix color_matrix)
Definition: color_filter.cc:25
impeller::BlendColorFilter::GetCPUColorFilterProc
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
Definition: color_filter.cc:55
impeller::ColorFilter::~ColorFilter
virtual ~ColorFilter()
impeller::ColorFilter::MakeLinearToSrgb
static std::shared_ptr< ColorFilter > MakeLinearToSrgb()
Definition: color_filter.cc:33
impeller::LinearToSrgbColorFilter::~LinearToSrgbColorFilter
~LinearToSrgbColorFilter() override
impeller::ColorFilterContents::MakeColorMatrix
static std::shared_ptr< ColorFilterContents > MakeColorMatrix(FilterInput::Ref input, const ColorMatrix &color_matrix)
Definition: color_filter_contents.cc:58
color.h
color_filter.h
impeller::ColorFilter::MakeSrgbToLinear
static std::shared_ptr< ColorFilter > MakeSrgbToLinear()
Definition: color_filter.cc:29
impeller::LinearToSrgbColorFilter::GetCPUColorFilterProc
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
Definition: color_filter.cc:136
impeller::SrgbToLinearColorFilter::GetCPUColorFilterProc
ColorFilterProc GetCPUColorFilterProc() const override
Returns a function that can be used to filter unpremultiplied Impeller Colors on the CPU.
Definition: color_filter.cc:110
impeller::ColorMatrix
Definition: color.h:115
impeller::ColorFilterContents::MakeBlend
static std::shared_ptr< ColorFilterContents > MakeBlend(BlendMode blend_mode, FilterInput::Vector inputs, std::optional< Color > foreground_color=std::nullopt)
the [inputs] are expected to be in the order of dst, src.
Definition: color_filter_contents.cc:17
impeller::ColorFilterContents::AbsorbOpacity
AbsorbOpacity
Definition: color_filter_contents.h:13
impeller
Definition: aiks_context.cc:10