animation/lottie: improved the precision of frame values.

Refined the logic for updating frame numbers
to ensure greater accuracy in value precision.

issue: https://github.com/thorvg/thorvg/issues/2266
This commit is contained in:
Hermet Park 2024-05-13 12:22:55 +09:00 committed by Hermet Park
parent 6a9a390e9d
commit 38bd34b01f
3 changed files with 11 additions and 7 deletions

View file

@ -1805,6 +1805,7 @@ public:
*
* @note For efficiency, ThorVG ignores updates to the new frame value if the difference from the current frame value
* is less than 0.001. In such cases, it returns @c Result::InsufficientCondition.
* Values less than 0.001 may be disregarded and may not be accurately retained by the Animation.
*
* @see totalFrame()
*

View file

@ -2254,6 +2254,7 @@ TVG_API Tvg_Animation* tvg_animation_new();
*
* \note For efficiency, ThorVG ignores updates to the new frame value if the difference from the current frame value
* is less than 0.001. In such cases, it returns @c Result::InsufficientCondition.
* Values less than 0.001 may be disregarded and may not be accurately retained by the Animation.
* \see tvg_animation_get_total_frame()
*
* \since 0.13

View file

@ -313,17 +313,19 @@ bool LottieLoader::override(const char* slot)
bool LottieLoader::frame(float no)
{
auto frameNo = no + startFrame();
//This ensures that the target frame number is reached.
frameNo *= 10000.0f;
frameNo = roundf(frameNo);
frameNo *= 0.0001f;
//Skip update if frame diff is too small.
if (fabsf(this->frameNo - no) < 0.0009f) return false;
if (fabsf(this->frameNo - frameNo) <= 0.0009f) return false;
this->done();
//This ensures that the perfect last frame is reached.
no *= 1000.0f;
no = roundf(no);
no *= 0.001f;
this->frameNo = no + startFrame();
this->frameNo = frameNo;
TaskScheduler::request(this);