27 std::vector<uint8_t> a_tbl, b_tbl, g_tbl, r_tbl;
30 switch (child->tag()) {
32 a_tbl =
static_cast<const SkSVGFeFunc*
>(child.get())->getTable();
35 b_tbl =
static_cast<const SkSVGFeFunc*
>(child.get())->getTable();
38 g_tbl =
static_cast<const SkSVGFeFunc*
>(child.get())->getTable();
41 r_tbl =
static_cast<const SkSVGFeFunc*
>(child.get())->getTable();
47 SkASSERT(a_tbl.empty() || a_tbl.size() == 256);
48 SkASSERT(b_tbl.empty() || b_tbl.size() == 256);
49 SkASSERT(g_tbl.empty() || g_tbl.size() == 256);
50 SkASSERT(r_tbl.empty() || r_tbl.size() == 256);
58 r_tbl.empty() ?
nullptr : r_tbl.data(),
59 g_tbl.empty() ?
nullptr : g_tbl.data(),
60 b_tbl.empty() ?
nullptr : b_tbl.data());
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;
72 for (
size_t i = 0;
i < 256; ++
i) {
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();
84 for (
size_t i = 0;
i < 256; ++
i) {
85 const float component =
offset + std::pow(
i * (1 / 255.f), exponent);
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) {
99 const size_t n = vals.size() - 1;
101 std::vector<uint8_t> tbl(256);
102 for (
size_t k = 0; k < n; ++k) {
105 v1 =
SkTPin(vals[k + 1], 0.f, 1.f);
108 const size_t c_start = k * 255 / n,
109 c_end = (k + 1) * 255 / n;
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);
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;
132 const auto make_discrete = [&]() -> std::vector<uint8_t> {
133 return lerp_from_table_values([](
float v0,
float v1,
float t) {
138 switch (this->getType()) {
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)) ||
158 this->setType(SkSVGAttributeParser::parse<SkSVGFeFuncType>(
"type",
name, val));
163 static constexpr std::tuple<const char*, SkSVGFeFuncType> gTypeMap[] = {
171 return this->parseEnumMap(gTypeMap,
type) && this->parseEOSToken();
#define sk_float_round2int(x)
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
constexpr uint8_t SkToU8(S x)
static sk_sp< SkColorFilter > TableARGB(const uint8_t tableA[256], const uint8_t tableR[256], const uint8_t tableG[256], const uint8_t tableB[256])
static sk_sp< SkImageFilter > ColorFilter(sk_sp< SkColorFilter > cf, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
bool parse(SkSVGIntegerType *v)
skia_private::STArray< 1, sk_sp< SkSVGNode >, true > fChildren
sk_sp< SkImageFilter > onMakeImageFilter(const SkSVGRenderContext &, const SkSVGFilterContext &) const override
bool parseAndSetAttribute(const char *, const char *) override
std::vector< uint8_t > getTable() const
SkRect resolveFilterSubregion(const SkSVGRenderContext &, const SkSVGFilterContext &) const
virtual SkSVGColorspace resolveColorspace(const SkSVGRenderContext &, const SkSVGFilterContext &) const
sk_sp< SkImageFilter > resolveInput(const SkSVGRenderContext &, const SkSVGFeInputType &) const
virtual bool parseAndSetAttribute(const char *name, const char *value)
static sk_sp< SkShader > make_linear(const GradRun &run, SkTileMode mode)
DEF_SWITCHES_START aot vmservice shared library name