65 {
66
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) {
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);
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
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
105 v1 =
SkTPin(vals[k + 1], 0.f, 1.f);
106
107
108 const size_t c_start = k * 255 / n,
109 c_end = (k + 1) * 255 / n;
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
118 }
119 }
120
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()) {
144 }
145
147}
#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< SkShader > make_linear(const GradRun &run, SkTileMode mode)