Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
SkSVGFeFunc Class Referencefinal

#include <SkSVGFeComponentTransfer.h>

Inheritance diagram for SkSVGFeFunc:
SkSVGHiddenContainer SkSVGContainer SkSVGTransformableNode SkSVGNode SkRefCnt SkRefCntBase

Public Member Functions

std::vector< uint8_t > getTable () const
 
- Public Member Functions inherited from SkSVGContainer
void appendChild (sk_sp< SkSVGNode >) override
 
- Public Member Functions inherited from SkSVGTransformableNode
void setTransform (const SkSVGTransformType &t)
 
- Public Member Functions inherited from SkSVGNode
 ~SkSVGNode () override
 
SkSVGTag tag () const
 
virtual void appendChild (sk_sp< SkSVGNode >)=0
 
void render (const SkSVGRenderContext &) const
 
bool asPaint (const SkSVGRenderContext &, SkPaint *) const
 
SkPath asPath (const SkSVGRenderContext &) const
 
SkRect objectBoundingBox (const SkSVGRenderContext &) const
 
void setAttribute (SkSVGAttribute, const SkSVGValue &)
 
bool setAttribute (const char *attributeName, const char *attributeValue)
 
virtual bool parseAndSetAttribute (const char *name, const char *value)
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static sk_sp< SkSVGFeFuncMakeFuncA ()
 
static sk_sp< SkSVGFeFuncMakeFuncR ()
 
static sk_sp< SkSVGFeFuncMakeFuncG ()
 
static sk_sp< SkSVGFeFuncMakeFuncB ()
 

Protected Member Functions

bool parseAndSetAttribute (const char *, const char *) override
 
- Protected Member Functions inherited from SkSVGHiddenContainer
 SkSVGHiddenContainer (SkSVGTag t)
 
void onRender (const SkSVGRenderContext &) const final
 
- Protected Member Functions inherited from SkSVGContainer
 SkSVGContainer (SkSVGTag)
 
void onRender (const SkSVGRenderContext &) const override
 
SkPath onAsPath (const SkSVGRenderContext &) const override
 
SkRect onObjectBoundingBox (const SkSVGRenderContext &) const override
 
bool hasChildren () const final
 
template<typename NodeType , typename Func >
void forEachChild (Func func) const
 
- Protected Member Functions inherited from SkSVGTransformableNode
 SkSVGTransformableNode (SkSVGTag)
 
bool onPrepareToRender (SkSVGRenderContext *) const override
 
void onSetAttribute (SkSVGAttribute, const SkSVGValue &) override
 
void mapToParent (SkPath *) const
 
void mapToParent (SkRect *) const
 
- Protected Member Functions inherited from SkSVGNode
 SkSVGNode (SkSVGTag)
 
virtual bool onPrepareToRender (SkSVGRenderContext *) const
 
virtual void onRender (const SkSVGRenderContext &) const =0
 
virtual bool onAsPaint (const SkSVGRenderContext &, SkPaint *) const
 
virtual SkPath onAsPath (const SkSVGRenderContext &) const =0
 
virtual void onSetAttribute (SkSVGAttribute, const SkSVGValue &)
 
virtual bool hasChildren () const
 
virtual SkRect onObjectBoundingBox (const SkSVGRenderContext &) const
 

Additional Inherited Members

- Static Protected Member Functions inherited from SkSVGNode
static SkMatrix ComputeViewboxMatrix (const SkRect &, const SkRect &, SkSVGPreserveAspectRatio)
 
- Protected Attributes inherited from SkSVGContainer
skia_private::STArray< 1, sk_sp< SkSVGNode >, truefChildren
 

Detailed Description

Definition at line 18 of file SkSVGFeComponentTransfer.h.

Member Function Documentation

◆ getTable()

std::vector< uint8_t > SkSVGFeFunc::getTable ( ) const

Definition at line 65 of file SkSVGFeComponentTransfer.cpp.

65 {
66 // https://www.w3.org/TR/SVG11/filters.html#feComponentTransferTypeAttribute
67 const auto make_linear = [this]() -> std::vector<uint8_t> {
68 std::vector<uint8_t> tbl(256);
69 const float slope = this->getSlope(),
70 intercept255 = this->getIntercept() * 255;
71
72 for (size_t i = 0; i < 256; ++i) {
73 tbl[i] = SkTPin<int>(sk_float_round2int(intercept255 + i * slope), 0, 255);
74 }
75
76 return tbl;
77 };
78
79 const auto make_gamma = [this]() -> std::vector<uint8_t> {
80 std::vector<uint8_t> tbl(256);
81 const float exponent = this->getExponent(),
82 offset = this->getOffset();
83
84 for (size_t i = 0; i < 256; ++i) {
85 const float component = offset + std::pow(i * (1 / 255.f), exponent);
86 tbl[i] = SkTPin<int>(sk_float_round2int(component * 255), 0, 255);
87 }
88
89 return tbl;
90 };
91
92 const auto lerp_from_table_values = [this](auto lerp_func) -> std::vector<uint8_t> {
93 const auto& vals = this->getTableValues();
94 if (vals.size() < 2 || vals.size() > 255) {
95 return {};
96 }
97
98 // number of interpolation intervals
99 const size_t n = vals.size() - 1;
100
101 std::vector<uint8_t> tbl(256);
102 for (size_t k = 0; k < n; ++k) {
103 // interpolation values
104 const SkSVGNumberType v0 = SkTPin(vals[k + 0], 0.f, 1.f),
105 v1 = SkTPin(vals[k + 1], 0.f, 1.f);
106
107 // start/end component table indices
108 const size_t c_start = k * 255 / n,
109 c_end = (k + 1) * 255 / n;
110 SkASSERT(c_end <= 255);
111
112 for (size_t ci = c_start; ci < c_end; ++ci) {
113 const float lerp_t = static_cast<float>(ci - c_start) / (c_end - c_start),
114 component = lerp_func(v0, v1, lerp_t);
115 SkASSERT(component >= 0 && component <= 1);
116
117 tbl[ci] = SkToU8(sk_float_round2int(component * 255));
118 }
119 }
120
121 tbl.back() = SkToU8(sk_float_round2int(255 * SkTPin(vals.back(), 0.f, 1.f)));
122
123 return tbl;
124 };
125
126 const auto make_table = [&]() -> std::vector<uint8_t> {
127 return lerp_from_table_values([](float v0, float v1, float t) {
128 return v0 + (v1 - v0) * t;
129 });
130 };
131
132 const auto make_discrete = [&]() -> std::vector<uint8_t> {
133 return lerp_from_table_values([](float v0, float v1, float t) {
134 return v0;
135 });
136 };
137
138 switch (this->getType()) {
139 case SkSVGFeFuncType::kIdentity: return {};
140 case SkSVGFeFuncType::kTable: return make_table();
141 case SkSVGFeFuncType::kDiscrete: return make_discrete();
143 case SkSVGFeFuncType::kGamma: return make_gamma();
144 }
145
147}
#define SkUNREACHABLE
Definition: SkAssert.h:135
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define sk_float_round2int(x)
SkScalar SkSVGNumberType
Definition: SkSVGTypes.h:27
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition: SkTPin.h:19
constexpr uint8_t SkToU8(S x)
Definition: SkTo.h:22
static sk_sp< SkShader > make_linear(const GradRun &run, SkTileMode mode)
Definition: gradients.cpp:778
SeparatedVector2 offset

◆ MakeFuncA()

static sk_sp< SkSVGFeFunc > SkSVGFeFunc::MakeFuncA ( )
inlinestatic

◆ MakeFuncB()

static sk_sp< SkSVGFeFunc > SkSVGFeFunc::MakeFuncB ( )
inlinestatic

Definition at line 32 of file SkSVGFeComponentTransfer.h.

◆ MakeFuncG()

static sk_sp< SkSVGFeFunc > SkSVGFeFunc::MakeFuncG ( )
inlinestatic

Definition at line 28 of file SkSVGFeComponentTransfer.h.

◆ MakeFuncR()

static sk_sp< SkSVGFeFunc > SkSVGFeFunc::MakeFuncR ( )
inlinestatic

Definition at line 24 of file SkSVGFeComponentTransfer.h.

◆ parseAndSetAttribute()

bool SkSVGFeFunc::parseAndSetAttribute ( const char *  name,
const char *  val 
)
overrideprotectedvirtual

Reimplemented from SkSVGNode.

Definition at line 149 of file SkSVGFeComponentTransfer.cpp.

149 {
151 this->setAmplitude(SkSVGAttributeParser::parse<SkSVGNumberType>("amplitude", name, val)) ||
152 this->setExponent(SkSVGAttributeParser::parse<SkSVGNumberType>("exponent", name, val)) ||
153 this->setIntercept(SkSVGAttributeParser::parse<SkSVGNumberType>("intercept", name, val)) ||
154 this->setOffset(SkSVGAttributeParser::parse<SkSVGNumberType>("offset", name, val)) ||
155 this->setSlope(SkSVGAttributeParser::parse<SkSVGNumberType>("slope", name, val)) ||
156 this->setTableValues(SkSVGAttributeParser::parse<std::vector<SkSVGNumberType>>("tableValues",
157 name, val)) ||
158 this->setType(SkSVGAttributeParser::parse<SkSVGFeFuncType>("type", name, val));
159}
bool parse(SkSVGIntegerType *v)
virtual bool parseAndSetAttribute(const char *name, const char *value)
Definition: SkSVGNode.cpp:90
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

The documentation for this class was generated from the following files: