MCPcopy Create free account
hub / github.com/Samsung/rlottie / generateGradientColorTable

Method generateGradientColorTable

src/vector/vdrawhelper.cpp:127–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125};
126
127bool VGradientCache::generateGradientColorTable(const VGradientStops &stops,
128 float opacity,
129 uint32_t *colorTable, int size)
130{
131 int dist, idist, pos = 0;
132 size_t i;
133 bool alpha = false;
134 size_t stopCount = stops.size();
135 const VGradientStop *curr, *next, *start;
136 uint32_t curColor, nextColor;
137 float delta, t, incr, fpos;
138
139 if (!vCompare(opacity, 1.0f)) alpha = true;
140
141 start = stops.data();
142 curr = start;
143 if (!curr->second.isOpaque()) alpha = true;
144 curColor = curr->second.premulARGB(opacity);
145 incr = 1.0f / (float)size;
146 fpos = 1.5f * incr;
147
148 colorTable[pos++] = curColor;
149
150 while (fpos <= curr->first) {
151 colorTable[pos] = colorTable[pos - 1];
152 pos++;
153 fpos += incr;
154 }
155
156 for (i = 0; i < stopCount - 1; ++i) {
157 curr = (start + i);
158 next = (start + i + 1);
159 delta = 1 / (next->first - curr->first);
160 if (!next->second.isOpaque()) alpha = true;
161 nextColor = next->second.premulARGB(opacity);
162 while (fpos < next->first && pos < size) {
163 t = (fpos - curr->first) * delta;
164 dist = (int)(255 * t);
165 idist = 255 - dist;
166 colorTable[pos] =
167 interpolate_pixel(curColor, idist, nextColor, dist);
168 ++pos;
169 fpos += incr;
170 }
171 curColor = nextColor;
172 }
173
174 for (; pos < size; ++pos) colorTable[pos] = curColor;
175
176 // Make sure the last color stop is represented at the end of the table
177 colorTable[size - 1] = curColor;
178 return alpha;
179}
180
181void VRasterBuffer::clear()
182{

Callers

nothing calls this directly

Calls 6

vCompareFunction · 0.85
interpolate_pixelFunction · 0.85
isOpaqueMethod · 0.80
premulARGBMethod · 0.80
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected