lottie: fixed a corrupted colorstop population

the color stop number should be retained during
the population of frames

issue: https://github.com/thorvg/thorvg/issues/2765
This commit is contained in:
Hermet Park 2024-10-03 13:07:29 +09:00
parent 1c48cd3cdc
commit 2b3a2e5ddf
2 changed files with 9 additions and 8 deletions

View file

@ -183,15 +183,14 @@ void LottieTrimpath::segment(float frameNo, float& start, float& end, LottieExpr
} }
uint32_t LottieGradient::populate(ColorStop& color) uint32_t LottieGradient::populate(ColorStop& color, size_t count)
{ {
colorStops.populated = true;
if (!color.input) return 0; if (!color.input) return 0;
uint32_t alphaCnt = (color.input->count - (colorStops.count * 4)) / 2; uint32_t alphaCnt = (color.input->count - (count * 4)) / 2;
Array<Fill::ColorStop> output(colorStops.count + alphaCnt); Array<Fill::ColorStop> output(count + alphaCnt);
uint32_t cidx = 0; //color count uint32_t cidx = 0; //color count
uint32_t clast = colorStops.count * 4; uint32_t clast = count * 4;
if (clast > color.input->count) clast = color.input->count; if (clast > color.input->count) clast = color.input->count;
uint32_t aidx = clast; //alpha count uint32_t aidx = clast; //alpha count
Fill::ColorStop cs; Fill::ColorStop cs;

View file

@ -558,13 +558,15 @@ struct LottieGradient : LottieObject
bool prepare() bool prepare()
{ {
if (!colorStops.populated) { if (!colorStops.populated) {
auto count = colorStops.count; //colorstop count can be modified after population
if (colorStops.frames) { if (colorStops.frames) {
for (auto v = colorStops.frames->begin(); v < colorStops.frames->end(); ++v) { for (auto v = colorStops.frames->begin(); v < colorStops.frames->end(); ++v) {
colorStops.count = populate(v->value); colorStops.count = populate(v->value, count);
} }
} else { } else {
colorStops.count = populate(colorStops.value); colorStops.count = populate(colorStops.value, count);
} }
colorStops.populated = true;
} }
if (start.frames || end.frames || height.frames || angle.frames || opacity.frames || colorStops.frames) return true; if (start.frames || end.frames || height.frames || angle.frames || opacity.frames || colorStops.frames) return true;
return false; return false;
@ -582,7 +584,7 @@ struct LottieGradient : LottieObject
} }
uint32_t populate(ColorStop& color); uint32_t populate(ColorStop& color, size_t count);
Fill* fill(float frameNo, LottieExpressions* exps); Fill* fill(float frameNo, LottieExpressions* exps);
LottiePoint start = Point{0.0f, 0.0f}; LottiePoint start = Point{0.0f, 0.0f};