1 #include "lottieanimation.h"
4 using namespace lottie;
8 struct Lottie_Animation_S
10 std::unique_ptr<Animation> mAnimation;
11 std::future<Surface> mRenderTask;
15 LOT_EXPORT Lottie_Animation_S *lottie_animation_from_file(const char *path)
17 if (auto animation = Animation::loadFromFile(path) ) {
18 Lottie_Animation_S *handle = new Lottie_Animation_S();
19 handle->mAnimation = std::move(animation);
26 LOT_EXPORT Lottie_Animation_S *lottie_animation_from_data(const char *data, const char *key)
28 if (auto animation = Animation::loadFromData(data, key) ) {
29 Lottie_Animation_S *handle = new Lottie_Animation_S();
30 handle->mAnimation = std::move(animation);
37 LOT_EXPORT void lottie_animation_destroy(Lottie_Animation_S *animation)
40 if (animation->mRenderTask.valid()) {
41 animation->mRenderTask.get();
43 animation->mAnimation = nullptr;
48 LOT_EXPORT void lottie_animation_get_size(const Lottie_Animation_S *animation, size_t *width, size_t *height)
50 if (!animation) return;
52 animation->mAnimation->size(*width, *height);
55 LOT_EXPORT double lottie_animation_get_duration(const Lottie_Animation_S *animation)
57 if (!animation) return 0;
59 return animation->mAnimation->duration();
62 LOT_EXPORT size_t lottie_animation_get_totalframe(const Lottie_Animation_S *animation)
64 if (!animation) return 0;
66 return animation->mAnimation->totalFrame();
70 LOT_EXPORT double lottie_animation_get_framerate(const Lottie_Animation_S *animation)
72 if (!animation) return 0;
74 return animation->mAnimation->frameRate();
77 LOT_EXPORT const LOTLayerNode * lottie_animation_render_tree(Lottie_Animation_S *animation, size_t frame_num, size_t width, size_t height)
79 if (!animation) return nullptr;
81 return animation->mAnimation->renderTree(frame_num, width, height);
85 lottie_animation_get_frame_at_pos(const Lottie_Animation_S *animation, float pos)
87 if (!animation) return 0;
89 return animation->mAnimation->frameAtPos(pos);
93 lottie_animation_render_async(Lottie_Animation_S *animation,
98 size_t bytes_per_line)
100 if (!animation) return;
102 lottie::Surface surface(buffer, width, height, bytes_per_line);
103 animation->mRenderTask = animation->mAnimation->render(frame_number, surface);
104 animation->mBufferRef = buffer;
107 LOT_EXPORT uint32_t *
108 lottie_animation_render_flush(Lottie_Animation_S *animation)
110 if (!animation) return nullptr;
112 if (animation->mRenderTask.valid()) {
113 animation->mRenderTask.get();
116 return animation->mBufferRef;