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 LOT_EXPORT 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];
102 LOT_EXPORT const LOTLayerNode * lottie_animation_render_tree(Lottie_Animation_S *animation, size_t frameNo, size_t w, size_t h)
104 if (!animation) return nullptr;
106 animation->mFrameNo = frameNo;
107 animation->mWidth = w;
108 animation->mHeight = h;
109 return animation->mAnimation->renderTree(frameNo, w, h);
113 lottie_animation_render_async(Lottie_Animation_S *animation,
118 size_t bytes_per_line)
120 if (!animation) return;
122 lottie::Surface surface(buffer, width, height, bytes_per_line);
123 animation->mRenderTask = animation->mAnimation->render(frame_number, surface);
127 lottie_animation_render_flush(Lottie_Animation_S *animation)
129 if (!animation) return;
131 if (animation->mRenderTask.valid()) {
132 animation->mRenderTask.get();