Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
modules
svg
src
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
8
#include "
include/core/SkColorFilter.h
"
9
#include "
include/effects/SkImageFilters.h
"
10
#include "
include/private/SkColorData.h
"
11
#include "
modules/svg/include/SkSVGAttributeParser.h
"
12
#include "
modules/svg/include/SkSVGFeColorMatrix.h
"
13
#include "
modules/svg/include/SkSVGFilterContext.h
"
14
#include "
modules/svg/include/SkSVGRenderContext.h
"
15
#include "
modules/svg/include/SkSVGValue.h
"
16
17
bool
SkSVGFeColorMatrix::parseAndSetAttribute
(
const
char
*
name
,
const
char
* value) {
18
return
INHERITED::parseAndSetAttribute
(
name
,
value
) ||
19
this->setType(
20
SkSVGAttributeParser::parse<SkSVGFeColorMatrixType>(
"type"
,
name
,
value
)) ||
21
this->setValues(
22
SkSVGAttributeParser::parse<SkSVGFeColorMatrixValues>(
"values"
,
name
,
value
));
23
}
24
25
SkColorMatrix
SkSVGFeColorMatrix::makeMatrixForType()
const
{
26
if
(fValues.empty() && fType !=
SkSVGFeColorMatrixType::kLuminanceToAlpha
) {
27
return
SkColorMatrix
();
28
}
29
30
switch
(fType) {
31
case
SkSVGFeColorMatrixType::kMatrix
: {
32
if
(fValues.size() < 20) {
33
return
SkColorMatrix
();
34
}
35
SkColorMatrix
m
;
36
m
.setRowMajor(fValues.data());
37
return
m
;
38
}
39
case
SkSVGFeColorMatrixType::kSaturate
:
40
return
MakeSaturate(!fValues.empty() ? fValues[0] : 1);
41
case
SkSVGFeColorMatrixType::kHueRotate
:
42
return
MakeHueRotate(!fValues.empty() ? fValues[0] : 0);
43
case
SkSVGFeColorMatrixType::kLuminanceToAlpha
:
44
return
MakeLuminanceToAlpha();
45
}
46
47
SkUNREACHABLE
;
48
}
49
50
SkColorMatrix
SkSVGFeColorMatrix::MakeSaturate(
SkSVGNumberType
s
) {
51
SkColorMatrix
m
;
52
m
.setSaturation(
s
);
53
return
m
;
54
}
55
56
SkColorMatrix
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
83
SkColorMatrix
SkSVGFeColorMatrix::MakeLuminanceToAlpha() {
84
return
SkColorMatrix
(
85
0, 0, 0, 0, 0,
86
0, 0, 0, 0, 0,
87
0, 0, 0, 0, 0,
88
SK_LUM_COEFF_R
,
SK_LUM_COEFF_G
,
SK_LUM_COEFF_B
, 0, 0
89
);
90
}
91
92
sk_sp<SkImageFilter>
SkSVGFeColorMatrix::onMakeImageFilter
(
const
SkSVGRenderContext
& ctx,
93
const
SkSVGFilterContext
& fctx)
const
{
94
return
SkImageFilters::ColorFilter
(
95
SkColorFilters::Matrix
(makeMatrixForType()),
96
fctx.
resolveInput
(ctx, this->getIn(), this->resolveColorspace(ctx, fctx)),
97
this->resolveFilterSubregion(ctx, fctx));
98
}
99
100
template
<>
bool
SkSVGAttributeParser::parse
(
SkSVGFeColorMatrixType
*
type
) {
101
static
constexpr
std::tuple<const char*, SkSVGFeColorMatrixType> gTypeMap[] = {
102
{
"matrix"
,
SkSVGFeColorMatrixType::kMatrix
},
103
{
"saturate"
,
SkSVGFeColorMatrixType::kSaturate
},
104
{
"hueRotate"
,
SkSVGFeColorMatrixType::kHueRotate
},
105
{
"luminanceToAlpha"
,
SkSVGFeColorMatrixType::kLuminanceToAlpha
},
106
};
107
108
return
this->parseEnumMap(gTypeMap,
type
) && this->parseEOSToken();
109
}
SkUNREACHABLE
#define SkUNREACHABLE
Definition
SkAssert.h:135
SkColorData.h
SK_LUM_COEFF_B
#define SK_LUM_COEFF_B
Definition
SkColorData.h:112
SK_LUM_COEFF_R
#define SK_LUM_COEFF_R
Definition
SkColorData.h:110
SK_LUM_COEFF_G
#define SK_LUM_COEFF_G
Definition
SkColorData.h:111
SkColorFilter.h
SkImageFilters.h
SkSVGAttributeParser.h
SkSVGFeColorMatrix.h
SkSVGFilterContext.h
SkSVGRenderContext.h
SkSVGNumberType
SkScalar SkSVGNumberType
Definition
SkSVGTypes.h:27
SkSVGFeColorMatrixType
SkSVGFeColorMatrixType
Definition
SkSVGTypes.h:670
SkSVGFeColorMatrixType::kHueRotate
@ kHueRotate
SkSVGFeColorMatrixType::kMatrix
@ kMatrix
SkSVGFeColorMatrixType::kSaturate
@ kSaturate
SkSVGFeColorMatrixType::kLuminanceToAlpha
@ kLuminanceToAlpha
SkSVGValue.h
SkDegreesToRadians
#define SkDegreesToRadians(degrees)
Definition
SkScalar.h:77
SkScalarSin
#define SkScalarSin(radians)
Definition
SkScalar.h:45
SkScalarCos
#define SkScalarCos(radians)
Definition
SkScalar.h:46
SkColorFilters::Matrix
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
Definition
SkMatrixColorFilter.cpp:103
SkColorMatrix
Definition
SkColorMatrix.h:18
SkImageFilters::ColorFilter
static sk_sp< SkImageFilter > ColorFilter(sk_sp< SkColorFilter > cf, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
Definition
SkColorFilterImageFilter.cpp:72
SkSVGAttributeParser::parse
bool parse(SkSVGIntegerType *v)
Definition
SkSVGAttributeParser.h:27
SkSVGFeColorMatrix::parseAndSetAttribute
bool parseAndSetAttribute(const char *, const char *) override
Definition
SkSVGFeColorMatrix.cpp:17
SkSVGFeColorMatrix::onMakeImageFilter
sk_sp< SkImageFilter > onMakeImageFilter(const SkSVGRenderContext &, const SkSVGFilterContext &) const override
Definition
SkSVGFeColorMatrix.cpp:92
SkSVGFe::parseAndSetAttribute
bool parseAndSetAttribute(const char *, const char *) override
Definition
SkSVGFe.cpp:93
SkSVGFilterContext
Definition
SkSVGFilterContext.h:21
SkSVGFilterContext::resolveInput
sk_sp< SkImageFilter > resolveInput(const SkSVGRenderContext &, const SkSVGFeInputType &) const
Definition
SkSVGFilterContext.cpp:145
SkSVGRenderContext
Definition
SkSVGRenderContext.h:63
sk_sp
Definition
SkRefCnt.h:220
SkScalar
float SkScalar
Definition
extension.cpp:12
s
struct MyStruct s
value
uint8_t value
Definition
fl_standard_message_codec.cc:36
type
uint8_t type
Definition
fl_standard_message_codec_test.cc:1115
name
const char * name
Definition
fuchsia.cc:50
dart_profiler_symbols.m
m
Definition
dart_profiler_symbols.py:64
Generated on Fri Apr 26 2024 06:16:27 for Flutter Engine by
1.9.8