Flutter Engine
The Flutter Engine
SkSVGFeColorMatrix.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
16
17bool SkSVGFeColorMatrix::parseAndSetAttribute(const char* name, const char* value) {
19 this->setType(
20 SkSVGAttributeParser::parse<SkSVGFeColorMatrixType>("type", name, value)) ||
21 this->setValues(
22 SkSVGAttributeParser::parse<SkSVGFeColorMatrixValues>("values", name, value));
23}
24
25SkColorMatrix SkSVGFeColorMatrix::makeMatrixForType() const {
26 if (fValues.empty() && fType != SkSVGFeColorMatrixType::kLuminanceToAlpha) {
27 return SkColorMatrix();
28 }
29
30 switch (fType) {
32 if (fValues.size() < 20) {
33 return SkColorMatrix();
34 }
36 m.setRowMajor(fValues.data());
37 return m;
38 }
40 return MakeSaturate(!fValues.empty() ? fValues[0] : 1);
42 return MakeHueRotate(!fValues.empty() ? fValues[0] : 0);
44 return MakeLuminanceToAlpha();
45 }
46
48}
49
50SkColorMatrix SkSVGFeColorMatrix::MakeSaturate(SkSVGNumberType s) {
52 m.setSaturation(s);
53 return m;
54}
55
56SkColorMatrix SkSVGFeColorMatrix::MakeHueRotate(SkSVGNumberType degrees) {
57 const SkScalar theta = SkDegreesToRadians(degrees);
58 const SkSVGNumberType c = SkScalarCos(theta);
59 const SkSVGNumberType s = SkScalarSin(theta);
60 return SkColorMatrix(
61 0.213f + c* 0.787f + s*-0.213f,
62 0.715f + c*-0.715f + s*-0.715f,
63 0.072f + c*-0.072f + s* 0.928f,
64 0,
65 0,
66
67 0.213f + c*-0.213f + s* 0.143f,
68 0.715f + c* 0.285f + s* 0.140f,
69 0.072f + c*-0.072f + s*-0.283f,
70 0,
71 0,
72
73 0.213f + c*-0.213f + s*-0.787f,
74 0.715f + c*-0.715f + s* 0.715f,
75 0.072f + c* 0.928f + s* 0.072f,
76 0,
77 0,
78
79 0,0,0,1,0
80 );
81}
82
83SkColorMatrix SkSVGFeColorMatrix::MakeLuminanceToAlpha() {
84 return SkColorMatrix(
85 0, 0, 0, 0, 0,
86 0, 0, 0, 0, 0,
87 0, 0, 0, 0, 0,
89 );
90}
91
93 const SkSVGFilterContext& fctx) const {
95 SkColorFilters::Matrix(makeMatrixForType()),
96 fctx.resolveInput(ctx, this->getIn(), this->resolveColorspace(ctx, fctx)),
97 this->resolveFilterSubregion(ctx, fctx));
98}
99
101 static constexpr std::tuple<const char*, SkSVGFeColorMatrixType> gTypeMap[] = {
105 {"luminanceToAlpha", SkSVGFeColorMatrixType::kLuminanceToAlpha},
106 };
107
108 return this->parseEnumMap(gTypeMap, type) && this->parseEOSToken();
109}
#define SkUNREACHABLE
Definition: SkAssert.h:135
#define SK_LUM_COEFF_B
Definition: SkColorData.h:112
#define SK_LUM_COEFF_R
Definition: SkColorData.h:110
#define SK_LUM_COEFF_G
Definition: SkColorData.h:111
SkScalar SkSVGNumberType
Definition: SkSVGTypes.h:27
SkSVGFeColorMatrixType
Definition: SkSVGTypes.h:670
#define SkDegreesToRadians(degrees)
Definition: SkScalar.h:77
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SkScalarCos(radians)
Definition: SkScalar.h:46
GLenum type
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
static sk_sp< SkImageFilter > ColorFilter(sk_sp< SkColorFilter > cf, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
bool parse(SkSVGIntegerType *v)
bool parseAndSetAttribute(const char *, const char *) override
sk_sp< SkImageFilter > onMakeImageFilter(const SkSVGRenderContext &, const SkSVGFilterContext &) const override
bool parseAndSetAttribute(const char *, const char *) override
Definition: SkSVGFe.cpp:93
sk_sp< SkImageFilter > resolveInput(const SkSVGRenderContext &, const SkSVGFeInputType &) const
float SkScalar
Definition: extension.cpp:12
struct MyStruct s
uint8_t value
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32