size_t width, size_t height);
/**
+ * @brief Maps position to frame number and returns it.
+ *
+ * @param[in] animation Animation object.
+ * @param[in] pos position in the range [ 0.0 .. 1.0 ].
+ *
+ * @return mapped frame numbe in the range [ start_frame .. end_frame ].
+ * @c 0 if the Lottie resource has no animation.
+ *
+ *
+ * @ingroup Lottie_Animation
+ * @internal
+ */
+LOT_EXPORT size_t lottie_animation_get_frame_at_pos(const Lottie_Animation *animation, float pos);
+
+/**
* @brief Request to render the content of the frame @p frame_num to buffer @p buffer asynchronously.
*
* @param[in] animation Animation object.
* @warning User must call lottie_animation_render_async() and lottie_animation_render_flush()
* in pair to get the benefit of async rendering.
*
+ * @return the pixel buffer it finished rendering.
+ *
* @ingroup Lottie_Animation
* @internal
*/
-LOT_EXPORT void
+LOT_EXPORT uint32_t *
lottie_animation_render_flush(Lottie_Animation *animation);
#ifdef __cplusplus
{
std::unique_ptr<Animation> mAnimation;
std::future<Surface> mRenderTask;
+ uint32_t *mBufferRef;
};
LOT_EXPORT Lottie_Animation_S *lottie_animation_from_file(const char *path)
return animation->mAnimation->renderTree(frame_num, width, height);
}
+LOT_EXPORT size_t
+lottie_animation_get_frame_at_pos(const Lottie_Animation_S *animation, float pos)
+{
+ if (!animation) return 0;
+
+ return animation->mAnimation->frameAtPos(pos);
+}
+
LOT_EXPORT void
lottie_animation_render_async(Lottie_Animation_S *animation,
size_t frame_number,
lottie::Surface surface(buffer, width, height, bytes_per_line);
animation->mRenderTask = animation->mAnimation->render(frame_number, surface);
+ animation->mBufferRef = buffer;
}
-LOT_EXPORT void
+LOT_EXPORT uint32_t *
lottie_animation_render_flush(Lottie_Animation_S *animation)
{
- if (!animation) return;
+ if (!animation) return nullptr;
if (animation->mRenderTask.valid()) {
animation->mRenderTask.get();
}
+
+ return animation->mBufferRef;
}
}