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)
43 LOT_EXPORT void lottie_animation_get_size(const Lottie_Animation_S *animation, size_t *width, size_t *height)
45 if (!animation) return;
47 animation->mAnimation->size(*width, *height);
50 LOT_EXPORT double lottie_animation_get_duration(const Lottie_Animation_S *animation)
52 if (!animation) return 0;
54 return animation->mAnimation->duration();
57 LOT_EXPORT size_t lottie_animation_get_totalframe(const Lottie_Animation_S *animation)
59 if (!animation) return 0;
61 return animation->mAnimation->totalFrame();
65 LOT_EXPORT double lottie_animation_get_framerate(const Lottie_Animation_S *animation)
67 if (!animation) return 0;
69 return animation->mAnimation->frameRate();
72 LOT_EXPORT const LOTLayerNode * lottie_animation_render_tree(Lottie_Animation_S *animation, size_t frame_num, size_t width, size_t height)
74 if (!animation) return nullptr;
76 return animation->mAnimation->renderTree(frame_num, width, height);
80 lottie_animation_get_frame_at_pos(const Lottie_Animation_S *animation, float pos)
82 if (!animation) return 0;
84 return animation->mAnimation->frameAtPos(pos);
88 lottie_animation_render_async(Lottie_Animation_S *animation,
93 size_t bytes_per_line)
95 if (!animation) return;
97 lottie::Surface surface(buffer, width, height, bytes_per_line);
98 animation->mRenderTask = animation->mAnimation->render(frame_number, surface);
99 animation->mBufferRef = buffer;
102 LOT_EXPORT uint32_t *
103 lottie_animation_render_flush(Lottie_Animation_S *animation)
105 if (!animation) return nullptr;
107 if (animation->mRenderTask.valid()) {
108 animation->mRenderTask.get();
111 return animation->mBufferRef;