mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 20:14:37 +00:00
loader/lottie: correct the frame range.
Fixed some incorrect time-remapping logic, Also, the last frame should not be taken into account for the drawing.
This commit is contained in:
parent
87dee3c1f7
commit
42d7a5faed
3 changed files with 13 additions and 18 deletions
|
@ -140,7 +140,7 @@ static void _updateTransform(LottieLayer* layer, int32_t frameNo)
|
||||||
auto transform = layer->transform;
|
auto transform = layer->transform;
|
||||||
auto parent = layer->parent;
|
auto parent = layer->parent;
|
||||||
|
|
||||||
if (parent) _updateTransform(parent, parent->remap(frameNo));
|
if (parent) _updateTransform(parent, frameNo);
|
||||||
|
|
||||||
auto& matrix = layer->cache.matrix;
|
auto& matrix = layer->cache.matrix;
|
||||||
|
|
||||||
|
@ -718,7 +718,7 @@ static void _updatePrecomp(LottieLayer* precomp, int32_t frameNo)
|
||||||
{
|
{
|
||||||
if (precomp->children.count == 0) return;
|
if (precomp->children.count == 0) return;
|
||||||
|
|
||||||
frameNo -= precomp->startFrame;
|
frameNo = precomp->remap(frameNo);
|
||||||
|
|
||||||
//TODO: skip if the layer is static.
|
//TODO: skip if the layer is static.
|
||||||
for (auto child = precomp->children.end() - 1; child >= precomp->children.data; --child) {
|
for (auto child = precomp->children.end() - 1; child >= precomp->children.data; --child) {
|
||||||
|
@ -779,7 +779,7 @@ static void _updateLayer(LottieLayer* root, LottieLayer* layer, int32_t frameNo)
|
||||||
layer->scene = nullptr;
|
layer->scene = nullptr;
|
||||||
|
|
||||||
//visibility
|
//visibility
|
||||||
if (frameNo < layer->inFrame || frameNo > layer->outFrame) return;
|
if (frameNo < layer->inFrame || frameNo >= layer->outFrame) return;
|
||||||
|
|
||||||
_updateTransform(layer, frameNo);
|
_updateTransform(layer, frameNo);
|
||||||
|
|
||||||
|
@ -798,20 +798,18 @@ static void _updateLayer(LottieLayer* root, LottieLayer* layer, int32_t frameNo)
|
||||||
|
|
||||||
layer->scene->transform(layer->cache.matrix);
|
layer->scene->transform(layer->cache.matrix);
|
||||||
|
|
||||||
auto rFrameNo = layer->remap(frameNo);
|
|
||||||
|
|
||||||
switch (layer->type) {
|
switch (layer->type) {
|
||||||
case LottieLayer::Precomp: {
|
case LottieLayer::Precomp: {
|
||||||
_updatePrecomp(layer, rFrameNo);
|
_updatePrecomp(layer, frameNo);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case LottieLayer::Solid: {
|
case LottieLayer::Solid: {
|
||||||
_updateSolid(layer, rFrameNo);
|
_updateSolid(layer, frameNo);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
RenderContext ctx;
|
RenderContext ctx;
|
||||||
_updateChildren(layer, rFrameNo, ctx);
|
_updateChildren(layer, frameNo, ctx);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -826,7 +824,7 @@ static void _updateLayer(LottieLayer* root, LottieLayer* layer, int32_t frameNo)
|
||||||
if (layer->matte.target->scene) layer->scene->composite(cast<Scene>(layer->matte.target->scene), layer->matte.type);
|
if (layer->matte.target->scene) layer->scene->composite(cast<Scene>(layer->matte.target->scene), layer->matte.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateMaskings(layer, rFrameNo);
|
_updateMaskings(layer, frameNo);
|
||||||
|
|
||||||
//clip the layer viewport
|
//clip the layer viewport
|
||||||
if (layer->refId && layer->w > 0 && layer->h > 0) {
|
if (layer->refId && layer->w > 0 && layer->h > 0) {
|
||||||
|
@ -910,7 +908,7 @@ bool LottieBuilder::update(LottieComposition* comp, int32_t frameNo)
|
||||||
{
|
{
|
||||||
frameNo += comp->startFrame;
|
frameNo += comp->startFrame;
|
||||||
if (frameNo < comp->startFrame) frameNo = comp->startFrame;
|
if (frameNo < comp->startFrame) frameNo = comp->startFrame;
|
||||||
if (frameNo > comp->endFrame) frameNo = comp->endFrame;
|
if (frameNo >= comp->endFrame) frameNo = (comp->endFrame - 1);
|
||||||
|
|
||||||
//Update root layer
|
//Update root layer
|
||||||
auto root = comp->root;
|
auto root = comp->root;
|
||||||
|
|
|
@ -145,8 +145,10 @@ void LottieLayer::prepare()
|
||||||
|
|
||||||
int32_t LottieLayer::remap(int32_t frameNo)
|
int32_t LottieLayer::remap(int32_t frameNo)
|
||||||
{
|
{
|
||||||
if (timeRemap.frames) {
|
if (timeRemap.frames || timeRemap.value) {
|
||||||
frameNo = comp->frameAtTime(timeRemap(frameNo));
|
frameNo = comp->frameAtTime(timeRemap(frameNo));
|
||||||
|
} else {
|
||||||
|
frameNo -= startFrame;
|
||||||
}
|
}
|
||||||
return (int32_t)(frameNo / timeStretch);
|
return (int32_t)(frameNo / timeStretch);
|
||||||
}
|
}
|
||||||
|
|
|
@ -475,7 +475,7 @@ struct LottieComposition
|
||||||
|
|
||||||
float duration() const
|
float duration() const
|
||||||
{
|
{
|
||||||
return frameDuration() / frameRate; // in second
|
return frameCnt() / frameRate; // in second
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t frameAtTime(float timeInSec) const
|
int32_t frameAtTime(float timeInSec) const
|
||||||
|
@ -483,15 +483,10 @@ struct LottieComposition
|
||||||
auto p = timeInSec / duration();
|
auto p = timeInSec / duration();
|
||||||
if (p < 0.0f) p = 0.0f;
|
if (p < 0.0f) p = 0.0f;
|
||||||
else if (p > 1.0f) p = 1.0f;
|
else if (p > 1.0f) p = 1.0f;
|
||||||
return (int32_t)lroundf(p * frameDuration());
|
return (int32_t)lroundf(p * frameCnt());
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t frameCnt() const
|
uint32_t frameCnt() const
|
||||||
{
|
|
||||||
return frameDuration() + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t frameDuration() const
|
|
||||||
{
|
{
|
||||||
return endFrame - startFrame;
|
return endFrame - startFrame;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue