lottie: rectify the frame updates.

Currently, tvg ignores the frame value if the difference
is less than 0.001. In most cases, updating the frames
when the change is less than 1ms is just an unnecessary
burden on the system.

Instead, this ensures that the perfect last frame is reached.

issue: https://github.com/thorvg/thorvg/issues/2147
This commit is contained in:
Hermet Park 2024-04-09 15:52:23 +09:00
parent 1c74e1e40a
commit ca7aec5fff
3 changed files with 12 additions and 2 deletions

View file

@ -1853,6 +1853,9 @@ public:
* @retval Result::InsufficientCondition if the given @p no is the same as the current frame value.
* @retval Result::NonSupport The current Picture data does not support animations.
*
* @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.
*
* @see totalFrame()
*
*/

View file

@ -2253,6 +2253,8 @@ TVG_API Tvg_Animation* tvg_animation_new();
* \retval TVG_RESULT_INSUFFICIENT_CONDITION No animatable data loaded from the Picture.
* \retval TVG_RESULT_NOT_SUPPORTED The picture data does not support animations.
*
* \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.
* \see tvg_animation_get_total_frame()
*/
TVG_API Tvg_Result tvg_animation_set_frame(Tvg_Animation* animation, float no);

View file

@ -315,11 +315,16 @@ bool LottieLoader::override(const char* slot)
bool LottieLoader::frame(float no)
{
//no meaing to update if frame diff is less then 1ms
if (fabsf(this->frameNo - no) < 0.001f) return false;
//Skip update if frame diff is too small.
if (fabsf(this->frameNo - no) < 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;
TaskScheduler::request(this);