1 #include "lottieanimation.h"
4 using namespace lottie;
8 struct Lottie_Animation_S
10 std::unique_ptr<Animation> mAnimation;
14 std::future<Surface> mRenderTask;
17 LOT_EXPORT Lottie_Animation_S *lottie_animation_from_file(const char *file)
19 if (auto animation = Animation::loadFromFile(file) ) {
20 Lottie_Animation_S *handle = new Lottie_Animation_S();
21 handle->mAnimation = std::move(animation);
28 Lottie_Animation_S *lottie_animation_from_data(const char *data, const char *key)
30 if (auto animation = Animation::loadFromData(data, key) ) {
31 Lottie_Animation_S *handle = new Lottie_Animation_S();
32 handle->mAnimation = std::move(animation);
39 LOT_EXPORT void lottie_animation_destroy(Lottie_Animation_S *animation)
45 LOT_EXPORT void lottie_animation_get_size(const Lottie_Animation_S *animation, size_t *w, size_t *h)
47 if (!animation) return;
49 animation->mAnimation->size(*w, *h);
52 LOT_EXPORT double lottie_animation_get_duration(const Lottie_Animation_S *animation)
54 if (!animation) return 0;
56 return animation->mAnimation->duration();
59 LOT_EXPORT size_t lottie_animation_get_totalframe(const Lottie_Animation_S *animation)
61 if (!animation) return 0;
63 return animation->mAnimation->totalFrame();
67 LOT_EXPORT double lottie_animation_get_framerate(const Lottie_Animation_S *animation)
69 if (!animation) return 0;
71 return animation->mAnimation->frameRate();
74 LOT_EXPORT void lottie_animation_prepare_frame(Lottie_Animation_S *animation, size_t frameNo, size_t w, size_t h)
76 if (!animation) return;
78 auto list = animation->mAnimation->renderList(frameNo, w, h);
79 animation->mNodeArray = list.data();
80 animation->mArraySize = list.size();
83 LOT_EXPORT size_t lottie_animation_get_node_count(const Lottie_Animation_S *animation)
85 if (!animation) return 0;
87 return animation->mArraySize;
90 LOT_EXPORT const LOTNode* lottie_animation_get_node(const Lottie_Animation_S *animation, size_t idx)
92 if (!animation) return nullptr;
94 if (idx >= animation->mArraySize) return nullptr;
96 return animation->mNodeArray[idx];
100 lottie_animation_render_async(Lottie_Animation_S *animation,
105 size_t bytes_per_line)
107 if (!animation) return;
109 lottie::Surface surface(buffer, width, height, bytes_per_line);
110 animation->mRenderTask = animation->mAnimation->render(frame_number, surface);
114 lottie_animation_render_flush(Lottie_Animation_S *animation)
116 if (!animation) return;
118 if (animation->mRenderTask.valid()) {
119 animation->mRenderTask.get();