From e1875c5a0c7edfaff4c4c8ea2a19017866679ae2 Mon Sep 17 00:00:00 2001 From: Michal Maciola Date: Wed, 14 Sep 2022 12:07:04 +0200 Subject: [PATCH] Fix one frame missing 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: #527 --- src/lottie/lottieitem.cpp | 2 +- src/lottie/lottiemodel.h | 4 ++-- src/lottie/lottieparser.cpp | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index cb1bc2cd..4cd22e4c 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 3e043085..745571e2 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -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; } diff --git a/src/lottie/lottieparser.cpp b/src/lottie/lottieparser.cpp index 83be17e3..2c1dc946 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() - 0.01f); } else if (0 == strcmp(key, "fr")) { comp->mFrameRate = GetDouble(); } else if (0 == strcmp(key, "assets")) { @@ -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")) {