From c693c97cd8441ca3dff30b1715c63749be0c1aa2 Mon Sep 17 00:00:00 2001 From: Michal Maciola <71131832+mmaciola@users.noreply.github.com> Date: Mon, 19 Sep 2022 04:03:23 +0200 Subject: [PATCH] Fix one frame missing (#529) 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. issue: #527 Change-Id: I82f7d85ba6f932b2e47a4be68bf91dcc97da5b0a --- src/lottie/lottieitem.cpp | 2 +- src/lottie/lottiemodel.h | 4 ++-- src/lottie/lottieparser.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index cb1bc2c..4cd22e4 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -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) diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index 3e04308..745571e 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -539,8 +539,8 @@ public: { 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; } diff --git a/src/lottie/lottieparser.cpp b/src/lottie/lottieparser.cpp index 83be17e..e14fd5c 100644 --- a/src/lottie/lottieparser.cpp +++ b/src/lottie/lottieparser.cpp @@ -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()); } else if (0 == strcmp(key, "fr")) { comp->mFrameRate = GetDouble(); } else if (0 == strcmp(key, "assets")) { -- 2.34.1