Skip to content

Commit

Permalink
Fix one frame missing
Browse files Browse the repository at this point in the history
As mStartFrame and mEndFrame was counted from 0 and totalFrame() was
calculated as a difference, there were always one frame missing and
the animation rescaled. This patch adds one to the total frames count.
There is 0.01 subtract (copied from android implementation, needed
for some resources where frame no is non-whole number).

issue: Samsung#527
  • Loading branch information
mmaciola committed Sep 15, 2022
1 parent 30f300d commit e1875c5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lottie/lottieitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ VMatrix renderer::Layer::matrix(int frameNo) const
bool renderer::Layer::visible() const
{
return (frameNo() >= mLayerData->inFrame() &&
frameNo() < mLayerData->outFrame());
frameNo() <= mLayerData->outFrame());
}

void renderer::Layer::preprocess(const VRect &clip)
Expand Down
4 changes: 2 additions & 2 deletions src/lottie/lottiemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ class Composition : public Object {
{
return long(frameAtPos(timeInSec / duration()));
}
size_t totalFrame() const { return mEndFrame - mStartFrame; }
long frameDuration() const { return mEndFrame - mStartFrame - 1; }
size_t totalFrame() const { return mEndFrame - mStartFrame + 1; }
long frameDuration() const { return mEndFrame - mStartFrame; }
float frameRate() const { return mFrameRate; }
size_t startFrame() const { return mStartFrame; }
size_t endFrame() const { return mEndFrame; }
Expand Down
6 changes: 3 additions & 3 deletions src/lottie/lottieparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,9 @@ void LottieParserImpl::parseComposition()
} else if (0 == strcmp(key, "h")) {
comp->mSize.setHeight(GetInt());
} else if (0 == strcmp(key, "ip")) {
comp->mStartFrame = GetDouble();
comp->mStartFrame = std::lround(GetDouble());
} else if (0 == strcmp(key, "op")) {
comp->mEndFrame = GetDouble();
comp->mEndFrame = std::lround(GetDouble() - 0.01f);
} else if (0 == strcmp(key, "fr")) {
comp->mFrameRate = GetDouble();
} else if (0 == strcmp(key, "assets")) {
Expand Down Expand Up @@ -999,7 +999,7 @@ model::Layer *LottieParserImpl::parseLayer()
} else if (0 == strcmp(key, "ip")) {
layer->mInFrame = std::lround(GetDouble());
} else if (0 == strcmp(key, "op")) {
layer->mOutFrame = std::lround(GetDouble());
layer->mOutFrame = std::lround(GetDouble() - 0.01f);
} else if (0 == strcmp(key, "st")) {
layer->mStartFrame = GetDouble();
} else if (0 == strcmp(key, "bm")) {
Expand Down

0 comments on commit e1875c5

Please sign in to comment.