1 #include "lottieanimation.h"
4 using namespace lottie;
8 struct Lottie_Animation_S
10 std::unique_ptr<Animation> mAnimation;
12 std::future<Surface> mRenderTask;
19 LOT_EXPORT Lottie_Animation_S *lottie_animation_from_file(const char *file)
21 if (auto animation = Animation::loadFromFile(file) ) {
22 Lottie_Animation_S *handle = new Lottie_Animation_S();
23 handle->mAnimation = std::move(animation);
30 Lottie_Animation_S *lottie_animation_from_data(const char *data, const char *key)
32 if (auto animation = Animation::loadFromData(data, key) ) {
33 Lottie_Animation_S *handle = new Lottie_Animation_S();
34 handle->mAnimation = std::move(animation);
41 LOT_EXPORT void lottie_animation_destroy(Lottie_Animation_S *animation)
47 LOT_EXPORT void lottie_animation_get_size(const Lottie_Animation_S *animation, size_t *w, size_t *h)
49 if (!animation) return;
51 animation->mAnimation->size(*w, *h);
54 LOT_EXPORT double lottie_animation_get_duration(const Lottie_Animation_S *animation)
56 if (!animation) return 0;
58 return animation->mAnimation->duration();
61 LOT_EXPORT size_t lottie_animation_get_totalframe(const Lottie_Animation_S *animation)
63 if (!animation) return 0;
65 return animation->mAnimation->totalFrame();
69 LOT_EXPORT double lottie_animation_get_framerate(const Lottie_Animation_S *animation)
71 if (!animation) return 0;
73 return animation->mAnimation->frameRate();
76 LOT_EXPORT void lottie_animation_prepare_frame(Lottie_Animation_S *animation, size_t frameNo, size_t w, size_t h)
78 if (!animation) return;
80 animation->mFrameNo = frameNo;
81 animation->mWidth = w;
82 animation->mHeight = h;
83 animation->mArraySize = animation->mAnimation->renderList(frameNo, w, h).size();
86 LOT_EXPORT size_t lottie_animation_get_node_count(const Lottie_Animation_S *animation)
88 if (!animation) return 0;
90 return animation->mArraySize;
93 LOT_EXPORT const LOTNode* lottie_animation_get_node(const Lottie_Animation_S *animation, size_t idx)
95 if (!animation) return nullptr;
97 if (idx >= animation->mArraySize) return nullptr;
99 return animation->mAnimation->renderList(animation->mFrameNo, animation->mWidth, animation->mHeight)[idx];
103 lottie_animation_render_async(Lottie_Animation_S *animation,
108 size_t bytes_per_line)
110 if (!animation) return;
112 lottie::Surface surface(buffer, width, height, bytes_per_line);
113 animation->mRenderTask = animation->mAnimation->render(frame_number, surface);
117 lottie_animation_render_flush(Lottie_Animation_S *animation)
119 if (!animation) return;
121 if (animation->mRenderTask.valid()) {
122 animation->mRenderTask.get();